* gdb.texinfo (Set Watchpoints): Remove @vindex entry for
[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{++}.
9c16f35a 198For more information, see @ref{Supported languages,,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
ffed4509
AC
474Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
475Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
476
e2e0bcd1
JB
477Jim Blandy added support for preprocessor macros, while working for Red
478Hat.
c906108c 479
6d2ebf8b 480@node Sample Session
c906108c
SS
481@chapter A Sample @value{GDBN} Session
482
483You can use this manual at your leisure to read all about @value{GDBN}.
484However, a handful of commands are enough to get started using the
485debugger. This chapter illustrates those commands.
486
487@iftex
488In this sample session, we emphasize user input like this: @b{input},
489to make it easier to pick out from the surrounding output.
490@end iftex
491
492@c FIXME: this example may not be appropriate for some configs, where
493@c FIXME...primary interest is in remote use.
494
495One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
496processor) exhibits the following bug: sometimes, when we change its
497quote strings from the default, the commands used to capture one macro
498definition within another stop working. In the following short @code{m4}
499session, we define a macro @code{foo} which expands to @code{0000}; we
500then use the @code{m4} built-in @code{defn} to define @code{bar} as the
501same thing. However, when we change the open quote string to
502@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
503procedure fails to define a new synonym @code{baz}:
504
505@smallexample
506$ @b{cd gnu/m4}
507$ @b{./m4}
508@b{define(foo,0000)}
509
510@b{foo}
5110000
512@b{define(bar,defn(`foo'))}
513
514@b{bar}
5150000
516@b{changequote(<QUOTE>,<UNQUOTE>)}
517
518@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
519@b{baz}
520@b{C-d}
521m4: End of input: 0: fatal error: EOF in string
522@end smallexample
523
524@noindent
525Let us use @value{GDBN} to try to see what is going on.
526
c906108c
SS
527@smallexample
528$ @b{@value{GDBP} m4}
529@c FIXME: this falsifies the exact text played out, to permit smallbook
530@c FIXME... format to come out better.
531@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 532 of it under certain conditions; type "show copying" to see
c906108c 533 the conditions.
5d161b24 534There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
535 for details.
536
537@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
538(@value{GDBP})
539@end smallexample
c906108c
SS
540
541@noindent
542@value{GDBN} reads only enough symbol data to know where to find the
543rest when needed; as a result, the first prompt comes up very quickly.
544We now tell @value{GDBN} to use a narrower display width than usual, so
545that examples fit in this manual.
546
547@smallexample
548(@value{GDBP}) @b{set width 70}
549@end smallexample
550
551@noindent
552We need to see how the @code{m4} built-in @code{changequote} works.
553Having looked at the source, we know the relevant subroutine is
554@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
555@code{break} command.
556
557@smallexample
558(@value{GDBP}) @b{break m4_changequote}
559Breakpoint 1 at 0x62f4: file builtin.c, line 879.
560@end smallexample
561
562@noindent
563Using the @code{run} command, we start @code{m4} running under @value{GDBN}
564control; as long as control does not reach the @code{m4_changequote}
565subroutine, the program runs as usual:
566
567@smallexample
568(@value{GDBP}) @b{run}
569Starting program: /work/Editorial/gdb/gnu/m4/m4
570@b{define(foo,0000)}
571
572@b{foo}
5730000
574@end smallexample
575
576@noindent
577To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
578suspends execution of @code{m4}, displaying information about the
579context where it stops.
580
581@smallexample
582@b{changequote(<QUOTE>,<UNQUOTE>)}
583
5d161b24 584Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
585 at builtin.c:879
586879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
587@end smallexample
588
589@noindent
590Now we use the command @code{n} (@code{next}) to advance execution to
591the next line of the current function.
592
593@smallexample
594(@value{GDBP}) @b{n}
595882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
596 : nil,
597@end smallexample
598
599@noindent
600@code{set_quotes} looks like a promising subroutine. We can go into it
601by using the command @code{s} (@code{step}) instead of @code{next}.
602@code{step} goes to the next line to be executed in @emph{any}
603subroutine, so it steps into @code{set_quotes}.
604
605@smallexample
606(@value{GDBP}) @b{s}
607set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
608 at input.c:530
609530 if (lquote != def_lquote)
610@end smallexample
611
612@noindent
613The display that shows the subroutine where @code{m4} is now
614suspended (and its arguments) is called a stack frame display. It
615shows a summary of the stack. We can use the @code{backtrace}
616command (which can also be spelled @code{bt}), to see where we are
617in the stack as a whole: the @code{backtrace} command displays a
618stack frame for each active subroutine.
619
620@smallexample
621(@value{GDBP}) @b{bt}
622#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
623 at input.c:530
5d161b24 624#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
625 at builtin.c:882
626#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
627#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
628 at macro.c:71
629#4 0x79dc in expand_input () at macro.c:40
630#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
631@end smallexample
632
633@noindent
634We step through a few more lines to see what happens. The first two
635times, we can use @samp{s}; the next two times we use @code{n} to avoid
636falling into the @code{xstrdup} subroutine.
637
638@smallexample
639(@value{GDBP}) @b{s}
6400x3b5c 532 if (rquote != def_rquote)
641(@value{GDBP}) @b{s}
6420x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
643def_lquote : xstrdup(lq);
644(@value{GDBP}) @b{n}
645536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
646 : xstrdup(rq);
647(@value{GDBP}) @b{n}
648538 len_lquote = strlen(rquote);
649@end smallexample
650
651@noindent
652The last line displayed looks a little odd; we can examine the variables
653@code{lquote} and @code{rquote} to see if they are in fact the new left
654and right quotes we specified. We use the command @code{p}
655(@code{print}) to see their values.
656
657@smallexample
658(@value{GDBP}) @b{p lquote}
659$1 = 0x35d40 "<QUOTE>"
660(@value{GDBP}) @b{p rquote}
661$2 = 0x35d50 "<UNQUOTE>"
662@end smallexample
663
664@noindent
665@code{lquote} and @code{rquote} are indeed the new left and right quotes.
666To look at some context, we can display ten lines of source
667surrounding the current line with the @code{l} (@code{list}) command.
668
669@smallexample
670(@value{GDBP}) @b{l}
671533 xfree(rquote);
672534
673535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
674 : xstrdup (lq);
675536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
676 : xstrdup (rq);
677537
678538 len_lquote = strlen(rquote);
679539 len_rquote = strlen(lquote);
680540 @}
681541
682542 void
683@end smallexample
684
685@noindent
686Let us step past the two lines that set @code{len_lquote} and
687@code{len_rquote}, and then examine the values of those variables.
688
689@smallexample
690(@value{GDBP}) @b{n}
691539 len_rquote = strlen(lquote);
692(@value{GDBP}) @b{n}
693540 @}
694(@value{GDBP}) @b{p len_lquote}
695$3 = 9
696(@value{GDBP}) @b{p len_rquote}
697$4 = 7
698@end smallexample
699
700@noindent
701That certainly looks wrong, assuming @code{len_lquote} and
702@code{len_rquote} are meant to be the lengths of @code{lquote} and
703@code{rquote} respectively. We can set them to better values using
704the @code{p} command, since it can print the value of
705any expression---and that expression can include subroutine calls and
706assignments.
707
708@smallexample
709(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
710$5 = 7
711(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
712$6 = 9
713@end smallexample
714
715@noindent
716Is that enough to fix the problem of using the new quotes with the
717@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
718executing with the @code{c} (@code{continue}) command, and then try the
719example that caused trouble initially:
720
721@smallexample
722(@value{GDBP}) @b{c}
723Continuing.
724
725@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
726
727baz
7280000
729@end smallexample
730
731@noindent
732Success! The new quotes now work just as well as the default ones. The
733problem seems to have been just the two typos defining the wrong
734lengths. We allow @code{m4} exit by giving it an EOF as input:
735
736@smallexample
737@b{C-d}
738Program exited normally.
739@end smallexample
740
741@noindent
742The message @samp{Program exited normally.} is from @value{GDBN}; it
743indicates @code{m4} has finished executing. We can end our @value{GDBN}
744session with the @value{GDBN} @code{quit} command.
745
746@smallexample
747(@value{GDBP}) @b{quit}
748@end smallexample
c906108c 749
6d2ebf8b 750@node Invocation
c906108c
SS
751@chapter Getting In and Out of @value{GDBN}
752
753This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 754The essentials are:
c906108c 755@itemize @bullet
5d161b24 756@item
53a5351d 757type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 758@item
c906108c
SS
759type @kbd{quit} or @kbd{C-d} to exit.
760@end itemize
761
762@menu
763* Invoking GDB:: How to start @value{GDBN}
764* Quitting GDB:: How to quit @value{GDBN}
765* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 766* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
767@end menu
768
6d2ebf8b 769@node Invoking GDB
c906108c
SS
770@section Invoking @value{GDBN}
771
c906108c
SS
772Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
773@value{GDBN} reads commands from the terminal until you tell it to exit.
774
775You can also run @code{@value{GDBP}} with a variety of arguments and options,
776to specify more of your debugging environment at the outset.
777
c906108c
SS
778The command-line options described here are designed
779to cover a variety of situations; in some environments, some of these
5d161b24 780options may effectively be unavailable.
c906108c
SS
781
782The most usual way to start @value{GDBN} is with one argument,
783specifying an executable program:
784
474c8240 785@smallexample
c906108c 786@value{GDBP} @var{program}
474c8240 787@end smallexample
c906108c 788
c906108c
SS
789@noindent
790You can also start with both an executable program and a core file
791specified:
792
474c8240 793@smallexample
c906108c 794@value{GDBP} @var{program} @var{core}
474c8240 795@end smallexample
c906108c
SS
796
797You can, instead, specify a process ID as a second argument, if you want
798to debug a running process:
799
474c8240 800@smallexample
c906108c 801@value{GDBP} @var{program} 1234
474c8240 802@end smallexample
c906108c
SS
803
804@noindent
805would attach @value{GDBN} to process @code{1234} (unless you also have a file
806named @file{1234}; @value{GDBN} does check for a core file first).
807
c906108c 808Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
809complete operating system; when you use @value{GDBN} as a remote
810debugger attached to a bare board, there may not be any notion of
811``process'', and there is often no way to get a core dump. @value{GDBN}
812will warn you if it is unable to attach or to read core dumps.
c906108c 813
aa26fa3a
TT
814You can optionally have @code{@value{GDBP}} pass any arguments after the
815executable file to the inferior using @code{--args}. This option stops
816option processing.
474c8240 817@smallexample
aa26fa3a 818gdb --args gcc -O2 -c foo.c
474c8240 819@end smallexample
aa26fa3a
TT
820This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
821@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
822
96a2c332 823You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
824@value{GDBN}'s non-warranty, by specifying @code{-silent}:
825
826@smallexample
827@value{GDBP} -silent
828@end smallexample
829
830@noindent
831You can further control how @value{GDBN} starts up by using command-line
832options. @value{GDBN} itself can remind you of the options available.
833
834@noindent
835Type
836
474c8240 837@smallexample
c906108c 838@value{GDBP} -help
474c8240 839@end smallexample
c906108c
SS
840
841@noindent
842to display all available options and briefly describe their use
843(@samp{@value{GDBP} -h} is a shorter equivalent).
844
845All options and command line arguments you give are processed
846in sequential order. The order makes a difference when the
847@samp{-x} option is used.
848
849
850@menu
c906108c
SS
851* File Options:: Choosing files
852* Mode Options:: Choosing modes
6fc08d32 853* Startup:: What @value{GDBN} does during startup
c906108c
SS
854@end menu
855
6d2ebf8b 856@node File Options
c906108c
SS
857@subsection Choosing files
858
2df3850c 859When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
860specifying an executable file and core file (or process ID). This is
861the same as if the arguments were specified by the @samp{-se} and
19837790
MS
862@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
863first argument that does not have an associated option flag as
864equivalent to the @samp{-se} option followed by that argument; and the
865second argument that does not have an associated option flag, if any, as
866equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
867If the second argument begins with a decimal digit, @value{GDBN} will
868first attempt to attach to it as a process, and if that fails, attempt
869to open it as a corefile. If you have a corefile whose name begins with
b383017d 870a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 871prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
872
873If @value{GDBN} has not been configured to included core file support,
874such as for most embedded targets, then it will complain about a second
875argument and ignore it.
c906108c
SS
876
877Many options have both long and short forms; both are shown in the
878following list. @value{GDBN} also recognizes the long forms if you truncate
879them, so long as enough of the option is present to be unambiguous.
880(If you prefer, you can flag option arguments with @samp{--} rather
881than @samp{-}, though we illustrate the more usual convention.)
882
d700128c
EZ
883@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
884@c way, both those who look for -foo and --foo in the index, will find
885@c it.
886
c906108c
SS
887@table @code
888@item -symbols @var{file}
889@itemx -s @var{file}
d700128c
EZ
890@cindex @code{--symbols}
891@cindex @code{-s}
c906108c
SS
892Read symbol table from file @var{file}.
893
894@item -exec @var{file}
895@itemx -e @var{file}
d700128c
EZ
896@cindex @code{--exec}
897@cindex @code{-e}
7a292a7a
SS
898Use file @var{file} as the executable file to execute when appropriate,
899and for examining pure data in conjunction with a core dump.
c906108c
SS
900
901@item -se @var{file}
d700128c 902@cindex @code{--se}
c906108c
SS
903Read symbol table from file @var{file} and use it as the executable
904file.
905
c906108c
SS
906@item -core @var{file}
907@itemx -c @var{file}
d700128c
EZ
908@cindex @code{--core}
909@cindex @code{-c}
b383017d 910Use file @var{file} as a core dump to examine.
c906108c
SS
911
912@item -c @var{number}
19837790
MS
913@item -pid @var{number}
914@itemx -p @var{number}
915@cindex @code{--pid}
916@cindex @code{-p}
917Connect to process ID @var{number}, as with the @code{attach} command.
918If there is no such process, @value{GDBN} will attempt to open a core
919file named @var{number}.
c906108c
SS
920
921@item -command @var{file}
922@itemx -x @var{file}
d700128c
EZ
923@cindex @code{--command}
924@cindex @code{-x}
c906108c
SS
925Execute @value{GDBN} commands from file @var{file}. @xref{Command
926Files,, Command files}.
927
928@item -directory @var{directory}
929@itemx -d @var{directory}
d700128c
EZ
930@cindex @code{--directory}
931@cindex @code{-d}
c906108c
SS
932Add @var{directory} to the path to search for source files.
933
c906108c
SS
934@item -m
935@itemx -mapped
d700128c
EZ
936@cindex @code{--mapped}
937@cindex @code{-m}
c906108c
SS
938@emph{Warning: this option depends on operating system facilities that are not
939supported on all systems.}@*
940If memory-mapped files are available on your system through the @code{mmap}
5d161b24 941system call, you can use this option
c906108c
SS
942to have @value{GDBN} write the symbols from your
943program into a reusable file in the current directory. If the program you are debugging is
96a2c332 944called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
945Future @value{GDBN} debugging sessions notice the presence of this file,
946and can quickly map in symbol information from it, rather than reading
947the symbol table from the executable program.
948
949The @file{.syms} file is specific to the host machine where @value{GDBN}
950is run. It holds an exact image of the internal @value{GDBN} symbol
951table. It cannot be shared across multiple host platforms.
c906108c 952
c906108c
SS
953@item -r
954@itemx -readnow
d700128c
EZ
955@cindex @code{--readnow}
956@cindex @code{-r}
c906108c
SS
957Read each symbol file's entire symbol table immediately, rather than
958the default, which is to read it incrementally as it is needed.
959This makes startup slower, but makes future operations faster.
53a5351d 960
c906108c
SS
961@end table
962
2df3850c 963You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 964order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
965information. (@xref{Files,,Commands to specify files}, for information
966on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
967but build a @file{.syms} file for future use is:
c906108c 968
474c8240 969@smallexample
2df3850c 970gdb -batch -nx -mapped -readnow programname
474c8240 971@end smallexample
c906108c 972
6d2ebf8b 973@node Mode Options
c906108c
SS
974@subsection Choosing modes
975
976You can run @value{GDBN} in various alternative modes---for example, in
977batch mode or quiet mode.
978
979@table @code
980@item -nx
981@itemx -n
d700128c
EZ
982@cindex @code{--nx}
983@cindex @code{-n}
96565e91 984Do not execute commands found in any initialization files. Normally,
2df3850c
JM
985@value{GDBN} executes the commands in these files after all the command
986options and arguments have been processed. @xref{Command Files,,Command
987files}.
c906108c
SS
988
989@item -quiet
d700128c 990@itemx -silent
c906108c 991@itemx -q
d700128c
EZ
992@cindex @code{--quiet}
993@cindex @code{--silent}
994@cindex @code{-q}
c906108c
SS
995``Quiet''. Do not print the introductory and copyright messages. These
996messages are also suppressed in batch mode.
997
998@item -batch
d700128c 999@cindex @code{--batch}
c906108c
SS
1000Run in batch mode. Exit with status @code{0} after processing all the
1001command files specified with @samp{-x} (and all commands from
1002initialization files, if not inhibited with @samp{-n}). Exit with
1003nonzero status if an error occurs in executing the @value{GDBN} commands
1004in the command files.
1005
2df3850c
JM
1006Batch mode may be useful for running @value{GDBN} as a filter, for
1007example to download and run a program on another computer; in order to
1008make this more useful, the message
c906108c 1009
474c8240 1010@smallexample
c906108c 1011Program exited normally.
474c8240 1012@end smallexample
c906108c
SS
1013
1014@noindent
2df3850c
JM
1015(which is ordinarily issued whenever a program running under
1016@value{GDBN} control terminates) is not issued when running in batch
1017mode.
1018
1019@item -nowindows
1020@itemx -nw
d700128c
EZ
1021@cindex @code{--nowindows}
1022@cindex @code{-nw}
2df3850c 1023``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1024(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1025interface. If no GUI is available, this option has no effect.
1026
1027@item -windows
1028@itemx -w
d700128c
EZ
1029@cindex @code{--windows}
1030@cindex @code{-w}
2df3850c
JM
1031If @value{GDBN} includes a GUI, then this option requires it to be
1032used if possible.
c906108c
SS
1033
1034@item -cd @var{directory}
d700128c 1035@cindex @code{--cd}
c906108c
SS
1036Run @value{GDBN} using @var{directory} as its working directory,
1037instead of the current directory.
1038
c906108c
SS
1039@item -fullname
1040@itemx -f
d700128c
EZ
1041@cindex @code{--fullname}
1042@cindex @code{-f}
7a292a7a
SS
1043@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1044subprocess. It tells @value{GDBN} to output the full file name and line
1045number in a standard, recognizable fashion each time a stack frame is
1046displayed (which includes each time your program stops). This
1047recognizable format looks like two @samp{\032} characters, followed by
1048the file name, line number and character position separated by colons,
1049and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1050@samp{\032} characters as a signal to display the source code for the
1051frame.
c906108c 1052
d700128c
EZ
1053@item -epoch
1054@cindex @code{--epoch}
1055The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1056@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1057routines so as to allow Epoch to display values of expressions in a
1058separate window.
1059
1060@item -annotate @var{level}
1061@cindex @code{--annotate}
1062This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1063effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1064(@pxref{Annotations}). The annotation @var{level} controls how much
1065information @value{GDBN} prints together with its prompt, values of
1066expressions, source lines, and other types of output. Level 0 is the
1067normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1068@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1069that control @value{GDBN}, and level 2 has been deprecated.
1070
1071The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1072(@pxref{GDB/MI}).
d700128c 1073
aa26fa3a
TT
1074@item --args
1075@cindex @code{--args}
1076Change interpretation of command line so that arguments following the
1077executable file are passed as command line arguments to the inferior.
1078This option stops option processing.
1079
2df3850c
JM
1080@item -baud @var{bps}
1081@itemx -b @var{bps}
d700128c
EZ
1082@cindex @code{--baud}
1083@cindex @code{-b}
c906108c
SS
1084Set the line speed (baud rate or bits per second) of any serial
1085interface used by @value{GDBN} for remote debugging.
c906108c 1086
f47b1503
AS
1087@item -l @var{timeout}
1088@cindex @code{-l}
1089Set the timeout (in seconds) of any communication used by @value{GDBN}
1090for remote debugging.
1091
c906108c 1092@item -tty @var{device}
d700128c
EZ
1093@itemx -t @var{device}
1094@cindex @code{--tty}
1095@cindex @code{-t}
c906108c
SS
1096Run using @var{device} for your program's standard input and output.
1097@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1098
53a5351d 1099@c resolve the situation of these eventually
c4555f82
SC
1100@item -tui
1101@cindex @code{--tui}
d0d5df6f
AC
1102Activate the @dfn{Text User Interface} when starting. The Text User
1103Interface manages several text windows on the terminal, showing
1104source, assembly, registers and @value{GDBN} command outputs
1105(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1106Text User Interface can be enabled by invoking the program
1107@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1108Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1109
1110@c @item -xdb
d700128c 1111@c @cindex @code{--xdb}
53a5351d
JM
1112@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1113@c For information, see the file @file{xdb_trans.html}, which is usually
1114@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1115@c systems.
1116
d700128c
EZ
1117@item -interpreter @var{interp}
1118@cindex @code{--interpreter}
1119Use the interpreter @var{interp} for interface with the controlling
1120program or device. This option is meant to be set by programs which
94bbb2c0 1121communicate with @value{GDBN} using it as a back end.
21c294e6 1122@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1123
da0f9dcd 1124@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1125@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1126The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1127previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1128selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1129@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1130
1131@item -write
1132@cindex @code{--write}
1133Open the executable and core files for both reading and writing. This
1134is equivalent to the @samp{set write on} command inside @value{GDBN}
1135(@pxref{Patching}).
1136
1137@item -statistics
1138@cindex @code{--statistics}
1139This option causes @value{GDBN} to print statistics about time and
1140memory usage after it completes each command and returns to the prompt.
1141
1142@item -version
1143@cindex @code{--version}
1144This option causes @value{GDBN} to print its version number and
1145no-warranty blurb, and exit.
1146
c906108c
SS
1147@end table
1148
6fc08d32
EZ
1149@node Startup
1150@subsection What @value{GDBN} does during startup
1151@cindex @value{GDBN} startup
1152
1153Here's the description of what @value{GDBN} does during session startup:
1154
1155@enumerate
1156@item
1157Sets up the command interpreter as specified by the command line
1158(@pxref{Mode Options, interpreter}).
1159
1160@item
1161@cindex init file
1162Reads the @dfn{init file} (if any) in your home directory@footnote{On
1163DOS/Windows systems, the home directory is the one pointed to by the
1164@code{HOME} environment variable.} and executes all the commands in
1165that file.
1166
1167@item
1168Processes command line options and operands.
1169
1170@item
1171Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1172working directory. This is only done if the current directory is
1173different from your home directory. Thus, you can have more than one
1174init file, one generic in your home directory, and another, specific
1175to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1176@value{GDBN}.
1177
1178@item
1179Reads command files specified by the @samp{-x} option. @xref{Command
1180Files}, for more details about @value{GDBN} command files.
1181
1182@item
1183Reads the command history recorded in the @dfn{history file}.
1184@xref{History}, for more details about the command history and the
1185files where @value{GDBN} records it.
1186@end enumerate
1187
1188Init files use the same syntax as @dfn{command files} (@pxref{Command
1189Files}) and are processed by @value{GDBN} in the same way. The init
1190file in your home directory can set options (such as @samp{set
1191complaints}) that affect subsequent processing of command line options
1192and operands. Init files are not executed if you use the @samp{-nx}
1193option (@pxref{Mode Options, ,Choosing modes}).
1194
1195@cindex init file name
1196@cindex @file{.gdbinit}
119b882a 1197The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1198On some configurations of @value{GDBN}, the init file is known by a
1199different name (these are typically environments where a specialized
1200form of @value{GDBN} may need to coexist with other forms, hence a
1201different name for the specialized version's init file). These are the
1202environments with special init file names:
1203
6fc08d32 1204@itemize @bullet
119b882a
EZ
1205@cindex @file{gdb.ini}
1206@item
1207The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1208the limitations of file names imposed by DOS filesystems. The Windows
1209ports of @value{GDBN} use the standard name, but if they find a
1210@file{gdb.ini} file, they warn you about that and suggest to rename
1211the file to the standard name.
1212
1213@cindex @file{.vxgdbinit}
6fc08d32
EZ
1214@item
1215VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1216
1217@cindex @file{.os68gdbinit}
1218@item
1219OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1220
1221@cindex @file{.esgdbinit}
1222@item
1223ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1224
1225@item
1226CISCO 68k: @file{.cisco-gdbinit}
1227@end itemize
1228
1229
6d2ebf8b 1230@node Quitting GDB
c906108c
SS
1231@section Quitting @value{GDBN}
1232@cindex exiting @value{GDBN}
1233@cindex leaving @value{GDBN}
1234
1235@table @code
1236@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1237@kindex q @r{(@code{quit})}
96a2c332
SS
1238@item quit @r{[}@var{expression}@r{]}
1239@itemx q
1240To exit @value{GDBN}, use the @code{quit} command (abbreviated
1241@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1242do not supply @var{expression}, @value{GDBN} will terminate normally;
1243otherwise it will terminate using the result of @var{expression} as the
1244error code.
c906108c
SS
1245@end table
1246
1247@cindex interrupt
1248An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1249terminates the action of any @value{GDBN} command that is in progress and
1250returns to @value{GDBN} command level. It is safe to type the interrupt
1251character at any time because @value{GDBN} does not allow it to take effect
1252until a time when it is safe.
1253
c906108c
SS
1254If you have been using @value{GDBN} to control an attached process or
1255device, you can release it with the @code{detach} command
1256(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1257
6d2ebf8b 1258@node Shell Commands
c906108c
SS
1259@section Shell commands
1260
1261If you need to execute occasional shell commands during your
1262debugging session, there is no need to leave or suspend @value{GDBN}; you can
1263just use the @code{shell} command.
1264
1265@table @code
1266@kindex shell
1267@cindex shell escape
1268@item shell @var{command string}
1269Invoke a standard shell to execute @var{command string}.
c906108c 1270If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1271shell to run. Otherwise @value{GDBN} uses the default shell
1272(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1273@end table
1274
1275The utility @code{make} is often needed in development environments.
1276You do not have to use the @code{shell} command for this purpose in
1277@value{GDBN}:
1278
1279@table @code
1280@kindex make
1281@cindex calling make
1282@item make @var{make-args}
1283Execute the @code{make} program with the specified
1284arguments. This is equivalent to @samp{shell make @var{make-args}}.
1285@end table
1286
0fac0b41
DJ
1287@node Logging output
1288@section Logging output
1289@cindex logging @value{GDBN} output
9c16f35a 1290@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1291
1292You may want to save the output of @value{GDBN} commands to a file.
1293There are several commands to control @value{GDBN}'s logging.
1294
1295@table @code
1296@kindex set logging
1297@item set logging on
1298Enable logging.
1299@item set logging off
1300Disable logging.
9c16f35a 1301@cindex logging file name
0fac0b41
DJ
1302@item set logging file @var{file}
1303Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1304@item set logging overwrite [on|off]
1305By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1306you want @code{set logging on} to overwrite the logfile instead.
1307@item set logging redirect [on|off]
1308By default, @value{GDBN} output will go to both the terminal and the logfile.
1309Set @code{redirect} if you want output to go only to the log file.
1310@kindex show logging
1311@item show logging
1312Show the current values of the logging settings.
1313@end table
1314
6d2ebf8b 1315@node Commands
c906108c
SS
1316@chapter @value{GDBN} Commands
1317
1318You can abbreviate a @value{GDBN} command to the first few letters of the command
1319name, if that abbreviation is unambiguous; and you can repeat certain
1320@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1321key to get @value{GDBN} to fill out the rest of a word in a command (or to
1322show you the alternatives available, if there is more than one possibility).
1323
1324@menu
1325* Command Syntax:: How to give commands to @value{GDBN}
1326* Completion:: Command completion
1327* Help:: How to ask @value{GDBN} for help
1328@end menu
1329
6d2ebf8b 1330@node Command Syntax
c906108c
SS
1331@section Command syntax
1332
1333A @value{GDBN} command is a single line of input. There is no limit on
1334how long it can be. It starts with a command name, which is followed by
1335arguments whose meaning depends on the command name. For example, the
1336command @code{step} accepts an argument which is the number of times to
1337step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1338with no arguments. Some commands do not allow any arguments.
c906108c
SS
1339
1340@cindex abbreviation
1341@value{GDBN} command names may always be truncated if that abbreviation is
1342unambiguous. Other possible command abbreviations are listed in the
1343documentation for individual commands. In some cases, even ambiguous
1344abbreviations are allowed; for example, @code{s} is specially defined as
1345equivalent to @code{step} even though there are other commands whose
1346names start with @code{s}. You can test abbreviations by using them as
1347arguments to the @code{help} command.
1348
1349@cindex repeating commands
41afff9a 1350@kindex RET @r{(repeat last command)}
c906108c 1351A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1352repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1353will not repeat this way; these are commands whose unintentional
1354repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1355repeat. User-defined commands can disable this feature; see
1356@ref{Define, dont-repeat}.
c906108c
SS
1357
1358The @code{list} and @code{x} commands, when you repeat them with
1359@key{RET}, construct new arguments rather than repeating
1360exactly as typed. This permits easy scanning of source or memory.
1361
1362@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1363output, in a way similar to the common utility @code{more}
1364(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1365@key{RET} too many in this situation, @value{GDBN} disables command
1366repetition after any command that generates this sort of display.
1367
41afff9a 1368@kindex # @r{(a comment)}
c906108c
SS
1369@cindex comment
1370Any text from a @kbd{#} to the end of the line is a comment; it does
1371nothing. This is useful mainly in command files (@pxref{Command
1372Files,,Command files}).
1373
88118b3a
TT
1374@cindex repeating command sequences
1375@kindex C-o @r{(operate-and-get-next)}
1376The @kbd{C-o} binding is useful for repeating a complex sequence of
1377commands. This command accepts the current line, like @kbd{RET}, and
1378then fetches the next line relative to the current line from the history
1379for editing.
1380
6d2ebf8b 1381@node Completion
c906108c
SS
1382@section Command completion
1383
1384@cindex completion
1385@cindex word completion
1386@value{GDBN} can fill in the rest of a word in a command for you, if there is
1387only one possibility; it can also show you what the valid possibilities
1388are for the next word in a command, at any time. This works for @value{GDBN}
1389commands, @value{GDBN} subcommands, and the names of symbols in your program.
1390
1391Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1392of a word. If there is only one possibility, @value{GDBN} fills in the
1393word, and waits for you to finish the command (or press @key{RET} to
1394enter it). For example, if you type
1395
1396@c FIXME "@key" does not distinguish its argument sufficiently to permit
1397@c complete accuracy in these examples; space introduced for clarity.
1398@c If texinfo enhancements make it unnecessary, it would be nice to
1399@c replace " @key" by "@key" in the following...
474c8240 1400@smallexample
c906108c 1401(@value{GDBP}) info bre @key{TAB}
474c8240 1402@end smallexample
c906108c
SS
1403
1404@noindent
1405@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1406the only @code{info} subcommand beginning with @samp{bre}:
1407
474c8240 1408@smallexample
c906108c 1409(@value{GDBP}) info breakpoints
474c8240 1410@end smallexample
c906108c
SS
1411
1412@noindent
1413You can either press @key{RET} at this point, to run the @code{info
1414breakpoints} command, or backspace and enter something else, if
1415@samp{breakpoints} does not look like the command you expected. (If you
1416were sure you wanted @code{info breakpoints} in the first place, you
1417might as well just type @key{RET} immediately after @samp{info bre},
1418to exploit command abbreviations rather than command completion).
1419
1420If there is more than one possibility for the next word when you press
1421@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1422characters and try again, or just press @key{TAB} a second time;
1423@value{GDBN} displays all the possible completions for that word. For
1424example, you might want to set a breakpoint on a subroutine whose name
1425begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1426just sounds the bell. Typing @key{TAB} again displays all the
1427function names in your program that begin with those characters, for
1428example:
1429
474c8240 1430@smallexample
c906108c
SS
1431(@value{GDBP}) b make_ @key{TAB}
1432@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1433make_a_section_from_file make_environ
1434make_abs_section make_function_type
1435make_blockvector make_pointer_type
1436make_cleanup make_reference_type
c906108c
SS
1437make_command make_symbol_completion_list
1438(@value{GDBP}) b make_
474c8240 1439@end smallexample
c906108c
SS
1440
1441@noindent
1442After displaying the available possibilities, @value{GDBN} copies your
1443partial input (@samp{b make_} in the example) so you can finish the
1444command.
1445
1446If you just want to see the list of alternatives in the first place, you
b37052ae 1447can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1448means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1449key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1450one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1451
1452@cindex quotes in commands
1453@cindex completion of quoted strings
1454Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1455parentheses or other characters that @value{GDBN} normally excludes from
1456its notion of a word. To permit word completion to work in this
1457situation, you may enclose words in @code{'} (single quote marks) in
1458@value{GDBN} commands.
c906108c 1459
c906108c 1460The most likely situation where you might need this is in typing the
b37052ae
EZ
1461name of a C@t{++} function. This is because C@t{++} allows function
1462overloading (multiple definitions of the same function, distinguished
1463by argument type). For example, when you want to set a breakpoint you
1464may need to distinguish whether you mean the version of @code{name}
1465that takes an @code{int} parameter, @code{name(int)}, or the version
1466that takes a @code{float} parameter, @code{name(float)}. To use the
1467word-completion facilities in this situation, type a single quote
1468@code{'} at the beginning of the function name. This alerts
1469@value{GDBN} that it may need to consider more information than usual
1470when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1471
474c8240 1472@smallexample
96a2c332 1473(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1474bubble(double,double) bubble(int,int)
1475(@value{GDBP}) b 'bubble(
474c8240 1476@end smallexample
c906108c
SS
1477
1478In some cases, @value{GDBN} can tell that completing a name requires using
1479quotes. When this happens, @value{GDBN} inserts the quote for you (while
1480completing as much as it can) if you do not type the quote in the first
1481place:
1482
474c8240 1483@smallexample
c906108c
SS
1484(@value{GDBP}) b bub @key{TAB}
1485@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1486(@value{GDBP}) b 'bubble(
474c8240 1487@end smallexample
c906108c
SS
1488
1489@noindent
1490In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1491you have not yet started typing the argument list when you ask for
1492completion on an overloaded symbol.
1493
d4f3574e 1494For more information about overloaded functions, see @ref{C plus plus
b37052ae 1495expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1496overload-resolution off} to disable overload resolution;
b37052ae 1497see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1498
1499
6d2ebf8b 1500@node Help
c906108c
SS
1501@section Getting help
1502@cindex online documentation
1503@kindex help
1504
5d161b24 1505You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1506using the command @code{help}.
1507
1508@table @code
41afff9a 1509@kindex h @r{(@code{help})}
c906108c
SS
1510@item help
1511@itemx h
1512You can use @code{help} (abbreviated @code{h}) with no arguments to
1513display a short list of named classes of commands:
1514
1515@smallexample
1516(@value{GDBP}) help
1517List of classes of commands:
1518
2df3850c 1519aliases -- Aliases of other commands
c906108c 1520breakpoints -- Making program stop at certain points
2df3850c 1521data -- Examining data
c906108c 1522files -- Specifying and examining files
2df3850c
JM
1523internals -- Maintenance commands
1524obscure -- Obscure features
1525running -- Running the program
1526stack -- Examining the stack
c906108c
SS
1527status -- Status inquiries
1528support -- Support facilities
96a2c332
SS
1529tracepoints -- Tracing of program execution without@*
1530 stopping the program
c906108c 1531user-defined -- User-defined commands
c906108c 1532
5d161b24 1533Type "help" followed by a class name for a list of
c906108c 1534commands in that class.
5d161b24 1535Type "help" followed by command name for full
c906108c
SS
1536documentation.
1537Command name abbreviations are allowed if unambiguous.
1538(@value{GDBP})
1539@end smallexample
96a2c332 1540@c the above line break eliminates huge line overfull...
c906108c
SS
1541
1542@item help @var{class}
1543Using one of the general help classes as an argument, you can get a
1544list of the individual commands in that class. For example, here is the
1545help display for the class @code{status}:
1546
1547@smallexample
1548(@value{GDBP}) help status
1549Status inquiries.
1550
1551List of commands:
1552
1553@c Line break in "show" line falsifies real output, but needed
1554@c to fit in smallbook page size.
2df3850c
JM
1555info -- Generic command for showing things
1556 about the program being debugged
1557show -- Generic command for showing things
1558 about the debugger
c906108c 1559
5d161b24 1560Type "help" followed by command name for full
c906108c
SS
1561documentation.
1562Command name abbreviations are allowed if unambiguous.
1563(@value{GDBP})
1564@end smallexample
1565
1566@item help @var{command}
1567With a command name as @code{help} argument, @value{GDBN} displays a
1568short paragraph on how to use that command.
1569
6837a0a2
DB
1570@kindex apropos
1571@item apropos @var{args}
09d4efe1 1572The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1573commands, and their documentation, for the regular expression specified in
1574@var{args}. It prints out all matches found. For example:
1575
1576@smallexample
1577apropos reload
1578@end smallexample
1579
b37052ae
EZ
1580@noindent
1581results in:
6837a0a2
DB
1582
1583@smallexample
6d2ebf8b
SS
1584@c @group
1585set symbol-reloading -- Set dynamic symbol table reloading
1586 multiple times in one run
1587show symbol-reloading -- Show dynamic symbol table reloading
1588 multiple times in one run
1589@c @end group
6837a0a2
DB
1590@end smallexample
1591
c906108c
SS
1592@kindex complete
1593@item complete @var{args}
1594The @code{complete @var{args}} command lists all the possible completions
1595for the beginning of a command. Use @var{args} to specify the beginning of the
1596command you want completed. For example:
1597
1598@smallexample
1599complete i
1600@end smallexample
1601
1602@noindent results in:
1603
1604@smallexample
1605@group
2df3850c
JM
1606if
1607ignore
c906108c
SS
1608info
1609inspect
c906108c
SS
1610@end group
1611@end smallexample
1612
1613@noindent This is intended for use by @sc{gnu} Emacs.
1614@end table
1615
1616In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1617and @code{show} to inquire about the state of your program, or the state
1618of @value{GDBN} itself. Each command supports many topics of inquiry; this
1619manual introduces each of them in the appropriate context. The listings
1620under @code{info} and under @code{show} in the Index point to
1621all the sub-commands. @xref{Index}.
1622
1623@c @group
1624@table @code
1625@kindex info
41afff9a 1626@kindex i @r{(@code{info})}
c906108c
SS
1627@item info
1628This command (abbreviated @code{i}) is for describing the state of your
1629program. For example, you can list the arguments given to your program
1630with @code{info args}, list the registers currently in use with @code{info
1631registers}, or list the breakpoints you have set with @code{info breakpoints}.
1632You can get a complete list of the @code{info} sub-commands with
1633@w{@code{help info}}.
1634
1635@kindex set
1636@item set
5d161b24 1637You can assign the result of an expression to an environment variable with
c906108c
SS
1638@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1639@code{set prompt $}.
1640
1641@kindex show
1642@item show
5d161b24 1643In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1644@value{GDBN} itself.
1645You can change most of the things you can @code{show}, by using the
1646related command @code{set}; for example, you can control what number
1647system is used for displays with @code{set radix}, or simply inquire
1648which is currently in use with @code{show radix}.
1649
1650@kindex info set
1651To display all the settable parameters and their current
1652values, you can use @code{show} with no arguments; you may also use
1653@code{info set}. Both commands produce the same display.
1654@c FIXME: "info set" violates the rule that "info" is for state of
1655@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1656@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1657@end table
1658@c @end group
1659
1660Here are three miscellaneous @code{show} subcommands, all of which are
1661exceptional in lacking corresponding @code{set} commands:
1662
1663@table @code
1664@kindex show version
9c16f35a 1665@cindex @value{GDBN} version number
c906108c
SS
1666@item show version
1667Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1668information in @value{GDBN} bug-reports. If multiple versions of
1669@value{GDBN} are in use at your site, you may need to determine which
1670version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1671commands are introduced, and old ones may wither away. Also, many
1672system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1673variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1674The version number is the same as the one announced when you start
1675@value{GDBN}.
c906108c
SS
1676
1677@kindex show copying
09d4efe1 1678@kindex info copying
9c16f35a 1679@cindex display @value{GDBN} copyright
c906108c 1680@item show copying
09d4efe1 1681@itemx info copying
c906108c
SS
1682Display information about permission for copying @value{GDBN}.
1683
1684@kindex show warranty
09d4efe1 1685@kindex info warranty
c906108c 1686@item show warranty
09d4efe1 1687@itemx info warranty
2df3850c 1688Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1689if your version of @value{GDBN} comes with one.
2df3850c 1690
c906108c
SS
1691@end table
1692
6d2ebf8b 1693@node Running
c906108c
SS
1694@chapter Running Programs Under @value{GDBN}
1695
1696When you run a program under @value{GDBN}, you must first generate
1697debugging information when you compile it.
7a292a7a
SS
1698
1699You may start @value{GDBN} with its arguments, if any, in an environment
1700of your choice. If you are doing native debugging, you may redirect
1701your program's input and output, debug an already running process, or
1702kill a child process.
c906108c
SS
1703
1704@menu
1705* Compilation:: Compiling for debugging
1706* Starting:: Starting your program
c906108c
SS
1707* Arguments:: Your program's arguments
1708* Environment:: Your program's environment
c906108c
SS
1709
1710* Working Directory:: Your program's working directory
1711* Input/Output:: Your program's input and output
1712* Attach:: Debugging an already-running process
1713* Kill Process:: Killing the child process
c906108c
SS
1714
1715* Threads:: Debugging programs with multiple threads
1716* Processes:: Debugging programs with multiple processes
1717@end menu
1718
6d2ebf8b 1719@node Compilation
c906108c
SS
1720@section Compiling for debugging
1721
1722In order to debug a program effectively, you need to generate
1723debugging information when you compile it. This debugging information
1724is stored in the object file; it describes the data type of each
1725variable or function and the correspondence between source line numbers
1726and addresses in the executable code.
1727
1728To request debugging information, specify the @samp{-g} option when you run
1729the compiler.
1730
514c4d71
EZ
1731Programs that are to be shipped to your customers are compiled with
1732optimizations, using the @samp{-O} compiler option. However, many
1733compilers are unable to handle the @samp{-g} and @samp{-O} options
1734together. Using those compilers, you cannot generate optimized
c906108c
SS
1735executables containing debugging information.
1736
514c4d71 1737@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1738without @samp{-O}, making it possible to debug optimized code. We
1739recommend that you @emph{always} use @samp{-g} whenever you compile a
1740program. You may think your program is correct, but there is no sense
1741in pushing your luck.
c906108c
SS
1742
1743@cindex optimized code, debugging
1744@cindex debugging optimized code
1745When you debug a program compiled with @samp{-g -O}, remember that the
1746optimizer is rearranging your code; the debugger shows you what is
1747really there. Do not be too surprised when the execution path does not
1748exactly match your source file! An extreme example: if you define a
1749variable, but never use it, @value{GDBN} never sees that
1750variable---because the compiler optimizes it out of existence.
1751
1752Some things do not work as well with @samp{-g -O} as with just
1753@samp{-g}, particularly on machines with instruction scheduling. If in
1754doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1755please report it to us as a bug (including a test case!).
15387254 1756@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1757
1758Older versions of the @sc{gnu} C compiler permitted a variant option
1759@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1760format; if your @sc{gnu} C compiler has this option, do not use it.
1761
514c4d71
EZ
1762@value{GDBN} knows about preprocessor macros and can show you their
1763expansion (@pxref{Macros}). Most compilers do not include information
1764about preprocessor macros in the debugging information if you specify
1765the @option{-g} flag alone, because this information is rather large.
1766Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1767provides macro information if you specify the options
1768@option{-gdwarf-2} and @option{-g3}; the former option requests
1769debugging information in the Dwarf 2 format, and the latter requests
1770``extra information''. In the future, we hope to find more compact
1771ways to represent macro information, so that it can be included with
1772@option{-g} alone.
1773
c906108c 1774@need 2000
6d2ebf8b 1775@node Starting
c906108c
SS
1776@section Starting your program
1777@cindex starting
1778@cindex running
1779
1780@table @code
1781@kindex run
41afff9a 1782@kindex r @r{(@code{run})}
c906108c
SS
1783@item run
1784@itemx r
7a292a7a
SS
1785Use the @code{run} command to start your program under @value{GDBN}.
1786You must first specify the program name (except on VxWorks) with an
1787argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1788@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1789(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1790
1791@end table
1792
c906108c
SS
1793If you are running your program in an execution environment that
1794supports processes, @code{run} creates an inferior process and makes
1795that process run your program. (In environments without processes,
1796@code{run} jumps to the start of your program.)
1797
1798The execution of a program is affected by certain information it
1799receives from its superior. @value{GDBN} provides ways to specify this
1800information, which you must do @emph{before} starting your program. (You
1801can change it after starting your program, but such changes only affect
1802your program the next time you start it.) This information may be
1803divided into four categories:
1804
1805@table @asis
1806@item The @emph{arguments.}
1807Specify the arguments to give your program as the arguments of the
1808@code{run} command. If a shell is available on your target, the shell
1809is used to pass the arguments, so that you may use normal conventions
1810(such as wildcard expansion or variable substitution) in describing
1811the arguments.
1812In Unix systems, you can control which shell is used with the
1813@code{SHELL} environment variable.
1814@xref{Arguments, ,Your program's arguments}.
1815
1816@item The @emph{environment.}
1817Your program normally inherits its environment from @value{GDBN}, but you can
1818use the @value{GDBN} commands @code{set environment} and @code{unset
1819environment} to change parts of the environment that affect
1820your program. @xref{Environment, ,Your program's environment}.
1821
1822@item The @emph{working directory.}
1823Your program inherits its working directory from @value{GDBN}. You can set
1824the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1825@xref{Working Directory, ,Your program's working directory}.
1826
1827@item The @emph{standard input and output.}
1828Your program normally uses the same device for standard input and
1829standard output as @value{GDBN} is using. You can redirect input and output
1830in the @code{run} command line, or you can use the @code{tty} command to
1831set a different device for your program.
1832@xref{Input/Output, ,Your program's input and output}.
1833
1834@cindex pipes
1835@emph{Warning:} While input and output redirection work, you cannot use
1836pipes to pass the output of the program you are debugging to another
1837program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1838wrong program.
1839@end table
c906108c
SS
1840
1841When you issue the @code{run} command, your program begins to execute
1842immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1843of how to arrange for your program to stop. Once your program has
1844stopped, you may call functions in your program, using the @code{print}
1845or @code{call} commands. @xref{Data, ,Examining Data}.
1846
1847If the modification time of your symbol file has changed since the last
1848time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1849table, and reads it again. When it does this, @value{GDBN} tries to retain
1850your current breakpoints.
1851
4e8b0763
JB
1852@table @code
1853@kindex start
1854@item start
1855@cindex run to main procedure
1856The name of the main procedure can vary from language to language.
1857With C or C@t{++}, the main procedure name is always @code{main}, but
1858other languages such as Ada do not require a specific name for their
1859main procedure. The debugger provides a convenient way to start the
1860execution of the program and to stop at the beginning of the main
1861procedure, depending on the language used.
1862
1863The @samp{start} command does the equivalent of setting a temporary
1864breakpoint at the beginning of the main procedure and then invoking
1865the @samp{run} command.
1866
f018e82f
EZ
1867@cindex elaboration phase
1868Some programs contain an @dfn{elaboration} phase where some startup code is
1869executed before the main procedure is called. This depends on the
1870languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1871constructors for static and global objects are executed before
1872@code{main} is called. It is therefore possible that the debugger stops
1873before reaching the main procedure. However, the temporary breakpoint
1874will remain to halt execution.
1875
1876Specify the arguments to give to your program as arguments to the
1877@samp{start} command. These arguments will be given verbatim to the
1878underlying @samp{run} command. Note that the same arguments will be
1879reused if no argument is provided during subsequent calls to
1880@samp{start} or @samp{run}.
1881
1882It is sometimes necessary to debug the program during elaboration. In
1883these cases, using the @code{start} command would stop the execution of
1884your program too late, as the program would have already completed the
1885elaboration phase. Under these circumstances, insert breakpoints in your
1886elaboration code before running your program.
1887@end table
1888
6d2ebf8b 1889@node Arguments
c906108c
SS
1890@section Your program's arguments
1891
1892@cindex arguments (to your program)
1893The arguments to your program can be specified by the arguments of the
5d161b24 1894@code{run} command.
c906108c
SS
1895They are passed to a shell, which expands wildcard characters and
1896performs redirection of I/O, and thence to your program. Your
1897@code{SHELL} environment variable (if it exists) specifies what shell
1898@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1899the default shell (@file{/bin/sh} on Unix).
1900
1901On non-Unix systems, the program is usually invoked directly by
1902@value{GDBN}, which emulates I/O redirection via the appropriate system
1903calls, and the wildcard characters are expanded by the startup code of
1904the program, not by the shell.
c906108c
SS
1905
1906@code{run} with no arguments uses the same arguments used by the previous
1907@code{run}, or those set by the @code{set args} command.
1908
c906108c 1909@table @code
41afff9a 1910@kindex set args
c906108c
SS
1911@item set args
1912Specify the arguments to be used the next time your program is run. If
1913@code{set args} has no arguments, @code{run} executes your program
1914with no arguments. Once you have run your program with arguments,
1915using @code{set args} before the next @code{run} is the only way to run
1916it again without arguments.
1917
1918@kindex show args
1919@item show args
1920Show the arguments to give your program when it is started.
1921@end table
1922
6d2ebf8b 1923@node Environment
c906108c
SS
1924@section Your program's environment
1925
1926@cindex environment (of your program)
1927The @dfn{environment} consists of a set of environment variables and
1928their values. Environment variables conventionally record such things as
1929your user name, your home directory, your terminal type, and your search
1930path for programs to run. Usually you set up environment variables with
1931the shell and they are inherited by all the other programs you run. When
1932debugging, it can be useful to try running your program with a modified
1933environment without having to start @value{GDBN} over again.
1934
1935@table @code
1936@kindex path
1937@item path @var{directory}
1938Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1939(the search path for executables) that will be passed to your program.
1940The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1941You may specify several directory names, separated by whitespace or by a
1942system-dependent separator character (@samp{:} on Unix, @samp{;} on
1943MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1944is moved to the front, so it is searched sooner.
c906108c
SS
1945
1946You can use the string @samp{$cwd} to refer to whatever is the current
1947working directory at the time @value{GDBN} searches the path. If you
1948use @samp{.} instead, it refers to the directory where you executed the
1949@code{path} command. @value{GDBN} replaces @samp{.} in the
1950@var{directory} argument (with the current path) before adding
1951@var{directory} to the search path.
1952@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1953@c document that, since repeating it would be a no-op.
1954
1955@kindex show paths
1956@item show paths
1957Display the list of search paths for executables (the @code{PATH}
1958environment variable).
1959
1960@kindex show environment
1961@item show environment @r{[}@var{varname}@r{]}
1962Print the value of environment variable @var{varname} to be given to
1963your program when it starts. If you do not supply @var{varname},
1964print the names and values of all environment variables to be given to
1965your program. You can abbreviate @code{environment} as @code{env}.
1966
1967@kindex set environment
53a5351d 1968@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1969Set environment variable @var{varname} to @var{value}. The value
1970changes for your program only, not for @value{GDBN} itself. @var{value} may
1971be any string; the values of environment variables are just strings, and
1972any interpretation is supplied by your program itself. The @var{value}
1973parameter is optional; if it is eliminated, the variable is set to a
1974null value.
1975@c "any string" here does not include leading, trailing
1976@c blanks. Gnu asks: does anyone care?
1977
1978For example, this command:
1979
474c8240 1980@smallexample
c906108c 1981set env USER = foo
474c8240 1982@end smallexample
c906108c
SS
1983
1984@noindent
d4f3574e 1985tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1986@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1987are not actually required.)
1988
1989@kindex unset environment
1990@item unset environment @var{varname}
1991Remove variable @var{varname} from the environment to be passed to your
1992program. This is different from @samp{set env @var{varname} =};
1993@code{unset environment} removes the variable from the environment,
1994rather than assigning it an empty value.
1995@end table
1996
d4f3574e
SS
1997@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1998the shell indicated
c906108c
SS
1999by your @code{SHELL} environment variable if it exists (or
2000@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2001that runs an initialization file---such as @file{.cshrc} for C-shell, or
2002@file{.bashrc} for BASH---any variables you set in that file affect
2003your program. You may wish to move setting of environment variables to
2004files that are only run when you sign on, such as @file{.login} or
2005@file{.profile}.
2006
6d2ebf8b 2007@node Working Directory
c906108c
SS
2008@section Your program's working directory
2009
2010@cindex working directory (of your program)
2011Each time you start your program with @code{run}, it inherits its
2012working directory from the current working directory of @value{GDBN}.
2013The @value{GDBN} working directory is initially whatever it inherited
2014from its parent process (typically the shell), but you can specify a new
2015working directory in @value{GDBN} with the @code{cd} command.
2016
2017The @value{GDBN} working directory also serves as a default for the commands
2018that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2019specify files}.
2020
2021@table @code
2022@kindex cd
721c2651 2023@cindex change working directory
c906108c
SS
2024@item cd @var{directory}
2025Set the @value{GDBN} working directory to @var{directory}.
2026
2027@kindex pwd
2028@item pwd
2029Print the @value{GDBN} working directory.
2030@end table
2031
60bf7e09
EZ
2032It is generally impossible to find the current working directory of
2033the process being debugged (since a program can change its directory
2034during its run). If you work on a system where @value{GDBN} is
2035configured with the @file{/proc} support, you can use the @code{info
2036proc} command (@pxref{SVR4 Process Information}) to find out the
2037current working directory of the debuggee.
2038
6d2ebf8b 2039@node Input/Output
c906108c
SS
2040@section Your program's input and output
2041
2042@cindex redirection
2043@cindex i/o
2044@cindex terminal
2045By default, the program you run under @value{GDBN} does input and output to
5d161b24 2046the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2047to its own terminal modes to interact with you, but it records the terminal
2048modes your program was using and switches back to them when you continue
2049running your program.
2050
2051@table @code
2052@kindex info terminal
2053@item info terminal
2054Displays information recorded by @value{GDBN} about the terminal modes your
2055program is using.
2056@end table
2057
2058You can redirect your program's input and/or output using shell
2059redirection with the @code{run} command. For example,
2060
474c8240 2061@smallexample
c906108c 2062run > outfile
474c8240 2063@end smallexample
c906108c
SS
2064
2065@noindent
2066starts your program, diverting its output to the file @file{outfile}.
2067
2068@kindex tty
2069@cindex controlling terminal
2070Another way to specify where your program should do input and output is
2071with the @code{tty} command. This command accepts a file name as
2072argument, and causes this file to be the default for future @code{run}
2073commands. It also resets the controlling terminal for the child
2074process, for future @code{run} commands. For example,
2075
474c8240 2076@smallexample
c906108c 2077tty /dev/ttyb
474c8240 2078@end smallexample
c906108c
SS
2079
2080@noindent
2081directs that processes started with subsequent @code{run} commands
2082default to do input and output on the terminal @file{/dev/ttyb} and have
2083that as their controlling terminal.
2084
2085An explicit redirection in @code{run} overrides the @code{tty} command's
2086effect on the input/output device, but not its effect on the controlling
2087terminal.
2088
2089When you use the @code{tty} command or redirect input in the @code{run}
2090command, only the input @emph{for your program} is affected. The input
2091for @value{GDBN} still comes from your terminal.
2092
6d2ebf8b 2093@node Attach
c906108c
SS
2094@section Debugging an already-running process
2095@kindex attach
2096@cindex attach
2097
2098@table @code
2099@item attach @var{process-id}
2100This command attaches to a running process---one that was started
2101outside @value{GDBN}. (@code{info files} shows your active
2102targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2103find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2104or with the @samp{jobs -l} shell command.
2105
2106@code{attach} does not repeat if you press @key{RET} a second time after
2107executing the command.
2108@end table
2109
2110To use @code{attach}, your program must be running in an environment
2111which supports processes; for example, @code{attach} does not work for
2112programs on bare-board targets that lack an operating system. You must
2113also have permission to send the process a signal.
2114
2115When you use @code{attach}, the debugger finds the program running in
2116the process first by looking in the current working directory, then (if
2117the program is not found) by using the source file search path
2118(@pxref{Source Path, ,Specifying source directories}). You can also use
2119the @code{file} command to load the program. @xref{Files, ,Commands to
2120Specify Files}.
2121
2122The first thing @value{GDBN} does after arranging to debug the specified
2123process is to stop it. You can examine and modify an attached process
53a5351d
JM
2124with all the @value{GDBN} commands that are ordinarily available when
2125you start processes with @code{run}. You can insert breakpoints; you
2126can step and continue; you can modify storage. If you would rather the
2127process continue running, you may use the @code{continue} command after
c906108c
SS
2128attaching @value{GDBN} to the process.
2129
2130@table @code
2131@kindex detach
2132@item detach
2133When you have finished debugging the attached process, you can use the
2134@code{detach} command to release it from @value{GDBN} control. Detaching
2135the process continues its execution. After the @code{detach} command,
2136that process and @value{GDBN} become completely independent once more, and you
2137are ready to @code{attach} another process or start one with @code{run}.
2138@code{detach} does not repeat if you press @key{RET} again after
2139executing the command.
2140@end table
2141
2142If you exit @value{GDBN} or use the @code{run} command while you have an
2143attached process, you kill that process. By default, @value{GDBN} asks
2144for confirmation if you try to do either of these things; you can
2145control whether or not you need to confirm by using the @code{set
2146confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2147messages}).
2148
6d2ebf8b 2149@node Kill Process
c906108c 2150@section Killing the child process
c906108c
SS
2151
2152@table @code
2153@kindex kill
2154@item kill
2155Kill the child process in which your program is running under @value{GDBN}.
2156@end table
2157
2158This command is useful if you wish to debug a core dump instead of a
2159running process. @value{GDBN} ignores any core dump file while your program
2160is running.
2161
2162On some operating systems, a program cannot be executed outside @value{GDBN}
2163while you have breakpoints set on it inside @value{GDBN}. You can use the
2164@code{kill} command in this situation to permit running your program
2165outside the debugger.
2166
2167The @code{kill} command is also useful if you wish to recompile and
2168relink your program, since on many systems it is impossible to modify an
2169executable file while it is running in a process. In this case, when you
2170next type @code{run}, @value{GDBN} notices that the file has changed, and
2171reads the symbol table again (while trying to preserve your current
2172breakpoint settings).
2173
6d2ebf8b 2174@node Threads
c906108c 2175@section Debugging programs with multiple threads
c906108c
SS
2176
2177@cindex threads of execution
2178@cindex multiple threads
2179@cindex switching threads
2180In some operating systems, such as HP-UX and Solaris, a single program
2181may have more than one @dfn{thread} of execution. The precise semantics
2182of threads differ from one operating system to another, but in general
2183the threads of a single program are akin to multiple processes---except
2184that they share one address space (that is, they can all examine and
2185modify the same variables). On the other hand, each thread has its own
2186registers and execution stack, and perhaps private memory.
2187
2188@value{GDBN} provides these facilities for debugging multi-thread
2189programs:
2190
2191@itemize @bullet
2192@item automatic notification of new threads
2193@item @samp{thread @var{threadno}}, a command to switch among threads
2194@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2195@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2196a command to apply a command to a list of threads
2197@item thread-specific breakpoints
2198@end itemize
2199
c906108c
SS
2200@quotation
2201@emph{Warning:} These facilities are not yet available on every
2202@value{GDBN} configuration where the operating system supports threads.
2203If your @value{GDBN} does not support threads, these commands have no
2204effect. For example, a system without thread support shows no output
2205from @samp{info threads}, and always rejects the @code{thread} command,
2206like this:
2207
2208@smallexample
2209(@value{GDBP}) info threads
2210(@value{GDBP}) thread 1
2211Thread ID 1 not known. Use the "info threads" command to
2212see the IDs of currently known threads.
2213@end smallexample
2214@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2215@c doesn't support threads"?
2216@end quotation
c906108c
SS
2217
2218@cindex focus of debugging
2219@cindex current thread
2220The @value{GDBN} thread debugging facility allows you to observe all
2221threads while your program runs---but whenever @value{GDBN} takes
2222control, one thread in particular is always the focus of debugging.
2223This thread is called the @dfn{current thread}. Debugging commands show
2224program information from the perspective of the current thread.
2225
41afff9a 2226@cindex @code{New} @var{systag} message
c906108c
SS
2227@cindex thread identifier (system)
2228@c FIXME-implementors!! It would be more helpful if the [New...] message
2229@c included GDB's numeric thread handle, so you could just go to that
2230@c thread without first checking `info threads'.
2231Whenever @value{GDBN} detects a new thread in your program, it displays
2232the target system's identification for the thread with a message in the
2233form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2234whose form varies depending on the particular system. For example, on
2235LynxOS, you might see
2236
474c8240 2237@smallexample
c906108c 2238[New process 35 thread 27]
474c8240 2239@end smallexample
c906108c
SS
2240
2241@noindent
2242when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2243the @var{systag} is simply something like @samp{process 368}, with no
2244further qualifier.
2245
2246@c FIXME!! (1) Does the [New...] message appear even for the very first
2247@c thread of a program, or does it only appear for the
6ca652b0 2248@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2249@c program?
2250@c (2) *Is* there necessarily a first thread always? Or do some
2251@c multithread systems permit starting a program with multiple
5d161b24 2252@c threads ab initio?
c906108c
SS
2253
2254@cindex thread number
2255@cindex thread identifier (GDB)
2256For debugging purposes, @value{GDBN} associates its own thread
2257number---always a single integer---with each thread in your program.
2258
2259@table @code
2260@kindex info threads
2261@item info threads
2262Display a summary of all threads currently in your
2263program. @value{GDBN} displays for each thread (in this order):
2264
2265@enumerate
09d4efe1
EZ
2266@item
2267the thread number assigned by @value{GDBN}
c906108c 2268
09d4efe1
EZ
2269@item
2270the target system's thread identifier (@var{systag})
c906108c 2271
09d4efe1
EZ
2272@item
2273the current stack frame summary for that thread
c906108c
SS
2274@end enumerate
2275
2276@noindent
2277An asterisk @samp{*} to the left of the @value{GDBN} thread number
2278indicates the current thread.
2279
5d161b24 2280For example,
c906108c
SS
2281@end table
2282@c end table here to get a little more width for example
2283
2284@smallexample
2285(@value{GDBP}) info threads
2286 3 process 35 thread 27 0x34e5 in sigpause ()
2287 2 process 35 thread 23 0x34e5 in sigpause ()
2288* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2289 at threadtest.c:68
2290@end smallexample
53a5351d
JM
2291
2292On HP-UX systems:
c906108c 2293
4644b6e3
EZ
2294@cindex debugging multithreaded programs (on HP-UX)
2295@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2296For debugging purposes, @value{GDBN} associates its own thread
2297number---a small integer assigned in thread-creation order---with each
2298thread in your program.
2299
41afff9a
EZ
2300@cindex @code{New} @var{systag} message, on HP-UX
2301@cindex thread identifier (system), on HP-UX
c906108c
SS
2302@c FIXME-implementors!! It would be more helpful if the [New...] message
2303@c included GDB's numeric thread handle, so you could just go to that
2304@c thread without first checking `info threads'.
2305Whenever @value{GDBN} detects a new thread in your program, it displays
2306both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2307form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2308whose form varies depending on the particular system. For example, on
2309HP-UX, you see
2310
474c8240 2311@smallexample
c906108c 2312[New thread 2 (system thread 26594)]
474c8240 2313@end smallexample
c906108c
SS
2314
2315@noindent
5d161b24 2316when @value{GDBN} notices a new thread.
c906108c
SS
2317
2318@table @code
4644b6e3 2319@kindex info threads (HP-UX)
c906108c
SS
2320@item info threads
2321Display a summary of all threads currently in your
2322program. @value{GDBN} displays for each thread (in this order):
2323
2324@enumerate
2325@item the thread number assigned by @value{GDBN}
2326
2327@item the target system's thread identifier (@var{systag})
2328
2329@item the current stack frame summary for that thread
2330@end enumerate
2331
2332@noindent
2333An asterisk @samp{*} to the left of the @value{GDBN} thread number
2334indicates the current thread.
2335
5d161b24 2336For example,
c906108c
SS
2337@end table
2338@c end table here to get a little more width for example
2339
474c8240 2340@smallexample
c906108c 2341(@value{GDBP}) info threads
6d2ebf8b
SS
2342 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2343 at quicksort.c:137
2344 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2345 from /usr/lib/libc.2
2346 1 system thread 27905 0x7b003498 in _brk () \@*
2347 from /usr/lib/libc.2
474c8240 2348@end smallexample
c906108c 2349
c45da7e6
EZ
2350On Solaris, you can display more information about user threads with a
2351Solaris-specific command:
2352
2353@table @code
2354@item maint info sol-threads
2355@kindex maint info sol-threads
2356@cindex thread info (Solaris)
2357Display info on Solaris user threads.
2358@end table
2359
c906108c
SS
2360@table @code
2361@kindex thread @var{threadno}
2362@item thread @var{threadno}
2363Make thread number @var{threadno} the current thread. The command
2364argument @var{threadno} is the internal @value{GDBN} thread number, as
2365shown in the first field of the @samp{info threads} display.
2366@value{GDBN} responds by displaying the system identifier of the thread
2367you selected, and its current stack frame summary:
2368
2369@smallexample
2370@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2371(@value{GDBP}) thread 2
c906108c 2372[Switching to process 35 thread 23]
c906108c
SS
23730x34e5 in sigpause ()
2374@end smallexample
2375
2376@noindent
2377As with the @samp{[New @dots{}]} message, the form of the text after
2378@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2379threads.
c906108c 2380
9c16f35a 2381@kindex thread apply
c906108c
SS
2382@item thread apply [@var{threadno}] [@var{all}] @var{args}
2383The @code{thread apply} command allows you to apply a command to one or
2384more threads. Specify the numbers of the threads that you want affected
2385with the command argument @var{threadno}. @var{threadno} is the internal
2386@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2387threads} display. To apply a command to all threads, use
2388@code{thread apply all} @var{args}.
c906108c
SS
2389@end table
2390
2391@cindex automatic thread selection
2392@cindex switching threads automatically
2393@cindex threads, automatic switching
2394Whenever @value{GDBN} stops your program, due to a breakpoint or a
2395signal, it automatically selects the thread where that breakpoint or
2396signal happened. @value{GDBN} alerts you to the context switch with a
2397message of the form @samp{[Switching to @var{systag}]} to identify the
2398thread.
2399
2400@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2401more information about how @value{GDBN} behaves when you stop and start
2402programs with multiple threads.
2403
2404@xref{Set Watchpoints,,Setting watchpoints}, for information about
2405watchpoints in programs with multiple threads.
c906108c 2406
6d2ebf8b 2407@node Processes
c906108c
SS
2408@section Debugging programs with multiple processes
2409
2410@cindex fork, debugging programs which call
2411@cindex multiple processes
2412@cindex processes, multiple
53a5351d
JM
2413On most systems, @value{GDBN} has no special support for debugging
2414programs which create additional processes using the @code{fork}
2415function. When a program forks, @value{GDBN} will continue to debug the
2416parent process and the child process will run unimpeded. If you have
2417set a breakpoint in any code which the child then executes, the child
2418will get a @code{SIGTRAP} signal which (unless it catches the signal)
2419will cause it to terminate.
c906108c
SS
2420
2421However, if you want to debug the child process there is a workaround
2422which isn't too painful. Put a call to @code{sleep} in the code which
2423the child process executes after the fork. It may be useful to sleep
2424only if a certain environment variable is set, or a certain file exists,
2425so that the delay need not occur when you don't want to run @value{GDBN}
2426on the child. While the child is sleeping, use the @code{ps} program to
2427get its process ID. Then tell @value{GDBN} (a new invocation of
2428@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2429the child process (@pxref{Attach}). From that point on you can debug
c906108c 2430the child process just like any other process which you attached to.
c906108c 2431
b51970ac
DJ
2432On some systems, @value{GDBN} provides support for debugging programs that
2433create additional processes using the @code{fork} or @code{vfork} functions.
2434Currently, the only platforms with this feature are HP-UX (11.x and later
2435only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2436
2437By default, when a program forks, @value{GDBN} will continue to debug
2438the parent process and the child process will run unimpeded.
2439
2440If you want to follow the child process instead of the parent process,
2441use the command @w{@code{set follow-fork-mode}}.
2442
2443@table @code
2444@kindex set follow-fork-mode
2445@item set follow-fork-mode @var{mode}
2446Set the debugger response to a program call of @code{fork} or
2447@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2448process. The @var{mode} argument can be:
c906108c
SS
2449
2450@table @code
2451@item parent
2452The original process is debugged after a fork. The child process runs
2df3850c 2453unimpeded. This is the default.
c906108c
SS
2454
2455@item child
2456The new process is debugged after a fork. The parent process runs
2457unimpeded.
2458
c906108c
SS
2459@end table
2460
9c16f35a 2461@kindex show follow-fork-mode
c906108c 2462@item show follow-fork-mode
2df3850c 2463Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2464@end table
2465
2466If you ask to debug a child process and a @code{vfork} is followed by an
2467@code{exec}, @value{GDBN} executes the new target up to the first
2468breakpoint in the new target. If you have a breakpoint set on
2469@code{main} in your original program, the breakpoint will also be set on
2470the child process's @code{main}.
2471
2472When a child process is spawned by @code{vfork}, you cannot debug the
2473child or parent until an @code{exec} call completes.
2474
2475If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2476call executes, the new target restarts. To restart the parent process,
2477use the @code{file} command with the parent executable name as its
2478argument.
2479
2480You can use the @code{catch} command to make @value{GDBN} stop whenever
2481a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2482Catchpoints, ,Setting catchpoints}.
c906108c 2483
6d2ebf8b 2484@node Stopping
c906108c
SS
2485@chapter Stopping and Continuing
2486
2487The principal purposes of using a debugger are so that you can stop your
2488program before it terminates; or so that, if your program runs into
2489trouble, you can investigate and find out why.
2490
7a292a7a
SS
2491Inside @value{GDBN}, your program may stop for any of several reasons,
2492such as a signal, a breakpoint, or reaching a new line after a
2493@value{GDBN} command such as @code{step}. You may then examine and
2494change variables, set new breakpoints or remove old ones, and then
2495continue execution. Usually, the messages shown by @value{GDBN} provide
2496ample explanation of the status of your program---but you can also
2497explicitly request this information at any time.
c906108c
SS
2498
2499@table @code
2500@kindex info program
2501@item info program
2502Display information about the status of your program: whether it is
7a292a7a 2503running or not, what process it is, and why it stopped.
c906108c
SS
2504@end table
2505
2506@menu
2507* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2508* Continuing and Stepping:: Resuming execution
c906108c 2509* Signals:: Signals
c906108c 2510* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2511@end menu
2512
6d2ebf8b 2513@node Breakpoints
c906108c
SS
2514@section Breakpoints, watchpoints, and catchpoints
2515
2516@cindex breakpoints
2517A @dfn{breakpoint} makes your program stop whenever a certain point in
2518the program is reached. For each breakpoint, you can add conditions to
2519control in finer detail whether your program stops. You can set
2520breakpoints with the @code{break} command and its variants (@pxref{Set
2521Breaks, ,Setting breakpoints}), to specify the place where your program
2522should stop by line number, function name or exact address in the
2523program.
2524
09d4efe1
EZ
2525On some systems, you can set breakpoints in shared libraries before
2526the executable is run. There is a minor limitation on HP-UX systems:
2527you must wait until the executable is run in order to set breakpoints
2528in shared library routines that are not called directly by the program
2529(for example, routines that are arguments in a @code{pthread_create}
2530call).
c906108c
SS
2531
2532@cindex watchpoints
2533@cindex memory tracing
2534@cindex breakpoint on memory address
2535@cindex breakpoint on variable modification
2536A @dfn{watchpoint} is a special breakpoint that stops your program
2537when the value of an expression changes. You must use a different
2538command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2539watchpoints}), but aside from that, you can manage a watchpoint like
2540any other breakpoint: you enable, disable, and delete both breakpoints
2541and watchpoints using the same commands.
2542
2543You can arrange to have values from your program displayed automatically
2544whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2545Automatic display}.
2546
2547@cindex catchpoints
2548@cindex breakpoint on events
2549A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2550when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2551exception or the loading of a library. As with watchpoints, you use a
2552different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2553catchpoints}), but aside from that, you can manage a catchpoint like any
2554other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2555@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2556
2557@cindex breakpoint numbers
2558@cindex numbers for breakpoints
2559@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2560catchpoint when you create it; these numbers are successive integers
2561starting with one. In many of the commands for controlling various
2562features of breakpoints you use the breakpoint number to say which
2563breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2564@dfn{disabled}; if disabled, it has no effect on your program until you
2565enable it again.
2566
c5394b80
JM
2567@cindex breakpoint ranges
2568@cindex ranges of breakpoints
2569Some @value{GDBN} commands accept a range of breakpoints on which to
2570operate. A breakpoint range is either a single breakpoint number, like
2571@samp{5}, or two such numbers, in increasing order, separated by a
2572hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2573all breakpoint in that range are operated on.
2574
c906108c
SS
2575@menu
2576* Set Breaks:: Setting breakpoints
2577* Set Watchpoints:: Setting watchpoints
2578* Set Catchpoints:: Setting catchpoints
2579* Delete Breaks:: Deleting breakpoints
2580* Disabling:: Disabling breakpoints
2581* Conditions:: Break conditions
2582* Break Commands:: Breakpoint command lists
c906108c 2583* Breakpoint Menus:: Breakpoint menus
d4f3574e 2584* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2585* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2586@end menu
2587
6d2ebf8b 2588@node Set Breaks
c906108c
SS
2589@subsection Setting breakpoints
2590
5d161b24 2591@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2592@c consider in particular declaration with/without initialization.
2593@c
2594@c FIXME 2 is there stuff on this already? break at fun start, already init?
2595
2596@kindex break
41afff9a
EZ
2597@kindex b @r{(@code{break})}
2598@vindex $bpnum@r{, convenience variable}
c906108c
SS
2599@cindex latest breakpoint
2600Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2601@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2602number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2603Vars,, Convenience variables}, for a discussion of what you can do with
2604convenience variables.
2605
2606You have several ways to say where the breakpoint should go.
2607
2608@table @code
2609@item break @var{function}
5d161b24 2610Set a breakpoint at entry to function @var{function}.
c906108c 2611When using source languages that permit overloading of symbols, such as
b37052ae 2612C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2613@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2614
2615@item break +@var{offset}
2616@itemx break -@var{offset}
2617Set a breakpoint some number of lines forward or back from the position
d4f3574e 2618at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2619(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2620
2621@item break @var{linenum}
2622Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2623The current source file is the last file whose source text was printed.
2624The breakpoint will stop your program just before it executes any of the
c906108c
SS
2625code on that line.
2626
2627@item break @var{filename}:@var{linenum}
2628Set a breakpoint at line @var{linenum} in source file @var{filename}.
2629
2630@item break @var{filename}:@var{function}
2631Set a breakpoint at entry to function @var{function} found in file
2632@var{filename}. Specifying a file name as well as a function name is
2633superfluous except when multiple files contain similarly named
2634functions.
2635
2636@item break *@var{address}
2637Set a breakpoint at address @var{address}. You can use this to set
2638breakpoints in parts of your program which do not have debugging
2639information or source files.
2640
2641@item break
2642When called without any arguments, @code{break} sets a breakpoint at
2643the next instruction to be executed in the selected stack frame
2644(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2645innermost, this makes your program stop as soon as control
2646returns to that frame. This is similar to the effect of a
2647@code{finish} command in the frame inside the selected frame---except
2648that @code{finish} does not leave an active breakpoint. If you use
2649@code{break} without an argument in the innermost frame, @value{GDBN} stops
2650the next time it reaches the current location; this may be useful
2651inside loops.
2652
2653@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2654least one instruction has been executed. If it did not do this, you
2655would be unable to proceed past a breakpoint without first disabling the
2656breakpoint. This rule applies whether or not the breakpoint already
2657existed when your program stopped.
2658
2659@item break @dots{} if @var{cond}
2660Set a breakpoint with condition @var{cond}; evaluate the expression
2661@var{cond} each time the breakpoint is reached, and stop only if the
2662value is nonzero---that is, if @var{cond} evaluates as true.
2663@samp{@dots{}} stands for one of the possible arguments described
2664above (or no argument) specifying where to break. @xref{Conditions,
2665,Break conditions}, for more information on breakpoint conditions.
2666
2667@kindex tbreak
2668@item tbreak @var{args}
2669Set a breakpoint enabled only for one stop. @var{args} are the
2670same as for the @code{break} command, and the breakpoint is set in the same
2671way, but the breakpoint is automatically deleted after the first time your
2672program stops there. @xref{Disabling, ,Disabling breakpoints}.
2673
c906108c 2674@kindex hbreak
ba04e063 2675@cindex hardware breakpoints
c906108c 2676@item hbreak @var{args}
d4f3574e
SS
2677Set a hardware-assisted breakpoint. @var{args} are the same as for the
2678@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2679breakpoint requires hardware support and some target hardware may not
2680have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2681debugging, so you can set a breakpoint at an instruction without
2682changing the instruction. This can be used with the new trap-generation
09d4efe1 2683provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2684will generate traps when a program accesses some data or instruction
2685address that is assigned to the debug registers. However the hardware
2686breakpoint registers can take a limited number of breakpoints. For
2687example, on the DSU, only two data breakpoints can be set at a time, and
2688@value{GDBN} will reject this command if more than two are used. Delete
2689or disable unused hardware breakpoints before setting new ones
2690(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2691For remote targets, you can restrict the number of hardware
2692breakpoints @value{GDBN} will use, see @ref{set remote
2693hardware-breakpoint-limit}.
501eef12 2694
c906108c
SS
2695
2696@kindex thbreak
2697@item thbreak @var{args}
2698Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2699are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2700the same way. However, like the @code{tbreak} command,
c906108c
SS
2701the breakpoint is automatically deleted after the
2702first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2703command, the breakpoint requires hardware support and some target hardware
2704may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2705See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2706
2707@kindex rbreak
2708@cindex regular expression
c45da7e6
EZ
2709@cindex breakpoints in functions matching a regexp
2710@cindex set breakpoints in many functions
c906108c 2711@item rbreak @var{regex}
c906108c 2712Set breakpoints on all functions matching the regular expression
11cf8741
JM
2713@var{regex}. This command sets an unconditional breakpoint on all
2714matches, printing a list of all breakpoints it set. Once these
2715breakpoints are set, they are treated just like the breakpoints set with
2716the @code{break} command. You can delete them, disable them, or make
2717them conditional the same way as any other breakpoint.
2718
2719The syntax of the regular expression is the standard one used with tools
2720like @file{grep}. Note that this is different from the syntax used by
2721shells, so for instance @code{foo*} matches all functions that include
2722an @code{fo} followed by zero or more @code{o}s. There is an implicit
2723@code{.*} leading and trailing the regular expression you supply, so to
2724match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2725
f7dc1244 2726@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2727When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2728breakpoints on overloaded functions that are not members of any special
2729classes.
c906108c 2730
f7dc1244
EZ
2731@cindex set breakpoints on all functions
2732The @code{rbreak} command can be used to set breakpoints in
2733@strong{all} the functions in a program, like this:
2734
2735@smallexample
2736(@value{GDBP}) rbreak .
2737@end smallexample
2738
c906108c
SS
2739@kindex info breakpoints
2740@cindex @code{$_} and @code{info breakpoints}
2741@item info breakpoints @r{[}@var{n}@r{]}
2742@itemx info break @r{[}@var{n}@r{]}
2743@itemx info watchpoints @r{[}@var{n}@r{]}
2744Print a table of all breakpoints, watchpoints, and catchpoints set and
2745not deleted, with the following columns for each breakpoint:
2746
2747@table @emph
2748@item Breakpoint Numbers
2749@item Type
2750Breakpoint, watchpoint, or catchpoint.
2751@item Disposition
2752Whether the breakpoint is marked to be disabled or deleted when hit.
2753@item Enabled or Disabled
2754Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2755that are not enabled.
2756@item Address
2650777c
JJ
2757Where the breakpoint is in your program, as a memory address. If the
2758breakpoint is pending (see below for details) on a future load of a shared library, the address
2759will be listed as @samp{<PENDING>}.
c906108c
SS
2760@item What
2761Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2762line number. For a pending breakpoint, the original string passed to
2763the breakpoint command will be listed as it cannot be resolved until
2764the appropriate shared library is loaded in the future.
c906108c
SS
2765@end table
2766
2767@noindent
2768If a breakpoint is conditional, @code{info break} shows the condition on
2769the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2770are listed after that. A pending breakpoint is allowed to have a condition
2771specified for it. The condition is not parsed for validity until a shared
2772library is loaded that allows the pending breakpoint to resolve to a
2773valid location.
c906108c
SS
2774
2775@noindent
2776@code{info break} with a breakpoint
2777number @var{n} as argument lists only that breakpoint. The
2778convenience variable @code{$_} and the default examining-address for
2779the @code{x} command are set to the address of the last breakpoint
5d161b24 2780listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2781
2782@noindent
2783@code{info break} displays a count of the number of times the breakpoint
2784has been hit. This is especially useful in conjunction with the
2785@code{ignore} command. You can ignore a large number of breakpoint
2786hits, look at the breakpoint info to see how many times the breakpoint
2787was hit, and then run again, ignoring one less than that number. This
2788will get you quickly to the last hit of that breakpoint.
2789@end table
2790
2791@value{GDBN} allows you to set any number of breakpoints at the same place in
2792your program. There is nothing silly or meaningless about this. When
2793the breakpoints are conditional, this is even useful
2794(@pxref{Conditions, ,Break conditions}).
2795
2650777c 2796@cindex pending breakpoints
dd79a6cf
JJ
2797If a specified breakpoint location cannot be found, it may be due to the fact
2798that the location is in a shared library that is yet to be loaded. In such
2799a case, you may want @value{GDBN} to create a special breakpoint (known as
2800a @dfn{pending breakpoint}) that
2801attempts to resolve itself in the future when an appropriate shared library
2802gets loaded.
2803
2804Pending breakpoints are useful to set at the start of your
2650777c
JJ
2805@value{GDBN} session for locations that you know will be dynamically loaded
2806later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2807a check is made to see if the load resolves any pending breakpoint locations.
2808If a pending breakpoint location gets resolved,
2809a regular breakpoint is created and the original pending breakpoint is removed.
2810
2811@value{GDBN} provides some additional commands for controlling pending
2812breakpoint support:
2813
2814@kindex set breakpoint pending
2815@kindex show breakpoint pending
2816@table @code
2817@item set breakpoint pending auto
2818This is the default behavior. When @value{GDBN} cannot find the breakpoint
2819location, it queries you whether a pending breakpoint should be created.
2820
2821@item set breakpoint pending on
2822This indicates that an unrecognized breakpoint location should automatically
2823result in a pending breakpoint being created.
2824
2825@item set breakpoint pending off
2826This indicates that pending breakpoints are not to be created. Any
2827unrecognized breakpoint location results in an error. This setting does
2828not affect any pending breakpoints previously created.
2829
2830@item show breakpoint pending
2831Show the current behavior setting for creating pending breakpoints.
2832@end table
2650777c 2833
649e03f6
RM
2834@cindex operations allowed on pending breakpoints
2835Normal breakpoint operations apply to pending breakpoints as well. You may
2836specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2837breakpoint is reached. You can also enable or disable
2838the pending breakpoint. When you specify a condition for a pending breakpoint,
2839the parsing of the condition will be deferred until the point where the
2840pending breakpoint location is resolved. Disabling a pending breakpoint
2841tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2842shared library load. When a pending breakpoint is re-enabled,
649e03f6 2843@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2844This is done because any number of shared library loads could have
2845occurred since the time the breakpoint was disabled and one or more
2846of these loads could resolve the location.
2847
c906108c
SS
2848@cindex negative breakpoint numbers
2849@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2850@value{GDBN} itself sometimes sets breakpoints in your program for
2851special purposes, such as proper handling of @code{longjmp} (in C
2852programs). These internal breakpoints are assigned negative numbers,
2853starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2854You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2855@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2856
2857
6d2ebf8b 2858@node Set Watchpoints
c906108c
SS
2859@subsection Setting watchpoints
2860
2861@cindex setting watchpoints
c906108c
SS
2862You can use a watchpoint to stop execution whenever the value of an
2863expression changes, without having to predict a particular place where
2864this may happen.
2865
82f2d802
EZ
2866@cindex software watchpoints
2867@cindex hardware watchpoints
c906108c 2868Depending on your system, watchpoints may be implemented in software or
2df3850c 2869hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2870program and testing the variable's value each time, which is hundreds of
2871times slower than normal execution. (But this may still be worth it, to
2872catch errors where you have no clue what part of your program is the
2873culprit.)
2874
82f2d802
EZ
2875On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2876x86-based targets, @value{GDBN} includes support for hardware
2877watchpoints, which do not slow down the running of your program.
c906108c
SS
2878
2879@table @code
2880@kindex watch
2881@item watch @var{expr}
2882Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2883is written into by the program and its value changes.
2884
2885@kindex rwatch
2886@item rwatch @var{expr}
09d4efe1
EZ
2887Set a watchpoint that will break when the value of @var{expr} is read
2888by the program.
c906108c
SS
2889
2890@kindex awatch
2891@item awatch @var{expr}
09d4efe1
EZ
2892Set a watchpoint that will break when @var{expr} is either read from
2893or written into by the program.
c906108c
SS
2894
2895@kindex info watchpoints
2896@item info watchpoints
2897This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2898it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2899@end table
2900
2901@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2902watchpoints execute very quickly, and the debugger reports a change in
2903value at the exact instruction where the change occurs. If @value{GDBN}
2904cannot set a hardware watchpoint, it sets a software watchpoint, which
2905executes more slowly and reports the change in value at the next
82f2d802
EZ
2906@emph{statement}, not the instruction, after the change occurs.
2907
82f2d802
EZ
2908@cindex use only software watchpoints
2909You can force @value{GDBN} to use only software watchpoints with the
2910@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2911zero, @value{GDBN} will never try to use hardware watchpoints, even if
2912the underlying system supports them. (Note that hardware-assisted
2913watchpoints that were set @emph{before} setting
2914@code{can-use-hw-watchpoints} to zero will still use the hardware
2915mechanism of watching expressiion values.)
c906108c 2916
9c16f35a
EZ
2917@table @code
2918@item set can-use-hw-watchpoints
2919@kindex set can-use-hw-watchpoints
2920Set whether or not to use hardware watchpoints.
2921
2922@item show can-use-hw-watchpoints
2923@kindex show can-use-hw-watchpoints
2924Show the current mode of using hardware watchpoints.
2925@end table
2926
2927For remote targets, you can restrict the number of hardware
2928watchpoints @value{GDBN} will use, see @ref{set remote
2929hardware-breakpoint-limit}.
2930
c906108c
SS
2931When you issue the @code{watch} command, @value{GDBN} reports
2932
474c8240 2933@smallexample
c906108c 2934Hardware watchpoint @var{num}: @var{expr}
474c8240 2935@end smallexample
c906108c
SS
2936
2937@noindent
2938if it was able to set a hardware watchpoint.
2939
7be570e7
JM
2940Currently, the @code{awatch} and @code{rwatch} commands can only set
2941hardware watchpoints, because accesses to data that don't change the
2942value of the watched expression cannot be detected without examining
2943every instruction as it is being executed, and @value{GDBN} does not do
2944that currently. If @value{GDBN} finds that it is unable to set a
2945hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2946will print a message like this:
2947
2948@smallexample
2949Expression cannot be implemented with read/access watchpoint.
2950@end smallexample
2951
2952Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2953data type of the watched expression is wider than what a hardware
2954watchpoint on the target machine can handle. For example, some systems
2955can only watch regions that are up to 4 bytes wide; on such systems you
2956cannot set hardware watchpoints for an expression that yields a
2957double-precision floating-point number (which is typically 8 bytes
2958wide). As a work-around, it might be possible to break the large region
2959into a series of smaller ones and watch them with separate watchpoints.
2960
2961If you set too many hardware watchpoints, @value{GDBN} might be unable
2962to insert all of them when you resume the execution of your program.
2963Since the precise number of active watchpoints is unknown until such
2964time as the program is about to be resumed, @value{GDBN} might not be
2965able to warn you about this when you set the watchpoints, and the
2966warning will be printed only when the program is resumed:
2967
2968@smallexample
2969Hardware watchpoint @var{num}: Could not insert watchpoint
2970@end smallexample
2971
2972@noindent
2973If this happens, delete or disable some of the watchpoints.
2974
2975The SPARClite DSU will generate traps when a program accesses some data
2976or instruction address that is assigned to the debug registers. For the
2977data addresses, DSU facilitates the @code{watch} command. However the
2978hardware breakpoint registers can only take two data watchpoints, and
2979both watchpoints must be the same kind. For example, you can set two
2980watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2981@strong{or} two with @code{awatch} commands, but you cannot set one
2982watchpoint with one command and the other with a different command.
c906108c
SS
2983@value{GDBN} will reject the command if you try to mix watchpoints.
2984Delete or disable unused watchpoint commands before setting new ones.
2985
2986If you call a function interactively using @code{print} or @code{call},
2df3850c 2987any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2988kind of breakpoint or the call completes.
2989
7be570e7
JM
2990@value{GDBN} automatically deletes watchpoints that watch local
2991(automatic) variables, or expressions that involve such variables, when
2992they go out of scope, that is, when the execution leaves the block in
2993which these variables were defined. In particular, when the program
2994being debugged terminates, @emph{all} local variables go out of scope,
2995and so only watchpoints that watch global variables remain set. If you
2996rerun the program, you will need to set all such watchpoints again. One
2997way of doing that would be to set a code breakpoint at the entry to the
2998@code{main} function and when it breaks, set all the watchpoints.
2999
c906108c
SS
3000@quotation
3001@cindex watchpoints and threads
3002@cindex threads and watchpoints
c906108c
SS
3003@emph{Warning:} In multi-thread programs, watchpoints have only limited
3004usefulness. With the current watchpoint implementation, @value{GDBN}
3005can only watch the value of an expression @emph{in a single thread}. If
3006you are confident that the expression can only change due to the current
3007thread's activity (and if you are also confident that no other thread
3008can become current), then you can use watchpoints as usual. However,
3009@value{GDBN} may not notice when a non-current thread's activity changes
3010the expression.
53a5351d 3011
d4f3574e 3012@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3013@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3014have only limited usefulness. If @value{GDBN} creates a software
3015watchpoint, it can only watch the value of an expression @emph{in a
3016single thread}. If you are confident that the expression can only
3017change due to the current thread's activity (and if you are also
3018confident that no other thread can become current), then you can use
3019software watchpoints as usual. However, @value{GDBN} may not notice
3020when a non-current thread's activity changes the expression. (Hardware
3021watchpoints, in contrast, watch an expression in all threads.)
c906108c 3022@end quotation
c906108c 3023
501eef12
AC
3024@xref{set remote hardware-watchpoint-limit}.
3025
6d2ebf8b 3026@node Set Catchpoints
c906108c 3027@subsection Setting catchpoints
d4f3574e 3028@cindex catchpoints, setting
c906108c
SS
3029@cindex exception handlers
3030@cindex event handling
3031
3032You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3033kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3034shared library. Use the @code{catch} command to set a catchpoint.
3035
3036@table @code
3037@kindex catch
3038@item catch @var{event}
3039Stop when @var{event} occurs. @var{event} can be any of the following:
3040@table @code
3041@item throw
4644b6e3 3042@cindex stop on C@t{++} exceptions
b37052ae 3043The throwing of a C@t{++} exception.
c906108c
SS
3044
3045@item catch
b37052ae 3046The catching of a C@t{++} exception.
c906108c
SS
3047
3048@item exec
4644b6e3 3049@cindex break on fork/exec
c906108c
SS
3050A call to @code{exec}. This is currently only available for HP-UX.
3051
3052@item fork
c906108c
SS
3053A call to @code{fork}. This is currently only available for HP-UX.
3054
3055@item vfork
c906108c
SS
3056A call to @code{vfork}. This is currently only available for HP-UX.
3057
3058@item load
3059@itemx load @var{libname}
4644b6e3 3060@cindex break on load/unload of shared library
c906108c
SS
3061The dynamic loading of any shared library, or the loading of the library
3062@var{libname}. This is currently only available for HP-UX.
3063
3064@item unload
3065@itemx unload @var{libname}
c906108c
SS
3066The unloading of any dynamically loaded shared library, or the unloading
3067of the library @var{libname}. This is currently only available for HP-UX.
3068@end table
3069
3070@item tcatch @var{event}
3071Set a catchpoint that is enabled only for one stop. The catchpoint is
3072automatically deleted after the first time the event is caught.
3073
3074@end table
3075
3076Use the @code{info break} command to list the current catchpoints.
3077
b37052ae 3078There are currently some limitations to C@t{++} exception handling
c906108c
SS
3079(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3080
3081@itemize @bullet
3082@item
3083If you call a function interactively, @value{GDBN} normally returns
3084control to you when the function has finished executing. If the call
3085raises an exception, however, the call may bypass the mechanism that
3086returns control to you and cause your program either to abort or to
3087simply continue running until it hits a breakpoint, catches a signal
3088that @value{GDBN} is listening for, or exits. This is the case even if
3089you set a catchpoint for the exception; catchpoints on exceptions are
3090disabled within interactive calls.
3091
3092@item
3093You cannot raise an exception interactively.
3094
3095@item
3096You cannot install an exception handler interactively.
3097@end itemize
3098
3099@cindex raise exceptions
3100Sometimes @code{catch} is not the best way to debug exception handling:
3101if you need to know exactly where an exception is raised, it is better to
3102stop @emph{before} the exception handler is called, since that way you
3103can see the stack before any unwinding takes place. If you set a
3104breakpoint in an exception handler instead, it may not be easy to find
3105out where the exception was raised.
3106
3107To stop just before an exception handler is called, you need some
b37052ae 3108knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3109raised by calling a library function named @code{__raise_exception}
3110which has the following ANSI C interface:
3111
474c8240 3112@smallexample
c906108c 3113 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3114 @var{id} is the exception identifier. */
3115 void __raise_exception (void **addr, void *id);
474c8240 3116@end smallexample
c906108c
SS
3117
3118@noindent
3119To make the debugger catch all exceptions before any stack
3120unwinding takes place, set a breakpoint on @code{__raise_exception}
3121(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3122
3123With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3124that depends on the value of @var{id}, you can stop your program when
3125a specific exception is raised. You can use multiple conditional
3126breakpoints to stop your program when any of a number of exceptions are
3127raised.
3128
3129
6d2ebf8b 3130@node Delete Breaks
c906108c
SS
3131@subsection Deleting breakpoints
3132
3133@cindex clearing breakpoints, watchpoints, catchpoints
3134@cindex deleting breakpoints, watchpoints, catchpoints
3135It is often necessary to eliminate a breakpoint, watchpoint, or
3136catchpoint once it has done its job and you no longer want your program
3137to stop there. This is called @dfn{deleting} the breakpoint. A
3138breakpoint that has been deleted no longer exists; it is forgotten.
3139
3140With the @code{clear} command you can delete breakpoints according to
3141where they are in your program. With the @code{delete} command you can
3142delete individual breakpoints, watchpoints, or catchpoints by specifying
3143their breakpoint numbers.
3144
3145It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3146automatically ignores breakpoints on the first instruction to be executed
3147when you continue execution without changing the execution address.
3148
3149@table @code
3150@kindex clear
3151@item clear
3152Delete any breakpoints at the next instruction to be executed in the
3153selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3154the innermost frame is selected, this is a good way to delete a
3155breakpoint where your program just stopped.
3156
3157@item clear @var{function}
3158@itemx clear @var{filename}:@var{function}
09d4efe1 3159Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3160
3161@item clear @var{linenum}
3162@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3163Delete any breakpoints set at or within the code of the specified
3164@var{linenum} of the specified @var{filename}.
c906108c
SS
3165
3166@cindex delete breakpoints
3167@kindex delete
41afff9a 3168@kindex d @r{(@code{delete})}
c5394b80
JM
3169@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3170Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3171ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3172breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3173confirm off}). You can abbreviate this command as @code{d}.
3174@end table
3175
6d2ebf8b 3176@node Disabling
c906108c
SS
3177@subsection Disabling breakpoints
3178
4644b6e3 3179@cindex enable/disable a breakpoint
c906108c
SS
3180Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3181prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3182it had been deleted, but remembers the information on the breakpoint so
3183that you can @dfn{enable} it again later.
3184
3185You disable and enable breakpoints, watchpoints, and catchpoints with
3186the @code{enable} and @code{disable} commands, optionally specifying one
3187or more breakpoint numbers as arguments. Use @code{info break} or
3188@code{info watch} to print a list of breakpoints, watchpoints, and
3189catchpoints if you do not know which numbers to use.
3190
3191A breakpoint, watchpoint, or catchpoint can have any of four different
3192states of enablement:
3193
3194@itemize @bullet
3195@item
3196Enabled. The breakpoint stops your program. A breakpoint set
3197with the @code{break} command starts out in this state.
3198@item
3199Disabled. The breakpoint has no effect on your program.
3200@item
3201Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3202disabled.
c906108c
SS
3203@item
3204Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3205immediately after it does so it is deleted permanently. A breakpoint
3206set with the @code{tbreak} command starts out in this state.
c906108c
SS
3207@end itemize
3208
3209You can use the following commands to enable or disable breakpoints,
3210watchpoints, and catchpoints:
3211
3212@table @code
c906108c 3213@kindex disable
41afff9a 3214@kindex dis @r{(@code{disable})}
c5394b80 3215@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3216Disable the specified breakpoints---or all breakpoints, if none are
3217listed. A disabled breakpoint has no effect but is not forgotten. All
3218options such as ignore-counts, conditions and commands are remembered in
3219case the breakpoint is enabled again later. You may abbreviate
3220@code{disable} as @code{dis}.
3221
c906108c 3222@kindex enable
c5394b80 3223@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3224Enable the specified breakpoints (or all defined breakpoints). They
3225become effective once again in stopping your program.
3226
c5394b80 3227@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3228Enable the specified breakpoints temporarily. @value{GDBN} disables any
3229of these breakpoints immediately after stopping your program.
3230
c5394b80 3231@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3232Enable the specified breakpoints to work once, then die. @value{GDBN}
3233deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3234Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3235@end table
3236
d4f3574e
SS
3237@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3238@c confusing: tbreak is also initially enabled.
c906108c
SS
3239Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3240,Setting breakpoints}), breakpoints that you set are initially enabled;
3241subsequently, they become disabled or enabled only when you use one of
3242the commands above. (The command @code{until} can set and delete a
3243breakpoint of its own, but it does not change the state of your other
3244breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3245stepping}.)
3246
6d2ebf8b 3247@node Conditions
c906108c
SS
3248@subsection Break conditions
3249@cindex conditional breakpoints
3250@cindex breakpoint conditions
3251
3252@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3253@c in particular for a watchpoint?
c906108c
SS
3254The simplest sort of breakpoint breaks every time your program reaches a
3255specified place. You can also specify a @dfn{condition} for a
3256breakpoint. A condition is just a Boolean expression in your
3257programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3258a condition evaluates the expression each time your program reaches it,
3259and your program stops only if the condition is @emph{true}.
3260
3261This is the converse of using assertions for program validation; in that
3262situation, you want to stop when the assertion is violated---that is,
3263when the condition is false. In C, if you want to test an assertion expressed
3264by the condition @var{assert}, you should set the condition
3265@samp{! @var{assert}} on the appropriate breakpoint.
3266
3267Conditions are also accepted for watchpoints; you may not need them,
3268since a watchpoint is inspecting the value of an expression anyhow---but
3269it might be simpler, say, to just set a watchpoint on a variable name,
3270and specify a condition that tests whether the new value is an interesting
3271one.
3272
3273Break conditions can have side effects, and may even call functions in
3274your program. This can be useful, for example, to activate functions
3275that log program progress, or to use your own print functions to
3276format special data structures. The effects are completely predictable
3277unless there is another enabled breakpoint at the same address. (In
3278that case, @value{GDBN} might see the other breakpoint first and stop your
3279program without checking the condition of this one.) Note that
d4f3574e
SS
3280breakpoint commands are usually more convenient and flexible than break
3281conditions for the
c906108c
SS
3282purpose of performing side effects when a breakpoint is reached
3283(@pxref{Break Commands, ,Breakpoint command lists}).
3284
3285Break conditions can be specified when a breakpoint is set, by using
3286@samp{if} in the arguments to the @code{break} command. @xref{Set
3287Breaks, ,Setting breakpoints}. They can also be changed at any time
3288with the @code{condition} command.
53a5351d 3289
c906108c
SS
3290You can also use the @code{if} keyword with the @code{watch} command.
3291The @code{catch} command does not recognize the @code{if} keyword;
3292@code{condition} is the only way to impose a further condition on a
3293catchpoint.
c906108c
SS
3294
3295@table @code
3296@kindex condition
3297@item condition @var{bnum} @var{expression}
3298Specify @var{expression} as the break condition for breakpoint,
3299watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3300breakpoint @var{bnum} stops your program only if the value of
3301@var{expression} is true (nonzero, in C). When you use
3302@code{condition}, @value{GDBN} checks @var{expression} immediately for
3303syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3304referents in the context of your breakpoint. If @var{expression} uses
3305symbols not referenced in the context of the breakpoint, @value{GDBN}
3306prints an error message:
3307
474c8240 3308@smallexample
d4f3574e 3309No symbol "foo" in current context.
474c8240 3310@end smallexample
d4f3574e
SS
3311
3312@noindent
c906108c
SS
3313@value{GDBN} does
3314not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3315command (or a command that sets a breakpoint with a condition, like
3316@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3317
3318@item condition @var{bnum}
3319Remove the condition from breakpoint number @var{bnum}. It becomes
3320an ordinary unconditional breakpoint.
3321@end table
3322
3323@cindex ignore count (of breakpoint)
3324A special case of a breakpoint condition is to stop only when the
3325breakpoint has been reached a certain number of times. This is so
3326useful that there is a special way to do it, using the @dfn{ignore
3327count} of the breakpoint. Every breakpoint has an ignore count, which
3328is an integer. Most of the time, the ignore count is zero, and
3329therefore has no effect. But if your program reaches a breakpoint whose
3330ignore count is positive, then instead of stopping, it just decrements
3331the ignore count by one and continues. As a result, if the ignore count
3332value is @var{n}, the breakpoint does not stop the next @var{n} times
3333your program reaches it.
3334
3335@table @code
3336@kindex ignore
3337@item ignore @var{bnum} @var{count}
3338Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3339The next @var{count} times the breakpoint is reached, your program's
3340execution does not stop; other than to decrement the ignore count, @value{GDBN}
3341takes no action.
3342
3343To make the breakpoint stop the next time it is reached, specify
3344a count of zero.
3345
3346When you use @code{continue} to resume execution of your program from a
3347breakpoint, you can specify an ignore count directly as an argument to
3348@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3349Stepping,,Continuing and stepping}.
3350
3351If a breakpoint has a positive ignore count and a condition, the
3352condition is not checked. Once the ignore count reaches zero,
3353@value{GDBN} resumes checking the condition.
3354
3355You could achieve the effect of the ignore count with a condition such
3356as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3357is decremented each time. @xref{Convenience Vars, ,Convenience
3358variables}.
3359@end table
3360
3361Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3362
3363
6d2ebf8b 3364@node Break Commands
c906108c
SS
3365@subsection Breakpoint command lists
3366
3367@cindex breakpoint commands
3368You can give any breakpoint (or watchpoint or catchpoint) a series of
3369commands to execute when your program stops due to that breakpoint. For
3370example, you might want to print the values of certain expressions, or
3371enable other breakpoints.
3372
3373@table @code
3374@kindex commands
3375@kindex end
3376@item commands @r{[}@var{bnum}@r{]}
3377@itemx @dots{} @var{command-list} @dots{}
3378@itemx end
3379Specify a list of commands for breakpoint number @var{bnum}. The commands
3380themselves appear on the following lines. Type a line containing just
3381@code{end} to terminate the commands.
3382
3383To remove all commands from a breakpoint, type @code{commands} and
3384follow it immediately with @code{end}; that is, give no commands.
3385
3386With no @var{bnum} argument, @code{commands} refers to the last
3387breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3388recently encountered).
3389@end table
3390
3391Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3392disabled within a @var{command-list}.
3393
3394You can use breakpoint commands to start your program up again. Simply
3395use the @code{continue} command, or @code{step}, or any other command
3396that resumes execution.
3397
3398Any other commands in the command list, after a command that resumes
3399execution, are ignored. This is because any time you resume execution
3400(even with a simple @code{next} or @code{step}), you may encounter
3401another breakpoint---which could have its own command list, leading to
3402ambiguities about which list to execute.
3403
3404@kindex silent
3405If the first command you specify in a command list is @code{silent}, the
3406usual message about stopping at a breakpoint is not printed. This may
3407be desirable for breakpoints that are to print a specific message and
3408then continue. If none of the remaining commands print anything, you
3409see no sign that the breakpoint was reached. @code{silent} is
3410meaningful only at the beginning of a breakpoint command list.
3411
3412The commands @code{echo}, @code{output}, and @code{printf} allow you to
3413print precisely controlled output, and are often useful in silent
3414breakpoints. @xref{Output, ,Commands for controlled output}.
3415
3416For example, here is how you could use breakpoint commands to print the
3417value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3418
474c8240 3419@smallexample
c906108c
SS
3420break foo if x>0
3421commands
3422silent
3423printf "x is %d\n",x
3424cont
3425end
474c8240 3426@end smallexample
c906108c
SS
3427
3428One application for breakpoint commands is to compensate for one bug so
3429you can test for another. Put a breakpoint just after the erroneous line
3430of code, give it a condition to detect the case in which something
3431erroneous has been done, and give it commands to assign correct values
3432to any variables that need them. End with the @code{continue} command
3433so that your program does not stop, and start with the @code{silent}
3434command so that no output is produced. Here is an example:
3435
474c8240 3436@smallexample
c906108c
SS
3437break 403
3438commands
3439silent
3440set x = y + 4
3441cont
3442end
474c8240 3443@end smallexample
c906108c 3444
6d2ebf8b 3445@node Breakpoint Menus
c906108c
SS
3446@subsection Breakpoint menus
3447@cindex overloading
3448@cindex symbol overloading
3449
b383017d 3450Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3451single function name
c906108c
SS
3452to be defined several times, for application in different contexts.
3453This is called @dfn{overloading}. When a function name is overloaded,
3454@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3455a breakpoint. If you realize this is a problem, you can use
3456something like @samp{break @var{function}(@var{types})} to specify which
3457particular version of the function you want. Otherwise, @value{GDBN} offers
3458you a menu of numbered choices for different possible breakpoints, and
3459waits for your selection with the prompt @samp{>}. The first two
3460options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3461sets a breakpoint at each definition of @var{function}, and typing
3462@kbd{0} aborts the @code{break} command without setting any new
3463breakpoints.
3464
3465For example, the following session excerpt shows an attempt to set a
3466breakpoint at the overloaded symbol @code{String::after}.
3467We choose three particular definitions of that function name:
3468
3469@c FIXME! This is likely to change to show arg type lists, at least
3470@smallexample
3471@group
3472(@value{GDBP}) b String::after
3473[0] cancel
3474[1] all
3475[2] file:String.cc; line number:867
3476[3] file:String.cc; line number:860
3477[4] file:String.cc; line number:875
3478[5] file:String.cc; line number:853
3479[6] file:String.cc; line number:846
3480[7] file:String.cc; line number:735
3481> 2 4 6
3482Breakpoint 1 at 0xb26c: file String.cc, line 867.
3483Breakpoint 2 at 0xb344: file String.cc, line 875.
3484Breakpoint 3 at 0xafcc: file String.cc, line 846.
3485Multiple breakpoints were set.
3486Use the "delete" command to delete unwanted
3487 breakpoints.
3488(@value{GDBP})
3489@end group
3490@end smallexample
c906108c
SS
3491
3492@c @ifclear BARETARGET
6d2ebf8b 3493@node Error in Breakpoints
d4f3574e 3494@subsection ``Cannot insert breakpoints''
c906108c
SS
3495@c
3496@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3497@c
d4f3574e
SS
3498Under some operating systems, breakpoints cannot be used in a program if
3499any other process is running that program. In this situation,
5d161b24 3500attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3501@value{GDBN} to print an error message:
3502
474c8240 3503@smallexample
d4f3574e
SS
3504Cannot insert breakpoints.
3505The same program may be running in another process.
474c8240 3506@end smallexample
d4f3574e
SS
3507
3508When this happens, you have three ways to proceed:
3509
3510@enumerate
3511@item
3512Remove or disable the breakpoints, then continue.
3513
3514@item
5d161b24 3515Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3516name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3517that @value{GDBN} should run your program under that name.
d4f3574e
SS
3518Then start your program again.
3519
3520@item
3521Relink your program so that the text segment is nonsharable, using the
3522linker option @samp{-N}. The operating system limitation may not apply
3523to nonsharable executables.
3524@end enumerate
c906108c
SS
3525@c @end ifclear
3526
d4f3574e
SS
3527A similar message can be printed if you request too many active
3528hardware-assisted breakpoints and watchpoints:
3529
3530@c FIXME: the precise wording of this message may change; the relevant
3531@c source change is not committed yet (Sep 3, 1999).
3532@smallexample
3533Stopped; cannot insert breakpoints.
3534You may have requested too many hardware breakpoints and watchpoints.
3535@end smallexample
3536
3537@noindent
3538This message is printed when you attempt to resume the program, since
3539only then @value{GDBN} knows exactly how many hardware breakpoints and
3540watchpoints it needs to insert.
3541
3542When this message is printed, you need to disable or remove some of the
3543hardware-assisted breakpoints and watchpoints, and then continue.
3544
1485d690
KB
3545@node Breakpoint related warnings
3546@subsection ``Breakpoint address adjusted...''
3547@cindex breakpoint address adjusted
3548
3549Some processor architectures place constraints on the addresses at
3550which breakpoints may be placed. For architectures thus constrained,
3551@value{GDBN} will attempt to adjust the breakpoint's address to comply
3552with the constraints dictated by the architecture.
3553
3554One example of such an architecture is the Fujitsu FR-V. The FR-V is
3555a VLIW architecture in which a number of RISC-like instructions may be
3556bundled together for parallel execution. The FR-V architecture
3557constrains the location of a breakpoint instruction within such a
3558bundle to the instruction with the lowest address. @value{GDBN}
3559honors this constraint by adjusting a breakpoint's address to the
3560first in the bundle.
3561
3562It is not uncommon for optimized code to have bundles which contain
3563instructions from different source statements, thus it may happen that
3564a breakpoint's address will be adjusted from one source statement to
3565another. Since this adjustment may significantly alter @value{GDBN}'s
3566breakpoint related behavior from what the user expects, a warning is
3567printed when the breakpoint is first set and also when the breakpoint
3568is hit.
3569
3570A warning like the one below is printed when setting a breakpoint
3571that's been subject to address adjustment:
3572
3573@smallexample
3574warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3575@end smallexample
3576
3577Such warnings are printed both for user settable and @value{GDBN}'s
3578internal breakpoints. If you see one of these warnings, you should
3579verify that a breakpoint set at the adjusted address will have the
3580desired affect. If not, the breakpoint in question may be removed and
b383017d 3581other breakpoints may be set which will have the desired behavior.
1485d690
KB
3582E.g., it may be sufficient to place the breakpoint at a later
3583instruction. A conditional breakpoint may also be useful in some
3584cases to prevent the breakpoint from triggering too often.
3585
3586@value{GDBN} will also issue a warning when stopping at one of these
3587adjusted breakpoints:
3588
3589@smallexample
3590warning: Breakpoint 1 address previously adjusted from 0x00010414
3591to 0x00010410.
3592@end smallexample
3593
3594When this warning is encountered, it may be too late to take remedial
3595action except in cases where the breakpoint is hit earlier or more
3596frequently than expected.
d4f3574e 3597
6d2ebf8b 3598@node Continuing and Stepping
c906108c
SS
3599@section Continuing and stepping
3600
3601@cindex stepping
3602@cindex continuing
3603@cindex resuming execution
3604@dfn{Continuing} means resuming program execution until your program
3605completes normally. In contrast, @dfn{stepping} means executing just
3606one more ``step'' of your program, where ``step'' may mean either one
3607line of source code, or one machine instruction (depending on what
7a292a7a
SS
3608particular command you use). Either when continuing or when stepping,
3609your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3610it stops due to a signal, you may want to use @code{handle}, or use
3611@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3612
3613@table @code
3614@kindex continue
41afff9a
EZ
3615@kindex c @r{(@code{continue})}
3616@kindex fg @r{(resume foreground execution)}
c906108c
SS
3617@item continue @r{[}@var{ignore-count}@r{]}
3618@itemx c @r{[}@var{ignore-count}@r{]}
3619@itemx fg @r{[}@var{ignore-count}@r{]}
3620Resume program execution, at the address where your program last stopped;
3621any breakpoints set at that address are bypassed. The optional argument
3622@var{ignore-count} allows you to specify a further number of times to
3623ignore a breakpoint at this location; its effect is like that of
3624@code{ignore} (@pxref{Conditions, ,Break conditions}).
3625
3626The argument @var{ignore-count} is meaningful only when your program
3627stopped due to a breakpoint. At other times, the argument to
3628@code{continue} is ignored.
3629
d4f3574e
SS
3630The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3631debugged program is deemed to be the foreground program) are provided
3632purely for convenience, and have exactly the same behavior as
3633@code{continue}.
c906108c
SS
3634@end table
3635
3636To resume execution at a different place, you can use @code{return}
3637(@pxref{Returning, ,Returning from a function}) to go back to the
3638calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3639different address}) to go to an arbitrary location in your program.
3640
3641A typical technique for using stepping is to set a breakpoint
3642(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3643beginning of the function or the section of your program where a problem
3644is believed to lie, run your program until it stops at that breakpoint,
3645and then step through the suspect area, examining the variables that are
3646interesting, until you see the problem happen.
3647
3648@table @code
3649@kindex step
41afff9a 3650@kindex s @r{(@code{step})}
c906108c
SS
3651@item step
3652Continue running your program until control reaches a different source
3653line, then stop it and return control to @value{GDBN}. This command is
3654abbreviated @code{s}.
3655
3656@quotation
3657@c "without debugging information" is imprecise; actually "without line
3658@c numbers in the debugging information". (gcc -g1 has debugging info but
3659@c not line numbers). But it seems complex to try to make that
3660@c distinction here.
3661@emph{Warning:} If you use the @code{step} command while control is
3662within a function that was compiled without debugging information,
3663execution proceeds until control reaches a function that does have
3664debugging information. Likewise, it will not step into a function which
3665is compiled without debugging information. To step through functions
3666without debugging information, use the @code{stepi} command, described
3667below.
3668@end quotation
3669
4a92d011
EZ
3670The @code{step} command only stops at the first instruction of a source
3671line. This prevents the multiple stops that could otherwise occur in
3672@code{switch} statements, @code{for} loops, etc. @code{step} continues
3673to stop if a function that has debugging information is called within
3674the line. In other words, @code{step} @emph{steps inside} any functions
3675called within the line.
c906108c 3676
d4f3574e
SS
3677Also, the @code{step} command only enters a function if there is line
3678number information for the function. Otherwise it acts like the
5d161b24 3679@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3680on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3681was any debugging information about the routine.
c906108c
SS
3682
3683@item step @var{count}
3684Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3685breakpoint is reached, or a signal not related to stepping occurs before
3686@var{count} steps, stepping stops right away.
c906108c
SS
3687
3688@kindex next
41afff9a 3689@kindex n @r{(@code{next})}
c906108c
SS
3690@item next @r{[}@var{count}@r{]}
3691Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3692This is similar to @code{step}, but function calls that appear within
3693the line of code are executed without stopping. Execution stops when
3694control reaches a different line of code at the original stack level
3695that was executing when you gave the @code{next} command. This command
3696is abbreviated @code{n}.
c906108c
SS
3697
3698An argument @var{count} is a repeat count, as for @code{step}.
3699
3700
3701@c FIX ME!! Do we delete this, or is there a way it fits in with
3702@c the following paragraph? --- Vctoria
3703@c
3704@c @code{next} within a function that lacks debugging information acts like
3705@c @code{step}, but any function calls appearing within the code of the
3706@c function are executed without stopping.
3707
d4f3574e
SS
3708The @code{next} command only stops at the first instruction of a
3709source line. This prevents multiple stops that could otherwise occur in
4a92d011 3710@code{switch} statements, @code{for} loops, etc.
c906108c 3711
b90a5f51
CF
3712@kindex set step-mode
3713@item set step-mode
3714@cindex functions without line info, and stepping
3715@cindex stepping into functions with no line info
3716@itemx set step-mode on
4a92d011 3717The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3718stop at the first instruction of a function which contains no debug line
3719information rather than stepping over it.
3720
4a92d011
EZ
3721This is useful in cases where you may be interested in inspecting the
3722machine instructions of a function which has no symbolic info and do not
3723want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3724
3725@item set step-mode off
4a92d011 3726Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3727debug information. This is the default.
3728
9c16f35a
EZ
3729@item show step-mode
3730Show whether @value{GDBN} will stop in or step over functions without
3731source line debug information.
3732
c906108c
SS
3733@kindex finish
3734@item finish
3735Continue running until just after function in the selected stack frame
3736returns. Print the returned value (if any).
3737
3738Contrast this with the @code{return} command (@pxref{Returning,
3739,Returning from a function}).
3740
3741@kindex until
41afff9a 3742@kindex u @r{(@code{until})}
09d4efe1 3743@cindex run until specified location
c906108c
SS
3744@item until
3745@itemx u
3746Continue running until a source line past the current line, in the
3747current stack frame, is reached. This command is used to avoid single
3748stepping through a loop more than once. It is like the @code{next}
3749command, except that when @code{until} encounters a jump, it
3750automatically continues execution until the program counter is greater
3751than the address of the jump.
3752
3753This means that when you reach the end of a loop after single stepping
3754though it, @code{until} makes your program continue execution until it
3755exits the loop. In contrast, a @code{next} command at the end of a loop
3756simply steps back to the beginning of the loop, which forces you to step
3757through the next iteration.
3758
3759@code{until} always stops your program if it attempts to exit the current
3760stack frame.
3761
3762@code{until} may produce somewhat counterintuitive results if the order
3763of machine code does not match the order of the source lines. For
3764example, in the following excerpt from a debugging session, the @code{f}
3765(@code{frame}) command shows that execution is stopped at line
3766@code{206}; yet when we use @code{until}, we get to line @code{195}:
3767
474c8240 3768@smallexample
c906108c
SS
3769(@value{GDBP}) f
3770#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3771206 expand_input();
3772(@value{GDBP}) until
3773195 for ( ; argc > 0; NEXTARG) @{
474c8240 3774@end smallexample
c906108c
SS
3775
3776This happened because, for execution efficiency, the compiler had
3777generated code for the loop closure test at the end, rather than the
3778start, of the loop---even though the test in a C @code{for}-loop is
3779written before the body of the loop. The @code{until} command appeared
3780to step back to the beginning of the loop when it advanced to this
3781expression; however, it has not really gone to an earlier
3782statement---not in terms of the actual machine code.
3783
3784@code{until} with no argument works by means of single
3785instruction stepping, and hence is slower than @code{until} with an
3786argument.
3787
3788@item until @var{location}
3789@itemx u @var{location}
3790Continue running your program until either the specified location is
3791reached, or the current stack frame returns. @var{location} is any of
3792the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3793,Setting breakpoints}). This form of the command uses breakpoints, and
3794hence is quicker than @code{until} without an argument. The specified
3795location is actually reached only if it is in the current frame. This
3796implies that @code{until} can be used to skip over recursive function
3797invocations. For instance in the code below, if the current location is
3798line @code{96}, issuing @code{until 99} will execute the program up to
3799line @code{99} in the same invocation of factorial, i.e. after the inner
3800invocations have returned.
3801
3802@smallexample
380394 int factorial (int value)
380495 @{
380596 if (value > 1) @{
380697 value *= factorial (value - 1);
380798 @}
380899 return (value);
3809100 @}
3810@end smallexample
3811
3812
3813@kindex advance @var{location}
3814@itemx advance @var{location}
09d4efe1
EZ
3815Continue running the program up to the given @var{location}. An argument is
3816required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3817command. Execution will also stop upon exit from the current stack
3818frame. This command is similar to @code{until}, but @code{advance} will
3819not skip over recursive function calls, and the target location doesn't
3820have to be in the same frame as the current one.
3821
c906108c
SS
3822
3823@kindex stepi
41afff9a 3824@kindex si @r{(@code{stepi})}
c906108c 3825@item stepi
96a2c332 3826@itemx stepi @var{arg}
c906108c
SS
3827@itemx si
3828Execute one machine instruction, then stop and return to the debugger.
3829
3830It is often useful to do @samp{display/i $pc} when stepping by machine
3831instructions. This makes @value{GDBN} automatically display the next
3832instruction to be executed, each time your program stops. @xref{Auto
3833Display,, Automatic display}.
3834
3835An argument is a repeat count, as in @code{step}.
3836
3837@need 750
3838@kindex nexti
41afff9a 3839@kindex ni @r{(@code{nexti})}
c906108c 3840@item nexti
96a2c332 3841@itemx nexti @var{arg}
c906108c
SS
3842@itemx ni
3843Execute one machine instruction, but if it is a function call,
3844proceed until the function returns.
3845
3846An argument is a repeat count, as in @code{next}.
3847@end table
3848
6d2ebf8b 3849@node Signals
c906108c
SS
3850@section Signals
3851@cindex signals
3852
3853A signal is an asynchronous event that can happen in a program. The
3854operating system defines the possible kinds of signals, and gives each
3855kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3856signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3857@code{SIGSEGV} is the signal a program gets from referencing a place in
3858memory far away from all the areas in use; @code{SIGALRM} occurs when
3859the alarm clock timer goes off (which happens only if your program has
3860requested an alarm).
3861
3862@cindex fatal signals
3863Some signals, including @code{SIGALRM}, are a normal part of the
3864functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3865errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3866program has not specified in advance some other way to handle the signal.
3867@code{SIGINT} does not indicate an error in your program, but it is normally
3868fatal so it can carry out the purpose of the interrupt: to kill the program.
3869
3870@value{GDBN} has the ability to detect any occurrence of a signal in your
3871program. You can tell @value{GDBN} in advance what to do for each kind of
3872signal.
3873
3874@cindex handling signals
24f93129
EZ
3875Normally, @value{GDBN} is set up to let the non-erroneous signals like
3876@code{SIGALRM} be silently passed to your program
3877(so as not to interfere with their role in the program's functioning)
c906108c
SS
3878but to stop your program immediately whenever an error signal happens.
3879You can change these settings with the @code{handle} command.
3880
3881@table @code
3882@kindex info signals
09d4efe1 3883@kindex info handle
c906108c 3884@item info signals
96a2c332 3885@itemx info handle
c906108c
SS
3886Print a table of all the kinds of signals and how @value{GDBN} has been told to
3887handle each one. You can use this to see the signal numbers of all
3888the defined types of signals.
3889
d4f3574e 3890@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3891
3892@kindex handle
3893@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3894Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3895can be the number of a signal or its name (with or without the
24f93129 3896@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3897@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3898known signals. The @var{keywords} say what change to make.
c906108c
SS
3899@end table
3900
3901@c @group
3902The keywords allowed by the @code{handle} command can be abbreviated.
3903Their full names are:
3904
3905@table @code
3906@item nostop
3907@value{GDBN} should not stop your program when this signal happens. It may
3908still print a message telling you that the signal has come in.
3909
3910@item stop
3911@value{GDBN} should stop your program when this signal happens. This implies
3912the @code{print} keyword as well.
3913
3914@item print
3915@value{GDBN} should print a message when this signal happens.
3916
3917@item noprint
3918@value{GDBN} should not mention the occurrence of the signal at all. This
3919implies the @code{nostop} keyword as well.
3920
3921@item pass
5ece1a18 3922@itemx noignore
c906108c
SS
3923@value{GDBN} should allow your program to see this signal; your program
3924can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3925and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3926
3927@item nopass
5ece1a18 3928@itemx ignore
c906108c 3929@value{GDBN} should not allow your program to see this signal.
5ece1a18 3930@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3931@end table
3932@c @end group
3933
d4f3574e
SS
3934When a signal stops your program, the signal is not visible to the
3935program until you
c906108c
SS
3936continue. Your program sees the signal then, if @code{pass} is in
3937effect for the signal in question @emph{at that time}. In other words,
3938after @value{GDBN} reports a signal, you can use the @code{handle}
3939command with @code{pass} or @code{nopass} to control whether your
3940program sees that signal when you continue.
3941
24f93129
EZ
3942The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3943non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3944@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3945erroneous signals.
3946
c906108c
SS
3947You can also use the @code{signal} command to prevent your program from
3948seeing a signal, or cause it to see a signal it normally would not see,
3949or to give it any signal at any time. For example, if your program stopped
3950due to some sort of memory reference error, you might store correct
3951values into the erroneous variables and continue, hoping to see more
3952execution; but your program would probably terminate immediately as
3953a result of the fatal signal once it saw the signal. To prevent this,
3954you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3955program a signal}.
c906108c 3956
6d2ebf8b 3957@node Thread Stops
c906108c
SS
3958@section Stopping and starting multi-thread programs
3959
3960When your program has multiple threads (@pxref{Threads,, Debugging
3961programs with multiple threads}), you can choose whether to set
3962breakpoints on all threads, or on a particular thread.
3963
3964@table @code
3965@cindex breakpoints and threads
3966@cindex thread breakpoints
3967@kindex break @dots{} thread @var{threadno}
3968@item break @var{linespec} thread @var{threadno}
3969@itemx break @var{linespec} thread @var{threadno} if @dots{}
3970@var{linespec} specifies source lines; there are several ways of
3971writing them, but the effect is always to specify some source line.
3972
3973Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3974to specify that you only want @value{GDBN} to stop the program when a
3975particular thread reaches this breakpoint. @var{threadno} is one of the
3976numeric thread identifiers assigned by @value{GDBN}, shown in the first
3977column of the @samp{info threads} display.
3978
3979If you do not specify @samp{thread @var{threadno}} when you set a
3980breakpoint, the breakpoint applies to @emph{all} threads of your
3981program.
3982
3983You can use the @code{thread} qualifier on conditional breakpoints as
3984well; in this case, place @samp{thread @var{threadno}} before the
3985breakpoint condition, like this:
3986
3987@smallexample
2df3850c 3988(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3989@end smallexample
3990
3991@end table
3992
3993@cindex stopped threads
3994@cindex threads, stopped
3995Whenever your program stops under @value{GDBN} for any reason,
3996@emph{all} threads of execution stop, not just the current thread. This
3997allows you to examine the overall state of the program, including
3998switching between threads, without worrying that things may change
3999underfoot.
4000
36d86913
MC
4001@cindex thread breakpoints and system calls
4002@cindex system calls and thread breakpoints
4003@cindex premature return from system calls
4004There is an unfortunate side effect. If one thread stops for a
4005breakpoint, or for some other reason, and another thread is blocked in a
4006system call, then the system call may return prematurely. This is a
4007consequence of the interaction between multiple threads and the signals
4008that @value{GDBN} uses to implement breakpoints and other events that
4009stop execution.
4010
4011To handle this problem, your program should check the return value of
4012each system call and react appropriately. This is good programming
4013style anyways.
4014
4015For example, do not write code like this:
4016
4017@smallexample
4018 sleep (10);
4019@end smallexample
4020
4021The call to @code{sleep} will return early if a different thread stops
4022at a breakpoint or for some other reason.
4023
4024Instead, write this:
4025
4026@smallexample
4027 int unslept = 10;
4028 while (unslept > 0)
4029 unslept = sleep (unslept);
4030@end smallexample
4031
4032A system call is allowed to return early, so the system is still
4033conforming to its specification. But @value{GDBN} does cause your
4034multi-threaded program to behave differently than it would without
4035@value{GDBN}.
4036
4037Also, @value{GDBN} uses internal breakpoints in the thread library to
4038monitor certain events such as thread creation and thread destruction.
4039When such an event happens, a system call in another thread may return
4040prematurely, even though your program does not appear to stop.
4041
c906108c
SS
4042@cindex continuing threads
4043@cindex threads, continuing
4044Conversely, whenever you restart the program, @emph{all} threads start
4045executing. @emph{This is true even when single-stepping} with commands
5d161b24 4046like @code{step} or @code{next}.
c906108c
SS
4047
4048In particular, @value{GDBN} cannot single-step all threads in lockstep.
4049Since thread scheduling is up to your debugging target's operating
4050system (not controlled by @value{GDBN}), other threads may
4051execute more than one statement while the current thread completes a
4052single step. Moreover, in general other threads stop in the middle of a
4053statement, rather than at a clean statement boundary, when the program
4054stops.
4055
4056You might even find your program stopped in another thread after
4057continuing or even single-stepping. This happens whenever some other
4058thread runs into a breakpoint, a signal, or an exception before the
4059first thread completes whatever you requested.
4060
4061On some OSes, you can lock the OS scheduler and thus allow only a single
4062thread to run.
4063
4064@table @code
4065@item set scheduler-locking @var{mode}
9c16f35a
EZ
4066@cindex scheduler locking mode
4067@cindex lock scheduler
c906108c
SS
4068Set the scheduler locking mode. If it is @code{off}, then there is no
4069locking and any thread may run at any time. If @code{on}, then only the
4070current thread may run when the inferior is resumed. The @code{step}
4071mode optimizes for single-stepping. It stops other threads from
4072``seizing the prompt'' by preempting the current thread while you are
4073stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4074when you step. They are more likely to run when you @samp{next} over a
c906108c 4075function call, and they are completely free to run when you use commands
d4f3574e 4076like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4077thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4078@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4079
4080@item show scheduler-locking
4081Display the current scheduler locking mode.
4082@end table
4083
c906108c 4084
6d2ebf8b 4085@node Stack
c906108c
SS
4086@chapter Examining the Stack
4087
4088When your program has stopped, the first thing you need to know is where it
4089stopped and how it got there.
4090
4091@cindex call stack
5d161b24
DB
4092Each time your program performs a function call, information about the call
4093is generated.
4094That information includes the location of the call in your program,
4095the arguments of the call,
c906108c 4096and the local variables of the function being called.
5d161b24 4097The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4098The stack frames are allocated in a region of memory called the @dfn{call
4099stack}.
4100
4101When your program stops, the @value{GDBN} commands for examining the
4102stack allow you to see all of this information.
4103
4104@cindex selected frame
4105One of the stack frames is @dfn{selected} by @value{GDBN} and many
4106@value{GDBN} commands refer implicitly to the selected frame. In
4107particular, whenever you ask @value{GDBN} for the value of a variable in
4108your program, the value is found in the selected frame. There are
4109special @value{GDBN} commands to select whichever frame you are
4110interested in. @xref{Selection, ,Selecting a frame}.
4111
4112When your program stops, @value{GDBN} automatically selects the
5d161b24 4113currently executing frame and describes it briefly, similar to the
c906108c
SS
4114@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4115
4116@menu
4117* Frames:: Stack frames
4118* Backtrace:: Backtraces
4119* Selection:: Selecting a frame
4120* Frame Info:: Information on a frame
c906108c
SS
4121
4122@end menu
4123
6d2ebf8b 4124@node Frames
c906108c
SS
4125@section Stack frames
4126
d4f3574e 4127@cindex frame, definition
c906108c
SS
4128@cindex stack frame
4129The call stack is divided up into contiguous pieces called @dfn{stack
4130frames}, or @dfn{frames} for short; each frame is the data associated
4131with one call to one function. The frame contains the arguments given
4132to the function, the function's local variables, and the address at
4133which the function is executing.
4134
4135@cindex initial frame
4136@cindex outermost frame
4137@cindex innermost frame
4138When your program is started, the stack has only one frame, that of the
4139function @code{main}. This is called the @dfn{initial} frame or the
4140@dfn{outermost} frame. Each time a function is called, a new frame is
4141made. Each time a function returns, the frame for that function invocation
4142is eliminated. If a function is recursive, there can be many frames for
4143the same function. The frame for the function in which execution is
4144actually occurring is called the @dfn{innermost} frame. This is the most
4145recently created of all the stack frames that still exist.
4146
4147@cindex frame pointer
4148Inside your program, stack frames are identified by their addresses. A
4149stack frame consists of many bytes, each of which has its own address; each
4150kind of computer has a convention for choosing one byte whose
4151address serves as the address of the frame. Usually this address is kept
4152in a register called the @dfn{frame pointer register} while execution is
4153going on in that frame.
4154
4155@cindex frame number
4156@value{GDBN} assigns numbers to all existing stack frames, starting with
4157zero for the innermost frame, one for the frame that called it,
4158and so on upward. These numbers do not really exist in your program;
4159they are assigned by @value{GDBN} to give you a way of designating stack
4160frames in @value{GDBN} commands.
4161
6d2ebf8b
SS
4162@c The -fomit-frame-pointer below perennially causes hbox overflow
4163@c underflow problems.
c906108c
SS
4164@cindex frameless execution
4165Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4166without stack frames. (For example, the @value{GCC} option
474c8240 4167@smallexample
6d2ebf8b 4168@samp{-fomit-frame-pointer}
474c8240 4169@end smallexample
6d2ebf8b 4170generates functions without a frame.)
c906108c
SS
4171This is occasionally done with heavily used library functions to save
4172the frame setup time. @value{GDBN} has limited facilities for dealing
4173with these function invocations. If the innermost function invocation
4174has no stack frame, @value{GDBN} nevertheless regards it as though
4175it had a separate frame, which is numbered zero as usual, allowing
4176correct tracing of the function call chain. However, @value{GDBN} has
4177no provision for frameless functions elsewhere in the stack.
4178
4179@table @code
d4f3574e 4180@kindex frame@r{, command}
41afff9a 4181@cindex current stack frame
c906108c 4182@item frame @var{args}
5d161b24 4183The @code{frame} command allows you to move from one stack frame to another,
c906108c 4184and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4185address of the frame or the stack frame number. Without an argument,
4186@code{frame} prints the current stack frame.
c906108c
SS
4187
4188@kindex select-frame
41afff9a 4189@cindex selecting frame silently
c906108c
SS
4190@item select-frame
4191The @code{select-frame} command allows you to move from one stack frame
4192to another without printing the frame. This is the silent version of
4193@code{frame}.
4194@end table
4195
6d2ebf8b 4196@node Backtrace
c906108c
SS
4197@section Backtraces
4198
09d4efe1
EZ
4199@cindex traceback
4200@cindex call stack traces
c906108c
SS
4201A backtrace is a summary of how your program got where it is. It shows one
4202line per frame, for many frames, starting with the currently executing
4203frame (frame zero), followed by its caller (frame one), and on up the
4204stack.
4205
4206@table @code
4207@kindex backtrace
41afff9a 4208@kindex bt @r{(@code{backtrace})}
c906108c
SS
4209@item backtrace
4210@itemx bt
4211Print a backtrace of the entire stack: one line per frame for all
4212frames in the stack.
4213
4214You can stop the backtrace at any time by typing the system interrupt
4215character, normally @kbd{C-c}.
4216
4217@item backtrace @var{n}
4218@itemx bt @var{n}
4219Similar, but print only the innermost @var{n} frames.
4220
4221@item backtrace -@var{n}
4222@itemx bt -@var{n}
4223Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4224
4225@item backtrace full
4226Print the values of the local variables also.
4227@itemx bt full
c906108c
SS
4228@end table
4229
4230@kindex where
4231@kindex info stack
c906108c
SS
4232The names @code{where} and @code{info stack} (abbreviated @code{info s})
4233are additional aliases for @code{backtrace}.
4234
4235Each line in the backtrace shows the frame number and the function name.
4236The program counter value is also shown---unless you use @code{set
4237print address off}. The backtrace also shows the source file name and
4238line number, as well as the arguments to the function. The program
4239counter value is omitted if it is at the beginning of the code for that
4240line number.
4241
4242Here is an example of a backtrace. It was made with the command
4243@samp{bt 3}, so it shows the innermost three frames.
4244
4245@smallexample
4246@group
5d161b24 4247#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4248 at builtin.c:993
4249#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4250#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4251 at macro.c:71
4252(More stack frames follow...)
4253@end group
4254@end smallexample
4255
4256@noindent
4257The display for frame zero does not begin with a program counter
4258value, indicating that your program has stopped at the beginning of the
4259code for line @code{993} of @code{builtin.c}.
4260
18999be5
EZ
4261@cindex value optimized out, in backtrace
4262@cindex function call arguments, optimized out
4263If your program was compiled with optimizations, some compilers will
4264optimize away arguments passed to functions if those arguments are
4265never used after the call. Such optimizations generate code that
4266passes arguments through registers, but doesn't store those arguments
4267in the stack frame. @value{GDBN} has no way of displaying such
4268arguments in stack frames other than the innermost one. Here's what
4269such a backtrace might look like:
4270
4271@smallexample
4272@group
4273#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4274 at builtin.c:993
4275#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4276#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4277 at macro.c:71
4278(More stack frames follow...)
4279@end group
4280@end smallexample
4281
4282@noindent
4283The values of arguments that were not saved in their stack frames are
4284shown as @samp{<value optimized out>}.
4285
4286If you need to display the values of such optimized-out arguments,
4287either deduce that from other variables whose values depend on the one
4288you are interested in, or recompile without optimizations.
4289
a8f24a35
EZ
4290@cindex backtrace beyond @code{main} function
4291@cindex program entry point
4292@cindex startup code, and backtrace
25d29d70
AC
4293Most programs have a standard user entry point---a place where system
4294libraries and startup code transition into user code. For C this is
4295@code{main}. When @value{GDBN} finds the entry function in a backtrace
4296it will terminate the backtrace, to avoid tracing into highly
4297system-specific (and generally uninteresting) code.
4298
4299If you need to examine the startup code, or limit the number of levels
4300in a backtrace, you can change this behavior:
95f90d25
DJ
4301
4302@table @code
25d29d70
AC
4303@item set backtrace past-main
4304@itemx set backtrace past-main on
4644b6e3 4305@kindex set backtrace
25d29d70
AC
4306Backtraces will continue past the user entry point.
4307
4308@item set backtrace past-main off
95f90d25
DJ
4309Backtraces will stop when they encounter the user entry point. This is the
4310default.
4311
25d29d70 4312@item show backtrace past-main
4644b6e3 4313@kindex show backtrace
25d29d70
AC
4314Display the current user entry point backtrace policy.
4315
2315ffec
RC
4316@item set backtrace past-entry
4317@itemx set backtrace past-entry on
a8f24a35 4318Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4319This entry point is encoded by the linker when the application is built,
4320and is likely before the user entry point @code{main} (or equivalent) is called.
4321
4322@item set backtrace past-entry off
4323Backtraces will stop when they encouter the internal entry point of an
4324application. This is the default.
4325
4326@item show backtrace past-entry
4327Display the current internal entry point backtrace policy.
4328
25d29d70
AC
4329@item set backtrace limit @var{n}
4330@itemx set backtrace limit 0
4331@cindex backtrace limit
4332Limit the backtrace to @var{n} levels. A value of zero means
4333unlimited.
95f90d25 4334
25d29d70
AC
4335@item show backtrace limit
4336Display the current limit on backtrace levels.
95f90d25
DJ
4337@end table
4338
6d2ebf8b 4339@node Selection
c906108c
SS
4340@section Selecting a frame
4341
4342Most commands for examining the stack and other data in your program work on
4343whichever stack frame is selected at the moment. Here are the commands for
4344selecting a stack frame; all of them finish by printing a brief description
4345of the stack frame just selected.
4346
4347@table @code
d4f3574e 4348@kindex frame@r{, selecting}
41afff9a 4349@kindex f @r{(@code{frame})}
c906108c
SS
4350@item frame @var{n}
4351@itemx f @var{n}
4352Select frame number @var{n}. Recall that frame zero is the innermost
4353(currently executing) frame, frame one is the frame that called the
4354innermost one, and so on. The highest-numbered frame is the one for
4355@code{main}.
4356
4357@item frame @var{addr}
4358@itemx f @var{addr}
4359Select the frame at address @var{addr}. This is useful mainly if the
4360chaining of stack frames has been damaged by a bug, making it
4361impossible for @value{GDBN} to assign numbers properly to all frames. In
4362addition, this can be useful when your program has multiple stacks and
4363switches between them.
4364
c906108c
SS
4365On the SPARC architecture, @code{frame} needs two addresses to
4366select an arbitrary frame: a frame pointer and a stack pointer.
4367
4368On the MIPS and Alpha architecture, it needs two addresses: a stack
4369pointer and a program counter.
4370
4371On the 29k architecture, it needs three addresses: a register stack
4372pointer, a program counter, and a memory stack pointer.
4373@c note to future updaters: this is conditioned on a flag
4374@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4375@c as of 27 Jan 1994.
c906108c
SS
4376
4377@kindex up
4378@item up @var{n}
4379Move @var{n} frames up the stack. For positive numbers @var{n}, this
4380advances toward the outermost frame, to higher frame numbers, to frames
4381that have existed longer. @var{n} defaults to one.
4382
4383@kindex down
41afff9a 4384@kindex do @r{(@code{down})}
c906108c
SS
4385@item down @var{n}
4386Move @var{n} frames down the stack. For positive numbers @var{n}, this
4387advances toward the innermost frame, to lower frame numbers, to frames
4388that were created more recently. @var{n} defaults to one. You may
4389abbreviate @code{down} as @code{do}.
4390@end table
4391
4392All of these commands end by printing two lines of output describing the
4393frame. The first line shows the frame number, the function name, the
4394arguments, and the source file and line number of execution in that
5d161b24 4395frame. The second line shows the text of that source line.
c906108c
SS
4396
4397@need 1000
4398For example:
4399
4400@smallexample
4401@group
4402(@value{GDBP}) up
4403#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4404 at env.c:10
440510 read_input_file (argv[i]);
4406@end group
4407@end smallexample
4408
4409After such a printout, the @code{list} command with no arguments
4410prints ten lines centered on the point of execution in the frame.
87885426
FN
4411You can also edit the program at the point of execution with your favorite
4412editing program by typing @code{edit}.
4413@xref{List, ,Printing source lines},
4414for details.
c906108c
SS
4415
4416@table @code
4417@kindex down-silently
4418@kindex up-silently
4419@item up-silently @var{n}
4420@itemx down-silently @var{n}
4421These two commands are variants of @code{up} and @code{down},
4422respectively; they differ in that they do their work silently, without
4423causing display of the new frame. They are intended primarily for use
4424in @value{GDBN} command scripts, where the output might be unnecessary and
4425distracting.
4426@end table
4427
6d2ebf8b 4428@node Frame Info
c906108c
SS
4429@section Information about a frame
4430
4431There are several other commands to print information about the selected
4432stack frame.
4433
4434@table @code
4435@item frame
4436@itemx f
4437When used without any argument, this command does not change which
4438frame is selected, but prints a brief description of the currently
4439selected stack frame. It can be abbreviated @code{f}. With an
4440argument, this command is used to select a stack frame.
4441@xref{Selection, ,Selecting a frame}.
4442
4443@kindex info frame
41afff9a 4444@kindex info f @r{(@code{info frame})}
c906108c
SS
4445@item info frame
4446@itemx info f
4447This command prints a verbose description of the selected stack frame,
4448including:
4449
4450@itemize @bullet
5d161b24
DB
4451@item
4452the address of the frame
c906108c
SS
4453@item
4454the address of the next frame down (called by this frame)
4455@item
4456the address of the next frame up (caller of this frame)
4457@item
4458the language in which the source code corresponding to this frame is written
4459@item
4460the address of the frame's arguments
4461@item
d4f3574e
SS
4462the address of the frame's local variables
4463@item
c906108c
SS
4464the program counter saved in it (the address of execution in the caller frame)
4465@item
4466which registers were saved in the frame
4467@end itemize
4468
4469@noindent The verbose description is useful when
4470something has gone wrong that has made the stack format fail to fit
4471the usual conventions.
4472
4473@item info frame @var{addr}
4474@itemx info f @var{addr}
4475Print a verbose description of the frame at address @var{addr}, without
4476selecting that frame. The selected frame remains unchanged by this
4477command. This requires the same kind of address (more than one for some
4478architectures) that you specify in the @code{frame} command.
4479@xref{Selection, ,Selecting a frame}.
4480
4481@kindex info args
4482@item info args
4483Print the arguments of the selected frame, each on a separate line.
4484
4485@item info locals
4486@kindex info locals
4487Print the local variables of the selected frame, each on a separate
4488line. These are all variables (declared either static or automatic)
4489accessible at the point of execution of the selected frame.
4490
c906108c 4491@kindex info catch
d4f3574e
SS
4492@cindex catch exceptions, list active handlers
4493@cindex exception handlers, how to list
c906108c
SS
4494@item info catch
4495Print a list of all the exception handlers that are active in the
4496current stack frame at the current point of execution. To see other
4497exception handlers, visit the associated frame (using the @code{up},
4498@code{down}, or @code{frame} commands); then type @code{info catch}.
4499@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4500
c906108c
SS
4501@end table
4502
c906108c 4503
6d2ebf8b 4504@node Source
c906108c
SS
4505@chapter Examining Source Files
4506
4507@value{GDBN} can print parts of your program's source, since the debugging
4508information recorded in the program tells @value{GDBN} what source files were
4509used to build it. When your program stops, @value{GDBN} spontaneously prints
4510the line where it stopped. Likewise, when you select a stack frame
4511(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4512execution in that frame has stopped. You can print other portions of
4513source files by explicit command.
4514
7a292a7a 4515If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4516prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4517@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4518
4519@menu
4520* List:: Printing source lines
87885426 4521* Edit:: Editing source files
c906108c 4522* Search:: Searching source files
c906108c
SS
4523* Source Path:: Specifying source directories
4524* Machine Code:: Source and machine code
4525@end menu
4526
6d2ebf8b 4527@node List
c906108c
SS
4528@section Printing source lines
4529
4530@kindex list
41afff9a 4531@kindex l @r{(@code{list})}
c906108c 4532To print lines from a source file, use the @code{list} command
5d161b24 4533(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4534There are several ways to specify what part of the file you want to print.
4535
4536Here are the forms of the @code{list} command most commonly used:
4537
4538@table @code
4539@item list @var{linenum}
4540Print lines centered around line number @var{linenum} in the
4541current source file.
4542
4543@item list @var{function}
4544Print lines centered around the beginning of function
4545@var{function}.
4546
4547@item list
4548Print more lines. If the last lines printed were printed with a
4549@code{list} command, this prints lines following the last lines
4550printed; however, if the last line printed was a solitary line printed
4551as part of displaying a stack frame (@pxref{Stack, ,Examining the
4552Stack}), this prints lines centered around that line.
4553
4554@item list -
4555Print lines just before the lines last printed.
4556@end table
4557
9c16f35a 4558@cindex @code{list}, how many lines to display
c906108c
SS
4559By default, @value{GDBN} prints ten source lines with any of these forms of
4560the @code{list} command. You can change this using @code{set listsize}:
4561
4562@table @code
4563@kindex set listsize
4564@item set listsize @var{count}
4565Make the @code{list} command display @var{count} source lines (unless
4566the @code{list} argument explicitly specifies some other number).
4567
4568@kindex show listsize
4569@item show listsize
4570Display the number of lines that @code{list} prints.
4571@end table
4572
4573Repeating a @code{list} command with @key{RET} discards the argument,
4574so it is equivalent to typing just @code{list}. This is more useful
4575than listing the same lines again. An exception is made for an
4576argument of @samp{-}; that argument is preserved in repetition so that
4577each repetition moves up in the source file.
4578
4579@cindex linespec
4580In general, the @code{list} command expects you to supply zero, one or two
4581@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4582of writing them, but the effect is always to specify some source line.
c906108c
SS
4583Here is a complete description of the possible arguments for @code{list}:
4584
4585@table @code
4586@item list @var{linespec}
4587Print lines centered around the line specified by @var{linespec}.
4588
4589@item list @var{first},@var{last}
4590Print lines from @var{first} to @var{last}. Both arguments are
4591linespecs.
4592
4593@item list ,@var{last}
4594Print lines ending with @var{last}.
4595
4596@item list @var{first},
4597Print lines starting with @var{first}.
4598
4599@item list +
4600Print lines just after the lines last printed.
4601
4602@item list -
4603Print lines just before the lines last printed.
4604
4605@item list
4606As described in the preceding table.
4607@end table
4608
4609Here are the ways of specifying a single source line---all the
4610kinds of linespec.
4611
4612@table @code
4613@item @var{number}
4614Specifies line @var{number} of the current source file.
4615When a @code{list} command has two linespecs, this refers to
4616the same source file as the first linespec.
4617
4618@item +@var{offset}
4619Specifies the line @var{offset} lines after the last line printed.
4620When used as the second linespec in a @code{list} command that has
4621two, this specifies the line @var{offset} lines down from the
4622first linespec.
4623
4624@item -@var{offset}
4625Specifies the line @var{offset} lines before the last line printed.
4626
4627@item @var{filename}:@var{number}
4628Specifies line @var{number} in the source file @var{filename}.
4629
4630@item @var{function}
4631Specifies the line that begins the body of the function @var{function}.
4632For example: in C, this is the line with the open brace.
4633
4634@item @var{filename}:@var{function}
4635Specifies the line of the open-brace that begins the body of the
4636function @var{function} in the file @var{filename}. You only need the
4637file name with a function name to avoid ambiguity when there are
4638identically named functions in different source files.
4639
4640@item *@var{address}
4641Specifies the line containing the program address @var{address}.
4642@var{address} may be any expression.
4643@end table
4644
87885426
FN
4645@node Edit
4646@section Editing source files
4647@cindex editing source files
4648
4649@kindex edit
4650@kindex e @r{(@code{edit})}
4651To edit the lines in a source file, use the @code{edit} command.
4652The editing program of your choice
4653is invoked with the current line set to
4654the active line in the program.
4655Alternatively, there are several ways to specify what part of the file you
4656want to print if you want to see other parts of the program.
4657
4658Here are the forms of the @code{edit} command most commonly used:
4659
4660@table @code
4661@item edit
4662Edit the current source file at the active line number in the program.
4663
4664@item edit @var{number}
4665Edit the current source file with @var{number} as the active line number.
4666
4667@item edit @var{function}
4668Edit the file containing @var{function} at the beginning of its definition.
4669
4670@item edit @var{filename}:@var{number}
4671Specifies line @var{number} in the source file @var{filename}.
4672
4673@item edit @var{filename}:@var{function}
4674Specifies the line that begins the body of the
4675function @var{function} in the file @var{filename}. You only need the
4676file name with a function name to avoid ambiguity when there are
4677identically named functions in different source files.
4678
4679@item edit *@var{address}
4680Specifies the line containing the program address @var{address}.
4681@var{address} may be any expression.
4682@end table
4683
4684@subsection Choosing your editor
4685You can customize @value{GDBN} to use any editor you want
4686@footnote{
4687The only restriction is that your editor (say @code{ex}), recognizes the
4688following command-line syntax:
10998722 4689@smallexample
87885426 4690ex +@var{number} file
10998722 4691@end smallexample
15387254
EZ
4692The optional numeric value +@var{number} specifies the number of the line in
4693the file where to start editing.}.
4694By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4695by setting the environment variable @code{EDITOR} before using
4696@value{GDBN}. For example, to configure @value{GDBN} to use the
4697@code{vi} editor, you could use these commands with the @code{sh} shell:
4698@smallexample
87885426
FN
4699EDITOR=/usr/bin/vi
4700export EDITOR
15387254 4701gdb @dots{}
10998722 4702@end smallexample
87885426 4703or in the @code{csh} shell,
10998722 4704@smallexample
87885426 4705setenv EDITOR /usr/bin/vi
15387254 4706gdb @dots{}
10998722 4707@end smallexample
87885426 4708
6d2ebf8b 4709@node Search
c906108c 4710@section Searching source files
15387254 4711@cindex searching source files
c906108c
SS
4712
4713There are two commands for searching through the current source file for a
4714regular expression.
4715
4716@table @code
4717@kindex search
4718@kindex forward-search
4719@item forward-search @var{regexp}
4720@itemx search @var{regexp}
4721The command @samp{forward-search @var{regexp}} checks each line,
4722starting with the one following the last line listed, for a match for
5d161b24 4723@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4724synonym @samp{search @var{regexp}} or abbreviate the command name as
4725@code{fo}.
4726
09d4efe1 4727@kindex reverse-search
c906108c
SS
4728@item reverse-search @var{regexp}
4729The command @samp{reverse-search @var{regexp}} checks each line, starting
4730with the one before the last line listed and going backward, for a match
4731for @var{regexp}. It lists the line that is found. You can abbreviate
4732this command as @code{rev}.
4733@end table
c906108c 4734
6d2ebf8b 4735@node Source Path
c906108c
SS
4736@section Specifying source directories
4737
4738@cindex source path
4739@cindex directories for source files
4740Executable programs sometimes do not record the directories of the source
4741files from which they were compiled, just the names. Even when they do,
4742the directories could be moved between the compilation and your debugging
4743session. @value{GDBN} has a list of directories to search for source files;
4744this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4745it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4746in the list, until it finds a file with the desired name.
4747
4748For example, suppose an executable references the file
4749@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4750@file{/mnt/cross}. The file is first looked up literally; if this
4751fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4752fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4753message is printed. @value{GDBN} does not look up the parts of the
4754source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4755Likewise, the subdirectories of the source path are not searched: if
4756the source path is @file{/mnt/cross}, and the binary refers to
4757@file{foo.c}, @value{GDBN} would not find it under
4758@file{/mnt/cross/usr/src/foo-1.0/lib}.
4759
4760Plain file names, relative file names with leading directories, file
4761names containing dots, etc.@: are all treated as described above; for
4762instance, if the source path is @file{/mnt/cross}, and the source file
4763is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4764@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4765that---@file{/mnt/cross/foo.c}.
4766
4767Note that the executable search path is @emph{not} used to locate the
4768source files. Neither is the current working directory, unless it
4769happens to be in the source path.
c906108c
SS
4770
4771Whenever you reset or rearrange the source path, @value{GDBN} clears out
4772any information it has cached about where source files are found and where
4773each line is in the file.
4774
4775@kindex directory
4776@kindex dir
d4f3574e
SS
4777When you start @value{GDBN}, its source path includes only @samp{cdir}
4778and @samp{cwd}, in that order.
c906108c
SS
4779To add other directories, use the @code{directory} command.
4780
4781@table @code
4782@item directory @var{dirname} @dots{}
4783@item dir @var{dirname} @dots{}
4784Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4785directory names may be given to this command, separated by @samp{:}
4786(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4787part of absolute file names) or
c906108c
SS
4788whitespace. You may specify a directory that is already in the source
4789path; this moves it forward, so @value{GDBN} searches it sooner.
4790
4791@kindex cdir
4792@kindex cwd
41afff9a
EZ
4793@vindex $cdir@r{, convenience variable}
4794@vindex $cwdr@r{, convenience variable}
c906108c
SS
4795@cindex compilation directory
4796@cindex current directory
4797@cindex working directory
4798@cindex directory, current
4799@cindex directory, compilation
4800You can use the string @samp{$cdir} to refer to the compilation
4801directory (if one is recorded), and @samp{$cwd} to refer to the current
4802working directory. @samp{$cwd} is not the same as @samp{.}---the former
4803tracks the current working directory as it changes during your @value{GDBN}
4804session, while the latter is immediately expanded to the current
4805directory at the time you add an entry to the source path.
4806
4807@item directory
4808Reset the source path to empty again. This requires confirmation.
4809
4810@c RET-repeat for @code{directory} is explicitly disabled, but since
4811@c repeating it would be a no-op we do not say that. (thanks to RMS)
4812
4813@item show directories
4814@kindex show directories
4815Print the source path: show which directories it contains.
4816@end table
4817
4818If your source path is cluttered with directories that are no longer of
4819interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4820versions of source. You can correct the situation as follows:
4821
4822@enumerate
4823@item
4824Use @code{directory} with no argument to reset the source path to empty.
4825
4826@item
4827Use @code{directory} with suitable arguments to reinstall the
4828directories you want in the source path. You can add all the
4829directories in one command.
4830@end enumerate
4831
6d2ebf8b 4832@node Machine Code
c906108c 4833@section Source and machine code
15387254 4834@cindex source line and its code address
c906108c
SS
4835
4836You can use the command @code{info line} to map source lines to program
4837addresses (and vice versa), and the command @code{disassemble} to display
4838a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4839mode, the @code{info line} command causes the arrow to point to the
5d161b24 4840line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4841well as hex.
4842
4843@table @code
4844@kindex info line
4845@item info line @var{linespec}
4846Print the starting and ending addresses of the compiled code for
4847source line @var{linespec}. You can specify source lines in any of
4848the ways understood by the @code{list} command (@pxref{List, ,Printing
4849source lines}).
4850@end table
4851
4852For example, we can use @code{info line} to discover the location of
4853the object code for the first line of function
4854@code{m4_changequote}:
4855
d4f3574e
SS
4856@c FIXME: I think this example should also show the addresses in
4857@c symbolic form, as they usually would be displayed.
c906108c 4858@smallexample
96a2c332 4859(@value{GDBP}) info line m4_changequote
c906108c
SS
4860Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4861@end smallexample
4862
4863@noindent
15387254 4864@cindex code address and its source line
c906108c
SS
4865We can also inquire (using @code{*@var{addr}} as the form for
4866@var{linespec}) what source line covers a particular address:
4867@smallexample
4868(@value{GDBP}) info line *0x63ff
4869Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4870@end smallexample
4871
4872@cindex @code{$_} and @code{info line}
15387254 4873@cindex @code{x} command, default address
41afff9a 4874@kindex x@r{(examine), and} info line
c906108c
SS
4875After @code{info line}, the default address for the @code{x} command
4876is changed to the starting address of the line, so that @samp{x/i} is
4877sufficient to begin examining the machine code (@pxref{Memory,
4878,Examining memory}). Also, this address is saved as the value of the
4879convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4880variables}).
4881
4882@table @code
4883@kindex disassemble
4884@cindex assembly instructions
4885@cindex instructions, assembly
4886@cindex machine instructions
4887@cindex listing machine instructions
4888@item disassemble
4889This specialized command dumps a range of memory as machine
4890instructions. The default memory range is the function surrounding the
4891program counter of the selected frame. A single argument to this
4892command is a program counter value; @value{GDBN} dumps the function
4893surrounding this value. Two arguments specify a range of addresses
4894(first inclusive, second exclusive) to dump.
4895@end table
4896
c906108c
SS
4897The following example shows the disassembly of a range of addresses of
4898HP PA-RISC 2.0 code:
4899
4900@smallexample
4901(@value{GDBP}) disas 0x32c4 0x32e4
4902Dump of assembler code from 0x32c4 to 0x32e4:
49030x32c4 <main+204>: addil 0,dp
49040x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49050x32cc <main+212>: ldil 0x3000,r31
49060x32d0 <main+216>: ble 0x3f8(sr4,r31)
49070x32d4 <main+220>: ldo 0(r31),rp
49080x32d8 <main+224>: addil -0x800,dp
49090x32dc <main+228>: ldo 0x588(r1),r26
49100x32e0 <main+232>: ldil 0x3000,r31
4911End of assembler dump.
4912@end smallexample
c906108c
SS
4913
4914Some architectures have more than one commonly-used set of instruction
4915mnemonics or other syntax.
4916
4917@table @code
d4f3574e 4918@kindex set disassembly-flavor
d4f3574e
SS
4919@cindex Intel disassembly flavor
4920@cindex AT&T disassembly flavor
4921@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4922Select the instruction set to use when disassembling the
4923program via the @code{disassemble} or @code{x/i} commands.
4924
4925Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4926can set @var{instruction-set} to either @code{intel} or @code{att}.
4927The default is @code{att}, the AT&T flavor used by default by Unix
4928assemblers for x86-based targets.
9c16f35a
EZ
4929
4930@kindex show disassembly-flavor
4931@item show disassembly-flavor
4932Show the current setting of the disassembly flavor.
c906108c
SS
4933@end table
4934
4935
6d2ebf8b 4936@node Data
c906108c
SS
4937@chapter Examining Data
4938
4939@cindex printing data
4940@cindex examining data
4941@kindex print
4942@kindex inspect
4943@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4944@c document because it is nonstandard... Under Epoch it displays in a
4945@c different window or something like that.
4946The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4947command (abbreviated @code{p}), or its synonym @code{inspect}. It
4948evaluates and prints the value of an expression of the language your
4949program is written in (@pxref{Languages, ,Using @value{GDBN} with
4950Different Languages}).
c906108c
SS
4951
4952@table @code
d4f3574e
SS
4953@item print @var{expr}
4954@itemx print /@var{f} @var{expr}
4955@var{expr} is an expression (in the source language). By default the
4956value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4957you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4958@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4959formats}.
4960
4961@item print
4962@itemx print /@var{f}
15387254 4963@cindex reprint the last value
d4f3574e 4964If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4965@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4966conveniently inspect the same value in an alternative format.
4967@end table
4968
4969A more low-level way of examining data is with the @code{x} command.
4970It examines data in memory at a specified address and prints it in a
4971specified format. @xref{Memory, ,Examining memory}.
4972
7a292a7a 4973If you are interested in information about types, or about how the
d4f3574e
SS
4974fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4975command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4976Table}.
c906108c
SS
4977
4978@menu
4979* Expressions:: Expressions
4980* Variables:: Program variables
4981* Arrays:: Artificial arrays
4982* Output Formats:: Output formats
4983* Memory:: Examining memory
4984* Auto Display:: Automatic display
4985* Print Settings:: Print settings
4986* Value History:: Value history
4987* Convenience Vars:: Convenience variables
4988* Registers:: Registers
c906108c 4989* Floating Point Hardware:: Floating point hardware
53c69bd7 4990* Vector Unit:: Vector Unit
721c2651 4991* OS Information:: Auxiliary data provided by operating system
29e57380 4992* Memory Region Attributes:: Memory region attributes
16d9dec6 4993* Dump/Restore Files:: Copy between memory and a file
384ee23f 4994* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4995* Character Sets:: Debugging programs that use a different
4996 character set than GDB does
09d4efe1 4997* Caching Remote Data:: Data caching for remote targets
c906108c
SS
4998@end menu
4999
6d2ebf8b 5000@node Expressions
c906108c
SS
5001@section Expressions
5002
5003@cindex expressions
5004@code{print} and many other @value{GDBN} commands accept an expression and
5005compute its value. Any kind of constant, variable or operator defined
5006by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5007@value{GDBN}. This includes conditional expressions, function calls,
5008casts, and string constants. It also includes preprocessor macros, if
5009you compiled your program to include this information; see
5010@ref{Compilation}.
c906108c 5011
15387254 5012@cindex arrays in expressions
d4f3574e
SS
5013@value{GDBN} supports array constants in expressions input by
5014the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5015you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5016memory that is @code{malloc}ed in the target program.
c906108c 5017
c906108c
SS
5018Because C is so widespread, most of the expressions shown in examples in
5019this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5020Languages}, for information on how to use expressions in other
5021languages.
5022
5023In this section, we discuss operators that you can use in @value{GDBN}
5024expressions regardless of your programming language.
5025
15387254 5026@cindex casts, in expressions
c906108c
SS
5027Casts are supported in all languages, not just in C, because it is so
5028useful to cast a number into a pointer in order to examine a structure
5029at that address in memory.
5030@c FIXME: casts supported---Mod2 true?
c906108c
SS
5031
5032@value{GDBN} supports these operators, in addition to those common
5033to programming languages:
5034
5035@table @code
5036@item @@
5037@samp{@@} is a binary operator for treating parts of memory as arrays.
5038@xref{Arrays, ,Artificial arrays}, for more information.
5039
5040@item ::
5041@samp{::} allows you to specify a variable in terms of the file or
5042function where it is defined. @xref{Variables, ,Program variables}.
5043
5044@cindex @{@var{type}@}
5045@cindex type casting memory
5046@cindex memory, viewing as typed object
5047@cindex casts, to view memory
5048@item @{@var{type}@} @var{addr}
5049Refers to an object of type @var{type} stored at address @var{addr} in
5050memory. @var{addr} may be any expression whose value is an integer or
5051pointer (but parentheses are required around binary operators, just as in
5052a cast). This construct is allowed regardless of what kind of data is
5053normally supposed to reside at @var{addr}.
5054@end table
5055
6d2ebf8b 5056@node Variables
c906108c
SS
5057@section Program variables
5058
5059The most common kind of expression to use is the name of a variable
5060in your program.
5061
5062Variables in expressions are understood in the selected stack frame
5063(@pxref{Selection, ,Selecting a frame}); they must be either:
5064
5065@itemize @bullet
5066@item
5067global (or file-static)
5068@end itemize
5069
5d161b24 5070@noindent or
c906108c
SS
5071
5072@itemize @bullet
5073@item
5074visible according to the scope rules of the
5075programming language from the point of execution in that frame
5d161b24 5076@end itemize
c906108c
SS
5077
5078@noindent This means that in the function
5079
474c8240 5080@smallexample
c906108c
SS
5081foo (a)
5082 int a;
5083@{
5084 bar (a);
5085 @{
5086 int b = test ();
5087 bar (b);
5088 @}
5089@}
474c8240 5090@end smallexample
c906108c
SS
5091
5092@noindent
5093you can examine and use the variable @code{a} whenever your program is
5094executing within the function @code{foo}, but you can only use or
5095examine the variable @code{b} while your program is executing inside
5096the block where @code{b} is declared.
5097
5098@cindex variable name conflict
5099There is an exception: you can refer to a variable or function whose
5100scope is a single source file even if the current execution point is not
5101in this file. But it is possible to have more than one such variable or
5102function with the same name (in different source files). If that
5103happens, referring to that name has unpredictable effects. If you wish,
5104you can specify a static variable in a particular function or file,
15387254 5105using the colon-colon (@code{::}) notation:
c906108c 5106
d4f3574e 5107@cindex colon-colon, context for variables/functions
c906108c
SS
5108@iftex
5109@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5110@cindex @code{::}, context for variables/functions
c906108c 5111@end iftex
474c8240 5112@smallexample
c906108c
SS
5113@var{file}::@var{variable}
5114@var{function}::@var{variable}
474c8240 5115@end smallexample
c906108c
SS
5116
5117@noindent
5118Here @var{file} or @var{function} is the name of the context for the
5119static @var{variable}. In the case of file names, you can use quotes to
5120make sure @value{GDBN} parses the file name as a single word---for example,
5121to print a global value of @code{x} defined in @file{f2.c}:
5122
474c8240 5123@smallexample
c906108c 5124(@value{GDBP}) p 'f2.c'::x
474c8240 5125@end smallexample
c906108c 5126
b37052ae 5127@cindex C@t{++} scope resolution
c906108c 5128This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5129use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5130scope resolution operator in @value{GDBN} expressions.
5131@c FIXME: Um, so what happens in one of those rare cases where it's in
5132@c conflict?? --mew
c906108c
SS
5133
5134@cindex wrong values
5135@cindex variable values, wrong
15387254
EZ
5136@cindex function entry/exit, wrong values of variables
5137@cindex optimized code, wrong values of variables
c906108c
SS
5138@quotation
5139@emph{Warning:} Occasionally, a local variable may appear to have the
5140wrong value at certain points in a function---just after entry to a new
5141scope, and just before exit.
5142@end quotation
5143You may see this problem when you are stepping by machine instructions.
5144This is because, on most machines, it takes more than one instruction to
5145set up a stack frame (including local variable definitions); if you are
5146stepping by machine instructions, variables may appear to have the wrong
5147values until the stack frame is completely built. On exit, it usually
5148also takes more than one machine instruction to destroy a stack frame;
5149after you begin stepping through that group of instructions, local
5150variable definitions may be gone.
5151
5152This may also happen when the compiler does significant optimizations.
5153To be sure of always seeing accurate values, turn off all optimization
5154when compiling.
5155
d4f3574e
SS
5156@cindex ``No symbol "foo" in current context''
5157Another possible effect of compiler optimizations is to optimize
5158unused variables out of existence, or assign variables to registers (as
5159opposed to memory addresses). Depending on the support for such cases
5160offered by the debug info format used by the compiler, @value{GDBN}
5161might not be able to display values for such local variables. If that
5162happens, @value{GDBN} will print a message like this:
5163
474c8240 5164@smallexample
d4f3574e 5165No symbol "foo" in current context.
474c8240 5166@end smallexample
d4f3574e
SS
5167
5168To solve such problems, either recompile without optimizations, or use a
5169different debug info format, if the compiler supports several such
15387254 5170formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5171usually supports the @option{-gstabs+} option. @option{-gstabs+}
5172produces debug info in a format that is superior to formats such as
5173COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5174an effective form for debug info. @xref{Debugging Options,,Options
5175for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5176@xref{C, , Debugging C++}, for more info about debug info formats
5177that are best suited to C@t{++} programs.
d4f3574e 5178
6d2ebf8b 5179@node Arrays
c906108c
SS
5180@section Artificial arrays
5181
5182@cindex artificial array
15387254 5183@cindex arrays
41afff9a 5184@kindex @@@r{, referencing memory as an array}
c906108c
SS
5185It is often useful to print out several successive objects of the
5186same type in memory; a section of an array, or an array of
5187dynamically determined size for which only a pointer exists in the
5188program.
5189
5190You can do this by referring to a contiguous span of memory as an
5191@dfn{artificial array}, using the binary operator @samp{@@}. The left
5192operand of @samp{@@} should be the first element of the desired array
5193and be an individual object. The right operand should be the desired length
5194of the array. The result is an array value whose elements are all of
5195the type of the left argument. The first element is actually the left
5196argument; the second element comes from bytes of memory immediately
5197following those that hold the first element, and so on. Here is an
5198example. If a program says
5199
474c8240 5200@smallexample
c906108c 5201int *array = (int *) malloc (len * sizeof (int));
474c8240 5202@end smallexample
c906108c
SS
5203
5204@noindent
5205you can print the contents of @code{array} with
5206
474c8240 5207@smallexample
c906108c 5208p *array@@len
474c8240 5209@end smallexample
c906108c
SS
5210
5211The left operand of @samp{@@} must reside in memory. Array values made
5212with @samp{@@} in this way behave just like other arrays in terms of
5213subscripting, and are coerced to pointers when used in expressions.
5214Artificial arrays most often appear in expressions via the value history
5215(@pxref{Value History, ,Value history}), after printing one out.
5216
5217Another way to create an artificial array is to use a cast.
5218This re-interprets a value as if it were an array.
5219The value need not be in memory:
474c8240 5220@smallexample
c906108c
SS
5221(@value{GDBP}) p/x (short[2])0x12345678
5222$1 = @{0x1234, 0x5678@}
474c8240 5223@end smallexample
c906108c
SS
5224
5225As a convenience, if you leave the array length out (as in
c3f6f71d 5226@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5227the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5228@smallexample
c906108c
SS
5229(@value{GDBP}) p/x (short[])0x12345678
5230$2 = @{0x1234, 0x5678@}
474c8240 5231@end smallexample
c906108c
SS
5232
5233Sometimes the artificial array mechanism is not quite enough; in
5234moderately complex data structures, the elements of interest may not
5235actually be adjacent---for example, if you are interested in the values
5236of pointers in an array. One useful work-around in this situation is
5237to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5238variables}) as a counter in an expression that prints the first
5239interesting value, and then repeat that expression via @key{RET}. For
5240instance, suppose you have an array @code{dtab} of pointers to
5241structures, and you are interested in the values of a field @code{fv}
5242in each structure. Here is an example of what you might type:
5243
474c8240 5244@smallexample
c906108c
SS
5245set $i = 0
5246p dtab[$i++]->fv
5247@key{RET}
5248@key{RET}
5249@dots{}
474c8240 5250@end smallexample
c906108c 5251
6d2ebf8b 5252@node Output Formats
c906108c
SS
5253@section Output formats
5254
5255@cindex formatted output
5256@cindex output formats
5257By default, @value{GDBN} prints a value according to its data type. Sometimes
5258this is not what you want. For example, you might want to print a number
5259in hex, or a pointer in decimal. Or you might want to view data in memory
5260at a certain address as a character string or as an instruction. To do
5261these things, specify an @dfn{output format} when you print a value.
5262
5263The simplest use of output formats is to say how to print a value
5264already computed. This is done by starting the arguments of the
5265@code{print} command with a slash and a format letter. The format
5266letters supported are:
5267
5268@table @code
5269@item x
5270Regard the bits of the value as an integer, and print the integer in
5271hexadecimal.
5272
5273@item d
5274Print as integer in signed decimal.
5275
5276@item u
5277Print as integer in unsigned decimal.
5278
5279@item o
5280Print as integer in octal.
5281
5282@item t
5283Print as integer in binary. The letter @samp{t} stands for ``two''.
5284@footnote{@samp{b} cannot be used because these format letters are also
5285used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5286see @ref{Memory,,Examining memory}.}
c906108c
SS
5287
5288@item a
5289@cindex unknown address, locating
3d67e040 5290@cindex locate address
c906108c
SS
5291Print as an address, both absolute in hexadecimal and as an offset from
5292the nearest preceding symbol. You can use this format used to discover
5293where (in what function) an unknown address is located:
5294
474c8240 5295@smallexample
c906108c
SS
5296(@value{GDBP}) p/a 0x54320
5297$3 = 0x54320 <_initialize_vx+396>
474c8240 5298@end smallexample
c906108c 5299
3d67e040
EZ
5300@noindent
5301The command @code{info symbol 0x54320} yields similar results.
5302@xref{Symbols, info symbol}.
5303
c906108c
SS
5304@item c
5305Regard as an integer and print it as a character constant.
5306
5307@item f
5308Regard the bits of the value as a floating point number and print
5309using typical floating point syntax.
5310@end table
5311
5312For example, to print the program counter in hex (@pxref{Registers}), type
5313
474c8240 5314@smallexample
c906108c 5315p/x $pc
474c8240 5316@end smallexample
c906108c
SS
5317
5318@noindent
5319Note that no space is required before the slash; this is because command
5320names in @value{GDBN} cannot contain a slash.
5321
5322To reprint the last value in the value history with a different format,
5323you can use the @code{print} command with just a format and no
5324expression. For example, @samp{p/x} reprints the last value in hex.
5325
6d2ebf8b 5326@node Memory
c906108c
SS
5327@section Examining memory
5328
5329You can use the command @code{x} (for ``examine'') to examine memory in
5330any of several formats, independently of your program's data types.
5331
5332@cindex examining memory
5333@table @code
41afff9a 5334@kindex x @r{(examine memory)}
c906108c
SS
5335@item x/@var{nfu} @var{addr}
5336@itemx x @var{addr}
5337@itemx x
5338Use the @code{x} command to examine memory.
5339@end table
5340
5341@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5342much memory to display and how to format it; @var{addr} is an
5343expression giving the address where you want to start displaying memory.
5344If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5345Several commands set convenient defaults for @var{addr}.
5346
5347@table @r
5348@item @var{n}, the repeat count
5349The repeat count is a decimal integer; the default is 1. It specifies
5350how much memory (counting by units @var{u}) to display.
5351@c This really is **decimal**; unaffected by 'set radix' as of GDB
5352@c 4.1.2.
5353
5354@item @var{f}, the display format
5355The display format is one of the formats used by @code{print},
5356@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5357The default is @samp{x} (hexadecimal) initially.
5358The default changes each time you use either @code{x} or @code{print}.
5359
5360@item @var{u}, the unit size
5361The unit size is any of
5362
5363@table @code
5364@item b
5365Bytes.
5366@item h
5367Halfwords (two bytes).
5368@item w
5369Words (four bytes). This is the initial default.
5370@item g
5371Giant words (eight bytes).
5372@end table
5373
5374Each time you specify a unit size with @code{x}, that size becomes the
5375default unit the next time you use @code{x}. (For the @samp{s} and
5376@samp{i} formats, the unit size is ignored and is normally not written.)
5377
5378@item @var{addr}, starting display address
5379@var{addr} is the address where you want @value{GDBN} to begin displaying
5380memory. The expression need not have a pointer value (though it may);
5381it is always interpreted as an integer address of a byte of memory.
5382@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5383@var{addr} is usually just after the last address examined---but several
5384other commands also set the default address: @code{info breakpoints} (to
5385the address of the last breakpoint listed), @code{info line} (to the
5386starting address of a line), and @code{print} (if you use it to display
5387a value from memory).
5388@end table
5389
5390For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5391(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5392starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5393words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5394@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5395
5396Since the letters indicating unit sizes are all distinct from the
5397letters specifying output formats, you do not have to remember whether
5398unit size or format comes first; either order works. The output
5399specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5400(However, the count @var{n} must come first; @samp{wx4} does not work.)
5401
5402Even though the unit size @var{u} is ignored for the formats @samp{s}
5403and @samp{i}, you might still want to use a count @var{n}; for example,
5404@samp{3i} specifies that you want to see three machine instructions,
5405including any operands. The command @code{disassemble} gives an
d4f3574e 5406alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5407Code,,Source and machine code}.
5408
5409All the defaults for the arguments to @code{x} are designed to make it
5410easy to continue scanning memory with minimal specifications each time
5411you use @code{x}. For example, after you have inspected three machine
5412instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5413with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5414the repeat count @var{n} is used again; the other arguments default as
5415for successive uses of @code{x}.
5416
5417@cindex @code{$_}, @code{$__}, and value history
5418The addresses and contents printed by the @code{x} command are not saved
5419in the value history because there is often too much of them and they
5420would get in the way. Instead, @value{GDBN} makes these values available for
5421subsequent use in expressions as values of the convenience variables
5422@code{$_} and @code{$__}. After an @code{x} command, the last address
5423examined is available for use in expressions in the convenience variable
5424@code{$_}. The contents of that address, as examined, are available in
5425the convenience variable @code{$__}.
5426
5427If the @code{x} command has a repeat count, the address and contents saved
5428are from the last memory unit printed; this is not the same as the last
5429address printed if several units were printed on the last line of output.
5430
09d4efe1
EZ
5431@cindex remote memory comparison
5432@cindex verify remote memory image
5433When you are debugging a program running on a remote target machine
5434(@pxref{Remote}), you may wish to verify the program's image in the
5435remote machine's memory against the executable file you downloaded to
5436the target. The @code{compare-sections} command is provided for such
5437situations.
5438
5439@table @code
5440@kindex compare-sections
5441@item compare-sections @r{[}@var{section-name}@r{]}
5442Compare the data of a loadable section @var{section-name} in the
5443executable file of the program being debugged with the same section in
5444the remote machine's memory, and report any mismatches. With no
5445arguments, compares all loadable sections. This command's
5446availability depends on the target's support for the @code{"qCRC"}
5447remote request.
5448@end table
5449
6d2ebf8b 5450@node Auto Display
c906108c
SS
5451@section Automatic display
5452@cindex automatic display
5453@cindex display of expressions
5454
5455If you find that you want to print the value of an expression frequently
5456(to see how it changes), you might want to add it to the @dfn{automatic
5457display list} so that @value{GDBN} prints its value each time your program stops.
5458Each expression added to the list is given a number to identify it;
5459to remove an expression from the list, you specify that number.
5460The automatic display looks like this:
5461
474c8240 5462@smallexample
c906108c
SS
54632: foo = 38
54643: bar[5] = (struct hack *) 0x3804
474c8240 5465@end smallexample
c906108c
SS
5466
5467@noindent
5468This display shows item numbers, expressions and their current values. As with
5469displays you request manually using @code{x} or @code{print}, you can
5470specify the output format you prefer; in fact, @code{display} decides
5471whether to use @code{print} or @code{x} depending on how elaborate your
5472format specification is---it uses @code{x} if you specify a unit size,
5473or one of the two formats (@samp{i} and @samp{s}) that are only
5474supported by @code{x}; otherwise it uses @code{print}.
5475
5476@table @code
5477@kindex display
d4f3574e
SS
5478@item display @var{expr}
5479Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5480each time your program stops. @xref{Expressions, ,Expressions}.
5481
5482@code{display} does not repeat if you press @key{RET} again after using it.
5483
d4f3574e 5484@item display/@var{fmt} @var{expr}
c906108c 5485For @var{fmt} specifying only a display format and not a size or
d4f3574e 5486count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5487arrange to display it each time in the specified format @var{fmt}.
5488@xref{Output Formats,,Output formats}.
5489
5490@item display/@var{fmt} @var{addr}
5491For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5492number of units, add the expression @var{addr} as a memory address to
5493be examined each time your program stops. Examining means in effect
5494doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5495@end table
5496
5497For example, @samp{display/i $pc} can be helpful, to see the machine
5498instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5499is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5500
5501@table @code
5502@kindex delete display
5503@kindex undisplay
5504@item undisplay @var{dnums}@dots{}
5505@itemx delete display @var{dnums}@dots{}
5506Remove item numbers @var{dnums} from the list of expressions to display.
5507
5508@code{undisplay} does not repeat if you press @key{RET} after using it.
5509(Otherwise you would just get the error @samp{No display number @dots{}}.)
5510
5511@kindex disable display
5512@item disable display @var{dnums}@dots{}
5513Disable the display of item numbers @var{dnums}. A disabled display
5514item is not printed automatically, but is not forgotten. It may be
5515enabled again later.
5516
5517@kindex enable display
5518@item enable display @var{dnums}@dots{}
5519Enable display of item numbers @var{dnums}. It becomes effective once
5520again in auto display of its expression, until you specify otherwise.
5521
5522@item display
5523Display the current values of the expressions on the list, just as is
5524done when your program stops.
5525
5526@kindex info display
5527@item info display
5528Print the list of expressions previously set up to display
5529automatically, each one with its item number, but without showing the
5530values. This includes disabled expressions, which are marked as such.
5531It also includes expressions which would not be displayed right now
5532because they refer to automatic variables not currently available.
5533@end table
5534
15387254 5535@cindex display disabled out of scope
c906108c
SS
5536If a display expression refers to local variables, then it does not make
5537sense outside the lexical context for which it was set up. Such an
5538expression is disabled when execution enters a context where one of its
5539variables is not defined. For example, if you give the command
5540@code{display last_char} while inside a function with an argument
5541@code{last_char}, @value{GDBN} displays this argument while your program
5542continues to stop inside that function. When it stops elsewhere---where
5543there is no variable @code{last_char}---the display is disabled
5544automatically. The next time your program stops where @code{last_char}
5545is meaningful, you can enable the display expression once again.
5546
6d2ebf8b 5547@node Print Settings
c906108c
SS
5548@section Print settings
5549
5550@cindex format options
5551@cindex print settings
5552@value{GDBN} provides the following ways to control how arrays, structures,
5553and symbols are printed.
5554
5555@noindent
5556These settings are useful for debugging programs in any language:
5557
5558@table @code
4644b6e3 5559@kindex set print
c906108c
SS
5560@item set print address
5561@itemx set print address on
4644b6e3 5562@cindex print/don't print memory addresses
c906108c
SS
5563@value{GDBN} prints memory addresses showing the location of stack
5564traces, structure values, pointer values, breakpoints, and so forth,
5565even when it also displays the contents of those addresses. The default
5566is @code{on}. For example, this is what a stack frame display looks like with
5567@code{set print address on}:
5568
5569@smallexample
5570@group
5571(@value{GDBP}) f
5572#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5573 at input.c:530
5574530 if (lquote != def_lquote)
5575@end group
5576@end smallexample
5577
5578@item set print address off
5579Do not print addresses when displaying their contents. For example,
5580this is the same stack frame displayed with @code{set print address off}:
5581
5582@smallexample
5583@group
5584(@value{GDBP}) set print addr off
5585(@value{GDBP}) f
5586#0 set_quotes (lq="<<", rq=">>") at input.c:530
5587530 if (lquote != def_lquote)
5588@end group
5589@end smallexample
5590
5591You can use @samp{set print address off} to eliminate all machine
5592dependent displays from the @value{GDBN} interface. For example, with
5593@code{print address off}, you should get the same text for backtraces on
5594all machines---whether or not they involve pointer arguments.
5595
4644b6e3 5596@kindex show print
c906108c
SS
5597@item show print address
5598Show whether or not addresses are to be printed.
5599@end table
5600
5601When @value{GDBN} prints a symbolic address, it normally prints the
5602closest earlier symbol plus an offset. If that symbol does not uniquely
5603identify the address (for example, it is a name whose scope is a single
5604source file), you may need to clarify. One way to do this is with
5605@code{info line}, for example @samp{info line *0x4537}. Alternately,
5606you can set @value{GDBN} to print the source file and line number when
5607it prints a symbolic address:
5608
5609@table @code
c906108c 5610@item set print symbol-filename on
9c16f35a
EZ
5611@cindex source file and line of a symbol
5612@cindex symbol, source file and line
c906108c
SS
5613Tell @value{GDBN} to print the source file name and line number of a
5614symbol in the symbolic form of an address.
5615
5616@item set print symbol-filename off
5617Do not print source file name and line number of a symbol. This is the
5618default.
5619
c906108c
SS
5620@item show print symbol-filename
5621Show whether or not @value{GDBN} will print the source file name and
5622line number of a symbol in the symbolic form of an address.
5623@end table
5624
5625Another situation where it is helpful to show symbol filenames and line
5626numbers is when disassembling code; @value{GDBN} shows you the line
5627number and source file that corresponds to each instruction.
5628
5629Also, you may wish to see the symbolic form only if the address being
5630printed is reasonably close to the closest earlier symbol:
5631
5632@table @code
c906108c 5633@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5634@cindex maximum value for offset of closest symbol
c906108c
SS
5635Tell @value{GDBN} to only display the symbolic form of an address if the
5636offset between the closest earlier symbol and the address is less than
5d161b24 5637@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5638to always print the symbolic form of an address if any symbol precedes it.
5639
c906108c
SS
5640@item show print max-symbolic-offset
5641Ask how large the maximum offset is that @value{GDBN} prints in a
5642symbolic address.
5643@end table
5644
5645@cindex wild pointer, interpreting
5646@cindex pointer, finding referent
5647If you have a pointer and you are not sure where it points, try
5648@samp{set print symbol-filename on}. Then you can determine the name
5649and source file location of the variable where it points, using
5650@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5651For example, here @value{GDBN} shows that a variable @code{ptt} points
5652at another variable @code{t}, defined in @file{hi2.c}:
5653
474c8240 5654@smallexample
c906108c
SS
5655(@value{GDBP}) set print symbol-filename on
5656(@value{GDBP}) p/a ptt
5657$4 = 0xe008 <t in hi2.c>
474c8240 5658@end smallexample
c906108c
SS
5659
5660@quotation
5661@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5662does not show the symbol name and filename of the referent, even with
5663the appropriate @code{set print} options turned on.
5664@end quotation
5665
5666Other settings control how different kinds of objects are printed:
5667
5668@table @code
c906108c
SS
5669@item set print array
5670@itemx set print array on
4644b6e3 5671@cindex pretty print arrays
c906108c
SS
5672Pretty print arrays. This format is more convenient to read,
5673but uses more space. The default is off.
5674
5675@item set print array off
5676Return to compressed format for arrays.
5677
c906108c
SS
5678@item show print array
5679Show whether compressed or pretty format is selected for displaying
5680arrays.
5681
c906108c 5682@item set print elements @var{number-of-elements}
4644b6e3 5683@cindex number of array elements to print
9c16f35a 5684@cindex limit on number of printed array elements
c906108c
SS
5685Set a limit on how many elements of an array @value{GDBN} will print.
5686If @value{GDBN} is printing a large array, it stops printing after it has
5687printed the number of elements set by the @code{set print elements} command.
5688This limit also applies to the display of strings.
d4f3574e 5689When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5690Setting @var{number-of-elements} to zero means that the printing is unlimited.
5691
c906108c
SS
5692@item show print elements
5693Display the number of elements of a large array that @value{GDBN} will print.
5694If the number is 0, then the printing is unlimited.
5695
9c16f35a
EZ
5696@item set print repeats
5697@cindex repeated array elements
5698Set the threshold for suppressing display of repeated array
5699elelments. When the number of consecutive identical elements of an
5700array exceeds the threshold, @value{GDBN} prints the string
5701@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5702identical repetitions, instead of displaying the identical elements
5703themselves. Setting the threshold to zero will cause all elements to
5704be individually printed. The default threshold is 10.
5705
5706@item show print repeats
5707Display the current threshold for printing repeated identical
5708elements.
5709
c906108c 5710@item set print null-stop
4644b6e3 5711@cindex @sc{null} elements in arrays
c906108c 5712Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5713@sc{null} is encountered. This is useful when large arrays actually
c906108c 5714contain only short strings.
d4f3574e 5715The default is off.
c906108c 5716
9c16f35a
EZ
5717@item show print null-stop
5718Show whether @value{GDBN} stops printing an array on the first
5719@sc{null} character.
5720
c906108c 5721@item set print pretty on
9c16f35a
EZ
5722@cindex print structures in indented form
5723@cindex indentation in structure display
5d161b24 5724Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5725per line, like this:
5726
5727@smallexample
5728@group
5729$1 = @{
5730 next = 0x0,
5731 flags = @{
5732 sweet = 1,
5733 sour = 1
5734 @},
5735 meat = 0x54 "Pork"
5736@}
5737@end group
5738@end smallexample
5739
5740@item set print pretty off
5741Cause @value{GDBN} to print structures in a compact format, like this:
5742
5743@smallexample
5744@group
5745$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5746meat = 0x54 "Pork"@}
5747@end group
5748@end smallexample
5749
5750@noindent
5751This is the default format.
5752
c906108c
SS
5753@item show print pretty
5754Show which format @value{GDBN} is using to print structures.
5755
c906108c 5756@item set print sevenbit-strings on
4644b6e3
EZ
5757@cindex eight-bit characters in strings
5758@cindex octal escapes in strings
c906108c
SS
5759Print using only seven-bit characters; if this option is set,
5760@value{GDBN} displays any eight-bit characters (in strings or
5761character values) using the notation @code{\}@var{nnn}. This setting is
5762best if you are working in English (@sc{ascii}) and you use the
5763high-order bit of characters as a marker or ``meta'' bit.
5764
5765@item set print sevenbit-strings off
5766Print full eight-bit characters. This allows the use of more
5767international character sets, and is the default.
5768
c906108c
SS
5769@item show print sevenbit-strings
5770Show whether or not @value{GDBN} is printing only seven-bit characters.
5771
c906108c 5772@item set print union on
4644b6e3 5773@cindex unions in structures, printing
9c16f35a
EZ
5774Tell @value{GDBN} to print unions which are contained in structures
5775and other unions. This is the default setting.
c906108c
SS
5776
5777@item set print union off
9c16f35a
EZ
5778Tell @value{GDBN} not to print unions which are contained in
5779structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5780instead.
c906108c 5781
c906108c
SS
5782@item show print union
5783Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5784structures and other unions.
c906108c
SS
5785
5786For example, given the declarations
5787
5788@smallexample
5789typedef enum @{Tree, Bug@} Species;
5790typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5791typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5792 Bug_forms;
5793
5794struct thing @{
5795 Species it;
5796 union @{
5797 Tree_forms tree;
5798 Bug_forms bug;
5799 @} form;
5800@};
5801
5802struct thing foo = @{Tree, @{Acorn@}@};
5803@end smallexample
5804
5805@noindent
5806with @code{set print union on} in effect @samp{p foo} would print
5807
5808@smallexample
5809$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5810@end smallexample
5811
5812@noindent
5813and with @code{set print union off} in effect it would print
5814
5815@smallexample
5816$1 = @{it = Tree, form = @{...@}@}
5817@end smallexample
9c16f35a
EZ
5818
5819@noindent
5820@code{set print union} affects programs written in C-like languages
5821and in Pascal.
c906108c
SS
5822@end table
5823
c906108c
SS
5824@need 1000
5825@noindent
b37052ae 5826These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5827
5828@table @code
4644b6e3 5829@cindex demangling C@t{++} names
c906108c
SS
5830@item set print demangle
5831@itemx set print demangle on
b37052ae 5832Print C@t{++} names in their source form rather than in the encoded
c906108c 5833(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5834linkage. The default is on.
c906108c 5835
c906108c 5836@item show print demangle
b37052ae 5837Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5838
c906108c
SS
5839@item set print asm-demangle
5840@itemx set print asm-demangle on
b37052ae 5841Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5842in assembler code printouts such as instruction disassemblies.
5843The default is off.
5844
c906108c 5845@item show print asm-demangle
b37052ae 5846Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5847or demangled form.
5848
b37052ae
EZ
5849@cindex C@t{++} symbol decoding style
5850@cindex symbol decoding style, C@t{++}
a8f24a35 5851@kindex set demangle-style
c906108c
SS
5852@item set demangle-style @var{style}
5853Choose among several encoding schemes used by different compilers to
b37052ae 5854represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5855
5856@table @code
5857@item auto
5858Allow @value{GDBN} to choose a decoding style by inspecting your program.
5859
5860@item gnu
b37052ae 5861Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5862This is the default.
c906108c
SS
5863
5864@item hp
b37052ae 5865Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5866
5867@item lucid
b37052ae 5868Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5869
5870@item arm
b37052ae 5871Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5872@strong{Warning:} this setting alone is not sufficient to allow
5873debugging @code{cfront}-generated executables. @value{GDBN} would
5874require further enhancement to permit that.
5875
5876@end table
5877If you omit @var{style}, you will see a list of possible formats.
5878
c906108c 5879@item show demangle-style
b37052ae 5880Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5881
c906108c
SS
5882@item set print object
5883@itemx set print object on
4644b6e3 5884@cindex derived type of an object, printing
9c16f35a 5885@cindex display derived types
c906108c
SS
5886When displaying a pointer to an object, identify the @emph{actual}
5887(derived) type of the object rather than the @emph{declared} type, using
5888the virtual function table.
5889
5890@item set print object off
5891Display only the declared type of objects, without reference to the
5892virtual function table. This is the default setting.
5893
c906108c
SS
5894@item show print object
5895Show whether actual, or declared, object types are displayed.
5896
c906108c
SS
5897@item set print static-members
5898@itemx set print static-members on
4644b6e3 5899@cindex static members of C@t{++} objects
b37052ae 5900Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5901
5902@item set print static-members off
b37052ae 5903Do not print static members when displaying a C@t{++} object.
c906108c 5904
c906108c 5905@item show print static-members
9c16f35a
EZ
5906Show whether C@t{++} static members are printed or not.
5907
5908@item set print pascal_static-members
5909@itemx set print pascal_static-members on
5910@cindex static members of Pacal objects
5911@cindex Pacal objects, static members display
5912Print static members when displaying a Pascal object. The default is on.
5913
5914@item set print pascal_static-members off
5915Do not print static members when displaying a Pascal object.
5916
5917@item show print pascal_static-members
5918Show whether Pascal static members are printed or not.
c906108c
SS
5919
5920@c These don't work with HP ANSI C++ yet.
c906108c
SS
5921@item set print vtbl
5922@itemx set print vtbl on
4644b6e3 5923@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5924@cindex virtual functions (C@t{++}) display
5925@cindex VTBL display
b37052ae 5926Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5927(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5928ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5929
5930@item set print vtbl off
b37052ae 5931Do not pretty print C@t{++} virtual function tables.
c906108c 5932
c906108c 5933@item show print vtbl
b37052ae 5934Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5935@end table
c906108c 5936
6d2ebf8b 5937@node Value History
c906108c
SS
5938@section Value history
5939
5940@cindex value history
9c16f35a 5941@cindex history of values printed by @value{GDBN}
5d161b24
DB
5942Values printed by the @code{print} command are saved in the @value{GDBN}
5943@dfn{value history}. This allows you to refer to them in other expressions.
5944Values are kept until the symbol table is re-read or discarded
5945(for example with the @code{file} or @code{symbol-file} commands).
5946When the symbol table changes, the value history is discarded,
5947since the values may contain pointers back to the types defined in the
c906108c
SS
5948symbol table.
5949
5950@cindex @code{$}
5951@cindex @code{$$}
5952@cindex history number
5953The values printed are given @dfn{history numbers} by which you can
5954refer to them. These are successive integers starting with one.
5955@code{print} shows you the history number assigned to a value by
5956printing @samp{$@var{num} = } before the value; here @var{num} is the
5957history number.
5958
5959To refer to any previous value, use @samp{$} followed by the value's
5960history number. The way @code{print} labels its output is designed to
5961remind you of this. Just @code{$} refers to the most recent value in
5962the history, and @code{$$} refers to the value before that.
5963@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5964is the value just prior to @code{$$}, @code{$$1} is equivalent to
5965@code{$$}, and @code{$$0} is equivalent to @code{$}.
5966
5967For example, suppose you have just printed a pointer to a structure and
5968want to see the contents of the structure. It suffices to type
5969
474c8240 5970@smallexample
c906108c 5971p *$
474c8240 5972@end smallexample
c906108c
SS
5973
5974If you have a chain of structures where the component @code{next} points
5975to the next one, you can print the contents of the next one with this:
5976
474c8240 5977@smallexample
c906108c 5978p *$.next
474c8240 5979@end smallexample
c906108c
SS
5980
5981@noindent
5982You can print successive links in the chain by repeating this
5983command---which you can do by just typing @key{RET}.
5984
5985Note that the history records values, not expressions. If the value of
5986@code{x} is 4 and you type these commands:
5987
474c8240 5988@smallexample
c906108c
SS
5989print x
5990set x=5
474c8240 5991@end smallexample
c906108c
SS
5992
5993@noindent
5994then the value recorded in the value history by the @code{print} command
5995remains 4 even though the value of @code{x} has changed.
5996
5997@table @code
5998@kindex show values
5999@item show values
6000Print the last ten values in the value history, with their item numbers.
6001This is like @samp{p@ $$9} repeated ten times, except that @code{show
6002values} does not change the history.
6003
6004@item show values @var{n}
6005Print ten history values centered on history item number @var{n}.
6006
6007@item show values +
6008Print ten history values just after the values last printed. If no more
6009values are available, @code{show values +} produces no display.
6010@end table
6011
6012Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6013same effect as @samp{show values +}.
6014
6d2ebf8b 6015@node Convenience Vars
c906108c
SS
6016@section Convenience variables
6017
6018@cindex convenience variables
9c16f35a 6019@cindex user-defined variables
c906108c
SS
6020@value{GDBN} provides @dfn{convenience variables} that you can use within
6021@value{GDBN} to hold on to a value and refer to it later. These variables
6022exist entirely within @value{GDBN}; they are not part of your program, and
6023setting a convenience variable has no direct effect on further execution
6024of your program. That is why you can use them freely.
6025
6026Convenience variables are prefixed with @samp{$}. Any name preceded by
6027@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6028the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6029(Value history references, in contrast, are @emph{numbers} preceded
6030by @samp{$}. @xref{Value History, ,Value history}.)
6031
6032You can save a value in a convenience variable with an assignment
6033expression, just as you would set a variable in your program.
6034For example:
6035
474c8240 6036@smallexample
c906108c 6037set $foo = *object_ptr
474c8240 6038@end smallexample
c906108c
SS
6039
6040@noindent
6041would save in @code{$foo} the value contained in the object pointed to by
6042@code{object_ptr}.
6043
6044Using a convenience variable for the first time creates it, but its
6045value is @code{void} until you assign a new value. You can alter the
6046value with another assignment at any time.
6047
6048Convenience variables have no fixed types. You can assign a convenience
6049variable any type of value, including structures and arrays, even if
6050that variable already has a value of a different type. The convenience
6051variable, when used as an expression, has the type of its current value.
6052
6053@table @code
6054@kindex show convenience
9c16f35a 6055@cindex show all user variables
c906108c
SS
6056@item show convenience
6057Print a list of convenience variables used so far, and their values.
d4f3574e 6058Abbreviated @code{show conv}.
c906108c
SS
6059@end table
6060
6061One of the ways to use a convenience variable is as a counter to be
6062incremented or a pointer to be advanced. For example, to print
6063a field from successive elements of an array of structures:
6064
474c8240 6065@smallexample
c906108c
SS
6066set $i = 0
6067print bar[$i++]->contents
474c8240 6068@end smallexample
c906108c 6069
d4f3574e
SS
6070@noindent
6071Repeat that command by typing @key{RET}.
c906108c
SS
6072
6073Some convenience variables are created automatically by @value{GDBN} and given
6074values likely to be useful.
6075
6076@table @code
41afff9a 6077@vindex $_@r{, convenience variable}
c906108c
SS
6078@item $_
6079The variable @code{$_} is automatically set by the @code{x} command to
6080the last address examined (@pxref{Memory, ,Examining memory}). Other
6081commands which provide a default address for @code{x} to examine also
6082set @code{$_} to that address; these commands include @code{info line}
6083and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6084except when set by the @code{x} command, in which case it is a pointer
6085to the type of @code{$__}.
6086
41afff9a 6087@vindex $__@r{, convenience variable}
c906108c
SS
6088@item $__
6089The variable @code{$__} is automatically set by the @code{x} command
6090to the value found in the last address examined. Its type is chosen
6091to match the format in which the data was printed.
6092
6093@item $_exitcode
41afff9a 6094@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6095The variable @code{$_exitcode} is automatically set to the exit code when
6096the program being debugged terminates.
6097@end table
6098
53a5351d
JM
6099On HP-UX systems, if you refer to a function or variable name that
6100begins with a dollar sign, @value{GDBN} searches for a user or system
6101name first, before it searches for a convenience variable.
c906108c 6102
6d2ebf8b 6103@node Registers
c906108c
SS
6104@section Registers
6105
6106@cindex registers
6107You can refer to machine register contents, in expressions, as variables
6108with names starting with @samp{$}. The names of registers are different
6109for each machine; use @code{info registers} to see the names used on
6110your machine.
6111
6112@table @code
6113@kindex info registers
6114@item info registers
6115Print the names and values of all registers except floating-point
c85508ee 6116and vector registers (in the selected stack frame).
c906108c
SS
6117
6118@kindex info all-registers
6119@cindex floating point registers
6120@item info all-registers
6121Print the names and values of all registers, including floating-point
c85508ee 6122and vector registers (in the selected stack frame).
c906108c
SS
6123
6124@item info registers @var{regname} @dots{}
6125Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6126As discussed in detail below, register values are normally relative to
6127the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6128the machine you are using, with or without the initial @samp{$}.
6129@end table
6130
6131@value{GDBN} has four ``standard'' register names that are available (in
6132expressions) on most machines---whenever they do not conflict with an
6133architecture's canonical mnemonics for registers. The register names
6134@code{$pc} and @code{$sp} are used for the program counter register and
6135the stack pointer. @code{$fp} is used for a register that contains a
6136pointer to the current stack frame, and @code{$ps} is used for a
6137register that contains the processor status. For example,
6138you could print the program counter in hex with
6139
474c8240 6140@smallexample
c906108c 6141p/x $pc
474c8240 6142@end smallexample
c906108c
SS
6143
6144@noindent
6145or print the instruction to be executed next with
6146
474c8240 6147@smallexample
c906108c 6148x/i $pc
474c8240 6149@end smallexample
c906108c
SS
6150
6151@noindent
6152or add four to the stack pointer@footnote{This is a way of removing
6153one word from the stack, on machines where stacks grow downward in
6154memory (most machines, nowadays). This assumes that the innermost
6155stack frame is selected; setting @code{$sp} is not allowed when other
6156stack frames are selected. To pop entire frames off the stack,
6157regardless of machine architecture, use @code{return};
d4f3574e 6158see @ref{Returning, ,Returning from a function}.} with
c906108c 6159
474c8240 6160@smallexample
c906108c 6161set $sp += 4
474c8240 6162@end smallexample
c906108c
SS
6163
6164Whenever possible, these four standard register names are available on
6165your machine even though the machine has different canonical mnemonics,
6166so long as there is no conflict. The @code{info registers} command
6167shows the canonical names. For example, on the SPARC, @code{info
6168registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6169can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6170is an alias for the @sc{eflags} register.
c906108c
SS
6171
6172@value{GDBN} always considers the contents of an ordinary register as an
6173integer when the register is examined in this way. Some machines have
6174special registers which can hold nothing but floating point; these
6175registers are considered to have floating point values. There is no way
6176to refer to the contents of an ordinary register as floating point value
6177(although you can @emph{print} it as a floating point value with
6178@samp{print/f $@var{regname}}).
6179
6180Some registers have distinct ``raw'' and ``virtual'' data formats. This
6181means that the data format in which the register contents are saved by
6182the operating system is not the same one that your program normally
6183sees. For example, the registers of the 68881 floating point
6184coprocessor are always saved in ``extended'' (raw) format, but all C
6185programs expect to work with ``double'' (virtual) format. In such
5d161b24 6186cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6187that makes sense for your program), but the @code{info registers} command
6188prints the data in both formats.
6189
6190Normally, register values are relative to the selected stack frame
6191(@pxref{Selection, ,Selecting a frame}). This means that you get the
6192value that the register would contain if all stack frames farther in
6193were exited and their saved registers restored. In order to see the
6194true contents of hardware registers, you must select the innermost
6195frame (with @samp{frame 0}).
6196
6197However, @value{GDBN} must deduce where registers are saved, from the machine
6198code generated by your compiler. If some registers are not saved, or if
6199@value{GDBN} is unable to locate the saved registers, the selected stack
6200frame makes no difference.
6201
6d2ebf8b 6202@node Floating Point Hardware
c906108c
SS
6203@section Floating point hardware
6204@cindex floating point
6205
6206Depending on the configuration, @value{GDBN} may be able to give
6207you more information about the status of the floating point hardware.
6208
6209@table @code
6210@kindex info float
6211@item info float
6212Display hardware-dependent information about the floating
6213point unit. The exact contents and layout vary depending on the
6214floating point chip. Currently, @samp{info float} is supported on
6215the ARM and x86 machines.
6216@end table
c906108c 6217
e76f1f2e
AC
6218@node Vector Unit
6219@section Vector Unit
6220@cindex vector unit
6221
6222Depending on the configuration, @value{GDBN} may be able to give you
6223more information about the status of the vector unit.
6224
6225@table @code
6226@kindex info vector
6227@item info vector
6228Display information about the vector unit. The exact contents and
6229layout vary depending on the hardware.
6230@end table
6231
721c2651
EZ
6232@node OS Information
6233@section Operating system auxiliary information
6234@cindex OS information
6235
6236@value{GDBN} provides interfaces to useful OS facilities that can help
6237you debug your program.
6238
6239@cindex @code{ptrace} system call
6240@cindex @code{struct user} contents
6241When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6242machines), it interfaces with the inferior via the @code{ptrace}
6243system call. The operating system creates a special sata structure,
6244called @code{struct user}, for this interface. You can use the
6245command @code{info udot} to display the contents of this data
6246structure.
6247
6248@table @code
6249@item info udot
6250@kindex info udot
6251Display the contents of the @code{struct user} maintained by the OS
6252kernel for the program being debugged. @value{GDBN} displays the
6253contents of @code{struct user} as a list of hex numbers, similar to
6254the @code{examine} command.
6255@end table
6256
b383017d
RM
6257@cindex auxiliary vector
6258@cindex vector, auxiliary
b383017d
RM
6259Some operating systems supply an @dfn{auxiliary vector} to programs at
6260startup. This is akin to the arguments and environment that you
6261specify for a program, but contains a system-dependent variety of
6262binary values that tell system libraries important details about the
6263hardware, operating system, and process. Each value's purpose is
6264identified by an integer tag; the meanings are well-known but system-specific.
6265Depending on the configuration and operating system facilities,
9c16f35a
EZ
6266@value{GDBN} may be able to show you this information. For remote
6267targets, this functionality may further depend on the remote stub's
6268support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6269configuration, auxiliary vector}.
b383017d
RM
6270
6271@table @code
6272@kindex info auxv
6273@item info auxv
6274Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6275live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6276numerically, and also shows names and text descriptions for recognized
6277tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6278pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6279most appropriate form for a recognized tag, and in hexadecimal for
6280an unrecognized tag.
6281@end table
6282
721c2651 6283
29e57380 6284@node Memory Region Attributes
b383017d 6285@section Memory region attributes
29e57380
C
6286@cindex memory region attributes
6287
b383017d
RM
6288@dfn{Memory region attributes} allow you to describe special handling
6289required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6290to determine whether to allow certain types of memory accesses; whether to
6291use specific width accesses; and whether to cache target memory.
6292
6293Defined memory regions can be individually enabled and disabled. When a
6294memory region is disabled, @value{GDBN} uses the default attributes when
6295accessing memory in that region. Similarly, if no memory regions have
6296been defined, @value{GDBN} uses the default attributes when accessing
6297all memory.
6298
b383017d 6299When a memory region is defined, it is given a number to identify it;
29e57380
C
6300to enable, disable, or remove a memory region, you specify that number.
6301
6302@table @code
6303@kindex mem
bfac230e 6304@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6305Define a memory region bounded by @var{lower} and @var{upper} with
6306attributes @var{attributes}@dots{}, and add it to the list of regions
6307monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6308case: it is treated as the the target's maximum memory address.
bfac230e 6309(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6310
6311@kindex delete mem
6312@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6313Remove memory regions @var{nums}@dots{} from the list of regions
6314monitored by @value{GDBN}.
29e57380
C
6315
6316@kindex disable mem
6317@item disable mem @var{nums}@dots{}
09d4efe1 6318Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6319A disabled memory region is not forgotten.
29e57380
C
6320It may be enabled again later.
6321
6322@kindex enable mem
6323@item enable mem @var{nums}@dots{}
09d4efe1 6324Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6325
6326@kindex info mem
6327@item info mem
6328Print a table of all defined memory regions, with the following columns
09d4efe1 6329for each region:
29e57380
C
6330
6331@table @emph
6332@item Memory Region Number
6333@item Enabled or Disabled.
b383017d 6334Enabled memory regions are marked with @samp{y}.
29e57380
C
6335Disabled memory regions are marked with @samp{n}.
6336
6337@item Lo Address
6338The address defining the inclusive lower bound of the memory region.
6339
6340@item Hi Address
6341The address defining the exclusive upper bound of the memory region.
6342
6343@item Attributes
6344The list of attributes set for this memory region.
6345@end table
6346@end table
6347
6348
6349@subsection Attributes
6350
b383017d 6351@subsubsection Memory Access Mode
29e57380
C
6352The access mode attributes set whether @value{GDBN} may make read or
6353write accesses to a memory region.
6354
6355While these attributes prevent @value{GDBN} from performing invalid
6356memory accesses, they do nothing to prevent the target system, I/O DMA,
6357etc. from accessing memory.
6358
6359@table @code
6360@item ro
6361Memory is read only.
6362@item wo
6363Memory is write only.
6364@item rw
6ca652b0 6365Memory is read/write. This is the default.
29e57380
C
6366@end table
6367
6368@subsubsection Memory Access Size
6369The acccess size attributes tells @value{GDBN} to use specific sized
6370accesses in the memory region. Often memory mapped device registers
6371require specific sized accesses. If no access size attribute is
6372specified, @value{GDBN} may use accesses of any size.
6373
6374@table @code
6375@item 8
6376Use 8 bit memory accesses.
6377@item 16
6378Use 16 bit memory accesses.
6379@item 32
6380Use 32 bit memory accesses.
6381@item 64
6382Use 64 bit memory accesses.
6383@end table
6384
6385@c @subsubsection Hardware/Software Breakpoints
6386@c The hardware/software breakpoint attributes set whether @value{GDBN}
6387@c will use hardware or software breakpoints for the internal breakpoints
6388@c used by the step, next, finish, until, etc. commands.
6389@c
6390@c @table @code
6391@c @item hwbreak
b383017d 6392@c Always use hardware breakpoints
29e57380
C
6393@c @item swbreak (default)
6394@c @end table
6395
6396@subsubsection Data Cache
6397The data cache attributes set whether @value{GDBN} will cache target
6398memory. While this generally improves performance by reducing debug
6399protocol overhead, it can lead to incorrect results because @value{GDBN}
6400does not know about volatile variables or memory mapped device
6401registers.
6402
6403@table @code
6404@item cache
b383017d 6405Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6406@item nocache
6407Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6408@end table
6409
6410@c @subsubsection Memory Write Verification
b383017d 6411@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6412@c will re-reads data after each write to verify the write was successful.
6413@c
6414@c @table @code
6415@c @item verify
6416@c @item noverify (default)
6417@c @end table
6418
16d9dec6
MS
6419@node Dump/Restore Files
6420@section Copy between memory and a file
6421@cindex dump/restore files
6422@cindex append data to a file
6423@cindex dump data to a file
6424@cindex restore data from a file
16d9dec6 6425
df5215a6
JB
6426You can use the commands @code{dump}, @code{append}, and
6427@code{restore} to copy data between target memory and a file. The
6428@code{dump} and @code{append} commands write data to a file, and the
6429@code{restore} command reads data from a file back into the inferior's
6430memory. Files may be in binary, Motorola S-record, Intel hex, or
6431Tektronix Hex format; however, @value{GDBN} can only append to binary
6432files.
6433
6434@table @code
6435
6436@kindex dump
6437@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6438@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6439Dump the contents of memory from @var{start_addr} to @var{end_addr},
6440or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6441
df5215a6 6442The @var{format} parameter may be any one of:
16d9dec6 6443@table @code
df5215a6
JB
6444@item binary
6445Raw binary form.
6446@item ihex
6447Intel hex format.
6448@item srec
6449Motorola S-record format.
6450@item tekhex
6451Tektronix Hex format.
6452@end table
6453
6454@value{GDBN} uses the same definitions of these formats as the
6455@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6456@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6457form.
6458
6459@kindex append
6460@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6461@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6462Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6463or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6464(@value{GDBN} can only append data to files in raw binary form.)
6465
6466@kindex restore
6467@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6468Restore the contents of file @var{filename} into memory. The
6469@code{restore} command can automatically recognize any known @sc{bfd}
6470file format, except for raw binary. To restore a raw binary file you
6471must specify the optional keyword @code{binary} after the filename.
16d9dec6 6472
b383017d 6473If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6474contained in the file. Binary files always start at address zero, so
6475they will be restored at address @var{bias}. Other bfd files have
6476a built-in location; they will be restored at offset @var{bias}
6477from that location.
6478
6479If @var{start} and/or @var{end} are non-zero, then only data between
6480file offset @var{start} and file offset @var{end} will be restored.
b383017d 6481These offsets are relative to the addresses in the file, before
16d9dec6
MS
6482the @var{bias} argument is applied.
6483
6484@end table
6485
384ee23f
EZ
6486@node Core File Generation
6487@section How to Produce a Core File from Your Program
6488@cindex dump core from inferior
6489
6490A @dfn{core file} or @dfn{core dump} is a file that records the memory
6491image of a running process and its process status (register values
6492etc.). Its primary use is post-mortem debugging of a program that
6493crashed while it ran outside a debugger. A program that crashes
6494automatically produces a core file, unless this feature is disabled by
6495the user. @xref{Files}, for information on invoking @value{GDBN} in
6496the post-mortem debugging mode.
6497
6498Occasionally, you may wish to produce a core file of the program you
6499are debugging in order to preserve a snapshot of its state.
6500@value{GDBN} has a special command for that.
6501
6502@table @code
6503@kindex gcore
6504@kindex generate-core-file
6505@item generate-core-file [@var{file}]
6506@itemx gcore [@var{file}]
6507Produce a core dump of the inferior process. The optional argument
6508@var{file} specifies the file name where to put the core dump. If not
6509specified, the file name defaults to @file{core.@var{pid}}, where
6510@var{pid} is the inferior process ID.
6511
6512Note that this command is implemented only for some systems (as of
6513this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6514@end table
6515
a0eb71c5
KB
6516@node Character Sets
6517@section Character Sets
6518@cindex character sets
6519@cindex charset
6520@cindex translating between character sets
6521@cindex host character set
6522@cindex target character set
6523
6524If the program you are debugging uses a different character set to
6525represent characters and strings than the one @value{GDBN} uses itself,
6526@value{GDBN} can automatically translate between the character sets for
6527you. The character set @value{GDBN} uses we call the @dfn{host
6528character set}; the one the inferior program uses we call the
6529@dfn{target character set}.
6530
6531For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6532uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6533remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6534running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6535then the host character set is Latin-1, and the target character set is
6536@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6537target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6538@sc{ebcdic} and Latin 1 as you print character or string values, or use
6539character and string literals in expressions.
6540
6541@value{GDBN} has no way to automatically recognize which character set
6542the inferior program uses; you must tell it, using the @code{set
6543target-charset} command, described below.
6544
6545Here are the commands for controlling @value{GDBN}'s character set
6546support:
6547
6548@table @code
6549@item set target-charset @var{charset}
6550@kindex set target-charset
6551Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6552character set names @value{GDBN} recognizes below, but if you type
6553@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6554list the target character sets it supports.
a0eb71c5
KB
6555@end table
6556
6557@table @code
6558@item set host-charset @var{charset}
6559@kindex set host-charset
6560Set the current host character set to @var{charset}.
6561
6562By default, @value{GDBN} uses a host character set appropriate to the
6563system it is running on; you can override that default using the
6564@code{set host-charset} command.
6565
6566@value{GDBN} can only use certain character sets as its host character
6567set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6568indicate which can be host character sets, but if you type
6569@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6570list the host character sets it supports.
a0eb71c5
KB
6571
6572@item set charset @var{charset}
6573@kindex set charset
e33d66ec
EZ
6574Set the current host and target character sets to @var{charset}. As
6575above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6576@value{GDBN} will list the name of the character sets that can be used
6577for both host and target.
6578
a0eb71c5
KB
6579
6580@item show charset
a0eb71c5 6581@kindex show charset
b383017d 6582Show the names of the current host and target charsets.
e33d66ec
EZ
6583
6584@itemx show host-charset
a0eb71c5 6585@kindex show host-charset
b383017d 6586Show the name of the current host charset.
e33d66ec
EZ
6587
6588@itemx show target-charset
a0eb71c5 6589@kindex show target-charset
b383017d 6590Show the name of the current target charset.
a0eb71c5
KB
6591
6592@end table
6593
6594@value{GDBN} currently includes support for the following character
6595sets:
6596
6597@table @code
6598
6599@item ASCII
6600@cindex ASCII character set
6601Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6602character set.
6603
6604@item ISO-8859-1
6605@cindex ISO 8859-1 character set
6606@cindex ISO Latin 1 character set
e33d66ec 6607The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6608characters needed for French, German, and Spanish. @value{GDBN} can use
6609this as its host character set.
6610
6611@item EBCDIC-US
6612@itemx IBM1047
6613@cindex EBCDIC character set
6614@cindex IBM1047 character set
6615Variants of the @sc{ebcdic} character set, used on some of IBM's
6616mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6617@value{GDBN} cannot use these as its host character set.
6618
6619@end table
6620
6621Note that these are all single-byte character sets. More work inside
6622GDB is needed to support multi-byte or variable-width character
6623encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6624
6625Here is an example of @value{GDBN}'s character set support in action.
6626Assume that the following source code has been placed in the file
6627@file{charset-test.c}:
6628
6629@smallexample
6630#include <stdio.h>
6631
6632char ascii_hello[]
6633 = @{72, 101, 108, 108, 111, 44, 32, 119,
6634 111, 114, 108, 100, 33, 10, 0@};
6635char ibm1047_hello[]
6636 = @{200, 133, 147, 147, 150, 107, 64, 166,
6637 150, 153, 147, 132, 90, 37, 0@};
6638
6639main ()
6640@{
6641 printf ("Hello, world!\n");
6642@}
10998722 6643@end smallexample
a0eb71c5
KB
6644
6645In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6646containing the string @samp{Hello, world!} followed by a newline,
6647encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6648
6649We compile the program, and invoke the debugger on it:
6650
6651@smallexample
6652$ gcc -g charset-test.c -o charset-test
6653$ gdb -nw charset-test
6654GNU gdb 2001-12-19-cvs
6655Copyright 2001 Free Software Foundation, Inc.
6656@dots{}
f7dc1244 6657(@value{GDBP})
10998722 6658@end smallexample
a0eb71c5
KB
6659
6660We can use the @code{show charset} command to see what character sets
6661@value{GDBN} is currently using to interpret and display characters and
6662strings:
6663
6664@smallexample
f7dc1244 6665(@value{GDBP}) show charset
e33d66ec 6666The current host and target character set is `ISO-8859-1'.
f7dc1244 6667(@value{GDBP})
10998722 6668@end smallexample
a0eb71c5
KB
6669
6670For the sake of printing this manual, let's use @sc{ascii} as our
6671initial character set:
6672@smallexample
f7dc1244
EZ
6673(@value{GDBP}) set charset ASCII
6674(@value{GDBP}) show charset
e33d66ec 6675The current host and target character set is `ASCII'.
f7dc1244 6676(@value{GDBP})
10998722 6677@end smallexample
a0eb71c5
KB
6678
6679Let's assume that @sc{ascii} is indeed the correct character set for our
6680host system --- in other words, let's assume that if @value{GDBN} prints
6681characters using the @sc{ascii} character set, our terminal will display
6682them properly. Since our current target character set is also
6683@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6684
6685@smallexample
f7dc1244 6686(@value{GDBP}) print ascii_hello
a0eb71c5 6687$1 = 0x401698 "Hello, world!\n"
f7dc1244 6688(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6689$2 = 72 'H'
f7dc1244 6690(@value{GDBP})
10998722 6691@end smallexample
a0eb71c5
KB
6692
6693@value{GDBN} uses the target character set for character and string
6694literals you use in expressions:
6695
6696@smallexample
f7dc1244 6697(@value{GDBP}) print '+'
a0eb71c5 6698$3 = 43 '+'
f7dc1244 6699(@value{GDBP})
10998722 6700@end smallexample
a0eb71c5
KB
6701
6702The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6703character.
6704
6705@value{GDBN} relies on the user to tell it which character set the
6706target program uses. If we print @code{ibm1047_hello} while our target
6707character set is still @sc{ascii}, we get jibberish:
6708
6709@smallexample
f7dc1244 6710(@value{GDBP}) print ibm1047_hello
a0eb71c5 6711$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6712(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6713$5 = 200 '\310'
f7dc1244 6714(@value{GDBP})
10998722 6715@end smallexample
a0eb71c5 6716
e33d66ec 6717If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6718@value{GDBN} tells us the character sets it supports:
6719
6720@smallexample
f7dc1244 6721(@value{GDBP}) set target-charset
b383017d 6722ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6723(@value{GDBP}) set target-charset
10998722 6724@end smallexample
a0eb71c5
KB
6725
6726We can select @sc{ibm1047} as our target character set, and examine the
6727program's strings again. Now the @sc{ascii} string is wrong, but
6728@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6729target character set, @sc{ibm1047}, to the host character set,
6730@sc{ascii}, and they display correctly:
6731
6732@smallexample
f7dc1244
EZ
6733(@value{GDBP}) set target-charset IBM1047
6734(@value{GDBP}) show charset
e33d66ec
EZ
6735The current host character set is `ASCII'.
6736The current target character set is `IBM1047'.
f7dc1244 6737(@value{GDBP}) print ascii_hello
a0eb71c5 6738$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6739(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6740$7 = 72 '\110'
f7dc1244 6741(@value{GDBP}) print ibm1047_hello
a0eb71c5 6742$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6743(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6744$9 = 200 'H'
f7dc1244 6745(@value{GDBP})
10998722 6746@end smallexample
a0eb71c5
KB
6747
6748As above, @value{GDBN} uses the target character set for character and
6749string literals you use in expressions:
6750
6751@smallexample
f7dc1244 6752(@value{GDBP}) print '+'
a0eb71c5 6753$10 = 78 '+'
f7dc1244 6754(@value{GDBP})
10998722 6755@end smallexample
a0eb71c5 6756
e33d66ec 6757The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6758character.
6759
09d4efe1
EZ
6760@node Caching Remote Data
6761@section Caching Data of Remote Targets
6762@cindex caching data of remote targets
6763
6764@value{GDBN} can cache data exchanged between the debugger and a
6765remote target (@pxref{Remote}). Such caching generally improves
6766performance, because it reduces the overhead of the remote protocol by
6767bundling memory reads and writes into large chunks. Unfortunately,
6768@value{GDBN} does not currently know anything about volatile
6769registers, and thus data caching will produce incorrect results when
6770volatile registers are in use.
6771
6772@table @code
6773@kindex set remotecache
6774@item set remotecache on
6775@itemx set remotecache off
6776Set caching state for remote targets. When @code{ON}, use data
6777caching. By default, this option is @code{OFF}.
6778
6779@kindex show remotecache
6780@item show remotecache
6781Show the current state of data caching for remote targets.
6782
6783@kindex info dcache
6784@item info dcache
6785Print the information about the data cache performance. The
6786information displayed includes: the dcache width and depth; and for
6787each cache line, how many times it was referenced, and its data and
6788state (dirty, bad, ok, etc.). This command is useful for debugging
6789the data cache operation.
6790@end table
6791
a0eb71c5 6792
e2e0bcd1
JB
6793@node Macros
6794@chapter C Preprocessor Macros
6795
49efadf5 6796Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6797``preprocessor macros'' which expand into strings of tokens.
6798@value{GDBN} can evaluate expressions containing macro invocations, show
6799the result of macro expansion, and show a macro's definition, including
6800where it was defined.
6801
6802You may need to compile your program specially to provide @value{GDBN}
6803with information about preprocessor macros. Most compilers do not
6804include macros in their debugging information, even when you compile
6805with the @option{-g} flag. @xref{Compilation}.
6806
6807A program may define a macro at one point, remove that definition later,
6808and then provide a different definition after that. Thus, at different
6809points in the program, a macro may have different definitions, or have
6810no definition at all. If there is a current stack frame, @value{GDBN}
6811uses the macros in scope at that frame's source code line. Otherwise,
6812@value{GDBN} uses the macros in scope at the current listing location;
6813see @ref{List}.
6814
6815At the moment, @value{GDBN} does not support the @code{##}
6816token-splicing operator, the @code{#} stringification operator, or
6817variable-arity macros.
6818
6819Whenever @value{GDBN} evaluates an expression, it always expands any
6820macro invocations present in the expression. @value{GDBN} also provides
6821the following commands for working with macros explicitly.
6822
6823@table @code
6824
6825@kindex macro expand
6826@cindex macro expansion, showing the results of preprocessor
6827@cindex preprocessor macro expansion, showing the results of
6828@cindex expanding preprocessor macros
6829@item macro expand @var{expression}
6830@itemx macro exp @var{expression}
6831Show the results of expanding all preprocessor macro invocations in
6832@var{expression}. Since @value{GDBN} simply expands macros, but does
6833not parse the result, @var{expression} need not be a valid expression;
6834it can be any string of tokens.
6835
09d4efe1 6836@kindex macro exp1
e2e0bcd1
JB
6837@item macro expand-once @var{expression}
6838@itemx macro exp1 @var{expression}
4644b6e3 6839@cindex expand macro once
e2e0bcd1
JB
6840@i{(This command is not yet implemented.)} Show the results of
6841expanding those preprocessor macro invocations that appear explicitly in
6842@var{expression}. Macro invocations appearing in that expansion are
6843left unchanged. This command allows you to see the effect of a
6844particular macro more clearly, without being confused by further
6845expansions. Since @value{GDBN} simply expands macros, but does not
6846parse the result, @var{expression} need not be a valid expression; it
6847can be any string of tokens.
6848
475b0867 6849@kindex info macro
e2e0bcd1
JB
6850@cindex macro definition, showing
6851@cindex definition, showing a macro's
475b0867 6852@item info macro @var{macro}
e2e0bcd1
JB
6853Show the definition of the macro named @var{macro}, and describe the
6854source location where that definition was established.
6855
6856@kindex macro define
6857@cindex user-defined macros
6858@cindex defining macros interactively
6859@cindex macros, user-defined
6860@item macro define @var{macro} @var{replacement-list}
6861@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6862@i{(This command is not yet implemented.)} Introduce a definition for a
6863preprocessor macro named @var{macro}, invocations of which are replaced
6864by the tokens given in @var{replacement-list}. The first form of this
6865command defines an ``object-like'' macro, which takes no arguments; the
6866second form defines a ``function-like'' macro, which takes the arguments
6867given in @var{arglist}.
6868
6869A definition introduced by this command is in scope in every expression
6870evaluated in @value{GDBN}, until it is removed with the @command{macro
6871undef} command, described below. The definition overrides all
6872definitions for @var{macro} present in the program being debugged, as
6873well as any previous user-supplied definition.
6874
6875@kindex macro undef
6876@item macro undef @var{macro}
6877@i{(This command is not yet implemented.)} Remove any user-supplied
6878definition for the macro named @var{macro}. This command only affects
6879definitions provided with the @command{macro define} command, described
6880above; it cannot remove definitions present in the program being
6881debugged.
6882
09d4efe1
EZ
6883@kindex macro list
6884@item macro list
6885@i{(This command is not yet implemented.)} List all the macros
6886defined using the @code{macro define} command.
e2e0bcd1
JB
6887@end table
6888
6889@cindex macros, example of debugging with
6890Here is a transcript showing the above commands in action. First, we
6891show our source files:
6892
6893@smallexample
6894$ cat sample.c
6895#include <stdio.h>
6896#include "sample.h"
6897
6898#define M 42
6899#define ADD(x) (M + x)
6900
6901main ()
6902@{
6903#define N 28
6904 printf ("Hello, world!\n");
6905#undef N
6906 printf ("We're so creative.\n");
6907#define N 1729
6908 printf ("Goodbye, world!\n");
6909@}
6910$ cat sample.h
6911#define Q <
6912$
6913@end smallexample
6914
6915Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6916We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6917compiler includes information about preprocessor macros in the debugging
6918information.
6919
6920@smallexample
6921$ gcc -gdwarf-2 -g3 sample.c -o sample
6922$
6923@end smallexample
6924
6925Now, we start @value{GDBN} on our sample program:
6926
6927@smallexample
6928$ gdb -nw sample
6929GNU gdb 2002-05-06-cvs
6930Copyright 2002 Free Software Foundation, Inc.
6931GDB is free software, @dots{}
f7dc1244 6932(@value{GDBP})
e2e0bcd1
JB
6933@end smallexample
6934
6935We can expand macros and examine their definitions, even when the
6936program is not running. @value{GDBN} uses the current listing position
6937to decide which macro definitions are in scope:
6938
6939@smallexample
f7dc1244 6940(@value{GDBP}) list main
e2e0bcd1
JB
69413
69424 #define M 42
69435 #define ADD(x) (M + x)
69446
69457 main ()
69468 @{
69479 #define N 28
694810 printf ("Hello, world!\n");
694911 #undef N
695012 printf ("We're so creative.\n");
f7dc1244 6951(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6952Defined at /home/jimb/gdb/macros/play/sample.c:5
6953#define ADD(x) (M + x)
f7dc1244 6954(@value{GDBP}) info macro Q
e2e0bcd1
JB
6955Defined at /home/jimb/gdb/macros/play/sample.h:1
6956 included at /home/jimb/gdb/macros/play/sample.c:2
6957#define Q <
f7dc1244 6958(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6959expands to: (42 + 1)
f7dc1244 6960(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6961expands to: once (M + 1)
f7dc1244 6962(@value{GDBP})
e2e0bcd1
JB
6963@end smallexample
6964
6965In the example above, note that @command{macro expand-once} expands only
6966the macro invocation explicit in the original text --- the invocation of
6967@code{ADD} --- but does not expand the invocation of the macro @code{M},
6968which was introduced by @code{ADD}.
6969
6970Once the program is running, GDB uses the macro definitions in force at
6971the source line of the current stack frame:
6972
6973@smallexample
f7dc1244 6974(@value{GDBP}) break main
e2e0bcd1 6975Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6976(@value{GDBP}) run
b383017d 6977Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6978
6979Breakpoint 1, main () at sample.c:10
698010 printf ("Hello, world!\n");
f7dc1244 6981(@value{GDBP})
e2e0bcd1
JB
6982@end smallexample
6983
6984At line 10, the definition of the macro @code{N} at line 9 is in force:
6985
6986@smallexample
f7dc1244 6987(@value{GDBP}) info macro N
e2e0bcd1
JB
6988Defined at /home/jimb/gdb/macros/play/sample.c:9
6989#define N 28
f7dc1244 6990(@value{GDBP}) macro expand N Q M
e2e0bcd1 6991expands to: 28 < 42
f7dc1244 6992(@value{GDBP}) print N Q M
e2e0bcd1 6993$1 = 1
f7dc1244 6994(@value{GDBP})
e2e0bcd1
JB
6995@end smallexample
6996
6997As we step over directives that remove @code{N}'s definition, and then
6998give it a new definition, @value{GDBN} finds the definition (or lack
6999thereof) in force at each point:
7000
7001@smallexample
f7dc1244 7002(@value{GDBP}) next
e2e0bcd1
JB
7003Hello, world!
700412 printf ("We're so creative.\n");
f7dc1244 7005(@value{GDBP}) info macro N
e2e0bcd1
JB
7006The symbol `N' has no definition as a C/C++ preprocessor macro
7007at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7008(@value{GDBP}) next
e2e0bcd1
JB
7009We're so creative.
701014 printf ("Goodbye, world!\n");
f7dc1244 7011(@value{GDBP}) info macro N
e2e0bcd1
JB
7012Defined at /home/jimb/gdb/macros/play/sample.c:13
7013#define N 1729
f7dc1244 7014(@value{GDBP}) macro expand N Q M
e2e0bcd1 7015expands to: 1729 < 42
f7dc1244 7016(@value{GDBP}) print N Q M
e2e0bcd1 7017$2 = 0
f7dc1244 7018(@value{GDBP})
e2e0bcd1
JB
7019@end smallexample
7020
7021
b37052ae
EZ
7022@node Tracepoints
7023@chapter Tracepoints
7024@c This chapter is based on the documentation written by Michael
7025@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7026
7027@cindex tracepoints
7028In some applications, it is not feasible for the debugger to interrupt
7029the program's execution long enough for the developer to learn
7030anything helpful about its behavior. If the program's correctness
7031depends on its real-time behavior, delays introduced by a debugger
7032might cause the program to change its behavior drastically, or perhaps
7033fail, even when the code itself is correct. It is useful to be able
7034to observe the program's behavior without interrupting it.
7035
7036Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7037specify locations in the program, called @dfn{tracepoints}, and
7038arbitrary expressions to evaluate when those tracepoints are reached.
7039Later, using the @code{tfind} command, you can examine the values
7040those expressions had when the program hit the tracepoints. The
7041expressions may also denote objects in memory---structures or arrays,
7042for example---whose values @value{GDBN} should record; while visiting
7043a particular tracepoint, you may inspect those objects as if they were
7044in memory at that moment. However, because @value{GDBN} records these
7045values without interacting with you, it can do so quickly and
7046unobtrusively, hopefully not disturbing the program's behavior.
7047
7048The tracepoint facility is currently available only for remote
2c0069bb
EZ
7049targets. @xref{Targets}. In addition, your remote target must know how
7050to collect trace data. This functionality is implemented in the remote
7051stub; however, none of the stubs distributed with @value{GDBN} support
7052tracepoints as of this writing.
b37052ae
EZ
7053
7054This chapter describes the tracepoint commands and features.
7055
7056@menu
b383017d
RM
7057* Set Tracepoints::
7058* Analyze Collected Data::
7059* Tracepoint Variables::
b37052ae
EZ
7060@end menu
7061
7062@node Set Tracepoints
7063@section Commands to Set Tracepoints
7064
7065Before running such a @dfn{trace experiment}, an arbitrary number of
7066tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7067tracepoint has a number assigned to it by @value{GDBN}. Like with
7068breakpoints, tracepoint numbers are successive integers starting from
7069one. Many of the commands associated with tracepoints take the
7070tracepoint number as their argument, to identify which tracepoint to
7071work on.
7072
7073For each tracepoint, you can specify, in advance, some arbitrary set
7074of data that you want the target to collect in the trace buffer when
7075it hits that tracepoint. The collected data can include registers,
7076local variables, or global data. Later, you can use @value{GDBN}
7077commands to examine the values these data had at the time the
7078tracepoint was hit.
7079
7080This section describes commands to set tracepoints and associated
7081conditions and actions.
7082
7083@menu
b383017d
RM
7084* Create and Delete Tracepoints::
7085* Enable and Disable Tracepoints::
7086* Tracepoint Passcounts::
7087* Tracepoint Actions::
7088* Listing Tracepoints::
7089* Starting and Stopping Trace Experiment::
b37052ae
EZ
7090@end menu
7091
7092@node Create and Delete Tracepoints
7093@subsection Create and Delete Tracepoints
7094
7095@table @code
7096@cindex set tracepoint
7097@kindex trace
7098@item trace
7099The @code{trace} command is very similar to the @code{break} command.
7100Its argument can be a source line, a function name, or an address in
7101the target program. @xref{Set Breaks}. The @code{trace} command
7102defines a tracepoint, which is a point in the target program where the
7103debugger will briefly stop, collect some data, and then allow the
7104program to continue. Setting a tracepoint or changing its commands
7105doesn't take effect until the next @code{tstart} command; thus, you
7106cannot change the tracepoint attributes once a trace experiment is
7107running.
7108
7109Here are some examples of using the @code{trace} command:
7110
7111@smallexample
7112(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7113
7114(@value{GDBP}) @b{trace +2} // 2 lines forward
7115
7116(@value{GDBP}) @b{trace my_function} // first source line of function
7117
7118(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7119
7120(@value{GDBP}) @b{trace *0x2117c4} // an address
7121@end smallexample
7122
7123@noindent
7124You can abbreviate @code{trace} as @code{tr}.
7125
7126@vindex $tpnum
7127@cindex last tracepoint number
7128@cindex recent tracepoint number
7129@cindex tracepoint number
7130The convenience variable @code{$tpnum} records the tracepoint number
7131of the most recently set tracepoint.
7132
7133@kindex delete tracepoint
7134@cindex tracepoint deletion
7135@item delete tracepoint @r{[}@var{num}@r{]}
7136Permanently delete one or more tracepoints. With no argument, the
7137default is to delete all tracepoints.
7138
7139Examples:
7140
7141@smallexample
7142(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7143
7144(@value{GDBP}) @b{delete trace} // remove all tracepoints
7145@end smallexample
7146
7147@noindent
7148You can abbreviate this command as @code{del tr}.
7149@end table
7150
7151@node Enable and Disable Tracepoints
7152@subsection Enable and Disable Tracepoints
7153
7154@table @code
7155@kindex disable tracepoint
7156@item disable tracepoint @r{[}@var{num}@r{]}
7157Disable tracepoint @var{num}, or all tracepoints if no argument
7158@var{num} is given. A disabled tracepoint will have no effect during
7159the next trace experiment, but it is not forgotten. You can re-enable
7160a disabled tracepoint using the @code{enable tracepoint} command.
7161
7162@kindex enable tracepoint
7163@item enable tracepoint @r{[}@var{num}@r{]}
7164Enable tracepoint @var{num}, or all tracepoints. The enabled
7165tracepoints will become effective the next time a trace experiment is
7166run.
7167@end table
7168
7169@node Tracepoint Passcounts
7170@subsection Tracepoint Passcounts
7171
7172@table @code
7173@kindex passcount
7174@cindex tracepoint pass count
7175@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7176Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7177automatically stop a trace experiment. If a tracepoint's passcount is
7178@var{n}, then the trace experiment will be automatically stopped on
7179the @var{n}'th time that tracepoint is hit. If the tracepoint number
7180@var{num} is not specified, the @code{passcount} command sets the
7181passcount of the most recently defined tracepoint. If no passcount is
7182given, the trace experiment will run until stopped explicitly by the
7183user.
7184
7185Examples:
7186
7187@smallexample
b383017d 7188(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7189@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7190
7191(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7192@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7193(@value{GDBP}) @b{trace foo}
7194(@value{GDBP}) @b{pass 3}
7195(@value{GDBP}) @b{trace bar}
7196(@value{GDBP}) @b{pass 2}
7197(@value{GDBP}) @b{trace baz}
7198(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7199@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7200@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7201@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7202@end smallexample
7203@end table
7204
7205@node Tracepoint Actions
7206@subsection Tracepoint Action Lists
7207
7208@table @code
7209@kindex actions
7210@cindex tracepoint actions
7211@item actions @r{[}@var{num}@r{]}
7212This command will prompt for a list of actions to be taken when the
7213tracepoint is hit. If the tracepoint number @var{num} is not
7214specified, this command sets the actions for the one that was most
7215recently defined (so that you can define a tracepoint and then say
7216@code{actions} without bothering about its number). You specify the
7217actions themselves on the following lines, one action at a time, and
7218terminate the actions list with a line containing just @code{end}. So
7219far, the only defined actions are @code{collect} and
7220@code{while-stepping}.
7221
7222@cindex remove actions from a tracepoint
7223To remove all actions from a tracepoint, type @samp{actions @var{num}}
7224and follow it immediately with @samp{end}.
7225
7226@smallexample
7227(@value{GDBP}) @b{collect @var{data}} // collect some data
7228
6826cf00 7229(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7230
6826cf00 7231(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7232@end smallexample
7233
7234In the following example, the action list begins with @code{collect}
7235commands indicating the things to be collected when the tracepoint is
7236hit. Then, in order to single-step and collect additional data
7237following the tracepoint, a @code{while-stepping} command is used,
7238followed by the list of things to be collected while stepping. The
7239@code{while-stepping} command is terminated by its own separate
7240@code{end} command. Lastly, the action list is terminated by an
7241@code{end} command.
7242
7243@smallexample
7244(@value{GDBP}) @b{trace foo}
7245(@value{GDBP}) @b{actions}
7246Enter actions for tracepoint 1, one per line:
7247> collect bar,baz
7248> collect $regs
7249> while-stepping 12
7250 > collect $fp, $sp
7251 > end
7252end
7253@end smallexample
7254
7255@kindex collect @r{(tracepoints)}
7256@item collect @var{expr1}, @var{expr2}, @dots{}
7257Collect values of the given expressions when the tracepoint is hit.
7258This command accepts a comma-separated list of any valid expressions.
7259In addition to global, static, or local variables, the following
7260special arguments are supported:
7261
7262@table @code
7263@item $regs
7264collect all registers
7265
7266@item $args
7267collect all function arguments
7268
7269@item $locals
7270collect all local variables.
7271@end table
7272
7273You can give several consecutive @code{collect} commands, each one
7274with a single argument, or one @code{collect} command with several
7275arguments separated by commas: the effect is the same.
7276
f5c37c66
EZ
7277The command @code{info scope} (@pxref{Symbols, info scope}) is
7278particularly useful for figuring out what data to collect.
7279
b37052ae
EZ
7280@kindex while-stepping @r{(tracepoints)}
7281@item while-stepping @var{n}
7282Perform @var{n} single-step traces after the tracepoint, collecting
7283new data at each step. The @code{while-stepping} command is
7284followed by the list of what to collect while stepping (followed by
7285its own @code{end} command):
7286
7287@smallexample
7288> while-stepping 12
7289 > collect $regs, myglobal
7290 > end
7291>
7292@end smallexample
7293
7294@noindent
7295You may abbreviate @code{while-stepping} as @code{ws} or
7296@code{stepping}.
7297@end table
7298
7299@node Listing Tracepoints
7300@subsection Listing Tracepoints
7301
7302@table @code
7303@kindex info tracepoints
09d4efe1 7304@kindex info tp
b37052ae
EZ
7305@cindex information about tracepoints
7306@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7307Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7308a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7309defined so far. For each tracepoint, the following information is
7310shown:
7311
7312@itemize @bullet
7313@item
7314its number
7315@item
7316whether it is enabled or disabled
7317@item
7318its address
7319@item
7320its passcount as given by the @code{passcount @var{n}} command
7321@item
7322its step count as given by the @code{while-stepping @var{n}} command
7323@item
7324where in the source files is the tracepoint set
7325@item
7326its action list as given by the @code{actions} command
7327@end itemize
7328
7329@smallexample
7330(@value{GDBP}) @b{info trace}
7331Num Enb Address PassC StepC What
73321 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73332 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73343 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7335(@value{GDBP})
7336@end smallexample
7337
7338@noindent
7339This command can be abbreviated @code{info tp}.
7340@end table
7341
7342@node Starting and Stopping Trace Experiment
7343@subsection Starting and Stopping Trace Experiment
7344
7345@table @code
7346@kindex tstart
7347@cindex start a new trace experiment
7348@cindex collected data discarded
7349@item tstart
7350This command takes no arguments. It starts the trace experiment, and
7351begins collecting data. This has the side effect of discarding all
7352the data collected in the trace buffer during the previous trace
7353experiment.
7354
7355@kindex tstop
7356@cindex stop a running trace experiment
7357@item tstop
7358This command takes no arguments. It ends the trace experiment, and
7359stops collecting data.
7360
68c71a2e 7361@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7362automatically if any tracepoint's passcount is reached
7363(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7364
7365@kindex tstatus
7366@cindex status of trace data collection
7367@cindex trace experiment, status of
7368@item tstatus
7369This command displays the status of the current trace data
7370collection.
7371@end table
7372
7373Here is an example of the commands we described so far:
7374
7375@smallexample
7376(@value{GDBP}) @b{trace gdb_c_test}
7377(@value{GDBP}) @b{actions}
7378Enter actions for tracepoint #1, one per line.
7379> collect $regs,$locals,$args
7380> while-stepping 11
7381 > collect $regs
7382 > end
7383> end
7384(@value{GDBP}) @b{tstart}
7385 [time passes @dots{}]
7386(@value{GDBP}) @b{tstop}
7387@end smallexample
7388
7389
7390@node Analyze Collected Data
7391@section Using the collected data
7392
7393After the tracepoint experiment ends, you use @value{GDBN} commands
7394for examining the trace data. The basic idea is that each tracepoint
7395collects a trace @dfn{snapshot} every time it is hit and another
7396snapshot every time it single-steps. All these snapshots are
7397consecutively numbered from zero and go into a buffer, and you can
7398examine them later. The way you examine them is to @dfn{focus} on a
7399specific trace snapshot. When the remote stub is focused on a trace
7400snapshot, it will respond to all @value{GDBN} requests for memory and
7401registers by reading from the buffer which belongs to that snapshot,
7402rather than from @emph{real} memory or registers of the program being
7403debugged. This means that @strong{all} @value{GDBN} commands
7404(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7405behave as if we were currently debugging the program state as it was
7406when the tracepoint occurred. Any requests for data that are not in
7407the buffer will fail.
7408
7409@menu
7410* tfind:: How to select a trace snapshot
7411* tdump:: How to display all data for a snapshot
7412* save-tracepoints:: How to save tracepoints for a future run
7413@end menu
7414
7415@node tfind
7416@subsection @code{tfind @var{n}}
7417
7418@kindex tfind
7419@cindex select trace snapshot
7420@cindex find trace snapshot
7421The basic command for selecting a trace snapshot from the buffer is
7422@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7423counting from zero. If no argument @var{n} is given, the next
7424snapshot is selected.
7425
7426Here are the various forms of using the @code{tfind} command.
7427
7428@table @code
7429@item tfind start
7430Find the first snapshot in the buffer. This is a synonym for
7431@code{tfind 0} (since 0 is the number of the first snapshot).
7432
7433@item tfind none
7434Stop debugging trace snapshots, resume @emph{live} debugging.
7435
7436@item tfind end
7437Same as @samp{tfind none}.
7438
7439@item tfind
7440No argument means find the next trace snapshot.
7441
7442@item tfind -
7443Find the previous trace snapshot before the current one. This permits
7444retracing earlier steps.
7445
7446@item tfind tracepoint @var{num}
7447Find the next snapshot associated with tracepoint @var{num}. Search
7448proceeds forward from the last examined trace snapshot. If no
7449argument @var{num} is given, it means find the next snapshot collected
7450for the same tracepoint as the current snapshot.
7451
7452@item tfind pc @var{addr}
7453Find the next snapshot associated with the value @var{addr} of the
7454program counter. Search proceeds forward from the last examined trace
7455snapshot. If no argument @var{addr} is given, it means find the next
7456snapshot with the same value of PC as the current snapshot.
7457
7458@item tfind outside @var{addr1}, @var{addr2}
7459Find the next snapshot whose PC is outside the given range of
7460addresses.
7461
7462@item tfind range @var{addr1}, @var{addr2}
7463Find the next snapshot whose PC is between @var{addr1} and
7464@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7465
7466@item tfind line @r{[}@var{file}:@r{]}@var{n}
7467Find the next snapshot associated with the source line @var{n}. If
7468the optional argument @var{file} is given, refer to line @var{n} in
7469that source file. Search proceeds forward from the last examined
7470trace snapshot. If no argument @var{n} is given, it means find the
7471next line other than the one currently being examined; thus saying
7472@code{tfind line} repeatedly can appear to have the same effect as
7473stepping from line to line in a @emph{live} debugging session.
7474@end table
7475
7476The default arguments for the @code{tfind} commands are specifically
7477designed to make it easy to scan through the trace buffer. For
7478instance, @code{tfind} with no argument selects the next trace
7479snapshot, and @code{tfind -} with no argument selects the previous
7480trace snapshot. So, by giving one @code{tfind} command, and then
7481simply hitting @key{RET} repeatedly you can examine all the trace
7482snapshots in order. Or, by saying @code{tfind -} and then hitting
7483@key{RET} repeatedly you can examine the snapshots in reverse order.
7484The @code{tfind line} command with no argument selects the snapshot
7485for the next source line executed. The @code{tfind pc} command with
7486no argument selects the next snapshot with the same program counter
7487(PC) as the current frame. The @code{tfind tracepoint} command with
7488no argument selects the next trace snapshot collected by the same
7489tracepoint as the current one.
7490
7491In addition to letting you scan through the trace buffer manually,
7492these commands make it easy to construct @value{GDBN} scripts that
7493scan through the trace buffer and print out whatever collected data
7494you are interested in. Thus, if we want to examine the PC, FP, and SP
7495registers from each trace frame in the buffer, we can say this:
7496
7497@smallexample
7498(@value{GDBP}) @b{tfind start}
7499(@value{GDBP}) @b{while ($trace_frame != -1)}
7500> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7501 $trace_frame, $pc, $sp, $fp
7502> tfind
7503> end
7504
7505Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7506Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7507Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7508Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7509Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7510Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7511Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7512Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7513Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7514Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7515Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7516@end smallexample
7517
7518Or, if we want to examine the variable @code{X} at each source line in
7519the buffer:
7520
7521@smallexample
7522(@value{GDBP}) @b{tfind start}
7523(@value{GDBP}) @b{while ($trace_frame != -1)}
7524> printf "Frame %d, X == %d\n", $trace_frame, X
7525> tfind line
7526> end
7527
7528Frame 0, X = 1
7529Frame 7, X = 2
7530Frame 13, X = 255
7531@end smallexample
7532
7533@node tdump
7534@subsection @code{tdump}
7535@kindex tdump
7536@cindex dump all data collected at tracepoint
7537@cindex tracepoint data, display
7538
7539This command takes no arguments. It prints all the data collected at
7540the current trace snapshot.
7541
7542@smallexample
7543(@value{GDBP}) @b{trace 444}
7544(@value{GDBP}) @b{actions}
7545Enter actions for tracepoint #2, one per line:
7546> collect $regs, $locals, $args, gdb_long_test
7547> end
7548
7549(@value{GDBP}) @b{tstart}
7550
7551(@value{GDBP}) @b{tfind line 444}
7552#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7553at gdb_test.c:444
7554444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7555
7556(@value{GDBP}) @b{tdump}
7557Data collected at tracepoint 2, trace frame 1:
7558d0 0xc4aa0085 -995491707
7559d1 0x18 24
7560d2 0x80 128
7561d3 0x33 51
7562d4 0x71aea3d 119204413
7563d5 0x22 34
7564d6 0xe0 224
7565d7 0x380035 3670069
7566a0 0x19e24a 1696330
7567a1 0x3000668 50333288
7568a2 0x100 256
7569a3 0x322000 3284992
7570a4 0x3000698 50333336
7571a5 0x1ad3cc 1758156
7572fp 0x30bf3c 0x30bf3c
7573sp 0x30bf34 0x30bf34
7574ps 0x0 0
7575pc 0x20b2c8 0x20b2c8
7576fpcontrol 0x0 0
7577fpstatus 0x0 0
7578fpiaddr 0x0 0
7579p = 0x20e5b4 "gdb-test"
7580p1 = (void *) 0x11
7581p2 = (void *) 0x22
7582p3 = (void *) 0x33
7583p4 = (void *) 0x44
7584p5 = (void *) 0x55
7585p6 = (void *) 0x66
7586gdb_long_test = 17 '\021'
7587
7588(@value{GDBP})
7589@end smallexample
7590
7591@node save-tracepoints
7592@subsection @code{save-tracepoints @var{filename}}
7593@kindex save-tracepoints
7594@cindex save tracepoints for future sessions
7595
7596This command saves all current tracepoint definitions together with
7597their actions and passcounts, into a file @file{@var{filename}}
7598suitable for use in a later debugging session. To read the saved
7599tracepoint definitions, use the @code{source} command (@pxref{Command
7600Files}).
7601
7602@node Tracepoint Variables
7603@section Convenience Variables for Tracepoints
7604@cindex tracepoint variables
7605@cindex convenience variables for tracepoints
7606
7607@table @code
7608@vindex $trace_frame
7609@item (int) $trace_frame
7610The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7611snapshot is selected.
7612
7613@vindex $tracepoint
7614@item (int) $tracepoint
7615The tracepoint for the current trace snapshot.
7616
7617@vindex $trace_line
7618@item (int) $trace_line
7619The line number for the current trace snapshot.
7620
7621@vindex $trace_file
7622@item (char []) $trace_file
7623The source file for the current trace snapshot.
7624
7625@vindex $trace_func
7626@item (char []) $trace_func
7627The name of the function containing @code{$tracepoint}.
7628@end table
7629
7630Note: @code{$trace_file} is not suitable for use in @code{printf},
7631use @code{output} instead.
7632
7633Here's a simple example of using these convenience variables for
7634stepping through all the trace snapshots and printing some of their
7635data.
7636
7637@smallexample
7638(@value{GDBP}) @b{tfind start}
7639
7640(@value{GDBP}) @b{while $trace_frame != -1}
7641> output $trace_file
7642> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7643> tfind
7644> end
7645@end smallexample
7646
df0cd8c5
JB
7647@node Overlays
7648@chapter Debugging Programs That Use Overlays
7649@cindex overlays
7650
7651If your program is too large to fit completely in your target system's
7652memory, you can sometimes use @dfn{overlays} to work around this
7653problem. @value{GDBN} provides some support for debugging programs that
7654use overlays.
7655
7656@menu
7657* How Overlays Work:: A general explanation of overlays.
7658* Overlay Commands:: Managing overlays in @value{GDBN}.
7659* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7660 mapped by asking the inferior.
7661* Overlay Sample Program:: A sample program using overlays.
7662@end menu
7663
7664@node How Overlays Work
7665@section How Overlays Work
7666@cindex mapped overlays
7667@cindex unmapped overlays
7668@cindex load address, overlay's
7669@cindex mapped address
7670@cindex overlay area
7671
7672Suppose you have a computer whose instruction address space is only 64
7673kilobytes long, but which has much more memory which can be accessed by
7674other means: special instructions, segment registers, or memory
7675management hardware, for example. Suppose further that you want to
7676adapt a program which is larger than 64 kilobytes to run on this system.
7677
7678One solution is to identify modules of your program which are relatively
7679independent, and need not call each other directly; call these modules
7680@dfn{overlays}. Separate the overlays from the main program, and place
7681their machine code in the larger memory. Place your main program in
7682instruction memory, but leave at least enough space there to hold the
7683largest overlay as well.
7684
7685Now, to call a function located in an overlay, you must first copy that
7686overlay's machine code from the large memory into the space set aside
7687for it in the instruction memory, and then jump to its entry point
7688there.
7689
c928edc0
AC
7690@c NB: In the below the mapped area's size is greater or equal to the
7691@c size of all overlays. This is intentional to remind the developer
7692@c that overlays don't necessarily need to be the same size.
7693
474c8240 7694@smallexample
df0cd8c5 7695@group
c928edc0
AC
7696 Data Instruction Larger
7697Address Space Address Space Address Space
7698+-----------+ +-----------+ +-----------+
7699| | | | | |
7700+-----------+ +-----------+ +-----------+<-- overlay 1
7701| program | | main | .----| overlay 1 | load address
7702| variables | | program | | +-----------+
7703| and heap | | | | | |
7704+-----------+ | | | +-----------+<-- overlay 2
7705| | +-----------+ | | | load address
7706+-----------+ | | | .-| overlay 2 |
7707 | | | | | |
7708 mapped --->+-----------+ | | +-----------+
7709 address | | | | | |
7710 | overlay | <-' | | |
7711 | area | <---' +-----------+<-- overlay 3
7712 | | <---. | | load address
7713 +-----------+ `--| overlay 3 |
7714 | | | |
7715 +-----------+ | |
7716 +-----------+
7717 | |
7718 +-----------+
7719
7720 @anchor{A code overlay}A code overlay
df0cd8c5 7721@end group
474c8240 7722@end smallexample
df0cd8c5 7723
c928edc0
AC
7724The diagram (@pxref{A code overlay}) shows a system with separate data
7725and instruction address spaces. To map an overlay, the program copies
7726its code from the larger address space to the instruction address space.
7727Since the overlays shown here all use the same mapped address, only one
7728may be mapped at a time. For a system with a single address space for
7729data and instructions, the diagram would be similar, except that the
7730program variables and heap would share an address space with the main
7731program and the overlay area.
df0cd8c5
JB
7732
7733An overlay loaded into instruction memory and ready for use is called a
7734@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7735instruction memory. An overlay not present (or only partially present)
7736in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7737is its address in the larger memory. The mapped address is also called
7738the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7739called the @dfn{load memory address}, or @dfn{LMA}.
7740
7741Unfortunately, overlays are not a completely transparent way to adapt a
7742program to limited instruction memory. They introduce a new set of
7743global constraints you must keep in mind as you design your program:
7744
7745@itemize @bullet
7746
7747@item
7748Before calling or returning to a function in an overlay, your program
7749must make sure that overlay is actually mapped. Otherwise, the call or
7750return will transfer control to the right address, but in the wrong
7751overlay, and your program will probably crash.
7752
7753@item
7754If the process of mapping an overlay is expensive on your system, you
7755will need to choose your overlays carefully to minimize their effect on
7756your program's performance.
7757
7758@item
7759The executable file you load onto your system must contain each
7760overlay's instructions, appearing at the overlay's load address, not its
7761mapped address. However, each overlay's instructions must be relocated
7762and its symbols defined as if the overlay were at its mapped address.
7763You can use GNU linker scripts to specify different load and relocation
7764addresses for pieces of your program; see @ref{Overlay Description,,,
7765ld.info, Using ld: the GNU linker}.
7766
7767@item
7768The procedure for loading executable files onto your system must be able
7769to load their contents into the larger address space as well as the
7770instruction and data spaces.
7771
7772@end itemize
7773
7774The overlay system described above is rather simple, and could be
7775improved in many ways:
7776
7777@itemize @bullet
7778
7779@item
7780If your system has suitable bank switch registers or memory management
7781hardware, you could use those facilities to make an overlay's load area
7782contents simply appear at their mapped address in instruction space.
7783This would probably be faster than copying the overlay to its mapped
7784area in the usual way.
7785
7786@item
7787If your overlays are small enough, you could set aside more than one
7788overlay area, and have more than one overlay mapped at a time.
7789
7790@item
7791You can use overlays to manage data, as well as instructions. In
7792general, data overlays are even less transparent to your design than
7793code overlays: whereas code overlays only require care when you call or
7794return to functions, data overlays require care every time you access
7795the data. Also, if you change the contents of a data overlay, you
7796must copy its contents back out to its load address before you can copy a
7797different data overlay into the same mapped area.
7798
7799@end itemize
7800
7801
7802@node Overlay Commands
7803@section Overlay Commands
7804
7805To use @value{GDBN}'s overlay support, each overlay in your program must
7806correspond to a separate section of the executable file. The section's
7807virtual memory address and load memory address must be the overlay's
7808mapped and load addresses. Identifying overlays with sections allows
7809@value{GDBN} to determine the appropriate address of a function or
7810variable, depending on whether the overlay is mapped or not.
7811
7812@value{GDBN}'s overlay commands all start with the word @code{overlay};
7813you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7814
7815@table @code
7816@item overlay off
4644b6e3 7817@kindex overlay
df0cd8c5
JB
7818Disable @value{GDBN}'s overlay support. When overlay support is
7819disabled, @value{GDBN} assumes that all functions and variables are
7820always present at their mapped addresses. By default, @value{GDBN}'s
7821overlay support is disabled.
7822
7823@item overlay manual
df0cd8c5
JB
7824@cindex manual overlay debugging
7825Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7826relies on you to tell it which overlays are mapped, and which are not,
7827using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7828commands described below.
7829
7830@item overlay map-overlay @var{overlay}
7831@itemx overlay map @var{overlay}
df0cd8c5
JB
7832@cindex map an overlay
7833Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7834be the name of the object file section containing the overlay. When an
7835overlay is mapped, @value{GDBN} assumes it can find the overlay's
7836functions and variables at their mapped addresses. @value{GDBN} assumes
7837that any other overlays whose mapped ranges overlap that of
7838@var{overlay} are now unmapped.
7839
7840@item overlay unmap-overlay @var{overlay}
7841@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7842@cindex unmap an overlay
7843Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7844must be the name of the object file section containing the overlay.
7845When an overlay is unmapped, @value{GDBN} assumes it can find the
7846overlay's functions and variables at their load addresses.
7847
7848@item overlay auto
df0cd8c5
JB
7849Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7850consults a data structure the overlay manager maintains in the inferior
7851to see which overlays are mapped. For details, see @ref{Automatic
7852Overlay Debugging}.
7853
7854@item overlay load-target
7855@itemx overlay load
df0cd8c5
JB
7856@cindex reloading the overlay table
7857Re-read the overlay table from the inferior. Normally, @value{GDBN}
7858re-reads the table @value{GDBN} automatically each time the inferior
7859stops, so this command should only be necessary if you have changed the
7860overlay mapping yourself using @value{GDBN}. This command is only
7861useful when using automatic overlay debugging.
7862
7863@item overlay list-overlays
7864@itemx overlay list
7865@cindex listing mapped overlays
7866Display a list of the overlays currently mapped, along with their mapped
7867addresses, load addresses, and sizes.
7868
7869@end table
7870
7871Normally, when @value{GDBN} prints a code address, it includes the name
7872of the function the address falls in:
7873
474c8240 7874@smallexample
f7dc1244 7875(@value{GDBP}) print main
df0cd8c5 7876$3 = @{int ()@} 0x11a0 <main>
474c8240 7877@end smallexample
df0cd8c5
JB
7878@noindent
7879When overlay debugging is enabled, @value{GDBN} recognizes code in
7880unmapped overlays, and prints the names of unmapped functions with
7881asterisks around them. For example, if @code{foo} is a function in an
7882unmapped overlay, @value{GDBN} prints it this way:
7883
474c8240 7884@smallexample
f7dc1244 7885(@value{GDBP}) overlay list
df0cd8c5 7886No sections are mapped.
f7dc1244 7887(@value{GDBP}) print foo
df0cd8c5 7888$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7889@end smallexample
df0cd8c5
JB
7890@noindent
7891When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7892name normally:
7893
474c8240 7894@smallexample
f7dc1244 7895(@value{GDBP}) overlay list
b383017d 7896Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7897 mapped at 0x1016 - 0x104a
f7dc1244 7898(@value{GDBP}) print foo
df0cd8c5 7899$6 = @{int (int)@} 0x1016 <foo>
474c8240 7900@end smallexample
df0cd8c5
JB
7901
7902When overlay debugging is enabled, @value{GDBN} can find the correct
7903address for functions and variables in an overlay, whether or not the
7904overlay is mapped. This allows most @value{GDBN} commands, like
7905@code{break} and @code{disassemble}, to work normally, even on unmapped
7906code. However, @value{GDBN}'s breakpoint support has some limitations:
7907
7908@itemize @bullet
7909@item
7910@cindex breakpoints in overlays
7911@cindex overlays, setting breakpoints in
7912You can set breakpoints in functions in unmapped overlays, as long as
7913@value{GDBN} can write to the overlay at its load address.
7914@item
7915@value{GDBN} can not set hardware or simulator-based breakpoints in
7916unmapped overlays. However, if you set a breakpoint at the end of your
7917overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7918you are using manual overlay management), @value{GDBN} will re-set its
7919breakpoints properly.
7920@end itemize
7921
7922
7923@node Automatic Overlay Debugging
7924@section Automatic Overlay Debugging
7925@cindex automatic overlay debugging
7926
7927@value{GDBN} can automatically track which overlays are mapped and which
7928are not, given some simple co-operation from the overlay manager in the
7929inferior. If you enable automatic overlay debugging with the
7930@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7931looks in the inferior's memory for certain variables describing the
7932current state of the overlays.
7933
7934Here are the variables your overlay manager must define to support
7935@value{GDBN}'s automatic overlay debugging:
7936
7937@table @asis
7938
7939@item @code{_ovly_table}:
7940This variable must be an array of the following structures:
7941
474c8240 7942@smallexample
df0cd8c5
JB
7943struct
7944@{
7945 /* The overlay's mapped address. */
7946 unsigned long vma;
7947
7948 /* The size of the overlay, in bytes. */
7949 unsigned long size;
7950
7951 /* The overlay's load address. */
7952 unsigned long lma;
7953
7954 /* Non-zero if the overlay is currently mapped;
7955 zero otherwise. */
7956 unsigned long mapped;
7957@}
474c8240 7958@end smallexample
df0cd8c5
JB
7959
7960@item @code{_novlys}:
7961This variable must be a four-byte signed integer, holding the total
7962number of elements in @code{_ovly_table}.
7963
7964@end table
7965
7966To decide whether a particular overlay is mapped or not, @value{GDBN}
7967looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7968@code{lma} members equal the VMA and LMA of the overlay's section in the
7969executable file. When @value{GDBN} finds a matching entry, it consults
7970the entry's @code{mapped} member to determine whether the overlay is
7971currently mapped.
7972
81d46470 7973In addition, your overlay manager may define a function called
def71bfa 7974@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7975will silently set a breakpoint there. If the overlay manager then
7976calls this function whenever it has changed the overlay table, this
7977will enable @value{GDBN} to accurately keep track of which overlays
7978are in program memory, and update any breakpoints that may be set
b383017d 7979in overlays. This will allow breakpoints to work even if the
81d46470
MS
7980overlays are kept in ROM or other non-writable memory while they
7981are not being executed.
df0cd8c5
JB
7982
7983@node Overlay Sample Program
7984@section Overlay Sample Program
7985@cindex overlay example program
7986
7987When linking a program which uses overlays, you must place the overlays
7988at their load addresses, while relocating them to run at their mapped
7989addresses. To do this, you must write a linker script (@pxref{Overlay
7990Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7991since linker scripts are specific to a particular host system, target
7992architecture, and target memory layout, this manual cannot provide
7993portable sample code demonstrating @value{GDBN}'s overlay support.
7994
7995However, the @value{GDBN} source distribution does contain an overlaid
7996program, with linker scripts for a few systems, as part of its test
7997suite. The program consists of the following files from
7998@file{gdb/testsuite/gdb.base}:
7999
8000@table @file
8001@item overlays.c
8002The main program file.
8003@item ovlymgr.c
8004A simple overlay manager, used by @file{overlays.c}.
8005@item foo.c
8006@itemx bar.c
8007@itemx baz.c
8008@itemx grbx.c
8009Overlay modules, loaded and used by @file{overlays.c}.
8010@item d10v.ld
8011@itemx m32r.ld
8012Linker scripts for linking the test program on the @code{d10v-elf}
8013and @code{m32r-elf} targets.
8014@end table
8015
8016You can build the test program using the @code{d10v-elf} GCC
8017cross-compiler like this:
8018
474c8240 8019@smallexample
df0cd8c5
JB
8020$ d10v-elf-gcc -g -c overlays.c
8021$ d10v-elf-gcc -g -c ovlymgr.c
8022$ d10v-elf-gcc -g -c foo.c
8023$ d10v-elf-gcc -g -c bar.c
8024$ d10v-elf-gcc -g -c baz.c
8025$ d10v-elf-gcc -g -c grbx.c
8026$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8027 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8028@end smallexample
df0cd8c5
JB
8029
8030The build process is identical for any other architecture, except that
8031you must substitute the appropriate compiler and linker script for the
8032target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8033
8034
6d2ebf8b 8035@node Languages
c906108c
SS
8036@chapter Using @value{GDBN} with Different Languages
8037@cindex languages
8038
c906108c
SS
8039Although programming languages generally have common aspects, they are
8040rarely expressed in the same manner. For instance, in ANSI C,
8041dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8042Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8043represented (and displayed) differently. Hex numbers in C appear as
c906108c 8044@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8045
8046@cindex working language
8047Language-specific information is built into @value{GDBN} for some languages,
8048allowing you to express operations like the above in your program's
8049native language, and allowing @value{GDBN} to output values in a manner
8050consistent with the syntax of your program's native language. The
8051language you use to build expressions is called the @dfn{working
8052language}.
8053
8054@menu
8055* Setting:: Switching between source languages
8056* Show:: Displaying the language
c906108c 8057* Checks:: Type and range checks
9c16f35a 8058* Supported languages:: Supported languages
4e562065 8059* Unsupported languages:: Unsupported languages
c906108c
SS
8060@end menu
8061
6d2ebf8b 8062@node Setting
c906108c
SS
8063@section Switching between source languages
8064
8065There are two ways to control the working language---either have @value{GDBN}
8066set it automatically, or select it manually yourself. You can use the
8067@code{set language} command for either purpose. On startup, @value{GDBN}
8068defaults to setting the language automatically. The working language is
8069used to determine how expressions you type are interpreted, how values
8070are printed, etc.
8071
8072In addition to the working language, every source file that
8073@value{GDBN} knows about has its own working language. For some object
8074file formats, the compiler might indicate which language a particular
8075source file is in. However, most of the time @value{GDBN} infers the
8076language from the name of the file. The language of a source file
b37052ae 8077controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8078show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8079set the language of a source file from within @value{GDBN}, but you can
8080set the language associated with a filename extension. @xref{Show, ,
8081Displaying the language}.
c906108c
SS
8082
8083This is most commonly a problem when you use a program, such
5d161b24 8084as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8085another language. In that case, make the
8086program use @code{#line} directives in its C output; that way
8087@value{GDBN} will know the correct language of the source code of the original
8088program, and will display that source code, not the generated C code.
8089
8090@menu
8091* Filenames:: Filename extensions and languages.
8092* Manually:: Setting the working language manually
8093* Automatically:: Having @value{GDBN} infer the source language
8094@end menu
8095
6d2ebf8b 8096@node Filenames
c906108c
SS
8097@subsection List of filename extensions and languages
8098
8099If a source file name ends in one of the following extensions, then
8100@value{GDBN} infers that its language is the one indicated.
8101
8102@table @file
e07c999f
PH
8103@item .ada
8104@itemx .ads
8105@itemx .adb
8106@itemx .a
8107Ada source file.
c906108c
SS
8108
8109@item .c
8110C source file
8111
8112@item .C
8113@itemx .cc
8114@itemx .cp
8115@itemx .cpp
8116@itemx .cxx
8117@itemx .c++
b37052ae 8118C@t{++} source file
c906108c 8119
b37303ee
AF
8120@item .m
8121Objective-C source file
8122
c906108c
SS
8123@item .f
8124@itemx .F
8125Fortran source file
8126
c906108c
SS
8127@item .mod
8128Modula-2 source file
c906108c
SS
8129
8130@item .s
8131@itemx .S
8132Assembler source file. This actually behaves almost like C, but
8133@value{GDBN} does not skip over function prologues when stepping.
8134@end table
8135
8136In addition, you may set the language associated with a filename
8137extension. @xref{Show, , Displaying the language}.
8138
6d2ebf8b 8139@node Manually
c906108c
SS
8140@subsection Setting the working language
8141
8142If you allow @value{GDBN} to set the language automatically,
8143expressions are interpreted the same way in your debugging session and
8144your program.
8145
8146@kindex set language
8147If you wish, you may set the language manually. To do this, issue the
8148command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8149a language, such as
c906108c 8150@code{c} or @code{modula-2}.
c906108c
SS
8151For a list of the supported languages, type @samp{set language}.
8152
c906108c
SS
8153Setting the language manually prevents @value{GDBN} from updating the working
8154language automatically. This can lead to confusion if you try
8155to debug a program when the working language is not the same as the
8156source language, when an expression is acceptable to both
8157languages---but means different things. For instance, if the current
8158source file were written in C, and @value{GDBN} was parsing Modula-2, a
8159command such as:
8160
474c8240 8161@smallexample
c906108c 8162print a = b + c
474c8240 8163@end smallexample
c906108c
SS
8164
8165@noindent
8166might not have the effect you intended. In C, this means to add
8167@code{b} and @code{c} and place the result in @code{a}. The result
8168printed would be the value of @code{a}. In Modula-2, this means to compare
8169@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8170
6d2ebf8b 8171@node Automatically
c906108c
SS
8172@subsection Having @value{GDBN} infer the source language
8173
8174To have @value{GDBN} set the working language automatically, use
8175@samp{set language local} or @samp{set language auto}. @value{GDBN}
8176then infers the working language. That is, when your program stops in a
8177frame (usually by encountering a breakpoint), @value{GDBN} sets the
8178working language to the language recorded for the function in that
8179frame. If the language for a frame is unknown (that is, if the function
8180or block corresponding to the frame was defined in a source file that
8181does not have a recognized extension), the current working language is
8182not changed, and @value{GDBN} issues a warning.
8183
8184This may not seem necessary for most programs, which are written
8185entirely in one source language. However, program modules and libraries
8186written in one source language can be used by a main program written in
8187a different source language. Using @samp{set language auto} in this
8188case frees you from having to set the working language manually.
8189
6d2ebf8b 8190@node Show
c906108c 8191@section Displaying the language
c906108c
SS
8192
8193The following commands help you find out which language is the
8194working language, and also what language source files were written in.
8195
c906108c
SS
8196@table @code
8197@item show language
9c16f35a 8198@kindex show language
c906108c
SS
8199Display the current working language. This is the
8200language you can use with commands such as @code{print} to
8201build and compute expressions that may involve variables in your program.
8202
8203@item info frame
4644b6e3 8204@kindex info frame@r{, show the source language}
5d161b24 8205Display the source language for this frame. This language becomes the
c906108c 8206working language if you use an identifier from this frame.
5d161b24 8207@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8208information listed here.
8209
8210@item info source
4644b6e3 8211@kindex info source@r{, show the source language}
c906108c 8212Display the source language of this source file.
5d161b24 8213@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8214information listed here.
8215@end table
8216
8217In unusual circumstances, you may have source files with extensions
8218not in the standard list. You can then set the extension associated
8219with a language explicitly:
8220
c906108c 8221@table @code
09d4efe1 8222@item set extension-language @var{ext} @var{language}
9c16f35a 8223@kindex set extension-language
09d4efe1
EZ
8224Tell @value{GDBN} that source files with extension @var{ext} are to be
8225assumed as written in the source language @var{language}.
c906108c
SS
8226
8227@item info extensions
9c16f35a 8228@kindex info extensions
c906108c
SS
8229List all the filename extensions and the associated languages.
8230@end table
8231
6d2ebf8b 8232@node Checks
c906108c
SS
8233@section Type and range checking
8234
8235@quotation
8236@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8237checking are included, but they do not yet have any effect. This
8238section documents the intended facilities.
8239@end quotation
8240@c FIXME remove warning when type/range code added
8241
8242Some languages are designed to guard you against making seemingly common
8243errors through a series of compile- and run-time checks. These include
8244checking the type of arguments to functions and operators, and making
8245sure mathematical overflows are caught at run time. Checks such as
8246these help to ensure a program's correctness once it has been compiled
8247by eliminating type mismatches, and providing active checks for range
8248errors when your program is running.
8249
8250@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8251Although @value{GDBN} does not check the statements in your program,
8252it can check expressions entered directly into @value{GDBN} for
8253evaluation via the @code{print} command, for example. As with the
8254working language, @value{GDBN} can also decide whether or not to check
8255automatically based on your program's source language.
8256@xref{Supported languages, ,Supported languages}, for the default
8257settings of supported languages.
c906108c
SS
8258
8259@menu
8260* Type Checking:: An overview of type checking
8261* Range Checking:: An overview of range checking
8262@end menu
8263
8264@cindex type checking
8265@cindex checks, type
6d2ebf8b 8266@node Type Checking
c906108c
SS
8267@subsection An overview of type checking
8268
8269Some languages, such as Modula-2, are strongly typed, meaning that the
8270arguments to operators and functions have to be of the correct type,
8271otherwise an error occurs. These checks prevent type mismatch
8272errors from ever causing any run-time problems. For example,
8273
8274@smallexample
82751 + 2 @result{} 3
8276@exdent but
8277@error{} 1 + 2.3
8278@end smallexample
8279
8280The second example fails because the @code{CARDINAL} 1 is not
8281type-compatible with the @code{REAL} 2.3.
8282
5d161b24
DB
8283For the expressions you use in @value{GDBN} commands, you can tell the
8284@value{GDBN} type checker to skip checking;
8285to treat any mismatches as errors and abandon the expression;
8286or to only issue warnings when type mismatches occur,
c906108c
SS
8287but evaluate the expression anyway. When you choose the last of
8288these, @value{GDBN} evaluates expressions like the second example above, but
8289also issues a warning.
8290
5d161b24
DB
8291Even if you turn type checking off, there may be other reasons
8292related to type that prevent @value{GDBN} from evaluating an expression.
8293For instance, @value{GDBN} does not know how to add an @code{int} and
8294a @code{struct foo}. These particular type errors have nothing to do
8295with the language in use, and usually arise from expressions, such as
c906108c
SS
8296the one described above, which make little sense to evaluate anyway.
8297
8298Each language defines to what degree it is strict about type. For
8299instance, both Modula-2 and C require the arguments to arithmetical
8300operators to be numbers. In C, enumerated types and pointers can be
8301represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8302operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8303details on specific languages.
8304
8305@value{GDBN} provides some additional commands for controlling the type checker:
8306
c906108c
SS
8307@kindex set check type
8308@kindex show check type
8309@table @code
8310@item set check type auto
8311Set type checking on or off based on the current working language.
9c16f35a 8312@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8313each language.
8314
8315@item set check type on
8316@itemx set check type off
8317Set type checking on or off, overriding the default setting for the
8318current working language. Issue a warning if the setting does not
8319match the language default. If any type mismatches occur in
d4f3574e 8320evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8321message and aborts evaluation of the expression.
8322
8323@item set check type warn
8324Cause the type checker to issue warnings, but to always attempt to
8325evaluate the expression. Evaluating the expression may still
8326be impossible for other reasons. For example, @value{GDBN} cannot add
8327numbers and structures.
8328
8329@item show type
5d161b24 8330Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8331is setting it automatically.
8332@end table
8333
8334@cindex range checking
8335@cindex checks, range
6d2ebf8b 8336@node Range Checking
c906108c
SS
8337@subsection An overview of range checking
8338
8339In some languages (such as Modula-2), it is an error to exceed the
8340bounds of a type; this is enforced with run-time checks. Such range
8341checking is meant to ensure program correctness by making sure
8342computations do not overflow, or indices on an array element access do
8343not exceed the bounds of the array.
8344
8345For expressions you use in @value{GDBN} commands, you can tell
8346@value{GDBN} to treat range errors in one of three ways: ignore them,
8347always treat them as errors and abandon the expression, or issue
8348warnings but evaluate the expression anyway.
8349
8350A range error can result from numerical overflow, from exceeding an
8351array index bound, or when you type a constant that is not a member
8352of any type. Some languages, however, do not treat overflows as an
8353error. In many implementations of C, mathematical overflow causes the
8354result to ``wrap around'' to lower values---for example, if @var{m} is
8355the largest integer value, and @var{s} is the smallest, then
8356
474c8240 8357@smallexample
c906108c 8358@var{m} + 1 @result{} @var{s}
474c8240 8359@end smallexample
c906108c
SS
8360
8361This, too, is specific to individual languages, and in some cases
9c16f35a 8362specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8363Supported languages}, for further details on specific languages.
8364
8365@value{GDBN} provides some additional commands for controlling the range checker:
8366
c906108c
SS
8367@kindex set check range
8368@kindex show check range
8369@table @code
8370@item set check range auto
8371Set range checking on or off based on the current working language.
9c16f35a 8372@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8373each language.
8374
8375@item set check range on
8376@itemx set check range off
8377Set range checking on or off, overriding the default setting for the
8378current working language. A warning is issued if the setting does not
c3f6f71d
JM
8379match the language default. If a range error occurs and range checking is on,
8380then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8381
8382@item set check range warn
8383Output messages when the @value{GDBN} range checker detects a range error,
8384but attempt to evaluate the expression anyway. Evaluating the
8385expression may still be impossible for other reasons, such as accessing
8386memory that the process does not own (a typical example from many Unix
8387systems).
8388
8389@item show range
8390Show the current setting of the range checker, and whether or not it is
8391being set automatically by @value{GDBN}.
8392@end table
c906108c 8393
9c16f35a 8394@node Supported languages
c906108c 8395@section Supported languages
c906108c 8396
9c16f35a
EZ
8397@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8398assembly, Modula-2, and Ada.
cce74817 8399@c This is false ...
c906108c
SS
8400Some @value{GDBN} features may be used in expressions regardless of the
8401language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8402and the @samp{@{type@}addr} construct (@pxref{Expressions,
8403,Expressions}) can be used with the constructs of any supported
8404language.
8405
8406The following sections detail to what degree each source language is
8407supported by @value{GDBN}. These sections are not meant to be language
8408tutorials or references, but serve only as a reference guide to what the
8409@value{GDBN} expression parser accepts, and what input and output
8410formats should look like for different languages. There are many good
8411books written on each of these languages; please look to these for a
8412language reference or tutorial.
8413
c906108c 8414@menu
b37303ee 8415* C:: C and C@t{++}
b383017d 8416* Objective-C:: Objective-C
09d4efe1 8417* Fortran:: Fortran
9c16f35a 8418* Pascal:: Pascal
b37303ee 8419* Modula-2:: Modula-2
e07c999f 8420* Ada:: Ada
c906108c
SS
8421@end menu
8422
6d2ebf8b 8423@node C
b37052ae 8424@subsection C and C@t{++}
7a292a7a 8425
b37052ae
EZ
8426@cindex C and C@t{++}
8427@cindex expressions in C or C@t{++}
c906108c 8428
b37052ae 8429Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8430to both languages. Whenever this is the case, we discuss those languages
8431together.
8432
41afff9a
EZ
8433@cindex C@t{++}
8434@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8435@cindex @sc{gnu} C@t{++}
8436The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8437compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8438effectively, you must compile your C@t{++} programs with a supported
8439C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8440compiler (@code{aCC}).
8441
0179ffac
DC
8442For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8443format; if it doesn't work on your system, try the stabs+ debugging
8444format. You can select those formats explicitly with the @code{g++}
8445command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8446@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8447CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8448
c906108c 8449@menu
b37052ae
EZ
8450* C Operators:: C and C@t{++} operators
8451* C Constants:: C and C@t{++} constants
8452* C plus plus expressions:: C@t{++} expressions
8453* C Defaults:: Default settings for C and C@t{++}
8454* C Checks:: C and C@t{++} type and range checks
c906108c 8455* Debugging C:: @value{GDBN} and C
b37052ae 8456* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8457@end menu
c906108c 8458
6d2ebf8b 8459@node C Operators
b37052ae 8460@subsubsection C and C@t{++} operators
7a292a7a 8461
b37052ae 8462@cindex C and C@t{++} operators
c906108c
SS
8463
8464Operators must be defined on values of specific types. For instance,
8465@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8466often defined on groups of types.
c906108c 8467
b37052ae 8468For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8469
8470@itemize @bullet
53a5351d 8471
c906108c 8472@item
c906108c 8473@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8474specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8475
8476@item
d4f3574e
SS
8477@emph{Floating-point types} include @code{float}, @code{double}, and
8478@code{long double} (if supported by the target platform).
c906108c
SS
8479
8480@item
53a5351d 8481@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8482
8483@item
8484@emph{Scalar types} include all of the above.
53a5351d 8485
c906108c
SS
8486@end itemize
8487
8488@noindent
8489The following operators are supported. They are listed here
8490in order of increasing precedence:
8491
8492@table @code
8493@item ,
8494The comma or sequencing operator. Expressions in a comma-separated list
8495are evaluated from left to right, with the result of the entire
8496expression being the last expression evaluated.
8497
8498@item =
8499Assignment. The value of an assignment expression is the value
8500assigned. Defined on scalar types.
8501
8502@item @var{op}=
8503Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8504and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8505@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8506@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8507@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8508
8509@item ?:
8510The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8511of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8512integral type.
8513
8514@item ||
8515Logical @sc{or}. Defined on integral types.
8516
8517@item &&
8518Logical @sc{and}. Defined on integral types.
8519
8520@item |
8521Bitwise @sc{or}. Defined on integral types.
8522
8523@item ^
8524Bitwise exclusive-@sc{or}. Defined on integral types.
8525
8526@item &
8527Bitwise @sc{and}. Defined on integral types.
8528
8529@item ==@r{, }!=
8530Equality and inequality. Defined on scalar types. The value of these
8531expressions is 0 for false and non-zero for true.
8532
8533@item <@r{, }>@r{, }<=@r{, }>=
8534Less than, greater than, less than or equal, greater than or equal.
8535Defined on scalar types. The value of these expressions is 0 for false
8536and non-zero for true.
8537
8538@item <<@r{, }>>
8539left shift, and right shift. Defined on integral types.
8540
8541@item @@
8542The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8543
8544@item +@r{, }-
8545Addition and subtraction. Defined on integral types, floating-point types and
8546pointer types.
8547
8548@item *@r{, }/@r{, }%
8549Multiplication, division, and modulus. Multiplication and division are
8550defined on integral and floating-point types. Modulus is defined on
8551integral types.
8552
8553@item ++@r{, }--
8554Increment and decrement. When appearing before a variable, the
8555operation is performed before the variable is used in an expression;
8556when appearing after it, the variable's value is used before the
8557operation takes place.
8558
8559@item *
8560Pointer dereferencing. Defined on pointer types. Same precedence as
8561@code{++}.
8562
8563@item &
8564Address operator. Defined on variables. Same precedence as @code{++}.
8565
b37052ae
EZ
8566For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8567allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8568(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8569where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8570stored.
c906108c
SS
8571
8572@item -
8573Negative. Defined on integral and floating-point types. Same
8574precedence as @code{++}.
8575
8576@item !
8577Logical negation. Defined on integral types. Same precedence as
8578@code{++}.
8579
8580@item ~
8581Bitwise complement operator. Defined on integral types. Same precedence as
8582@code{++}.
8583
8584
8585@item .@r{, }->
8586Structure member, and pointer-to-structure member. For convenience,
8587@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8588pointer based on the stored type information.
8589Defined on @code{struct} and @code{union} data.
8590
c906108c
SS
8591@item .*@r{, }->*
8592Dereferences of pointers to members.
c906108c
SS
8593
8594@item []
8595Array indexing. @code{@var{a}[@var{i}]} is defined as
8596@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8597
8598@item ()
8599Function parameter list. Same precedence as @code{->}.
8600
c906108c 8601@item ::
b37052ae 8602C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8603and @code{class} types.
c906108c
SS
8604
8605@item ::
7a292a7a
SS
8606Doubled colons also represent the @value{GDBN} scope operator
8607(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8608above.
c906108c
SS
8609@end table
8610
c906108c
SS
8611If an operator is redefined in the user code, @value{GDBN} usually
8612attempts to invoke the redefined version instead of using the operator's
8613predefined meaning.
c906108c 8614
c906108c 8615@menu
5d161b24 8616* C Constants::
c906108c
SS
8617@end menu
8618
6d2ebf8b 8619@node C Constants
b37052ae 8620@subsubsection C and C@t{++} constants
c906108c 8621
b37052ae 8622@cindex C and C@t{++} constants
c906108c 8623
b37052ae 8624@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8625following ways:
c906108c
SS
8626
8627@itemize @bullet
8628@item
8629Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8630specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8631by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8632@samp{l}, specifying that the constant should be treated as a
8633@code{long} value.
8634
8635@item
8636Floating point constants are a sequence of digits, followed by a decimal
8637point, followed by a sequence of digits, and optionally followed by an
8638exponent. An exponent is of the form:
8639@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8640sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8641A floating-point constant may also end with a letter @samp{f} or
8642@samp{F}, specifying that the constant should be treated as being of
8643the @code{float} (as opposed to the default @code{double}) type; or with
8644a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8645constant.
c906108c
SS
8646
8647@item
8648Enumerated constants consist of enumerated identifiers, or their
8649integral equivalents.
8650
8651@item
8652Character constants are a single character surrounded by single quotes
8653(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8654(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8655be represented by a letter or by @dfn{escape sequences}, which are of
8656the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8657of the character's ordinal value; or of the form @samp{\@var{x}}, where
8658@samp{@var{x}} is a predefined special character---for example,
8659@samp{\n} for newline.
8660
8661@item
96a2c332
SS
8662String constants are a sequence of character constants surrounded by
8663double quotes (@code{"}). Any valid character constant (as described
8664above) may appear. Double quotes within the string must be preceded by
8665a backslash, so for instance @samp{"a\"b'c"} is a string of five
8666characters.
c906108c
SS
8667
8668@item
8669Pointer constants are an integral value. You can also write pointers
8670to constants using the C operator @samp{&}.
8671
8672@item
8673Array constants are comma-separated lists surrounded by braces @samp{@{}
8674and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8675integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8676and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8677@end itemize
8678
c906108c 8679@menu
5d161b24
DB
8680* C plus plus expressions::
8681* C Defaults::
8682* C Checks::
c906108c 8683
5d161b24 8684* Debugging C::
c906108c
SS
8685@end menu
8686
6d2ebf8b 8687@node C plus plus expressions
b37052ae
EZ
8688@subsubsection C@t{++} expressions
8689
8690@cindex expressions in C@t{++}
8691@value{GDBN} expression handling can interpret most C@t{++} expressions.
8692
0179ffac
DC
8693@cindex debugging C@t{++} programs
8694@cindex C@t{++} compilers
8695@cindex debug formats and C@t{++}
8696@cindex @value{NGCC} and C@t{++}
c906108c 8697@quotation
b37052ae 8698@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8699proper compiler and the proper debug format. Currently, @value{GDBN}
8700works best when debugging C@t{++} code that is compiled with
8701@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8702@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8703stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8704stabs+ as their default debug format, so you usually don't need to
8705specify a debug format explicitly. Other compilers and/or debug formats
8706are likely to work badly or not at all when using @value{GDBN} to debug
8707C@t{++} code.
c906108c 8708@end quotation
c906108c
SS
8709
8710@enumerate
8711
8712@cindex member functions
8713@item
8714Member function calls are allowed; you can use expressions like
8715
474c8240 8716@smallexample
c906108c 8717count = aml->GetOriginal(x, y)
474c8240 8718@end smallexample
c906108c 8719
41afff9a 8720@vindex this@r{, inside C@t{++} member functions}
b37052ae 8721@cindex namespace in C@t{++}
c906108c
SS
8722@item
8723While a member function is active (in the selected stack frame), your
8724expressions have the same namespace available as the member function;
8725that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8726pointer @code{this} following the same rules as C@t{++}.
c906108c 8727
c906108c 8728@cindex call overloaded functions
d4f3574e 8729@cindex overloaded functions, calling
b37052ae 8730@cindex type conversions in C@t{++}
c906108c
SS
8731@item
8732You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8733call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8734perform overload resolution involving user-defined type conversions,
8735calls to constructors, or instantiations of templates that do not exist
8736in the program. It also cannot handle ellipsis argument lists or
8737default arguments.
8738
8739It does perform integral conversions and promotions, floating-point
8740promotions, arithmetic conversions, pointer conversions, conversions of
8741class objects to base classes, and standard conversions such as those of
8742functions or arrays to pointers; it requires an exact match on the
8743number of function arguments.
8744
8745Overload resolution is always performed, unless you have specified
8746@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8747,@value{GDBN} features for C@t{++}}.
c906108c 8748
d4f3574e 8749You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8750explicit function signature to call an overloaded function, as in
8751@smallexample
8752p 'foo(char,int)'('x', 13)
8753@end smallexample
d4f3574e 8754
c906108c 8755The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8756see @ref{Completion, ,Command completion}.
c906108c 8757
c906108c
SS
8758@cindex reference declarations
8759@item
b37052ae
EZ
8760@value{GDBN} understands variables declared as C@t{++} references; you can use
8761them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8762dereferenced.
8763
8764In the parameter list shown when @value{GDBN} displays a frame, the values of
8765reference variables are not displayed (unlike other variables); this
8766avoids clutter, since references are often used for large structures.
8767The @emph{address} of a reference variable is always shown, unless
8768you have specified @samp{set print address off}.
8769
8770@item
b37052ae 8771@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8772expressions can use it just as expressions in your program do. Since
8773one scope may be defined in another, you can use @code{::} repeatedly if
8774necessary, for example in an expression like
8775@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8776resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8777debugging (@pxref{Variables, ,Program variables}).
8778@end enumerate
8779
b37052ae 8780In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8781calling virtual functions correctly, printing out virtual bases of
8782objects, calling functions in a base subobject, casting objects, and
8783invoking user-defined operators.
c906108c 8784
6d2ebf8b 8785@node C Defaults
b37052ae 8786@subsubsection C and C@t{++} defaults
7a292a7a 8787
b37052ae 8788@cindex C and C@t{++} defaults
c906108c 8789
c906108c
SS
8790If you allow @value{GDBN} to set type and range checking automatically, they
8791both default to @code{off} whenever the working language changes to
b37052ae 8792C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8793selects the working language.
c906108c
SS
8794
8795If you allow @value{GDBN} to set the language automatically, it
8796recognizes source files whose names end with @file{.c}, @file{.C}, or
8797@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8798these files, it sets the working language to C or C@t{++}.
c906108c
SS
8799@xref{Automatically, ,Having @value{GDBN} infer the source language},
8800for further details.
8801
c906108c
SS
8802@c Type checking is (a) primarily motivated by Modula-2, and (b)
8803@c unimplemented. If (b) changes, it might make sense to let this node
8804@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8805
6d2ebf8b 8806@node C Checks
b37052ae 8807@subsubsection C and C@t{++} type and range checks
7a292a7a 8808
b37052ae 8809@cindex C and C@t{++} checks
c906108c 8810
b37052ae 8811By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8812is not used. However, if you turn type checking on, @value{GDBN}
8813considers two variables type equivalent if:
8814
8815@itemize @bullet
8816@item
8817The two variables are structured and have the same structure, union, or
8818enumerated tag.
8819
8820@item
8821The two variables have the same type name, or types that have been
8822declared equivalent through @code{typedef}.
8823
8824@ignore
8825@c leaving this out because neither J Gilmore nor R Pesch understand it.
8826@c FIXME--beers?
8827@item
8828The two @code{struct}, @code{union}, or @code{enum} variables are
8829declared in the same declaration. (Note: this may not be true for all C
8830compilers.)
8831@end ignore
8832@end itemize
8833
8834Range checking, if turned on, is done on mathematical operations. Array
8835indices are not checked, since they are often used to index a pointer
8836that is not itself an array.
c906108c 8837
6d2ebf8b 8838@node Debugging C
c906108c 8839@subsubsection @value{GDBN} and C
c906108c
SS
8840
8841The @code{set print union} and @code{show print union} commands apply to
8842the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8843inside a @code{struct} or @code{class} is also printed. Otherwise, it
8844appears as @samp{@{...@}}.
c906108c
SS
8845
8846The @code{@@} operator aids in the debugging of dynamic arrays, formed
8847with pointers and a memory allocation function. @xref{Expressions,
8848,Expressions}.
8849
c906108c 8850@menu
5d161b24 8851* Debugging C plus plus::
c906108c
SS
8852@end menu
8853
6d2ebf8b 8854@node Debugging C plus plus
b37052ae 8855@subsubsection @value{GDBN} features for C@t{++}
c906108c 8856
b37052ae 8857@cindex commands for C@t{++}
7a292a7a 8858
b37052ae
EZ
8859Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8860designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8861
8862@table @code
8863@cindex break in overloaded functions
8864@item @r{breakpoint menus}
8865When you want a breakpoint in a function whose name is overloaded,
8866@value{GDBN} breakpoint menus help you specify which function definition
8867you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8868
b37052ae 8869@cindex overloading in C@t{++}
c906108c
SS
8870@item rbreak @var{regex}
8871Setting breakpoints using regular expressions is helpful for setting
8872breakpoints on overloaded functions that are not members of any special
8873classes.
8874@xref{Set Breaks, ,Setting breakpoints}.
8875
b37052ae 8876@cindex C@t{++} exception handling
c906108c
SS
8877@item catch throw
8878@itemx catch catch
b37052ae 8879Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8880Catchpoints, , Setting catchpoints}.
8881
8882@cindex inheritance
8883@item ptype @var{typename}
8884Print inheritance relationships as well as other information for type
8885@var{typename}.
8886@xref{Symbols, ,Examining the Symbol Table}.
8887
b37052ae 8888@cindex C@t{++} symbol display
c906108c
SS
8889@item set print demangle
8890@itemx show print demangle
8891@itemx set print asm-demangle
8892@itemx show print asm-demangle
b37052ae
EZ
8893Control whether C@t{++} symbols display in their source form, both when
8894displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8895@xref{Print Settings, ,Print settings}.
8896
8897@item set print object
8898@itemx show print object
8899Choose whether to print derived (actual) or declared types of objects.
8900@xref{Print Settings, ,Print settings}.
8901
8902@item set print vtbl
8903@itemx show print vtbl
8904Control the format for printing virtual function tables.
8905@xref{Print Settings, ,Print settings}.
c906108c 8906(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8907ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8908
8909@kindex set overload-resolution
d4f3574e 8910@cindex overloaded functions, overload resolution
c906108c 8911@item set overload-resolution on
b37052ae 8912Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8913is on. For overloaded functions, @value{GDBN} evaluates the arguments
8914and searches for a function whose signature matches the argument types,
b37052ae 8915using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8916expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8917message.
8918
8919@item set overload-resolution off
b37052ae 8920Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8921overloaded functions that are not class member functions, @value{GDBN}
8922chooses the first function of the specified name that it finds in the
8923symbol table, whether or not its arguments are of the correct type. For
8924overloaded functions that are class member functions, @value{GDBN}
8925searches for a function whose signature @emph{exactly} matches the
8926argument types.
c906108c 8927
9c16f35a
EZ
8928@kindex show overload-resolution
8929@item show overload-resolution
8930Show the current setting of overload resolution.
8931
c906108c
SS
8932@item @r{Overloaded symbol names}
8933You can specify a particular definition of an overloaded symbol, using
b37052ae 8934the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8935@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8936also use the @value{GDBN} command-line word completion facilities to list the
8937available choices, or to finish the type list for you.
8938@xref{Completion,, Command completion}, for details on how to do this.
8939@end table
c906108c 8940
b37303ee
AF
8941@node Objective-C
8942@subsection Objective-C
8943
8944@cindex Objective-C
8945This section provides information about some commands and command
721c2651
EZ
8946options that are useful for debugging Objective-C code. See also
8947@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8948few more commands specific to Objective-C support.
b37303ee
AF
8949
8950@menu
b383017d
RM
8951* Method Names in Commands::
8952* The Print Command with Objective-C::
b37303ee
AF
8953@end menu
8954
8955@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8956@subsubsection Method Names in Commands
8957
8958The following commands have been extended to accept Objective-C method
8959names as line specifications:
8960
8961@kindex clear@r{, and Objective-C}
8962@kindex break@r{, and Objective-C}
8963@kindex info line@r{, and Objective-C}
8964@kindex jump@r{, and Objective-C}
8965@kindex list@r{, and Objective-C}
8966@itemize
8967@item @code{clear}
8968@item @code{break}
8969@item @code{info line}
8970@item @code{jump}
8971@item @code{list}
8972@end itemize
8973
8974A fully qualified Objective-C method name is specified as
8975
8976@smallexample
8977-[@var{Class} @var{methodName}]
8978@end smallexample
8979
c552b3bb
JM
8980where the minus sign is used to indicate an instance method and a
8981plus sign (not shown) is used to indicate a class method. The class
8982name @var{Class} and method name @var{methodName} are enclosed in
8983brackets, similar to the way messages are specified in Objective-C
8984source code. For example, to set a breakpoint at the @code{create}
8985instance method of class @code{Fruit} in the program currently being
8986debugged, enter:
b37303ee
AF
8987
8988@smallexample
8989break -[Fruit create]
8990@end smallexample
8991
8992To list ten program lines around the @code{initialize} class method,
8993enter:
8994
8995@smallexample
8996list +[NSText initialize]
8997@end smallexample
8998
c552b3bb
JM
8999In the current version of @value{GDBN}, the plus or minus sign is
9000required. In future versions of @value{GDBN}, the plus or minus
9001sign will be optional, but you can use it to narrow the search. It
9002is also possible to specify just a method name:
b37303ee
AF
9003
9004@smallexample
9005break create
9006@end smallexample
9007
9008You must specify the complete method name, including any colons. If
9009your program's source files contain more than one @code{create} method,
9010you'll be presented with a numbered list of classes that implement that
9011method. Indicate your choice by number, or type @samp{0} to exit if
9012none apply.
9013
9014As another example, to clear a breakpoint established at the
9015@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9016
9017@smallexample
9018clear -[NSWindow makeKeyAndOrderFront:]
9019@end smallexample
9020
9021@node The Print Command with Objective-C
9022@subsubsection The Print Command With Objective-C
721c2651 9023@cindex Objective-C, print objects
c552b3bb
JM
9024@kindex print-object
9025@kindex po @r{(@code{print-object})}
b37303ee 9026
c552b3bb 9027The print command has also been extended to accept methods. For example:
b37303ee
AF
9028
9029@smallexample
c552b3bb 9030print -[@var{object} hash]
b37303ee
AF
9031@end smallexample
9032
9033@cindex print an Objective-C object description
c552b3bb
JM
9034@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9035@noindent
9036will tell @value{GDBN} to send the @code{hash} message to @var{object}
9037and print the result. Also, an additional command has been added,
9038@code{print-object} or @code{po} for short, which is meant to print
9039the description of an object. However, this command may only work
9040with certain Objective-C libraries that have a particular hook
9041function, @code{_NSPrintForDebugger}, defined.
b37303ee 9042
09d4efe1
EZ
9043@node Fortran
9044@subsection Fortran
9045@cindex Fortran-specific support in @value{GDBN}
9046
9047@table @code
9048@cindex @code{COMMON} blocks, Fortran
9049@kindex info common
9050@item info common @r{[}@var{common-name}@r{]}
9051This command prints the values contained in the Fortran @code{COMMON}
9052block whose name is @var{common-name}. With no argument, the names of
9053all @code{COMMON} blocks visible at current program location are
9054printed.
9055@end table
9056
a8f24a35
EZ
9057Fortran symbols are usually case-insensitive, so @value{GDBN} by
9058default uses case-insensitive matches for Fortran symbols. You can
9059change that with the @samp{set case-insensitive} command, see
9060@ref{Symbols}, for the details.
9061
9c16f35a
EZ
9062@node Pascal
9063@subsection Pascal
9064
9065@cindex Pascal support in @value{GDBN}, limitations
9066Debugging Pascal programs which use sets, subranges, file variables, or
9067nested functions does not currently work. @value{GDBN} does not support
9068entering expressions, printing values, or similar features using Pascal
9069syntax.
9070
9071The Pascal-specific command @code{set print pascal_static-members}
9072controls whether static members of Pascal objects are displayed.
9073@xref{Print Settings, pascal_static-members}.
9074
09d4efe1 9075@node Modula-2
c906108c 9076@subsection Modula-2
7a292a7a 9077
d4f3574e 9078@cindex Modula-2, @value{GDBN} support
c906108c
SS
9079
9080The extensions made to @value{GDBN} to support Modula-2 only support
9081output from the @sc{gnu} Modula-2 compiler (which is currently being
9082developed). Other Modula-2 compilers are not currently supported, and
9083attempting to debug executables produced by them is most likely
9084to give an error as @value{GDBN} reads in the executable's symbol
9085table.
9086
9087@cindex expressions in Modula-2
9088@menu
9089* M2 Operators:: Built-in operators
9090* Built-In Func/Proc:: Built-in functions and procedures
9091* M2 Constants:: Modula-2 constants
9092* M2 Defaults:: Default settings for Modula-2
9093* Deviations:: Deviations from standard Modula-2
9094* M2 Checks:: Modula-2 type and range checks
9095* M2 Scope:: The scope operators @code{::} and @code{.}
9096* GDB/M2:: @value{GDBN} and Modula-2
9097@end menu
9098
6d2ebf8b 9099@node M2 Operators
c906108c
SS
9100@subsubsection Operators
9101@cindex Modula-2 operators
9102
9103Operators must be defined on values of specific types. For instance,
9104@code{+} is defined on numbers, but not on structures. Operators are
9105often defined on groups of types. For the purposes of Modula-2, the
9106following definitions hold:
9107
9108@itemize @bullet
9109
9110@item
9111@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9112their subranges.
9113
9114@item
9115@emph{Character types} consist of @code{CHAR} and its subranges.
9116
9117@item
9118@emph{Floating-point types} consist of @code{REAL}.
9119
9120@item
9121@emph{Pointer types} consist of anything declared as @code{POINTER TO
9122@var{type}}.
9123
9124@item
9125@emph{Scalar types} consist of all of the above.
9126
9127@item
9128@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9129
9130@item
9131@emph{Boolean types} consist of @code{BOOLEAN}.
9132@end itemize
9133
9134@noindent
9135The following operators are supported, and appear in order of
9136increasing precedence:
9137
9138@table @code
9139@item ,
9140Function argument or array index separator.
9141
9142@item :=
9143Assignment. The value of @var{var} @code{:=} @var{value} is
9144@var{value}.
9145
9146@item <@r{, }>
9147Less than, greater than on integral, floating-point, or enumerated
9148types.
9149
9150@item <=@r{, }>=
96a2c332 9151Less than or equal to, greater than or equal to
c906108c
SS
9152on integral, floating-point and enumerated types, or set inclusion on
9153set types. Same precedence as @code{<}.
9154
9155@item =@r{, }<>@r{, }#
9156Equality and two ways of expressing inequality, valid on scalar types.
9157Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9158available for inequality, since @code{#} conflicts with the script
9159comment character.
9160
9161@item IN
9162Set membership. Defined on set types and the types of their members.
9163Same precedence as @code{<}.
9164
9165@item OR
9166Boolean disjunction. Defined on boolean types.
9167
9168@item AND@r{, }&
d4f3574e 9169Boolean conjunction. Defined on boolean types.
c906108c
SS
9170
9171@item @@
9172The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9173
9174@item +@r{, }-
9175Addition and subtraction on integral and floating-point types, or union
9176and difference on set types.
9177
9178@item *
9179Multiplication on integral and floating-point types, or set intersection
9180on set types.
9181
9182@item /
9183Division on floating-point types, or symmetric set difference on set
9184types. Same precedence as @code{*}.
9185
9186@item DIV@r{, }MOD
9187Integer division and remainder. Defined on integral types. Same
9188precedence as @code{*}.
9189
9190@item -
9191Negative. Defined on @code{INTEGER} and @code{REAL} data.
9192
9193@item ^
9194Pointer dereferencing. Defined on pointer types.
9195
9196@item NOT
9197Boolean negation. Defined on boolean types. Same precedence as
9198@code{^}.
9199
9200@item .
9201@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9202precedence as @code{^}.
9203
9204@item []
9205Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9206
9207@item ()
9208Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9209as @code{^}.
9210
9211@item ::@r{, }.
9212@value{GDBN} and Modula-2 scope operators.
9213@end table
9214
9215@quotation
9216@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9217treats the use of the operator @code{IN}, or the use of operators
9218@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9219@code{<=}, and @code{>=} on sets as an error.
9220@end quotation
9221
cb51c4e0 9222
6d2ebf8b 9223@node Built-In Func/Proc
c906108c 9224@subsubsection Built-in functions and procedures
cb51c4e0 9225@cindex Modula-2 built-ins
c906108c
SS
9226
9227Modula-2 also makes available several built-in procedures and functions.
9228In describing these, the following metavariables are used:
9229
9230@table @var
9231
9232@item a
9233represents an @code{ARRAY} variable.
9234
9235@item c
9236represents a @code{CHAR} constant or variable.
9237
9238@item i
9239represents a variable or constant of integral type.
9240
9241@item m
9242represents an identifier that belongs to a set. Generally used in the
9243same function with the metavariable @var{s}. The type of @var{s} should
9244be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9245
9246@item n
9247represents a variable or constant of integral or floating-point type.
9248
9249@item r
9250represents a variable or constant of floating-point type.
9251
9252@item t
9253represents a type.
9254
9255@item v
9256represents a variable.
9257
9258@item x
9259represents a variable or constant of one of many types. See the
9260explanation of the function for details.
9261@end table
9262
9263All Modula-2 built-in procedures also return a result, described below.
9264
9265@table @code
9266@item ABS(@var{n})
9267Returns the absolute value of @var{n}.
9268
9269@item CAP(@var{c})
9270If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9271equivalent, otherwise it returns its argument.
c906108c
SS
9272
9273@item CHR(@var{i})
9274Returns the character whose ordinal value is @var{i}.
9275
9276@item DEC(@var{v})
c3f6f71d 9277Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9278
9279@item DEC(@var{v},@var{i})
9280Decrements the value in the variable @var{v} by @var{i}. Returns the
9281new value.
9282
9283@item EXCL(@var{m},@var{s})
9284Removes the element @var{m} from the set @var{s}. Returns the new
9285set.
9286
9287@item FLOAT(@var{i})
9288Returns the floating point equivalent of the integer @var{i}.
9289
9290@item HIGH(@var{a})
9291Returns the index of the last member of @var{a}.
9292
9293@item INC(@var{v})
c3f6f71d 9294Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9295
9296@item INC(@var{v},@var{i})
9297Increments the value in the variable @var{v} by @var{i}. Returns the
9298new value.
9299
9300@item INCL(@var{m},@var{s})
9301Adds the element @var{m} to the set @var{s} if it is not already
9302there. Returns the new set.
9303
9304@item MAX(@var{t})
9305Returns the maximum value of the type @var{t}.
9306
9307@item MIN(@var{t})
9308Returns the minimum value of the type @var{t}.
9309
9310@item ODD(@var{i})
9311Returns boolean TRUE if @var{i} is an odd number.
9312
9313@item ORD(@var{x})
9314Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9315value of a character is its @sc{ascii} value (on machines supporting the
9316@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9317integral, character and enumerated types.
9318
9319@item SIZE(@var{x})
9320Returns the size of its argument. @var{x} can be a variable or a type.
9321
9322@item TRUNC(@var{r})
9323Returns the integral part of @var{r}.
9324
9325@item VAL(@var{t},@var{i})
9326Returns the member of the type @var{t} whose ordinal value is @var{i}.
9327@end table
9328
9329@quotation
9330@emph{Warning:} Sets and their operations are not yet supported, so
9331@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9332an error.
9333@end quotation
9334
9335@cindex Modula-2 constants
6d2ebf8b 9336@node M2 Constants
c906108c
SS
9337@subsubsection Constants
9338
9339@value{GDBN} allows you to express the constants of Modula-2 in the following
9340ways:
9341
9342@itemize @bullet
9343
9344@item
9345Integer constants are simply a sequence of digits. When used in an
9346expression, a constant is interpreted to be type-compatible with the
9347rest of the expression. Hexadecimal integers are specified by a
9348trailing @samp{H}, and octal integers by a trailing @samp{B}.
9349
9350@item
9351Floating point constants appear as a sequence of digits, followed by a
9352decimal point and another sequence of digits. An optional exponent can
9353then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9354@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9355digits of the floating point constant must be valid decimal (base 10)
9356digits.
9357
9358@item
9359Character constants consist of a single character enclosed by a pair of
9360like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9361also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9362followed by a @samp{C}.
9363
9364@item
9365String constants consist of a sequence of characters enclosed by a
9366pair of like quotes, either single (@code{'}) or double (@code{"}).
9367Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9368Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9369sequences.
9370
9371@item
9372Enumerated constants consist of an enumerated identifier.
9373
9374@item
9375Boolean constants consist of the identifiers @code{TRUE} and
9376@code{FALSE}.
9377
9378@item
9379Pointer constants consist of integral values only.
9380
9381@item
9382Set constants are not yet supported.
9383@end itemize
9384
6d2ebf8b 9385@node M2 Defaults
c906108c
SS
9386@subsubsection Modula-2 defaults
9387@cindex Modula-2 defaults
9388
9389If type and range checking are set automatically by @value{GDBN}, they
9390both default to @code{on} whenever the working language changes to
d4f3574e 9391Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9392selected the working language.
9393
9394If you allow @value{GDBN} to set the language automatically, then entering
9395code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9396working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9397the language automatically}, for further details.
9398
6d2ebf8b 9399@node Deviations
c906108c
SS
9400@subsubsection Deviations from standard Modula-2
9401@cindex Modula-2, deviations from
9402
9403A few changes have been made to make Modula-2 programs easier to debug.
9404This is done primarily via loosening its type strictness:
9405
9406@itemize @bullet
9407@item
9408Unlike in standard Modula-2, pointer constants can be formed by
9409integers. This allows you to modify pointer variables during
9410debugging. (In standard Modula-2, the actual address contained in a
9411pointer variable is hidden from you; it can only be modified
9412through direct assignment to another pointer variable or expression that
9413returned a pointer.)
9414
9415@item
9416C escape sequences can be used in strings and characters to represent
9417non-printable characters. @value{GDBN} prints out strings with these
9418escape sequences embedded. Single non-printable characters are
9419printed using the @samp{CHR(@var{nnn})} format.
9420
9421@item
9422The assignment operator (@code{:=}) returns the value of its right-hand
9423argument.
9424
9425@item
9426All built-in procedures both modify @emph{and} return their argument.
9427@end itemize
9428
6d2ebf8b 9429@node M2 Checks
c906108c
SS
9430@subsubsection Modula-2 type and range checks
9431@cindex Modula-2 checks
9432
9433@quotation
9434@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9435range checking.
9436@end quotation
9437@c FIXME remove warning when type/range checks added
9438
9439@value{GDBN} considers two Modula-2 variables type equivalent if:
9440
9441@itemize @bullet
9442@item
9443They are of types that have been declared equivalent via a @code{TYPE
9444@var{t1} = @var{t2}} statement
9445
9446@item
9447They have been declared on the same line. (Note: This is true of the
9448@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9449@end itemize
9450
9451As long as type checking is enabled, any attempt to combine variables
9452whose types are not equivalent is an error.
9453
9454Range checking is done on all mathematical operations, assignment, array
9455index bounds, and all built-in functions and procedures.
9456
6d2ebf8b 9457@node M2 Scope
c906108c
SS
9458@subsubsection The scope operators @code{::} and @code{.}
9459@cindex scope
41afff9a 9460@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9461@cindex colon, doubled as scope operator
9462@ifinfo
41afff9a 9463@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9464@c Info cannot handle :: but TeX can.
9465@end ifinfo
9466@iftex
41afff9a 9467@vindex ::@r{, in Modula-2}
c906108c
SS
9468@end iftex
9469
9470There are a few subtle differences between the Modula-2 scope operator
9471(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9472similar syntax:
9473
474c8240 9474@smallexample
c906108c
SS
9475
9476@var{module} . @var{id}
9477@var{scope} :: @var{id}
474c8240 9478@end smallexample
c906108c
SS
9479
9480@noindent
9481where @var{scope} is the name of a module or a procedure,
9482@var{module} the name of a module, and @var{id} is any declared
9483identifier within your program, except another module.
9484
9485Using the @code{::} operator makes @value{GDBN} search the scope
9486specified by @var{scope} for the identifier @var{id}. If it is not
9487found in the specified scope, then @value{GDBN} searches all scopes
9488enclosing the one specified by @var{scope}.
9489
9490Using the @code{.} operator makes @value{GDBN} search the current scope for
9491the identifier specified by @var{id} that was imported from the
9492definition module specified by @var{module}. With this operator, it is
9493an error if the identifier @var{id} was not imported from definition
9494module @var{module}, or if @var{id} is not an identifier in
9495@var{module}.
9496
6d2ebf8b 9497@node GDB/M2
c906108c
SS
9498@subsubsection @value{GDBN} and Modula-2
9499
9500Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9501Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9502specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9503@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9504apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9505analogue in Modula-2.
9506
9507The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9508with any language, is not useful with Modula-2. Its
c906108c 9509intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9510created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9511address can be specified by an integral constant, the construct
d4f3574e 9512@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9513
9514@cindex @code{#} in Modula-2
9515In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9516interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9517
e07c999f
PH
9518@node Ada
9519@subsection Ada
9520@cindex Ada
9521
9522The extensions made to @value{GDBN} for Ada only support
9523output from the @sc{gnu} Ada (GNAT) compiler.
9524Other Ada compilers are not currently supported, and
9525attempting to debug executables produced by them is most likely
9526to be difficult.
9527
9528
9529@cindex expressions in Ada
9530@menu
9531* Ada Mode Intro:: General remarks on the Ada syntax
9532 and semantics supported by Ada mode
9533 in @value{GDBN}.
9534* Omissions from Ada:: Restrictions on the Ada expression syntax.
9535* Additions to Ada:: Extensions of the Ada expression syntax.
9536* Stopping Before Main Program:: Debugging the program during elaboration.
9537* Ada Glitches:: Known peculiarities of Ada mode.
9538@end menu
9539
9540@node Ada Mode Intro
9541@subsubsection Introduction
9542@cindex Ada mode, general
9543
9544The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9545syntax, with some extensions.
9546The philosophy behind the design of this subset is
9547
9548@itemize @bullet
9549@item
9550That @value{GDBN} should provide basic literals and access to operations for
9551arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9552leaving more sophisticated computations to subprograms written into the
9553program (which therefore may be called from @value{GDBN}).
9554
9555@item
9556That type safety and strict adherence to Ada language restrictions
9557are not particularly important to the @value{GDBN} user.
9558
9559@item
9560That brevity is important to the @value{GDBN} user.
9561@end itemize
9562
9563Thus, for brevity, the debugger acts as if there were
9564implicit @code{with} and @code{use} clauses in effect for all user-written
9565packages, making it unnecessary to fully qualify most names with
9566their packages, regardless of context. Where this causes ambiguity,
9567@value{GDBN} asks the user's intent.
9568
9569The debugger will start in Ada mode if it detects an Ada main program.
9570As for other languages, it will enter Ada mode when stopped in a program that
9571was translated from an Ada source file.
9572
9573While in Ada mode, you may use `@t{--}' for comments. This is useful
9574mostly for documenting command files. The standard @value{GDBN} comment
9575(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9576middle (to allow based literals).
9577
9578The debugger supports limited overloading. Given a subprogram call in which
9579the function symbol has multiple definitions, it will use the number of
9580actual parameters and some information about their types to attempt to narrow
9581the set of definitions. It also makes very limited use of context, preferring
9582procedures to functions in the context of the @code{call} command, and
9583functions to procedures elsewhere.
9584
9585@node Omissions from Ada
9586@subsubsection Omissions from Ada
9587@cindex Ada, omissions from
9588
9589Here are the notable omissions from the subset:
9590
9591@itemize @bullet
9592@item
9593Only a subset of the attributes are supported:
9594
9595@itemize @minus
9596@item
9597@t{'First}, @t{'Last}, and @t{'Length}
9598 on array objects (not on types and subtypes).
9599
9600@item
9601@t{'Min} and @t{'Max}.
9602
9603@item
9604@t{'Pos} and @t{'Val}.
9605
9606@item
9607@t{'Tag}.
9608
9609@item
9610@t{'Range} on array objects (not subtypes), but only as the right
9611operand of the membership (@code{in}) operator.
9612
9613@item
9614@t{'Access}, @t{'Unchecked_Access}, and
9615@t{'Unrestricted_Access} (a GNAT extension).
9616
9617@item
9618@t{'Address}.
9619@end itemize
9620
9621@item
9622The names in
9623@code{Characters.Latin_1} are not available and
9624concatenation is not implemented. Thus, escape characters in strings are
9625not currently available.
9626
9627@item
9628Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9629equality of representations. They will generally work correctly
9630for strings and arrays whose elements have integer or enumeration types.
9631They may not work correctly for arrays whose element
9632types have user-defined equality, for arrays of real values
9633(in particular, IEEE-conformant floating point, because of negative
9634zeroes and NaNs), and for arrays whose elements contain unused bits with
9635indeterminate values.
9636
9637@item
9638The other component-by-component array operations (@code{and}, @code{or},
9639@code{xor}, @code{not}, and relational tests other than equality)
9640are not implemented.
9641
9642@item
9643There are no record or array aggregates.
9644
9645@item
9646Calls to dispatching subprograms are not implemented.
9647
9648@item
9649The overloading algorithm is much more limited (i.e., less selective)
9650than that of real Ada. It makes only limited use of the context in which a subexpression
9651appears to resolve its meaning, and it is much looser in its rules for allowing
9652type matches. As a result, some function calls will be ambiguous, and the user
9653will be asked to choose the proper resolution.
9654
9655@item
9656The @code{new} operator is not implemented.
9657
9658@item
9659Entry calls are not implemented.
9660
9661@item
9662Aside from printing, arithmetic operations on the native VAX floating-point
9663formats are not supported.
9664
9665@item
9666It is not possible to slice a packed array.
9667@end itemize
9668
9669@node Additions to Ada
9670@subsubsection Additions to Ada
9671@cindex Ada, deviations from
9672
9673As it does for other languages, @value{GDBN} makes certain generic
9674extensions to Ada (@pxref{Expressions}):
9675
9676@itemize @bullet
9677@item
9678If the expression @var{E} is a variable residing in memory
9679(typically a local variable or array element) and @var{N} is
9680a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9681@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9682In Ada, this operator is generally not necessary, since its prime use
9683is in displaying parts of an array, and slicing will usually do this in Ada.
9684However, there are occasional uses when debugging programs
9685in which certain debugging information has been optimized away.
9686
9687@item
9688@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9689in function or file @var{B}.'' When @var{B} is a file name, you must typically
9690surround it in single quotes.
9691
9692@item
9693The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9694@var{type} that appears at address @var{addr}.''
9695
9696@item
9697A name starting with @samp{$} is a convenience variable
9698(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9699@end itemize
9700
9701In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9702to Ada:
9703
9704@itemize @bullet
9705@item
9706The assignment statement is allowed as an expression, returning
9707its right-hand operand as its value. Thus, you may enter
9708
9709@smallexample
9710set x := y + 3
9711print A(tmp := y + 1)
9712@end smallexample
9713
9714@item
9715The semicolon is allowed as an ``operator,'' returning as its value
9716the value of its right-hand operand.
9717This allows, for example,
9718complex conditional breaks:
9719
9720@smallexample
9721break f
9722condition 1 (report(i); k += 1; A(k) > 100)
9723@end smallexample
9724
9725@item
9726Rather than use catenation and symbolic character names to introduce special
9727characters into strings, one may instead use a special bracket notation,
9728which is also used to print strings. A sequence of characters of the form
9729@samp{["@var{XX}"]} within a string or character literal denotes the
9730(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9731sequence of characters @samp{["""]} also denotes a single quotation mark
9732in strings. For example,
9733@smallexample
9734 "One line.["0a"]Next line.["0a"]"
9735@end smallexample
9736@noindent
9737contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9738period.
9739
9740@item
9741The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9742@t{'Max} is optional (and is ignored in any case). For example, it is valid
9743to write
9744
9745@smallexample
9746print 'max(x, y)
9747@end smallexample
9748
9749@item
9750When printing arrays, @value{GDBN} uses positional notation when the
9751array has a lower bound of 1, and uses a modified named notation otherwise.
9752For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9753
9754@smallexample
9755(3 => 10, 17, 1)
9756@end smallexample
9757
9758@noindent
9759That is, in contrast to valid Ada, only the first component has a @code{=>}
9760clause.
9761
9762@item
9763You may abbreviate attributes in expressions with any unique,
9764multi-character subsequence of
9765their names (an exact match gets preference).
9766For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9767in place of @t{a'length}.
9768
9769@item
9770@cindex quoting Ada internal identifiers
9771Since Ada is case-insensitive, the debugger normally maps identifiers you type
9772to lower case. The GNAT compiler uses upper-case characters for
9773some of its internal identifiers, which are normally of no interest to users.
9774For the rare occasions when you actually have to look at them,
9775enclose them in angle brackets to avoid the lower-case mapping.
9776For example,
9777@smallexample
9778@value{GDBP} print <JMPBUF_SAVE>[0]
9779@end smallexample
9780
9781@item
9782Printing an object of class-wide type or dereferencing an
9783access-to-class-wide value will display all the components of the object's
9784specific type (as indicated by its run-time tag). Likewise, component
9785selection on such a value will operate on the specific type of the
9786object.
9787
9788@end itemize
9789
9790@node Stopping Before Main Program
9791@subsubsection Stopping at the Very Beginning
9792
9793@cindex breakpointing Ada elaboration code
9794It is sometimes necessary to debug the program during elaboration, and
9795before reaching the main procedure.
9796As defined in the Ada Reference
9797Manual, the elaboration code is invoked from a procedure called
9798@code{adainit}. To run your program up to the beginning of
9799elaboration, simply use the following two commands:
9800@code{tbreak adainit} and @code{run}.
9801
9802@node Ada Glitches
9803@subsubsection Known Peculiarities of Ada Mode
9804@cindex Ada, problems
9805
9806Besides the omissions listed previously (@pxref{Omissions from Ada}),
9807we know of several problems with and limitations of Ada mode in
9808@value{GDBN},
9809some of which will be fixed with planned future releases of the debugger
9810and the GNU Ada compiler.
9811
9812@itemize @bullet
9813@item
9814Currently, the debugger
9815has insufficient information to determine whether certain pointers represent
9816pointers to objects or the objects themselves.
9817Thus, the user may have to tack an extra @code{.all} after an expression
9818to get it printed properly.
9819
9820@item
9821Static constants that the compiler chooses not to materialize as objects in
9822storage are invisible to the debugger.
9823
9824@item
9825Named parameter associations in function argument lists are ignored (the
9826argument lists are treated as positional).
9827
9828@item
9829Many useful library packages are currently invisible to the debugger.
9830
9831@item
9832Fixed-point arithmetic, conversions, input, and output is carried out using
9833floating-point arithmetic, and may give results that only approximate those on
9834the host machine.
9835
9836@item
9837The type of the @t{'Address} attribute may not be @code{System.Address}.
9838
9839@item
9840The GNAT compiler never generates the prefix @code{Standard} for any of
9841the standard symbols defined by the Ada language. @value{GDBN} knows about
9842this: it will strip the prefix from names when you use it, and will never
9843look for a name you have so qualified among local symbols, nor match against
9844symbols in other packages or subprograms. If you have
9845defined entities anywhere in your program other than parameters and
9846local variables whose simple names match names in @code{Standard},
9847GNAT's lack of qualification here can cause confusion. When this happens,
9848you can usually resolve the confusion
9849by qualifying the problematic names with package
9850@code{Standard} explicitly.
9851@end itemize
9852
4e562065
JB
9853@node Unsupported languages
9854@section Unsupported languages
9855
9856@cindex unsupported languages
9857@cindex minimal language
9858In addition to the other fully-supported programming languages,
9859@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9860It does not represent a real programming language, but provides a set
9861of capabilities close to what the C or assembly languages provide.
9862This should allow most simple operations to be performed while debugging
9863an application that uses a language currently not supported by @value{GDBN}.
9864
9865If the language is set to @code{auto}, @value{GDBN} will automatically
9866select this language if the current frame corresponds to an unsupported
9867language.
9868
6d2ebf8b 9869@node Symbols
c906108c
SS
9870@chapter Examining the Symbol Table
9871
d4f3574e 9872The commands described in this chapter allow you to inquire about the
c906108c
SS
9873symbols (names of variables, functions and types) defined in your
9874program. This information is inherent in the text of your program and
9875does not change as your program executes. @value{GDBN} finds it in your
9876program's symbol table, in the file indicated when you started @value{GDBN}
9877(@pxref{File Options, ,Choosing files}), or by one of the
9878file-management commands (@pxref{Files, ,Commands to specify files}).
9879
9880@cindex symbol names
9881@cindex names of symbols
9882@cindex quoting names
9883Occasionally, you may need to refer to symbols that contain unusual
9884characters, which @value{GDBN} ordinarily treats as word delimiters. The
9885most frequent case is in referring to static variables in other
9886source files (@pxref{Variables,,Program variables}). File names
9887are recorded in object files as debugging symbols, but @value{GDBN} would
9888ordinarily parse a typical file name, like @file{foo.c}, as the three words
9889@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9890@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9891
474c8240 9892@smallexample
c906108c 9893p 'foo.c'::x
474c8240 9894@end smallexample
c906108c
SS
9895
9896@noindent
9897looks up the value of @code{x} in the scope of the file @file{foo.c}.
9898
9899@table @code
a8f24a35
EZ
9900@cindex case-insensitive symbol names
9901@cindex case sensitivity in symbol names
9902@kindex set case-sensitive
9903@item set case-sensitive on
9904@itemx set case-sensitive off
9905@itemx set case-sensitive auto
9906Normally, when @value{GDBN} looks up symbols, it matches their names
9907with case sensitivity determined by the current source language.
9908Occasionally, you may wish to control that. The command @code{set
9909case-sensitive} lets you do that by specifying @code{on} for
9910case-sensitive matches or @code{off} for case-insensitive ones. If
9911you specify @code{auto}, case sensitivity is reset to the default
9912suitable for the source language. The default is case-sensitive
9913matches for all languages except for Fortran, for which the default is
9914case-insensitive matches.
9915
9c16f35a
EZ
9916@kindex show case-sensitive
9917@item show case-sensitive
a8f24a35
EZ
9918This command shows the current setting of case sensitivity for symbols
9919lookups.
9920
c906108c 9921@kindex info address
b37052ae 9922@cindex address of a symbol
c906108c
SS
9923@item info address @var{symbol}
9924Describe where the data for @var{symbol} is stored. For a register
9925variable, this says which register it is kept in. For a non-register
9926local variable, this prints the stack-frame offset at which the variable
9927is always stored.
9928
9929Note the contrast with @samp{print &@var{symbol}}, which does not work
9930at all for a register variable, and for a stack local variable prints
9931the exact address of the current instantiation of the variable.
9932
3d67e040 9933@kindex info symbol
b37052ae 9934@cindex symbol from address
9c16f35a 9935@cindex closest symbol and offset for an address
3d67e040
EZ
9936@item info symbol @var{addr}
9937Print the name of a symbol which is stored at the address @var{addr}.
9938If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9939nearest symbol and an offset from it:
9940
474c8240 9941@smallexample
3d67e040
EZ
9942(@value{GDBP}) info symbol 0x54320
9943_initialize_vx + 396 in section .text
474c8240 9944@end smallexample
3d67e040
EZ
9945
9946@noindent
9947This is the opposite of the @code{info address} command. You can use
9948it to find out the name of a variable or a function given its address.
9949
c906108c 9950@kindex whatis
d4f3574e
SS
9951@item whatis @var{expr}
9952Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9953actually evaluated, and any side-effecting operations (such as
9954assignments or function calls) inside it do not take place.
9955@xref{Expressions, ,Expressions}.
9956
9957@item whatis
9958Print the data type of @code{$}, the last value in the value history.
9959
9960@kindex ptype
9961@item ptype @var{typename}
9962Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9963the name of a type, or for C code it may have the form @samp{class
9964@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9965@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9966
d4f3574e 9967@item ptype @var{expr}
c906108c 9968@itemx ptype
d4f3574e 9969Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9970differs from @code{whatis} by printing a detailed description, instead
9971of just the name of the type.
9972
9973For example, for this variable declaration:
9974
474c8240 9975@smallexample
c906108c 9976struct complex @{double real; double imag;@} v;
474c8240 9977@end smallexample
c906108c
SS
9978
9979@noindent
9980the two commands give this output:
9981
474c8240 9982@smallexample
c906108c
SS
9983@group
9984(@value{GDBP}) whatis v
9985type = struct complex
9986(@value{GDBP}) ptype v
9987type = struct complex @{
9988 double real;
9989 double imag;
9990@}
9991@end group
474c8240 9992@end smallexample
c906108c
SS
9993
9994@noindent
9995As with @code{whatis}, using @code{ptype} without an argument refers to
9996the type of @code{$}, the last value in the value history.
9997
9998@kindex info types
9999@item info types @var{regexp}
10000@itemx info types
09d4efe1
EZ
10001Print a brief description of all types whose names match the regular
10002expression @var{regexp} (or all types in your program, if you supply
10003no argument). Each complete typename is matched as though it were a
10004complete line; thus, @samp{i type value} gives information on all
10005types in your program whose names include the string @code{value}, but
10006@samp{i type ^value$} gives information only on types whose complete
10007name is @code{value}.
c906108c
SS
10008
10009This command differs from @code{ptype} in two ways: first, like
10010@code{whatis}, it does not print a detailed description; second, it
10011lists all source files where a type is defined.
10012
b37052ae
EZ
10013@kindex info scope
10014@cindex local variables
09d4efe1 10015@item info scope @var{location}
b37052ae 10016List all the variables local to a particular scope. This command
09d4efe1
EZ
10017accepts a @var{location} argument---a function name, a source line, or
10018an address preceded by a @samp{*}, and prints all the variables local
10019to the scope defined by that location. For example:
b37052ae
EZ
10020
10021@smallexample
10022(@value{GDBP}) @b{info scope command_line_handler}
10023Scope for command_line_handler:
10024Symbol rl is an argument at stack/frame offset 8, length 4.
10025Symbol linebuffer is in static storage at address 0x150a18, length 4.
10026Symbol linelength is in static storage at address 0x150a1c, length 4.
10027Symbol p is a local variable in register $esi, length 4.
10028Symbol p1 is a local variable in register $ebx, length 4.
10029Symbol nline is a local variable in register $edx, length 4.
10030Symbol repeat is a local variable at frame offset -8, length 4.
10031@end smallexample
10032
f5c37c66
EZ
10033@noindent
10034This command is especially useful for determining what data to collect
10035during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10036collect}.
10037
c906108c
SS
10038@kindex info source
10039@item info source
919d772c
JB
10040Show information about the current source file---that is, the source file for
10041the function containing the current point of execution:
10042@itemize @bullet
10043@item
10044the name of the source file, and the directory containing it,
10045@item
10046the directory it was compiled in,
10047@item
10048its length, in lines,
10049@item
10050which programming language it is written in,
10051@item
10052whether the executable includes debugging information for that file, and
10053if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10054@item
10055whether the debugging information includes information about
10056preprocessor macros.
10057@end itemize
10058
c906108c
SS
10059
10060@kindex info sources
10061@item info sources
10062Print the names of all source files in your program for which there is
10063debugging information, organized into two lists: files whose symbols
10064have already been read, and files whose symbols will be read when needed.
10065
10066@kindex info functions
10067@item info functions
10068Print the names and data types of all defined functions.
10069
10070@item info functions @var{regexp}
10071Print the names and data types of all defined functions
10072whose names contain a match for regular expression @var{regexp}.
10073Thus, @samp{info fun step} finds all functions whose names
10074include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10075start with @code{step}. If a function name contains characters
10076that conflict with the regular expression language (eg.
1c5dfdad 10077@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10078
10079@kindex info variables
10080@item info variables
10081Print the names and data types of all variables that are declared
6ca652b0 10082outside of functions (i.e.@: excluding local variables).
c906108c
SS
10083
10084@item info variables @var{regexp}
10085Print the names and data types of all variables (except for local
10086variables) whose names contain a match for regular expression
10087@var{regexp}.
10088
b37303ee 10089@kindex info classes
721c2651 10090@cindex Objective-C, classes and selectors
b37303ee
AF
10091@item info classes
10092@itemx info classes @var{regexp}
10093Display all Objective-C classes in your program, or
10094(with the @var{regexp} argument) all those matching a particular regular
10095expression.
10096
10097@kindex info selectors
10098@item info selectors
10099@itemx info selectors @var{regexp}
10100Display all Objective-C selectors in your program, or
10101(with the @var{regexp} argument) all those matching a particular regular
10102expression.
10103
c906108c
SS
10104@ignore
10105This was never implemented.
10106@kindex info methods
10107@item info methods
10108@itemx info methods @var{regexp}
10109The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10110methods within C@t{++} program, or (with the @var{regexp} argument) a
10111specific set of methods found in the various C@t{++} classes. Many
10112C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10113from the @code{ptype} command can be overwhelming and hard to use. The
10114@code{info-methods} command filters the methods, printing only those
10115which match the regular-expression @var{regexp}.
10116@end ignore
10117
c906108c
SS
10118@cindex reloading symbols
10119Some systems allow individual object files that make up your program to
7a292a7a
SS
10120be replaced without stopping and restarting your program. For example,
10121in VxWorks you can simply recompile a defective object file and keep on
10122running. If you are running on one of these systems, you can allow
10123@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10124
10125@table @code
10126@kindex set symbol-reloading
10127@item set symbol-reloading on
10128Replace symbol definitions for the corresponding source file when an
10129object file with a particular name is seen again.
10130
10131@item set symbol-reloading off
6d2ebf8b
SS
10132Do not replace symbol definitions when encountering object files of the
10133same name more than once. This is the default state; if you are not
10134running on a system that permits automatic relinking of modules, you
10135should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10136may discard symbols when linking large programs, that may contain
10137several modules (from different directories or libraries) with the same
10138name.
c906108c
SS
10139
10140@kindex show symbol-reloading
10141@item show symbol-reloading
10142Show the current @code{on} or @code{off} setting.
10143@end table
c906108c 10144
9c16f35a 10145@cindex opaque data types
c906108c
SS
10146@kindex set opaque-type-resolution
10147@item set opaque-type-resolution on
10148Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10149declared as a pointer to a @code{struct}, @code{class}, or
10150@code{union}---for example, @code{struct MyType *}---that is used in one
10151source file although the full declaration of @code{struct MyType} is in
10152another source file. The default is on.
10153
10154A change in the setting of this subcommand will not take effect until
10155the next time symbols for a file are loaded.
10156
10157@item set opaque-type-resolution off
10158Tell @value{GDBN} not to resolve opaque types. In this case, the type
10159is printed as follows:
10160@smallexample
10161@{<no data fields>@}
10162@end smallexample
10163
10164@kindex show opaque-type-resolution
10165@item show opaque-type-resolution
10166Show whether opaque types are resolved or not.
c906108c
SS
10167
10168@kindex maint print symbols
10169@cindex symbol dump
10170@kindex maint print psymbols
10171@cindex partial symbol dump
10172@item maint print symbols @var{filename}
10173@itemx maint print psymbols @var{filename}
10174@itemx maint print msymbols @var{filename}
10175Write a dump of debugging symbol data into the file @var{filename}.
10176These commands are used to debug the @value{GDBN} symbol-reading code. Only
10177symbols with debugging data are included. If you use @samp{maint print
10178symbols}, @value{GDBN} includes all the symbols for which it has already
10179collected full details: that is, @var{filename} reflects symbols for
10180only those files whose symbols @value{GDBN} has read. You can use the
10181command @code{info sources} to find out which files these are. If you
10182use @samp{maint print psymbols} instead, the dump shows information about
10183symbols that @value{GDBN} only knows partially---that is, symbols defined in
10184files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10185@samp{maint print msymbols} dumps just the minimal symbol information
10186required for each object file from which @value{GDBN} has read some symbols.
10187@xref{Files, ,Commands to specify files}, for a discussion of how
10188@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10189
5e7b2f39
JB
10190@kindex maint info symtabs
10191@kindex maint info psymtabs
44ea7b70
JB
10192@cindex listing @value{GDBN}'s internal symbol tables
10193@cindex symbol tables, listing @value{GDBN}'s internal
10194@cindex full symbol tables, listing @value{GDBN}'s internal
10195@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10196@item maint info symtabs @r{[} @var{regexp} @r{]}
10197@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10198
10199List the @code{struct symtab} or @code{struct partial_symtab}
10200structures whose names match @var{regexp}. If @var{regexp} is not
10201given, list them all. The output includes expressions which you can
10202copy into a @value{GDBN} debugging this one to examine a particular
10203structure in more detail. For example:
10204
10205@smallexample
5e7b2f39 10206(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10207@{ objfile /home/gnu/build/gdb/gdb
10208 ((struct objfile *) 0x82e69d0)
b383017d 10209 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10210 ((struct partial_symtab *) 0x8474b10)
10211 readin no
10212 fullname (null)
10213 text addresses 0x814d3c8 -- 0x8158074
10214 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10215 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10216 dependencies (none)
10217 @}
10218@}
5e7b2f39 10219(@value{GDBP}) maint info symtabs
44ea7b70
JB
10220(@value{GDBP})
10221@end smallexample
10222@noindent
10223We see that there is one partial symbol table whose filename contains
10224the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10225and we see that @value{GDBN} has not read in any symtabs yet at all.
10226If we set a breakpoint on a function, that will cause @value{GDBN} to
10227read the symtab for the compilation unit containing that function:
10228
10229@smallexample
10230(@value{GDBP}) break dwarf2_psymtab_to_symtab
10231Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10232line 1574.
5e7b2f39 10233(@value{GDBP}) maint info symtabs
b383017d 10234@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10235 ((struct objfile *) 0x82e69d0)
b383017d 10236 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10237 ((struct symtab *) 0x86c1f38)
10238 dirname (null)
10239 fullname (null)
10240 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10241 debugformat DWARF 2
10242 @}
10243@}
b383017d 10244(@value{GDBP})
44ea7b70 10245@end smallexample
c906108c
SS
10246@end table
10247
44ea7b70 10248
6d2ebf8b 10249@node Altering
c906108c
SS
10250@chapter Altering Execution
10251
10252Once you think you have found an error in your program, you might want to
10253find out for certain whether correcting the apparent error would lead to
10254correct results in the rest of the run. You can find the answer by
10255experiment, using the @value{GDBN} features for altering execution of the
10256program.
10257
10258For example, you can store new values into variables or memory
7a292a7a
SS
10259locations, give your program a signal, restart it at a different
10260address, or even return prematurely from a function.
c906108c
SS
10261
10262@menu
10263* Assignment:: Assignment to variables
10264* Jumping:: Continuing at a different address
c906108c 10265* Signaling:: Giving your program a signal
c906108c
SS
10266* Returning:: Returning from a function
10267* Calling:: Calling your program's functions
10268* Patching:: Patching your program
10269@end menu
10270
6d2ebf8b 10271@node Assignment
c906108c
SS
10272@section Assignment to variables
10273
10274@cindex assignment
10275@cindex setting variables
10276To alter the value of a variable, evaluate an assignment expression.
10277@xref{Expressions, ,Expressions}. For example,
10278
474c8240 10279@smallexample
c906108c 10280print x=4
474c8240 10281@end smallexample
c906108c
SS
10282
10283@noindent
10284stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10285value of the assignment expression (which is 4).
c906108c
SS
10286@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10287information on operators in supported languages.
c906108c
SS
10288
10289@kindex set variable
10290@cindex variables, setting
10291If you are not interested in seeing the value of the assignment, use the
10292@code{set} command instead of the @code{print} command. @code{set} is
10293really the same as @code{print} except that the expression's value is
10294not printed and is not put in the value history (@pxref{Value History,
10295,Value history}). The expression is evaluated only for its effects.
10296
c906108c
SS
10297If the beginning of the argument string of the @code{set} command
10298appears identical to a @code{set} subcommand, use the @code{set
10299variable} command instead of just @code{set}. This command is identical
10300to @code{set} except for its lack of subcommands. For example, if your
10301program has a variable @code{width}, you get an error if you try to set
10302a new value with just @samp{set width=13}, because @value{GDBN} has the
10303command @code{set width}:
10304
474c8240 10305@smallexample
c906108c
SS
10306(@value{GDBP}) whatis width
10307type = double
10308(@value{GDBP}) p width
10309$4 = 13
10310(@value{GDBP}) set width=47
10311Invalid syntax in expression.
474c8240 10312@end smallexample
c906108c
SS
10313
10314@noindent
10315The invalid expression, of course, is @samp{=47}. In
10316order to actually set the program's variable @code{width}, use
10317
474c8240 10318@smallexample
c906108c 10319(@value{GDBP}) set var width=47
474c8240 10320@end smallexample
53a5351d 10321
c906108c
SS
10322Because the @code{set} command has many subcommands that can conflict
10323with the names of program variables, it is a good idea to use the
10324@code{set variable} command instead of just @code{set}. For example, if
10325your program has a variable @code{g}, you run into problems if you try
10326to set a new value with just @samp{set g=4}, because @value{GDBN} has
10327the command @code{set gnutarget}, abbreviated @code{set g}:
10328
474c8240 10329@smallexample
c906108c
SS
10330@group
10331(@value{GDBP}) whatis g
10332type = double
10333(@value{GDBP}) p g
10334$1 = 1
10335(@value{GDBP}) set g=4
2df3850c 10336(@value{GDBP}) p g
c906108c
SS
10337$2 = 1
10338(@value{GDBP}) r
10339The program being debugged has been started already.
10340Start it from the beginning? (y or n) y
10341Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10342"/home/smith/cc_progs/a.out": can't open to read symbols:
10343 Invalid bfd target.
c906108c
SS
10344(@value{GDBP}) show g
10345The current BFD target is "=4".
10346@end group
474c8240 10347@end smallexample
c906108c
SS
10348
10349@noindent
10350The program variable @code{g} did not change, and you silently set the
10351@code{gnutarget} to an invalid value. In order to set the variable
10352@code{g}, use
10353
474c8240 10354@smallexample
c906108c 10355(@value{GDBP}) set var g=4
474c8240 10356@end smallexample
c906108c
SS
10357
10358@value{GDBN} allows more implicit conversions in assignments than C; you can
10359freely store an integer value into a pointer variable or vice versa,
10360and you can convert any structure to any other structure that is the
10361same length or shorter.
10362@comment FIXME: how do structs align/pad in these conversions?
10363@comment /doc@cygnus.com 18dec1990
10364
10365To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10366construct to generate a value of specified type at a specified address
10367(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10368to memory location @code{0x83040} as an integer (which implies a certain size
10369and representation in memory), and
10370
474c8240 10371@smallexample
c906108c 10372set @{int@}0x83040 = 4
474c8240 10373@end smallexample
c906108c
SS
10374
10375@noindent
10376stores the value 4 into that memory location.
10377
6d2ebf8b 10378@node Jumping
c906108c
SS
10379@section Continuing at a different address
10380
10381Ordinarily, when you continue your program, you do so at the place where
10382it stopped, with the @code{continue} command. You can instead continue at
10383an address of your own choosing, with the following commands:
10384
10385@table @code
10386@kindex jump
10387@item jump @var{linespec}
10388Resume execution at line @var{linespec}. Execution stops again
10389immediately if there is a breakpoint there. @xref{List, ,Printing
10390source lines}, for a description of the different forms of
10391@var{linespec}. It is common practice to use the @code{tbreak} command
10392in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10393breakpoints}.
10394
10395The @code{jump} command does not change the current stack frame, or
10396the stack pointer, or the contents of any memory location or any
10397register other than the program counter. If line @var{linespec} is in
10398a different function from the one currently executing, the results may
10399be bizarre if the two functions expect different patterns of arguments or
10400of local variables. For this reason, the @code{jump} command requests
10401confirmation if the specified line is not in the function currently
10402executing. However, even bizarre results are predictable if you are
10403well acquainted with the machine-language code of your program.
10404
10405@item jump *@var{address}
10406Resume execution at the instruction at address @var{address}.
10407@end table
10408
c906108c 10409@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10410On many systems, you can get much the same effect as the @code{jump}
10411command by storing a new value into the register @code{$pc}. The
10412difference is that this does not start your program running; it only
10413changes the address of where it @emph{will} run when you continue. For
10414example,
c906108c 10415
474c8240 10416@smallexample
c906108c 10417set $pc = 0x485
474c8240 10418@end smallexample
c906108c
SS
10419
10420@noindent
10421makes the next @code{continue} command or stepping command execute at
10422address @code{0x485}, rather than at the address where your program stopped.
10423@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10424
10425The most common occasion to use the @code{jump} command is to back
10426up---perhaps with more breakpoints set---over a portion of a program
10427that has already executed, in order to examine its execution in more
10428detail.
10429
c906108c 10430@c @group
6d2ebf8b 10431@node Signaling
c906108c 10432@section Giving your program a signal
9c16f35a 10433@cindex deliver a signal to a program
c906108c
SS
10434
10435@table @code
10436@kindex signal
10437@item signal @var{signal}
10438Resume execution where your program stopped, but immediately give it the
10439signal @var{signal}. @var{signal} can be the name or the number of a
10440signal. For example, on many systems @code{signal 2} and @code{signal
10441SIGINT} are both ways of sending an interrupt signal.
10442
10443Alternatively, if @var{signal} is zero, continue execution without
10444giving a signal. This is useful when your program stopped on account of
10445a signal and would ordinary see the signal when resumed with the
10446@code{continue} command; @samp{signal 0} causes it to resume without a
10447signal.
10448
10449@code{signal} does not repeat when you press @key{RET} a second time
10450after executing the command.
10451@end table
10452@c @end group
10453
10454Invoking the @code{signal} command is not the same as invoking the
10455@code{kill} utility from the shell. Sending a signal with @code{kill}
10456causes @value{GDBN} to decide what to do with the signal depending on
10457the signal handling tables (@pxref{Signals}). The @code{signal} command
10458passes the signal directly to your program.
10459
c906108c 10460
6d2ebf8b 10461@node Returning
c906108c
SS
10462@section Returning from a function
10463
10464@table @code
10465@cindex returning from a function
10466@kindex return
10467@item return
10468@itemx return @var{expression}
10469You can cancel execution of a function call with the @code{return}
10470command. If you give an
10471@var{expression} argument, its value is used as the function's return
10472value.
10473@end table
10474
10475When you use @code{return}, @value{GDBN} discards the selected stack frame
10476(and all frames within it). You can think of this as making the
10477discarded frame return prematurely. If you wish to specify a value to
10478be returned, give that value as the argument to @code{return}.
10479
10480This pops the selected stack frame (@pxref{Selection, ,Selecting a
10481frame}), and any other frames inside of it, leaving its caller as the
10482innermost remaining frame. That frame becomes selected. The
10483specified value is stored in the registers used for returning values
10484of functions.
10485
10486The @code{return} command does not resume execution; it leaves the
10487program stopped in the state that would exist if the function had just
10488returned. In contrast, the @code{finish} command (@pxref{Continuing
10489and Stepping, ,Continuing and stepping}) resumes execution until the
10490selected stack frame returns naturally.
10491
6d2ebf8b 10492@node Calling
c906108c
SS
10493@section Calling program functions
10494
f8568604 10495@table @code
c906108c 10496@cindex calling functions
f8568604
EZ
10497@cindex inferior functions, calling
10498@item print @var{expr}
9c16f35a 10499Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10500@var{expr} may include calls to functions in the program being
10501debugged.
10502
c906108c 10503@kindex call
c906108c
SS
10504@item call @var{expr}
10505Evaluate the expression @var{expr} without displaying @code{void}
10506returned values.
c906108c
SS
10507
10508You can use this variant of the @code{print} command if you want to
f8568604
EZ
10509execute a function from your program that does not return anything
10510(a.k.a.@: @dfn{a void function}), but without cluttering the output
10511with @code{void} returned values that @value{GDBN} will otherwise
10512print. If the result is not void, it is printed and saved in the
10513value history.
10514@end table
10515
9c16f35a
EZ
10516It is possible for the function you call via the @code{print} or
10517@code{call} command to generate a signal (e.g., if there's a bug in
10518the function, or if you passed it incorrect arguments). What happens
10519in that case is controlled by the @code{set unwindonsignal} command.
10520
10521@table @code
10522@item set unwindonsignal
10523@kindex set unwindonsignal
10524@cindex unwind stack in called functions
10525@cindex call dummy stack unwinding
10526Set unwinding of the stack if a signal is received while in a function
10527that @value{GDBN} called in the program being debugged. If set to on,
10528@value{GDBN} unwinds the stack it created for the call and restores
10529the context to what it was before the call. If set to off (the
10530default), @value{GDBN} stops in the frame where the signal was
10531received.
10532
10533@item show unwindonsignal
10534@kindex show unwindonsignal
10535Show the current setting of stack unwinding in the functions called by
10536@value{GDBN}.
10537@end table
10538
f8568604
EZ
10539@cindex weak alias functions
10540Sometimes, a function you wish to call is actually a @dfn{weak alias}
10541for another function. In such case, @value{GDBN} might not pick up
10542the type information, including the types of the function arguments,
10543which causes @value{GDBN} to call the inferior function incorrectly.
10544As a result, the called function will function erroneously and may
10545even crash. A solution to that is to use the name of the aliased
10546function instead.
c906108c 10547
6d2ebf8b 10548@node Patching
c906108c 10549@section Patching programs
7a292a7a 10550
c906108c
SS
10551@cindex patching binaries
10552@cindex writing into executables
c906108c 10553@cindex writing into corefiles
c906108c 10554
7a292a7a
SS
10555By default, @value{GDBN} opens the file containing your program's
10556executable code (or the corefile) read-only. This prevents accidental
10557alterations to machine code; but it also prevents you from intentionally
10558patching your program's binary.
c906108c
SS
10559
10560If you'd like to be able to patch the binary, you can specify that
10561explicitly with the @code{set write} command. For example, you might
10562want to turn on internal debugging flags, or even to make emergency
10563repairs.
10564
10565@table @code
10566@kindex set write
10567@item set write on
10568@itemx set write off
7a292a7a
SS
10569If you specify @samp{set write on}, @value{GDBN} opens executable and
10570core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10571off} (the default), @value{GDBN} opens them read-only.
10572
10573If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10574@code{exec-file} or @code{core-file} command) after changing @code{set
10575write}, for your new setting to take effect.
c906108c
SS
10576
10577@item show write
10578@kindex show write
7a292a7a
SS
10579Display whether executable files and core files are opened for writing
10580as well as reading.
c906108c
SS
10581@end table
10582
6d2ebf8b 10583@node GDB Files
c906108c
SS
10584@chapter @value{GDBN} Files
10585
7a292a7a
SS
10586@value{GDBN} needs to know the file name of the program to be debugged,
10587both in order to read its symbol table and in order to start your
10588program. To debug a core dump of a previous run, you must also tell
10589@value{GDBN} the name of the core dump file.
c906108c
SS
10590
10591@menu
10592* Files:: Commands to specify files
5b5d99cf 10593* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10594* Symbol Errors:: Errors reading symbol files
10595@end menu
10596
6d2ebf8b 10597@node Files
c906108c 10598@section Commands to specify files
c906108c 10599
7a292a7a 10600@cindex symbol table
c906108c 10601@cindex core dump file
7a292a7a
SS
10602
10603You may want to specify executable and core dump file names. The usual
10604way to do this is at start-up time, using the arguments to
10605@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10606Out of @value{GDBN}}).
c906108c
SS
10607
10608Occasionally it is necessary to change to a different file during a
10609@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
10610a file you want to use. In these situations the @value{GDBN} commands
10611to specify new files are useful.
10612
10613@table @code
10614@cindex executable file
10615@kindex file
10616@item file @var{filename}
10617Use @var{filename} as the program to be debugged. It is read for its
10618symbols and for the contents of pure memory. It is also the program
10619executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10620directory and the file is not found in the @value{GDBN} working directory,
10621@value{GDBN} uses the environment variable @code{PATH} as a list of
10622directories to search, just as the shell does when looking for a program
10623to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10624and your program, using the @code{path} command.
10625
6d2ebf8b 10626On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10627@file{@var{filename}.syms} may hold symbol table information for
10628@var{filename}. If so, @value{GDBN} maps in the symbol table from
10629@file{@var{filename}.syms}, starting up more quickly. See the
10630descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10631(available on the command line, see @ref{File Options, , -readnow},
10632and with the commands @code{file}, @code{symbol-file}, or
10633@code{add-symbol-file}, described below), for more information.
c906108c
SS
10634
10635@item file
10636@code{file} with no argument makes @value{GDBN} discard any information it
10637has on both executable file and the symbol table.
10638
10639@kindex exec-file
10640@item exec-file @r{[} @var{filename} @r{]}
10641Specify that the program to be run (but not the symbol table) is found
10642in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10643if necessary to locate your program. Omitting @var{filename} means to
10644discard information on the executable file.
10645
10646@kindex symbol-file
10647@item symbol-file @r{[} @var{filename} @r{]}
10648Read symbol table information from file @var{filename}. @code{PATH} is
10649searched when necessary. Use the @code{file} command to get both symbol
10650table and program to run from the same file.
10651
10652@code{symbol-file} with no argument clears out @value{GDBN} information on your
10653program's symbol table.
10654
5d161b24 10655The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10656of its convenience variables, the value history, and all breakpoints and
10657auto-display expressions. This is because they may contain pointers to
10658the internal data recording symbols and data types, which are part of
10659the old symbol table data being discarded inside @value{GDBN}.
10660
10661@code{symbol-file} does not repeat if you press @key{RET} again after
10662executing it once.
10663
10664When @value{GDBN} is configured for a particular environment, it
10665understands debugging information in whatever format is the standard
10666generated for that environment; you may use either a @sc{gnu} compiler, or
10667other compilers that adhere to the local conventions.
c906108c
SS
10668Best results are usually obtained from @sc{gnu} compilers; for example,
10669using @code{@value{GCC}} you can generate debugging information for
10670optimized code.
c906108c
SS
10671
10672For most kinds of object files, with the exception of old SVR3 systems
10673using COFF, the @code{symbol-file} command does not normally read the
10674symbol table in full right away. Instead, it scans the symbol table
10675quickly to find which source files and which symbols are present. The
10676details are read later, one source file at a time, as they are needed.
10677
10678The purpose of this two-stage reading strategy is to make @value{GDBN}
10679start up faster. For the most part, it is invisible except for
10680occasional pauses while the symbol table details for a particular source
10681file are being read. (The @code{set verbose} command can turn these
10682pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10683warnings and messages}.)
10684
c906108c
SS
10685We have not implemented the two-stage strategy for COFF yet. When the
10686symbol table is stored in COFF format, @code{symbol-file} reads the
10687symbol table data in full right away. Note that ``stabs-in-COFF''
10688still does the two-stage strategy, since the debug info is actually
10689in stabs format.
10690
10691@kindex readnow
10692@cindex reading symbols immediately
10693@cindex symbols, reading immediately
10694@kindex mapped
10695@cindex memory-mapped symbol file
10696@cindex saving symbol table
10697@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10698@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10699You can override the @value{GDBN} two-stage strategy for reading symbol
10700tables by using the @samp{-readnow} option with any of the commands that
10701load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10702entire symbol table available.
c906108c 10703
c906108c
SS
10704If memory-mapped files are available on your system through the
10705@code{mmap} system call, you can use another option, @samp{-mapped}, to
10706cause @value{GDBN} to write the symbols for your program into a reusable
10707file. Future @value{GDBN} debugging sessions map in symbol information
10708from this auxiliary symbol file (if the program has not changed), rather
10709than spending time reading the symbol table from the executable
10710program. Using the @samp{-mapped} option has the same effect as
10711starting @value{GDBN} with the @samp{-mapped} command-line option.
10712
10713You can use both options together, to make sure the auxiliary symbol
10714file has all the symbol information for your program.
10715
10716The auxiliary symbol file for a program called @var{myprog} is called
10717@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10718than the corresponding executable), @value{GDBN} always attempts to use
10719it when you debug @var{myprog}; no special options or commands are
10720needed.
10721
10722The @file{.syms} file is specific to the host machine where you run
10723@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10724symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10725
10726@c FIXME: for now no mention of directories, since this seems to be in
10727@c flux. 13mar1992 status is that in theory GDB would look either in
10728@c current dir or in same dir as myprog; but issues like competing
10729@c GDB's, or clutter in system dirs, mean that in practice right now
10730@c only current dir is used. FFish says maybe a special GDB hierarchy
10731@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10732@c files.
10733
c906108c 10734@kindex core-file
09d4efe1 10735@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10736@itemx core
c906108c
SS
10737Specify the whereabouts of a core dump file to be used as the ``contents
10738of memory''. Traditionally, core files contain only some parts of the
10739address space of the process that generated them; @value{GDBN} can access the
10740executable file itself for other parts.
10741
10742@code{core-file} with no argument specifies that no core file is
10743to be used.
10744
10745Note that the core file is ignored when your program is actually running
7a292a7a
SS
10746under @value{GDBN}. So, if you have been running your program and you
10747wish to debug a core file instead, you must kill the subprocess in which
10748the program is running. To do this, use the @code{kill} command
c906108c 10749(@pxref{Kill Process, ,Killing the child process}).
c906108c 10750
c906108c
SS
10751@kindex add-symbol-file
10752@cindex dynamic linking
10753@item add-symbol-file @var{filename} @var{address}
10754@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10755@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10756The @code{add-symbol-file} command reads additional symbol table
10757information from the file @var{filename}. You would use this command
10758when @var{filename} has been dynamically loaded (by some other means)
10759into the program that is running. @var{address} should be the memory
10760address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10761this out for itself. You can additionally specify an arbitrary number
10762of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10763section name and base address for that section. You can specify any
10764@var{address} as an expression.
c906108c
SS
10765
10766The symbol table of the file @var{filename} is added to the symbol table
10767originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10768@code{add-symbol-file} command any number of times; the new symbol data
10769thus read keeps adding to the old. To discard all old symbol data
10770instead, use the @code{symbol-file} command without any arguments.
c906108c 10771
17d9d558
JB
10772@cindex relocatable object files, reading symbols from
10773@cindex object files, relocatable, reading symbols from
10774@cindex reading symbols from relocatable object files
10775@cindex symbols, reading from relocatable object files
10776@cindex @file{.o} files, reading symbols from
10777Although @var{filename} is typically a shared library file, an
10778executable file, or some other object file which has been fully
10779relocated for loading into a process, you can also load symbolic
10780information from relocatable @file{.o} files, as long as:
10781
10782@itemize @bullet
10783@item
10784the file's symbolic information refers only to linker symbols defined in
10785that file, not to symbols defined by other object files,
10786@item
10787every section the file's symbolic information refers to has actually
10788been loaded into the inferior, as it appears in the file, and
10789@item
10790you can determine the address at which every section was loaded, and
10791provide these to the @code{add-symbol-file} command.
10792@end itemize
10793
10794@noindent
10795Some embedded operating systems, like Sun Chorus and VxWorks, can load
10796relocatable files into an already running program; such systems
10797typically make the requirements above easy to meet. However, it's
10798important to recognize that many native systems use complex link
49efadf5 10799procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10800assembly, for example) that make the requirements difficult to meet. In
10801general, one cannot assume that using @code{add-symbol-file} to read a
10802relocatable object file's symbolic information will have the same effect
10803as linking the relocatable object file into the program in the normal
10804way.
10805
c906108c
SS
10806@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10807
10808You can use the @samp{-mapped} and @samp{-readnow} options just as with
10809the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10810table information for @var{filename}.
10811
c45da7e6
EZ
10812@kindex add-symbol-file-from-memory
10813@cindex @code{syscall DSO}
10814@cindex load symbols from memory
10815@item add-symbol-file-from-memory @var{address}
10816Load symbols from the given @var{address} in a dynamically loaded
10817object file whose image is mapped directly into the inferior's memory.
10818For example, the Linux kernel maps a @code{syscall DSO} into each
10819process's address space; this DSO provides kernel-specific code for
10820some system calls. The argument can be any expression whose
10821evaluation yields the address of the file's shared object file header.
10822For this command to work, you must have used @code{symbol-file} or
10823@code{exec-file} commands in advance.
10824
09d4efe1
EZ
10825@kindex add-shared-symbol-files
10826@kindex assf
10827@item add-shared-symbol-files @var{library-file}
10828@itemx assf @var{library-file}
10829The @code{add-shared-symbol-files} command can currently be used only
10830in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10831alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10832@value{GDBN} automatically looks for shared libraries, however if
10833@value{GDBN} does not find yours, you can invoke
10834@code{add-shared-symbol-files}. It takes one argument: the shared
10835library's file name. @code{assf} is a shorthand alias for
10836@code{add-shared-symbol-files}.
c906108c 10837
c906108c 10838@kindex section
09d4efe1
EZ
10839@item section @var{section} @var{addr}
10840The @code{section} command changes the base address of the named
10841@var{section} of the exec file to @var{addr}. This can be used if the
10842exec file does not contain section addresses, (such as in the
10843@code{a.out} format), or when the addresses specified in the file
10844itself are wrong. Each section must be changed separately. The
10845@code{info files} command, described below, lists all the sections and
10846their addresses.
c906108c
SS
10847
10848@kindex info files
10849@kindex info target
10850@item info files
10851@itemx info target
7a292a7a
SS
10852@code{info files} and @code{info target} are synonymous; both print the
10853current target (@pxref{Targets, ,Specifying a Debugging Target}),
10854including the names of the executable and core dump files currently in
10855use by @value{GDBN}, and the files from which symbols were loaded. The
10856command @code{help target} lists all possible targets rather than
10857current ones.
10858
fe95c787
MS
10859@kindex maint info sections
10860@item maint info sections
10861Another command that can give you extra information about program sections
10862is @code{maint info sections}. In addition to the section information
10863displayed by @code{info files}, this command displays the flags and file
10864offset of each section in the executable and core dump files. In addition,
10865@code{maint info sections} provides the following command options (which
10866may be arbitrarily combined):
10867
10868@table @code
10869@item ALLOBJ
10870Display sections for all loaded object files, including shared libraries.
10871@item @var{sections}
6600abed 10872Display info only for named @var{sections}.
fe95c787
MS
10873@item @var{section-flags}
10874Display info only for sections for which @var{section-flags} are true.
10875The section flags that @value{GDBN} currently knows about are:
10876@table @code
10877@item ALLOC
10878Section will have space allocated in the process when loaded.
10879Set for all sections except those containing debug information.
10880@item LOAD
10881Section will be loaded from the file into the child process memory.
10882Set for pre-initialized code and data, clear for @code{.bss} sections.
10883@item RELOC
10884Section needs to be relocated before loading.
10885@item READONLY
10886Section cannot be modified by the child process.
10887@item CODE
10888Section contains executable code only.
6600abed 10889@item DATA
fe95c787
MS
10890Section contains data only (no executable code).
10891@item ROM
10892Section will reside in ROM.
10893@item CONSTRUCTOR
10894Section contains data for constructor/destructor lists.
10895@item HAS_CONTENTS
10896Section is not empty.
10897@item NEVER_LOAD
10898An instruction to the linker to not output the section.
10899@item COFF_SHARED_LIBRARY
10900A notification to the linker that the section contains
10901COFF shared library information.
10902@item IS_COMMON
10903Section contains common symbols.
10904@end table
10905@end table
6763aef9 10906@kindex set trust-readonly-sections
9c16f35a 10907@cindex read-only sections
6763aef9
MS
10908@item set trust-readonly-sections on
10909Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10910really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10911In that case, @value{GDBN} can fetch values from these sections
10912out of the object file, rather than from the target program.
10913For some targets (notably embedded ones), this can be a significant
10914enhancement to debugging performance.
10915
10916The default is off.
10917
10918@item set trust-readonly-sections off
15110bc3 10919Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10920the contents of the section might change while the program is running,
10921and must therefore be fetched from the target when needed.
9c16f35a
EZ
10922
10923@item show trust-readonly-sections
10924Show the current setting of trusting readonly sections.
c906108c
SS
10925@end table
10926
10927All file-specifying commands allow both absolute and relative file names
10928as arguments. @value{GDBN} always converts the file name to an absolute file
10929name and remembers it that way.
10930
c906108c 10931@cindex shared libraries
9c16f35a
EZ
10932@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10933and IBM RS/6000 AIX shared libraries.
53a5351d 10934
c906108c
SS
10935@value{GDBN} automatically loads symbol definitions from shared libraries
10936when you use the @code{run} command, or when you examine a core file.
10937(Before you issue the @code{run} command, @value{GDBN} does not understand
10938references to a function in a shared library, however---unless you are
10939debugging a core file).
53a5351d
JM
10940
10941On HP-UX, if the program loads a library explicitly, @value{GDBN}
10942automatically loads the symbols at the time of the @code{shl_load} call.
10943
c906108c
SS
10944@c FIXME: some @value{GDBN} release may permit some refs to undef
10945@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10946@c FIXME...lib; check this from time to time when updating manual
10947
b7209cb4
FF
10948There are times, however, when you may wish to not automatically load
10949symbol definitions from shared libraries, such as when they are
10950particularly large or there are many of them.
10951
10952To control the automatic loading of shared library symbols, use the
10953commands:
10954
10955@table @code
10956@kindex set auto-solib-add
10957@item set auto-solib-add @var{mode}
10958If @var{mode} is @code{on}, symbols from all shared object libraries
10959will be loaded automatically when the inferior begins execution, you
10960attach to an independently started inferior, or when the dynamic linker
10961informs @value{GDBN} that a new library has been loaded. If @var{mode}
10962is @code{off}, symbols must be loaded manually, using the
10963@code{sharedlibrary} command. The default value is @code{on}.
10964
dcaf7c2c
EZ
10965@cindex memory used for symbol tables
10966If your program uses lots of shared libraries with debug info that
10967takes large amounts of memory, you can decrease the @value{GDBN}
10968memory footprint by preventing it from automatically loading the
10969symbols from shared libraries. To that end, type @kbd{set
10970auto-solib-add off} before running the inferior, then load each
10971library whose debug symbols you do need with @kbd{sharedlibrary
10972@var{regexp}}, where @var{regexp} is a regular expresion that matches
10973the libraries whose symbols you want to be loaded.
10974
b7209cb4
FF
10975@kindex show auto-solib-add
10976@item show auto-solib-add
10977Display the current autoloading mode.
10978@end table
10979
c45da7e6 10980@cindex load shared library
b7209cb4
FF
10981To explicitly load shared library symbols, use the @code{sharedlibrary}
10982command:
10983
c906108c
SS
10984@table @code
10985@kindex info sharedlibrary
10986@kindex info share
10987@item info share
10988@itemx info sharedlibrary
10989Print the names of the shared libraries which are currently loaded.
10990
10991@kindex sharedlibrary
10992@kindex share
10993@item sharedlibrary @var{regex}
10994@itemx share @var{regex}
c906108c
SS
10995Load shared object library symbols for files matching a
10996Unix regular expression.
10997As with files loaded automatically, it only loads shared libraries
10998required by your program for a core file or after typing @code{run}. If
10999@var{regex} is omitted all shared libraries required by your program are
11000loaded.
c45da7e6
EZ
11001
11002@item nosharedlibrary
11003@kindex nosharedlibrary
11004@cindex unload symbols from shared libraries
11005Unload all shared object library symbols. This discards all symbols
11006that have been loaded from all shared libraries. Symbols from shared
11007libraries that were loaded by explicit user requests are not
11008discarded.
c906108c
SS
11009@end table
11010
721c2651
EZ
11011Sometimes you may wish that @value{GDBN} stops and gives you control
11012when any of shared library events happen. Use the @code{set
11013stop-on-solib-events} command for this:
11014
11015@table @code
11016@item set stop-on-solib-events
11017@kindex set stop-on-solib-events
11018This command controls whether @value{GDBN} should give you control
11019when the dynamic linker notifies it about some shared library event.
11020The most common event of interest is loading or unloading of a new
11021shared library.
11022
11023@item show stop-on-solib-events
11024@kindex show stop-on-solib-events
11025Show whether @value{GDBN} stops and gives you control when shared
11026library events happen.
11027@end table
11028
f5ebfba0
DJ
11029Shared libraries are also supported in many cross or remote debugging
11030configurations. A copy of the target's libraries need to be present on the
11031host system; they need to be the same as the target libraries, although the
11032copies on the target can be stripped as long as the copies on the host are
11033not.
11034
11035You need to tell @value{GDBN} where the target libraries are, so that it can
11036load the correct copies---otherwise, it may try to load the host's libraries.
11037@value{GDBN} has two variables to specify the search directories for target
11038libraries.
11039
11040@table @code
11041@kindex set solib-absolute-prefix
11042@item set solib-absolute-prefix @var{path}
11043If this variable is set, @var{path} will be used as a prefix for any
11044absolute shared library paths; many runtime loaders store the absolute
11045paths to the shared library in the target program's memory. If you use
11046@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11047out in the same way that they are on the target, with e.g.@: a
11048@file{/usr/lib} hierarchy under @var{path}.
11049
11050You can set the default value of @samp{solib-absolute-prefix} by using the
11051configure-time @samp{--with-sysroot} option.
11052
11053@kindex show solib-absolute-prefix
11054@item show solib-absolute-prefix
11055Display the current shared library prefix.
11056
11057@kindex set solib-search-path
11058@item set solib-search-path @var{path}
11059If this variable is set, @var{path} is a colon-separated list of directories
11060to search for shared libraries. @samp{solib-search-path} is used after
11061@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11062the library is relative instead of absolute. If you want to use
11063@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11064set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11065@value{GDBN} from finding your host's libraries.
11066
11067@kindex show solib-search-path
11068@item show solib-search-path
11069Display the current shared library search path.
11070@end table
11071
5b5d99cf
JB
11072
11073@node Separate Debug Files
11074@section Debugging Information in Separate Files
11075@cindex separate debugging information files
11076@cindex debugging information in separate files
11077@cindex @file{.debug} subdirectories
11078@cindex debugging information directory, global
11079@cindex global debugging information directory
11080
11081@value{GDBN} allows you to put a program's debugging information in a
11082file separate from the executable itself, in a way that allows
11083@value{GDBN} to find and load the debugging information automatically.
11084Since debugging information can be very large --- sometimes larger
11085than the executable code itself --- some systems distribute debugging
11086information for their executables in separate files, which users can
11087install only when they need to debug a problem.
11088
11089If an executable's debugging information has been extracted to a
11090separate file, the executable should contain a @dfn{debug link} giving
11091the name of the debugging information file (with no directory
11092components), and a checksum of its contents. (The exact form of a
11093debug link is described below.) If the full name of the directory
11094containing the executable is @var{execdir}, and the executable has a
11095debug link that specifies the name @var{debugfile}, then @value{GDBN}
11096will automatically search for the debugging information file in three
11097places:
11098
11099@itemize @bullet
11100@item
11101the directory containing the executable file (that is, it will look
11102for a file named @file{@var{execdir}/@var{debugfile}},
11103@item
11104a subdirectory of that directory named @file{.debug} (that is, the
11105file @file{@var{execdir}/.debug/@var{debugfile}}, and
11106@item
11107a subdirectory of the global debug file directory that includes the
11108executable's full path, and the name from the link (that is, the file
11109@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11110@var{globaldebugdir} is the global debug file directory, and
11111@var{execdir} has been turned into a relative path).
11112@end itemize
11113@noindent
11114@value{GDBN} checks under each of these names for a debugging
11115information file whose checksum matches that given in the link, and
11116reads the debugging information from the first one it finds.
11117
11118So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11119which has a link containing the name @file{ls.debug}, and the global
11120debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11121for debug information in @file{/usr/bin/ls.debug},
11122@file{/usr/bin/.debug/ls.debug}, and
11123@file{/usr/lib/debug/usr/bin/ls.debug}.
11124
11125You can set the global debugging info directory's name, and view the
11126name @value{GDBN} is currently using.
11127
11128@table @code
11129
11130@kindex set debug-file-directory
11131@item set debug-file-directory @var{directory}
11132Set the directory which @value{GDBN} searches for separate debugging
11133information files to @var{directory}.
11134
11135@kindex show debug-file-directory
11136@item show debug-file-directory
11137Show the directory @value{GDBN} searches for separate debugging
11138information files.
11139
11140@end table
11141
11142@cindex @code{.gnu_debuglink} sections
11143@cindex debug links
11144A debug link is a special section of the executable file named
11145@code{.gnu_debuglink}. The section must contain:
11146
11147@itemize
11148@item
11149A filename, with any leading directory components removed, followed by
11150a zero byte,
11151@item
11152zero to three bytes of padding, as needed to reach the next four-byte
11153boundary within the section, and
11154@item
11155a four-byte CRC checksum, stored in the same endianness used for the
11156executable file itself. The checksum is computed on the debugging
11157information file's full contents by the function given below, passing
11158zero as the @var{crc} argument.
11159@end itemize
11160
11161Any executable file format can carry a debug link, as long as it can
11162contain a section named @code{.gnu_debuglink} with the contents
11163described above.
11164
11165The debugging information file itself should be an ordinary
11166executable, containing a full set of linker symbols, sections, and
11167debugging information. The sections of the debugging information file
11168should have the same names, addresses and sizes as the original file,
11169but they need not contain any data --- much like a @code{.bss} section
11170in an ordinary executable.
11171
11172As of December 2002, there is no standard GNU utility to produce
11173separated executable / debugging information file pairs. Ulrich
11174Drepper's @file{elfutils} package, starting with version 0.53,
11175contains a version of the @code{strip} command such that the command
11176@kbd{strip foo -f foo.debug} removes the debugging information from
11177the executable file @file{foo}, places it in the file
11178@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11179
11180Since there are many different ways to compute CRC's (different
11181polynomials, reversals, byte ordering, etc.), the simplest way to
11182describe the CRC used in @code{.gnu_debuglink} sections is to give the
11183complete code for a function that computes it:
11184
4644b6e3 11185@kindex gnu_debuglink_crc32
5b5d99cf
JB
11186@smallexample
11187unsigned long
11188gnu_debuglink_crc32 (unsigned long crc,
11189 unsigned char *buf, size_t len)
11190@{
11191 static const unsigned long crc32_table[256] =
11192 @{
11193 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11194 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11195 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11196 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11197 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11198 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11199 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11200 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11201 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11202 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11203 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11204 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11205 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11206 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11207 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11208 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11209 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11210 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11211 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11212 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11213 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11214 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11215 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11216 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11217 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11218 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11219 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11220 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11221 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11222 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11223 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11224 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11225 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11226 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11227 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11228 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11229 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11230 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11231 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11232 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11233 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11234 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11235 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11236 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11237 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11238 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11239 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11240 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11241 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11242 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11243 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11244 0x2d02ef8d
11245 @};
11246 unsigned char *end;
11247
11248 crc = ~crc & 0xffffffff;
11249 for (end = buf + len; buf < end; ++buf)
11250 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11251 return ~crc & 0xffffffff;
5b5d99cf
JB
11252@}
11253@end smallexample
11254
11255
6d2ebf8b 11256@node Symbol Errors
c906108c
SS
11257@section Errors reading symbol files
11258
11259While reading a symbol file, @value{GDBN} occasionally encounters problems,
11260such as symbol types it does not recognize, or known bugs in compiler
11261output. By default, @value{GDBN} does not notify you of such problems, since
11262they are relatively common and primarily of interest to people
11263debugging compilers. If you are interested in seeing information
11264about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11265only one message about each such type of problem, no matter how many
11266times the problem occurs; or you can ask @value{GDBN} to print more messages,
11267to see how many times the problems occur, with the @code{set
11268complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11269messages}).
11270
11271The messages currently printed, and their meanings, include:
11272
11273@table @code
11274@item inner block not inside outer block in @var{symbol}
11275
11276The symbol information shows where symbol scopes begin and end
11277(such as at the start of a function or a block of statements). This
11278error indicates that an inner scope block is not fully contained
11279in its outer scope blocks.
11280
11281@value{GDBN} circumvents the problem by treating the inner block as if it had
11282the same scope as the outer block. In the error message, @var{symbol}
11283may be shown as ``@code{(don't know)}'' if the outer block is not a
11284function.
11285
11286@item block at @var{address} out of order
11287
11288The symbol information for symbol scope blocks should occur in
11289order of increasing addresses. This error indicates that it does not
11290do so.
11291
11292@value{GDBN} does not circumvent this problem, and has trouble
11293locating symbols in the source file whose symbols it is reading. (You
11294can often determine what source file is affected by specifying
11295@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11296messages}.)
11297
11298@item bad block start address patched
11299
11300The symbol information for a symbol scope block has a start address
11301smaller than the address of the preceding source line. This is known
11302to occur in the SunOS 4.1.1 (and earlier) C compiler.
11303
11304@value{GDBN} circumvents the problem by treating the symbol scope block as
11305starting on the previous source line.
11306
11307@item bad string table offset in symbol @var{n}
11308
11309@cindex foo
11310Symbol number @var{n} contains a pointer into the string table which is
11311larger than the size of the string table.
11312
11313@value{GDBN} circumvents the problem by considering the symbol to have the
11314name @code{foo}, which may cause other problems if many symbols end up
11315with this name.
11316
11317@item unknown symbol type @code{0x@var{nn}}
11318
7a292a7a
SS
11319The symbol information contains new data types that @value{GDBN} does
11320not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11321uncomprehended information, in hexadecimal.
c906108c 11322
7a292a7a
SS
11323@value{GDBN} circumvents the error by ignoring this symbol information.
11324This usually allows you to debug your program, though certain symbols
c906108c 11325are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11326debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11327on @code{complain}, then go up to the function @code{read_dbx_symtab}
11328and examine @code{*bufp} to see the symbol.
c906108c
SS
11329
11330@item stub type has NULL name
c906108c 11331
7a292a7a 11332@value{GDBN} could not find the full definition for a struct or class.
c906108c 11333
7a292a7a 11334@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11335The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11336information that recent versions of the compiler should have output for
11337it.
c906108c
SS
11338
11339@item info mismatch between compiler and debugger
11340
11341@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11342
c906108c
SS
11343@end table
11344
6d2ebf8b 11345@node Targets
c906108c 11346@chapter Specifying a Debugging Target
7a292a7a 11347
c906108c 11348@cindex debugging target
c906108c 11349A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11350
11351Often, @value{GDBN} runs in the same host environment as your program;
11352in that case, the debugging target is specified as a side effect when
11353you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11354flexibility---for example, running @value{GDBN} on a physically separate
11355host, or controlling a standalone system over a serial port or a
53a5351d
JM
11356realtime system over a TCP/IP connection---you can use the @code{target}
11357command to specify one of the target types configured for @value{GDBN}
11358(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11359
a8f24a35
EZ
11360@cindex target architecture
11361It is possible to build @value{GDBN} for several different @dfn{target
11362architectures}. When @value{GDBN} is built like that, you can choose
11363one of the available architectures with the @kbd{set architecture}
11364command.
11365
11366@table @code
11367@kindex set architecture
11368@kindex show architecture
11369@item set architecture @var{arch}
11370This command sets the current target architecture to @var{arch}. The
11371value of @var{arch} can be @code{"auto"}, in addition to one of the
11372supported architectures.
11373
11374@item show architecture
11375Show the current target architecture.
9c16f35a
EZ
11376
11377@item set processor
11378@itemx processor
11379@kindex set processor
11380@kindex show processor
11381These are alias commands for, respectively, @code{set architecture}
11382and @code{show architecture}.
a8f24a35
EZ
11383@end table
11384
c906108c
SS
11385@menu
11386* Active Targets:: Active targets
11387* Target Commands:: Commands for managing targets
c906108c
SS
11388* Byte Order:: Choosing target byte order
11389* Remote:: Remote debugging
96baa820 11390* KOD:: Kernel Object Display
c906108c
SS
11391
11392@end menu
11393
6d2ebf8b 11394@node Active Targets
c906108c 11395@section Active targets
7a292a7a 11396
c906108c
SS
11397@cindex stacking targets
11398@cindex active targets
11399@cindex multiple targets
11400
c906108c 11401There are three classes of targets: processes, core files, and
7a292a7a
SS
11402executable files. @value{GDBN} can work concurrently on up to three
11403active targets, one in each class. This allows you to (for example)
11404start a process and inspect its activity without abandoning your work on
11405a core file.
c906108c
SS
11406
11407For example, if you execute @samp{gdb a.out}, then the executable file
11408@code{a.out} is the only active target. If you designate a core file as
11409well---presumably from a prior run that crashed and coredumped---then
11410@value{GDBN} has two active targets and uses them in tandem, looking
11411first in the corefile target, then in the executable file, to satisfy
11412requests for memory addresses. (Typically, these two classes of target
11413are complementary, since core files contain only a program's
11414read-write memory---variables and so on---plus machine status, while
11415executable files contain only the program text and initialized data.)
c906108c
SS
11416
11417When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11418target as well. When a process target is active, all @value{GDBN}
11419commands requesting memory addresses refer to that target; addresses in
11420an active core file or executable file target are obscured while the
11421process target is active.
c906108c 11422
7a292a7a
SS
11423Use the @code{core-file} and @code{exec-file} commands to select a new
11424core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11425files}). To specify as a target a process that is already running, use
7a292a7a
SS
11426the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11427process}).
c906108c 11428
6d2ebf8b 11429@node Target Commands
c906108c
SS
11430@section Commands for managing targets
11431
11432@table @code
11433@item target @var{type} @var{parameters}
7a292a7a
SS
11434Connects the @value{GDBN} host environment to a target machine or
11435process. A target is typically a protocol for talking to debugging
11436facilities. You use the argument @var{type} to specify the type or
11437protocol of the target machine.
c906108c
SS
11438
11439Further @var{parameters} are interpreted by the target protocol, but
11440typically include things like device names or host names to connect
11441with, process numbers, and baud rates.
c906108c
SS
11442
11443The @code{target} command does not repeat if you press @key{RET} again
11444after executing the command.
11445
11446@kindex help target
11447@item help target
11448Displays the names of all targets available. To display targets
11449currently selected, use either @code{info target} or @code{info files}
11450(@pxref{Files, ,Commands to specify files}).
11451
11452@item help target @var{name}
11453Describe a particular target, including any parameters necessary to
11454select it.
11455
11456@kindex set gnutarget
11457@item set gnutarget @var{args}
5d161b24 11458@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11459knows whether it is reading an @dfn{executable},
5d161b24
DB
11460a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11461with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11462with @code{gnutarget} the @code{target} refers to a program, not a machine.
11463
d4f3574e 11464@quotation
c906108c
SS
11465@emph{Warning:} To specify a file format with @code{set gnutarget},
11466you must know the actual BFD name.
d4f3574e 11467@end quotation
c906108c 11468
d4f3574e
SS
11469@noindent
11470@xref{Files, , Commands to specify files}.
c906108c 11471
5d161b24 11472@kindex show gnutarget
c906108c
SS
11473@item show gnutarget
11474Use the @code{show gnutarget} command to display what file format
11475@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11476@value{GDBN} will determine the file format for each file automatically,
11477and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11478@end table
11479
4644b6e3 11480@cindex common targets
c906108c
SS
11481Here are some common targets (available, or not, depending on the GDB
11482configuration):
c906108c
SS
11483
11484@table @code
4644b6e3 11485@kindex target
c906108c 11486@item target exec @var{program}
4644b6e3 11487@cindex executable file target
c906108c
SS
11488An executable file. @samp{target exec @var{program}} is the same as
11489@samp{exec-file @var{program}}.
11490
c906108c 11491@item target core @var{filename}
4644b6e3 11492@cindex core dump file target
c906108c
SS
11493A core dump file. @samp{target core @var{filename}} is the same as
11494@samp{core-file @var{filename}}.
c906108c 11495
c906108c 11496@item target remote @var{dev}
4644b6e3 11497@cindex remote target
c906108c
SS
11498Remote serial target in GDB-specific protocol. The argument @var{dev}
11499specifies what serial device to use for the connection (e.g.
11500@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11501supports the @code{load} command. This is only useful if you have
c906108c
SS
11502some other way of getting the stub to the target system, and you can put
11503it somewhere in memory where it won't get clobbered by the download.
11504
c906108c 11505@item target sim
4644b6e3 11506@cindex built-in simulator target
2df3850c 11507Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11508In general,
474c8240 11509@smallexample
104c1213
JM
11510 target sim
11511 load
11512 run
474c8240 11513@end smallexample
d4f3574e 11514@noindent
104c1213 11515works; however, you cannot assume that a specific memory map, device
d4f3574e 11516drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11517provide these. For info about any processor-specific simulator details,
11518see the appropriate section in @ref{Embedded Processors, ,Embedded
11519Processors}.
11520
c906108c
SS
11521@end table
11522
104c1213 11523Some configurations may include these targets as well:
c906108c
SS
11524
11525@table @code
11526
c906108c 11527@item target nrom @var{dev}
4644b6e3 11528@cindex NetROM ROM emulator target
c906108c
SS
11529NetROM ROM emulator. This target only supports downloading.
11530
c906108c
SS
11531@end table
11532
5d161b24 11533Different targets are available on different configurations of @value{GDBN};
c906108c 11534your configuration may have more or fewer targets.
c906108c 11535
721c2651
EZ
11536Many remote targets require you to download the executable's code once
11537you've successfully established a connection. You may wish to control
11538various aspects of this process, such as the size of the data chunks
11539used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11540
11541@table @code
11542@kindex set download-write-size
11543@item set download-write-size @var{size}
11544Set the write size used when downloading a program. Only used when
11545downloading a program onto a remote target. Specify zero or a
11546negative value to disable blocked writes. The actual size of each
11547transfer is also limited by the size of the target packet and the
11548memory cache.
11549
11550@kindex show download-write-size
11551@item show download-write-size
721c2651 11552@kindex show download-write-size
a8f24a35 11553Show the current value of the write size.
721c2651
EZ
11554
11555@item set hash
11556@kindex set hash@r{, for remote monitors}
11557@cindex hash mark while downloading
11558This command controls whether a hash mark @samp{#} is displayed while
11559downloading a file to the remote monitor. If on, a hash mark is
11560displayed after each S-record is successfully downloaded to the
11561monitor.
11562
11563@item show hash
11564@kindex show hash@r{, for remote monitors}
11565Show the current status of displaying the hash mark.
11566
11567@item set debug monitor
11568@kindex set debug monitor
11569@cindex display remote monitor communications
11570Enable or disable display of communications messages between
11571@value{GDBN} and the remote monitor.
11572
11573@item show debug monitor
11574@kindex show debug monitor
11575Show the current status of displaying communications between
11576@value{GDBN} and the remote monitor.
a8f24a35 11577@end table
c906108c
SS
11578
11579@table @code
11580
11581@kindex load @var{filename}
11582@item load @var{filename}
c906108c
SS
11583Depending on what remote debugging facilities are configured into
11584@value{GDBN}, the @code{load} command may be available. Where it exists, it
11585is meant to make @var{filename} (an executable) available for debugging
11586on the remote system---by downloading, or dynamic linking, for example.
11587@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11588the @code{add-symbol-file} command.
11589
11590If your @value{GDBN} does not have a @code{load} command, attempting to
11591execute it gets the error message ``@code{You can't do that when your
11592target is @dots{}}''
c906108c
SS
11593
11594The file is loaded at whatever address is specified in the executable.
11595For some object file formats, you can specify the load address when you
11596link the program; for other formats, like a.out, the object file format
11597specifies a fixed address.
11598@c FIXME! This would be a good place for an xref to the GNU linker doc.
11599
c906108c
SS
11600@code{load} does not repeat if you press @key{RET} again after using it.
11601@end table
11602
6d2ebf8b 11603@node Byte Order
c906108c 11604@section Choosing target byte order
7a292a7a 11605
c906108c
SS
11606@cindex choosing target byte order
11607@cindex target byte order
c906108c 11608
172c2a43 11609Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11610offer the ability to run either big-endian or little-endian byte
11611orders. Usually the executable or symbol will include a bit to
11612designate the endian-ness, and you will not need to worry about
11613which to use. However, you may still find it useful to adjust
d4f3574e 11614@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11615
11616@table @code
4644b6e3 11617@kindex set endian
c906108c
SS
11618@item set endian big
11619Instruct @value{GDBN} to assume the target is big-endian.
11620
c906108c
SS
11621@item set endian little
11622Instruct @value{GDBN} to assume the target is little-endian.
11623
c906108c
SS
11624@item set endian auto
11625Instruct @value{GDBN} to use the byte order associated with the
11626executable.
11627
11628@item show endian
11629Display @value{GDBN}'s current idea of the target byte order.
11630
11631@end table
11632
11633Note that these commands merely adjust interpretation of symbolic
11634data on the host, and that they have absolutely no effect on the
11635target system.
11636
6d2ebf8b 11637@node Remote
c906108c
SS
11638@section Remote debugging
11639@cindex remote debugging
11640
11641If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11642@value{GDBN} in the usual way, it is often useful to use remote debugging.
11643For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11644or on a small system which does not have a general purpose operating system
11645powerful enough to run a full-featured debugger.
11646
11647Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11648to make this work with particular debugging targets. In addition,
5d161b24 11649@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11650but not specific to any particular target system) which you can use if you
11651write the remote stubs---the code that runs on the remote system to
11652communicate with @value{GDBN}.
11653
11654Other remote targets may be available in your
11655configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11656
c45da7e6
EZ
11657Once you've connected to the remote target, @value{GDBN} allows you to
11658send arbitrary commands to the remote monitor:
11659
11660@table @code
11661@item remote @var{command}
11662@kindex remote@r{, a command}
11663@cindex send command to remote monitor
11664Send an arbitrary @var{command} string to the remote monitor.
11665@end table
11666
11667
6f05cf9f
AC
11668@node KOD
11669@section Kernel Object Display
6f05cf9f 11670@cindex kernel object display
6f05cf9f
AC
11671@cindex KOD
11672
11673Some targets support kernel object display. Using this facility,
11674@value{GDBN} communicates specially with the underlying operating system
11675and can display information about operating system-level objects such as
11676mutexes and other synchronization objects. Exactly which objects can be
11677displayed is determined on a per-OS basis.
11678
3bbe9696 11679@kindex set os
6f05cf9f
AC
11680Use the @code{set os} command to set the operating system. This tells
11681@value{GDBN} which kernel object display module to initialize:
11682
474c8240 11683@smallexample
6f05cf9f 11684(@value{GDBP}) set os cisco
474c8240 11685@end smallexample
6f05cf9f 11686
3bbe9696
EZ
11687@kindex show os
11688The associated command @code{show os} displays the operating system
11689set with the @code{set os} command; if no operating system has been
11690set, @code{show os} will display an empty string @samp{""}.
11691
6f05cf9f
AC
11692If @code{set os} succeeds, @value{GDBN} will display some information
11693about the operating system, and will create a new @code{info} command
11694which can be used to query the target. The @code{info} command is named
11695after the operating system:
c906108c 11696
3bbe9696 11697@kindex info cisco
474c8240 11698@smallexample
6f05cf9f
AC
11699(@value{GDBP}) info cisco
11700List of Cisco Kernel Objects
11701Object Description
11702any Any and all objects
474c8240 11703@end smallexample
6f05cf9f
AC
11704
11705Further subcommands can be used to query about particular objects known
11706by the kernel.
11707
3bbe9696
EZ
11708There is currently no way to determine whether a given operating
11709system is supported other than to try setting it with @kbd{set os
11710@var{name}}, where @var{name} is the name of the operating system you
11711want to try.
6f05cf9f
AC
11712
11713
11714@node Remote Debugging
11715@chapter Debugging remote programs
11716
6b2f586d 11717@menu
07f31aa6 11718* Connecting:: Connecting to a remote target
6b2f586d
AC
11719* Server:: Using the gdbserver program
11720* NetWare:: Using the gdbserve.nlm program
501eef12 11721* Remote configuration:: Remote configuration
6b2f586d 11722* remote stub:: Implementing a remote stub
6b2f586d
AC
11723@end menu
11724
07f31aa6
DJ
11725@node Connecting
11726@section Connecting to a remote target
11727
11728On the @value{GDBN} host machine, you will need an unstripped copy of
11729your program, since @value{GDBN} needs symobl and debugging information.
11730Start up @value{GDBN} as usual, using the name of the local copy of your
11731program as the first argument.
11732
11733@cindex serial line, @code{target remote}
11734If you're using a serial line, you may want to give @value{GDBN} the
11735@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11736(@pxref{Remote configuration, set remotebaud}) before the
11737@code{target} command.
07f31aa6
DJ
11738
11739After that, use @code{target remote} to establish communications with
11740the target machine. Its argument specifies how to communicate---either
11741via a devicename attached to a direct serial line, or a TCP or UDP port
11742(possibly to a terminal server which in turn has a serial line to the
11743target). For example, to use a serial line connected to the device
11744named @file{/dev/ttyb}:
11745
11746@smallexample
11747target remote /dev/ttyb
11748@end smallexample
11749
11750@cindex TCP port, @code{target remote}
11751To use a TCP connection, use an argument of the form
11752@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11753For example, to connect to port 2828 on a
11754terminal server named @code{manyfarms}:
11755
11756@smallexample
11757target remote manyfarms:2828
11758@end smallexample
11759
11760If your remote target is actually running on the same machine as
11761your debugger session (e.g.@: a simulator of your target running on
11762the same host), you can omit the hostname. For example, to connect
11763to port 1234 on your local machine:
11764
11765@smallexample
11766target remote :1234
11767@end smallexample
11768@noindent
11769
11770Note that the colon is still required here.
11771
11772@cindex UDP port, @code{target remote}
11773To use a UDP connection, use an argument of the form
11774@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11775on a terminal server named @code{manyfarms}:
11776
11777@smallexample
11778target remote udp:manyfarms:2828
11779@end smallexample
11780
11781When using a UDP connection for remote debugging, you should keep in mind
11782that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11783busy or unreliable networks, which will cause havoc with your debugging
11784session.
11785
11786Now you can use all the usual commands to examine and change data and to
11787step and continue the remote program.
11788
11789@cindex interrupting remote programs
11790@cindex remote programs, interrupting
11791Whenever @value{GDBN} is waiting for the remote program, if you type the
11792interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11793program. This may or may not succeed, depending in part on the hardware
11794and the serial drivers the remote system uses. If you type the
11795interrupt character once again, @value{GDBN} displays this prompt:
11796
11797@smallexample
11798Interrupted while waiting for the program.
11799Give up (and stop debugging it)? (y or n)
11800@end smallexample
11801
11802If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11803(If you decide you want to try again later, you can use @samp{target
11804remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11805goes back to waiting.
11806
11807@table @code
11808@kindex detach (remote)
11809@item detach
11810When you have finished debugging the remote program, you can use the
11811@code{detach} command to release it from @value{GDBN} control.
11812Detaching from the target normally resumes its execution, but the results
11813will depend on your particular remote stub. After the @code{detach}
11814command, @value{GDBN} is free to connect to another target.
11815
11816@kindex disconnect
11817@item disconnect
11818The @code{disconnect} command behaves like @code{detach}, except that
11819the target is generally not resumed. It will wait for @value{GDBN}
11820(this instance or another one) to connect and continue debugging. After
11821the @code{disconnect} command, @value{GDBN} is again free to connect to
11822another target.
09d4efe1
EZ
11823
11824@cindex send command to remote monitor
11825@kindex monitor
11826@item monitor @var{cmd}
11827This command allows you to send commands directly to the remote
11828monitor.
07f31aa6
DJ
11829@end table
11830
6f05cf9f
AC
11831@node Server
11832@section Using the @code{gdbserver} program
11833
11834@kindex gdbserver
11835@cindex remote connection without stubs
11836@code{gdbserver} is a control program for Unix-like systems, which
11837allows you to connect your program with a remote @value{GDBN} via
11838@code{target remote}---but without linking in the usual debugging stub.
11839
11840@code{gdbserver} is not a complete replacement for the debugging stubs,
11841because it requires essentially the same operating-system facilities
11842that @value{GDBN} itself does. In fact, a system that can run
11843@code{gdbserver} to connect to a remote @value{GDBN} could also run
11844@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11845because it is a much smaller program than @value{GDBN} itself. It is
11846also easier to port than all of @value{GDBN}, so you may be able to get
11847started more quickly on a new system by using @code{gdbserver}.
11848Finally, if you develop code for real-time systems, you may find that
11849the tradeoffs involved in real-time operation make it more convenient to
11850do as much development work as possible on another system, for example
11851by cross-compiling. You can use @code{gdbserver} to make a similar
11852choice for debugging.
11853
11854@value{GDBN} and @code{gdbserver} communicate via either a serial line
11855or a TCP connection, using the standard @value{GDBN} remote serial
11856protocol.
11857
11858@table @emph
11859@item On the target machine,
11860you need to have a copy of the program you want to debug.
11861@code{gdbserver} does not need your program's symbol table, so you can
11862strip the program if necessary to save space. @value{GDBN} on the host
11863system does all the symbol handling.
11864
11865To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11866the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11867syntax is:
11868
11869@smallexample
11870target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11871@end smallexample
11872
11873@var{comm} is either a device name (to use a serial line) or a TCP
11874hostname and portnumber. For example, to debug Emacs with the argument
11875@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11876@file{/dev/com1}:
11877
11878@smallexample
11879target> gdbserver /dev/com1 emacs foo.txt
11880@end smallexample
11881
11882@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11883with it.
11884
11885To use a TCP connection instead of a serial line:
11886
11887@smallexample
11888target> gdbserver host:2345 emacs foo.txt
11889@end smallexample
11890
11891The only difference from the previous example is the first argument,
11892specifying that you are communicating with the host @value{GDBN} via
11893TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11894expect a TCP connection from machine @samp{host} to local TCP port 2345.
11895(Currently, the @samp{host} part is ignored.) You can choose any number
11896you want for the port number as long as it does not conflict with any
11897TCP ports already in use on the target system (for example, @code{23} is
11898reserved for @code{telnet}).@footnote{If you choose a port number that
11899conflicts with another service, @code{gdbserver} prints an error message
11900and exits.} You must use the same port number with the host @value{GDBN}
11901@code{target remote} command.
11902
56460a61
DJ
11903On some targets, @code{gdbserver} can also attach to running programs.
11904This is accomplished via the @code{--attach} argument. The syntax is:
11905
11906@smallexample
11907target> gdbserver @var{comm} --attach @var{pid}
11908@end smallexample
11909
11910@var{pid} is the process ID of a currently running process. It isn't necessary
11911to point @code{gdbserver} at a binary for the running process.
11912
b1fe9455
DJ
11913@pindex pidof
11914@cindex attach to a program by name
11915You can debug processes by name instead of process ID if your target has the
11916@code{pidof} utility:
11917
11918@smallexample
11919target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11920@end smallexample
11921
11922In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11923has multiple threads, most versions of @code{pidof} support the
11924@code{-s} option to only return the first process ID.
11925
07f31aa6
DJ
11926@item On the host machine,
11927connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11928For TCP connections, you must start up @code{gdbserver} prior to using
11929the @code{target remote} command. Otherwise you may get an error whose
11930text depends on the host system, but which usually looks something like
07f31aa6
DJ
11931@samp{Connection refused}. You don't need to use the @code{load}
11932command in @value{GDBN} when using gdbserver, since the program is
11933already on the target.
11934
6f05cf9f
AC
11935@end table
11936
11937@node NetWare
11938@section Using the @code{gdbserve.nlm} program
11939
11940@kindex gdbserve.nlm
11941@code{gdbserve.nlm} is a control program for NetWare systems, which
11942allows you to connect your program with a remote @value{GDBN} via
11943@code{target remote}.
11944
11945@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11946using the standard @value{GDBN} remote serial protocol.
11947
11948@table @emph
11949@item On the target machine,
11950you need to have a copy of the program you want to debug.
11951@code{gdbserve.nlm} does not need your program's symbol table, so you
11952can strip the program if necessary to save space. @value{GDBN} on the
11953host system does all the symbol handling.
11954
11955To use the server, you must tell it how to communicate with
11956@value{GDBN}; the name of your program; and the arguments for your
11957program. The syntax is:
11958
11959@smallexample
11960load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11961 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11962@end smallexample
11963
11964@var{board} and @var{port} specify the serial line; @var{baud} specifies
11965the baud rate used by the connection. @var{port} and @var{node} default
11966to 0, @var{baud} defaults to 9600@dmn{bps}.
11967
11968For example, to debug Emacs with the argument @samp{foo.txt}and
11969communicate with @value{GDBN} over serial port number 2 or board 1
11970using a 19200@dmn{bps} connection:
11971
11972@smallexample
11973load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11974@end smallexample
11975
07f31aa6
DJ
11976@item
11977On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11978Connecting to a remote target}).
6f05cf9f 11979
6f05cf9f
AC
11980@end table
11981
501eef12
AC
11982@node Remote configuration
11983@section Remote configuration
11984
9c16f35a
EZ
11985@kindex set remote
11986@kindex show remote
11987This section documents the configuration options available when
11988debugging remote programs. For the options related to the File I/O
11989extensions of the remote protocol, see @ref{The system call,
11990system-call-allowed}.
501eef12
AC
11991
11992@table @code
9c16f35a
EZ
11993@item set remoteaddresssize @var{bits}
11994@cindex adress size for remote targets
11995@cindex bits in remote address
11996Set the maximum size of address in a memory packet to the specified
11997number of bits. @value{GDBN} will mask off the address bits above
11998that number, when it passes addresses to the remote target. The
11999default value is the number of bits in the target's address.
12000
12001@item show remoteaddresssize
12002Show the current value of remote address size in bits.
12003
12004@item set remotebaud @var{n}
12005@cindex baud rate for remote targets
12006Set the baud rate for the remote serial I/O to @var{n} baud. The
12007value is used to set the speed of the serial port used for debugging
12008remote targets.
12009
12010@item show remotebaud
12011Show the current speed of the remote connection.
12012
12013@item set remotebreak
12014@cindex interrupt remote programs
12015@cindex BREAK signal instead of Ctrl-C
12016If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12017when you press the @key{Ctrl-C} key to interrupt the program running
12018on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12019character instead. The default is off, since most remote systems
12020expect to see @samp{Ctrl-C} as the interrupt signal.
12021
12022@item show remotebreak
12023Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12024interrupt the remote program.
12025
12026@item set remotedebug
12027@cindex debug remote protocol
12028@cindex remote protocol debugging
12029@cindex display remote packets
12030Control the debugging of the remote protocol. When enabled, each
12031packet sent to or received from the remote target is displayed. The
12032defaults is off.
12033
12034@item show remotedebug
12035Show the current setting of the remote protocol debugging.
12036
12037@item set remotedevice @var{device}
12038@cindex serial port name
12039Set the name of the serial port through which to communicate to the
12040remote target to @var{device}. This is the device used by
12041@value{GDBN} to open the serial communications line to the remote
12042target. There's no default, so you must set a valid port name for the
12043remote serial communications to work. (Some varieties of the
12044@code{target} command accept the port name as part of their
12045arguments.)
12046
12047@item show remotedevice
12048Show the current name of the serial port.
12049
12050@item set remotelogbase @var{base}
12051Set the base (a.k.a.@: radix) of logging serial protocol
12052communications to @var{base}. Supported values of @var{base} are:
12053@code{ascii}, @code{octal}, and @code{hex}. The default is
12054@code{ascii}.
12055
12056@item show remotelogbase
12057Show the current setting of the radix for logging remote serial
12058protocol.
12059
12060@item set remotelogfile @var{file}
12061@cindex record serial communications on file
12062Record remote serial communications on the named @var{file}. The
12063default is not to record at all.
12064
12065@item show remotelogfile.
12066Show the current setting of the file name on which to record the
12067serial communications.
12068
12069@item set remotetimeout @var{num}
12070@cindex timeout for serial communications
12071@cindex remote timeout
12072Set the timeout limit to wait for the remote target to respond to
12073@var{num} seconds. The default is 2 seconds.
12074
12075@item show remotetimeout
12076Show the current number of seconds to wait for the remote target
12077responses.
12078
12079@cindex limit hardware breakpoints and watchpoints
12080@cindex remote target, limit break- and watchpoints
501eef12
AC
12081@anchor{set remote hardware-watchpoint-limit}
12082@anchor{set remote hardware-breakpoint-limit}
12083@item set remote hardware-watchpoint-limit @var{limit}
12084@itemx set remote hardware-breakpoint-limit @var{limit}
12085Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12086watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12087
12088@item set remote fetch-register-packet
12089@itemx set remote set-register-packet
12090@itemx set remote P-packet
12091@itemx set remote p-packet
12092@cindex P-packet
12093@cindex fetch registers from remote targets
12094@cindex set registers in remote targets
12095Determine whether @value{GDBN} can set and fetch registers from the
12096remote target using the @samp{P} packets. The default depends on the
12097remote stub's support of the @samp{P} packets (@value{GDBN} queries
12098the stub when this packet is first required).
12099
12100@item show remote fetch-register-packet
12101@itemx show remote set-register-packet
12102@itemx show remote P-packet
12103@itemx show remote p-packet
12104Show the current setting of using the @samp{P} packets for setting and
12105fetching registers from the remote target.
12106
12107@cindex binary downloads
12108@cindex X-packet
12109@item set remote binary-download-packet
12110@itemx set remote X-packet
12111Determine whether @value{GDBN} sends downloads in binary mode using
12112the @samp{X} packets. The default is on.
12113
12114@item show remote binary-download-packet
12115@itemx show remote X-packet
12116Show the current setting of using the @samp{X} packets for binary
12117downloads.
12118
12119@item set remote read-aux-vector-packet
12120@cindex auxiliary vector of remote target
12121@cindex @code{auxv}, and remote targets
12122Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12123auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12124remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12125Auxiliary Vector}. The default setting depends on the remote stub's
12126support of this request (@value{GDBN} queries the stub when this
12127request is first required). @xref{General Query Packets, qPart}, for
12128more information about this request.
9c16f35a
EZ
12129
12130@item show remote read-aux-vector-packet
12131Show the current setting of use of the @samp{qPart:auxv:read} request.
12132
12133@item set remote symbol-lookup-packet
12134@cindex remote symbol lookup request
12135Set the use of the remote protocol's @samp{qSymbol} (target symbol
12136lookup) request. This request is used to communicate symbol
12137information to the remote target, e.g., whenever a new shared library
12138is loaded by the remote (@pxref{Files, shared libraries}). The
12139default setting depends on the remote stub's support of this request
12140(@value{GDBN} queries the stub when this request is first required).
12141@xref{General Query Packets, qSymbol}, for more information about this
12142request.
12143
12144@item show remote symbol-lookup-packet
12145Show the current setting of use of the @samp{qSymbol} request.
12146
12147@item set remote verbose-resume-packet
12148@cindex resume remote target
12149@cindex signal thread, and remote targets
12150@cindex single-step thread, and remote targets
12151@cindex thread-specific operations on remote targets
12152Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12153request. This request is used to resume specific threads in the
12154remote target, and to single-step or signal them. The default setting
12155depends on the remote stub's support of this request (@value{GDBN}
12156queries the stub when this request is first required). This setting
12157affects debugging of multithreaded programs: if @samp{vCont} cannot be
12158used, @value{GDBN} might be unable to single-step a specific thread,
12159especially under @code{set scheduler-locking off}; it is also
12160impossible to pause a specific thread. @xref{Packets, vCont}, for
12161more details.
12162
12163@item show remote verbose-resume-packet
12164Show the current setting of use of the @samp{vCont} request
12165
12166@item set remote software-breakpoint-packet
12167@itemx set remote hardware-breakpoint-packet
12168@itemx set remote write-watchpoint-packet
12169@itemx set remote read-watchpoint-packet
12170@itemx set remote access-watchpoint-packet
12171@itemx set remote Z-packet
12172@cindex Z-packet
12173@cindex remote hardware breakpoints and watchpoints
12174These commands enable or disable the use of @samp{Z} packets for
12175setting breakpoints and watchpoints in the remote target. The default
12176depends on the remote stub's support of the @samp{Z} packets
12177(@value{GDBN} queries the stub when each packet is first required).
12178The command @code{set remote Z-packet}, kept for back-compatibility,
12179turns on or off all the features that require the use of @samp{Z}
12180packets.
12181
12182@item show remote software-breakpoint-packet
12183@itemx show remote hardware-breakpoint-packet
12184@itemx show remote write-watchpoint-packet
12185@itemx show remote read-watchpoint-packet
12186@itemx show remote access-watchpoint-packet
12187@itemx show remote Z-packet
12188Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12189
12190@item set remote get-thread-local-storage-address
12191@kindex set remote get-thread-local-storage-address
12192@cindex thread local storage of remote targets
12193This command enables or disables the use of the @samp{qGetTLSAddr}
12194(Get Thread Local Storage Address) request packet. The default
12195depends on whether the remote stub supports this request.
12196@xref{General Query Packets, qGetTLSAddr}, for more details about this
12197packet.
12198
12199@item show remote get-thread-local-storage-address
12200@kindex show remote get-thread-local-storage-address
12201Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12202@end table
12203
6f05cf9f
AC
12204@node remote stub
12205@section Implementing a remote stub
7a292a7a 12206
8e04817f
AC
12207@cindex debugging stub, example
12208@cindex remote stub, example
12209@cindex stub example, remote debugging
12210The stub files provided with @value{GDBN} implement the target side of the
12211communication protocol, and the @value{GDBN} side is implemented in the
12212@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12213these subroutines to communicate, and ignore the details. (If you're
12214implementing your own stub file, you can still ignore the details: start
12215with one of the existing stub files. @file{sparc-stub.c} is the best
12216organized, and therefore the easiest to read.)
12217
104c1213
JM
12218@cindex remote serial debugging, overview
12219To debug a program running on another machine (the debugging
12220@dfn{target} machine), you must first arrange for all the usual
12221prerequisites for the program to run by itself. For example, for a C
12222program, you need:
c906108c 12223
104c1213
JM
12224@enumerate
12225@item
12226A startup routine to set up the C runtime environment; these usually
12227have a name like @file{crt0}. The startup routine may be supplied by
12228your hardware supplier, or you may have to write your own.
96baa820 12229
5d161b24 12230@item
d4f3574e 12231A C subroutine library to support your program's
104c1213 12232subroutine calls, notably managing input and output.
96baa820 12233
104c1213
JM
12234@item
12235A way of getting your program to the other machine---for example, a
12236download program. These are often supplied by the hardware
12237manufacturer, but you may have to write your own from hardware
12238documentation.
12239@end enumerate
96baa820 12240
104c1213
JM
12241The next step is to arrange for your program to use a serial port to
12242communicate with the machine where @value{GDBN} is running (the @dfn{host}
12243machine). In general terms, the scheme looks like this:
96baa820 12244
104c1213
JM
12245@table @emph
12246@item On the host,
12247@value{GDBN} already understands how to use this protocol; when everything
12248else is set up, you can simply use the @samp{target remote} command
12249(@pxref{Targets,,Specifying a Debugging Target}).
12250
12251@item On the target,
12252you must link with your program a few special-purpose subroutines that
12253implement the @value{GDBN} remote serial protocol. The file containing these
12254subroutines is called a @dfn{debugging stub}.
12255
12256On certain remote targets, you can use an auxiliary program
12257@code{gdbserver} instead of linking a stub into your program.
12258@xref{Server,,Using the @code{gdbserver} program}, for details.
12259@end table
96baa820 12260
104c1213
JM
12261The debugging stub is specific to the architecture of the remote
12262machine; for example, use @file{sparc-stub.c} to debug programs on
12263@sc{sparc} boards.
96baa820 12264
104c1213
JM
12265@cindex remote serial stub list
12266These working remote stubs are distributed with @value{GDBN}:
96baa820 12267
104c1213
JM
12268@table @code
12269
12270@item i386-stub.c
41afff9a 12271@cindex @file{i386-stub.c}
104c1213
JM
12272@cindex Intel
12273@cindex i386
12274For Intel 386 and compatible architectures.
12275
12276@item m68k-stub.c
41afff9a 12277@cindex @file{m68k-stub.c}
104c1213
JM
12278@cindex Motorola 680x0
12279@cindex m680x0
12280For Motorola 680x0 architectures.
12281
12282@item sh-stub.c
41afff9a 12283@cindex @file{sh-stub.c}
172c2a43 12284@cindex Renesas
104c1213 12285@cindex SH
172c2a43 12286For Renesas SH architectures.
104c1213
JM
12287
12288@item sparc-stub.c
41afff9a 12289@cindex @file{sparc-stub.c}
104c1213
JM
12290@cindex Sparc
12291For @sc{sparc} architectures.
12292
12293@item sparcl-stub.c
41afff9a 12294@cindex @file{sparcl-stub.c}
104c1213
JM
12295@cindex Fujitsu
12296@cindex SparcLite
12297For Fujitsu @sc{sparclite} architectures.
12298
12299@end table
12300
12301The @file{README} file in the @value{GDBN} distribution may list other
12302recently added stubs.
12303
12304@menu
12305* Stub Contents:: What the stub can do for you
12306* Bootstrapping:: What you must do for the stub
12307* Debug Session:: Putting it all together
104c1213
JM
12308@end menu
12309
6d2ebf8b 12310@node Stub Contents
6f05cf9f 12311@subsection What the stub can do for you
104c1213
JM
12312
12313@cindex remote serial stub
12314The debugging stub for your architecture supplies these three
12315subroutines:
12316
12317@table @code
12318@item set_debug_traps
4644b6e3 12319@findex set_debug_traps
104c1213
JM
12320@cindex remote serial stub, initialization
12321This routine arranges for @code{handle_exception} to run when your
12322program stops. You must call this subroutine explicitly near the
12323beginning of your program.
12324
12325@item handle_exception
4644b6e3 12326@findex handle_exception
104c1213
JM
12327@cindex remote serial stub, main routine
12328This is the central workhorse, but your program never calls it
12329explicitly---the setup code arranges for @code{handle_exception} to
12330run when a trap is triggered.
12331
12332@code{handle_exception} takes control when your program stops during
12333execution (for example, on a breakpoint), and mediates communications
12334with @value{GDBN} on the host machine. This is where the communications
12335protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12336representative on the target machine. It begins by sending summary
104c1213
JM
12337information on the state of your program, then continues to execute,
12338retrieving and transmitting any information @value{GDBN} needs, until you
12339execute a @value{GDBN} command that makes your program resume; at that point,
12340@code{handle_exception} returns control to your own code on the target
5d161b24 12341machine.
104c1213
JM
12342
12343@item breakpoint
12344@cindex @code{breakpoint} subroutine, remote
12345Use this auxiliary subroutine to make your program contain a
12346breakpoint. Depending on the particular situation, this may be the only
12347way for @value{GDBN} to get control. For instance, if your target
12348machine has some sort of interrupt button, you won't need to call this;
12349pressing the interrupt button transfers control to
12350@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12351simply receiving characters on the serial port may also trigger a trap;
12352again, in that situation, you don't need to call @code{breakpoint} from
12353your own program---simply running @samp{target remote} from the host
5d161b24 12354@value{GDBN} session gets control.
104c1213
JM
12355
12356Call @code{breakpoint} if none of these is true, or if you simply want
12357to make certain your program stops at a predetermined point for the
12358start of your debugging session.
12359@end table
12360
6d2ebf8b 12361@node Bootstrapping
6f05cf9f 12362@subsection What you must do for the stub
104c1213
JM
12363
12364@cindex remote stub, support routines
12365The debugging stubs that come with @value{GDBN} are set up for a particular
12366chip architecture, but they have no information about the rest of your
12367debugging target machine.
12368
12369First of all you need to tell the stub how to communicate with the
12370serial port.
12371
12372@table @code
12373@item int getDebugChar()
4644b6e3 12374@findex getDebugChar
104c1213
JM
12375Write this subroutine to read a single character from the serial port.
12376It may be identical to @code{getchar} for your target system; a
12377different name is used to allow you to distinguish the two if you wish.
12378
12379@item void putDebugChar(int)
4644b6e3 12380@findex putDebugChar
104c1213 12381Write this subroutine to write a single character to the serial port.
5d161b24 12382It may be identical to @code{putchar} for your target system; a
104c1213
JM
12383different name is used to allow you to distinguish the two if you wish.
12384@end table
12385
12386@cindex control C, and remote debugging
12387@cindex interrupting remote targets
12388If you want @value{GDBN} to be able to stop your program while it is
12389running, you need to use an interrupt-driven serial driver, and arrange
12390for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12391character). That is the character which @value{GDBN} uses to tell the
12392remote system to stop.
12393
12394Getting the debugging target to return the proper status to @value{GDBN}
12395probably requires changes to the standard stub; one quick and dirty way
12396is to just execute a breakpoint instruction (the ``dirty'' part is that
12397@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12398
12399Other routines you need to supply are:
12400
12401@table @code
12402@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12403@findex exceptionHandler
104c1213
JM
12404Write this function to install @var{exception_address} in the exception
12405handling tables. You need to do this because the stub does not have any
12406way of knowing what the exception handling tables on your target system
12407are like (for example, the processor's table might be in @sc{rom},
12408containing entries which point to a table in @sc{ram}).
12409@var{exception_number} is the exception number which should be changed;
12410its meaning is architecture-dependent (for example, different numbers
12411might represent divide by zero, misaligned access, etc). When this
12412exception occurs, control should be transferred directly to
12413@var{exception_address}, and the processor state (stack, registers,
12414and so on) should be just as it is when a processor exception occurs. So if
12415you want to use a jump instruction to reach @var{exception_address}, it
12416should be a simple jump, not a jump to subroutine.
12417
12418For the 386, @var{exception_address} should be installed as an interrupt
12419gate so that interrupts are masked while the handler runs. The gate
12420should be at privilege level 0 (the most privileged level). The
12421@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12422help from @code{exceptionHandler}.
12423
12424@item void flush_i_cache()
4644b6e3 12425@findex flush_i_cache
d4f3574e 12426On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12427instruction cache, if any, on your target machine. If there is no
12428instruction cache, this subroutine may be a no-op.
12429
12430On target machines that have instruction caches, @value{GDBN} requires this
12431function to make certain that the state of your program is stable.
12432@end table
12433
12434@noindent
12435You must also make sure this library routine is available:
12436
12437@table @code
12438@item void *memset(void *, int, int)
4644b6e3 12439@findex memset
104c1213
JM
12440This is the standard library function @code{memset} that sets an area of
12441memory to a known value. If you have one of the free versions of
12442@code{libc.a}, @code{memset} can be found there; otherwise, you must
12443either obtain it from your hardware manufacturer, or write your own.
12444@end table
12445
12446If you do not use the GNU C compiler, you may need other standard
12447library subroutines as well; this varies from one stub to another,
12448but in general the stubs are likely to use any of the common library
d4f3574e 12449subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12450
12451
6d2ebf8b 12452@node Debug Session
6f05cf9f 12453@subsection Putting it all together
104c1213
JM
12454
12455@cindex remote serial debugging summary
12456In summary, when your program is ready to debug, you must follow these
12457steps.
12458
12459@enumerate
12460@item
6d2ebf8b 12461Make sure you have defined the supporting low-level routines
104c1213
JM
12462(@pxref{Bootstrapping,,What you must do for the stub}):
12463@display
12464@code{getDebugChar}, @code{putDebugChar},
12465@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12466@end display
12467
12468@item
12469Insert these lines near the top of your program:
12470
474c8240 12471@smallexample
104c1213
JM
12472set_debug_traps();
12473breakpoint();
474c8240 12474@end smallexample
104c1213
JM
12475
12476@item
12477For the 680x0 stub only, you need to provide a variable called
12478@code{exceptionHook}. Normally you just use:
12479
474c8240 12480@smallexample
104c1213 12481void (*exceptionHook)() = 0;
474c8240 12482@end smallexample
104c1213 12483
d4f3574e 12484@noindent
104c1213 12485but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12486function in your program, that function is called when
104c1213
JM
12487@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12488error). The function indicated by @code{exceptionHook} is called with
12489one parameter: an @code{int} which is the exception number.
12490
12491@item
12492Compile and link together: your program, the @value{GDBN} debugging stub for
12493your target architecture, and the supporting subroutines.
12494
12495@item
12496Make sure you have a serial connection between your target machine and
12497the @value{GDBN} host, and identify the serial port on the host.
12498
12499@item
12500@c The "remote" target now provides a `load' command, so we should
12501@c document that. FIXME.
12502Download your program to your target machine (or get it there by
12503whatever means the manufacturer provides), and start it.
12504
12505@item
07f31aa6
DJ
12506Start @value{GDBN} on the host, and connect to the target
12507(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12508
104c1213
JM
12509@end enumerate
12510
8e04817f
AC
12511@node Configurations
12512@chapter Configuration-Specific Information
104c1213 12513
8e04817f
AC
12514While nearly all @value{GDBN} commands are available for all native and
12515cross versions of the debugger, there are some exceptions. This chapter
12516describes things that are only available in certain configurations.
104c1213 12517
8e04817f
AC
12518There are three major categories of configurations: native
12519configurations, where the host and target are the same, embedded
12520operating system configurations, which are usually the same for several
12521different processor architectures, and bare embedded processors, which
12522are quite different from each other.
104c1213 12523
8e04817f
AC
12524@menu
12525* Native::
12526* Embedded OS::
12527* Embedded Processors::
12528* Architectures::
12529@end menu
104c1213 12530
8e04817f
AC
12531@node Native
12532@section Native
104c1213 12533
8e04817f
AC
12534This section describes details specific to particular native
12535configurations.
6cf7e474 12536
8e04817f
AC
12537@menu
12538* HP-UX:: HP-UX
7561d450 12539* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12540* SVR4 Process Information:: SVR4 process information
12541* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12542* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12543* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12544* Neutrino:: Features specific to QNX Neutrino
8e04817f 12545@end menu
6cf7e474 12546
8e04817f
AC
12547@node HP-UX
12548@subsection HP-UX
104c1213 12549
8e04817f
AC
12550On HP-UX systems, if you refer to a function or variable name that
12551begins with a dollar sign, @value{GDBN} searches for a user or system
12552name first, before it searches for a convenience variable.
104c1213 12553
9c16f35a 12554
7561d450
MK
12555@node BSD libkvm Interface
12556@subsection BSD libkvm Interface
12557
12558@cindex libkvm
12559@cindex kernel memory image
12560@cindex kernel crash dump
12561
12562BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12563interface that provides a uniform interface for accessing kernel virtual
12564memory images, including live systems and crash dumps. @value{GDBN}
12565uses this interface to allow you to debug live kernels and kernel crash
12566dumps on many native BSD configurations. This is implemented as a
12567special @code{kvm} debugging target. For debugging a live system, load
12568the currently running kernel into @value{GDBN} and connect to the
12569@code{kvm} target:
12570
12571@smallexample
12572(@value{GDBP}) @b{target kvm}
12573@end smallexample
12574
12575For debugging crash dumps, provide the file name of the crash dump as an
12576argument:
12577
12578@smallexample
12579(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12580@end smallexample
12581
12582Once connected to the @code{kvm} target, the following commands are
12583available:
12584
12585@table @code
12586@kindex kvm
12587@item kvm pcb
721c2651 12588Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12589
12590@item kvm proc
12591Set current context from proc address. This command isn't available on
12592modern FreeBSD systems.
12593@end table
12594
8e04817f
AC
12595@node SVR4 Process Information
12596@subsection SVR4 process information
60bf7e09
EZ
12597@cindex /proc
12598@cindex examine process image
12599@cindex process info via @file{/proc}
104c1213 12600
60bf7e09
EZ
12601Many versions of SVR4 and compatible systems provide a facility called
12602@samp{/proc} that can be used to examine the image of a running
12603process using file-system subroutines. If @value{GDBN} is configured
12604for an operating system with this facility, the command @code{info
12605proc} is available to report information about the process running
12606your program, or about any process running on your system. @code{info
12607proc} works only on SVR4 systems that include the @code{procfs} code.
12608This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12609Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12610
8e04817f
AC
12611@table @code
12612@kindex info proc
60bf7e09 12613@cindex process ID
8e04817f 12614@item info proc
60bf7e09
EZ
12615@itemx info proc @var{process-id}
12616Summarize available information about any running process. If a
12617process ID is specified by @var{process-id}, display information about
12618that process; otherwise display information about the program being
12619debugged. The summary includes the debugged process ID, the command
12620line used to invoke it, its current working directory, and its
12621executable file's absolute file name.
12622
12623On some systems, @var{process-id} can be of the form
12624@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12625within a process. If the optional @var{pid} part is missing, it means
12626a thread from the process being debugged (the leading @samp{/} still
12627needs to be present, or else @value{GDBN} will interpret the number as
12628a process ID rather than a thread ID).
6cf7e474 12629
8e04817f 12630@item info proc mappings
60bf7e09
EZ
12631@cindex memory address space mappings
12632Report the memory address space ranges accessible in the program, with
12633information on whether the process has read, write, or execute access
12634rights to each range. On @sc{gnu}/Linux systems, each memory range
12635includes the object file which is mapped to that range, instead of the
12636memory access rights to that range.
12637
12638@item info proc stat
12639@itemx info proc status
12640@cindex process detailed status information
12641These subcommands are specific to @sc{gnu}/Linux systems. They show
12642the process-related information, including the user ID and group ID;
12643how many threads are there in the process; its virtual memory usage;
12644the signals that are pending, blocked, and ignored; its TTY; its
12645consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12646value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12647(type @kbd{man 5 proc} from your shell prompt).
12648
12649@item info proc all
12650Show all the information about the process described under all of the
12651above @code{info proc} subcommands.
12652
8e04817f
AC
12653@ignore
12654@comment These sub-options of 'info proc' were not included when
12655@comment procfs.c was re-written. Keep their descriptions around
12656@comment against the day when someone finds the time to put them back in.
12657@kindex info proc times
12658@item info proc times
12659Starting time, user CPU time, and system CPU time for your program and
12660its children.
6cf7e474 12661
8e04817f
AC
12662@kindex info proc id
12663@item info proc id
12664Report on the process IDs related to your program: its own process ID,
12665the ID of its parent, the process group ID, and the session ID.
8e04817f 12666@end ignore
721c2651
EZ
12667
12668@item set procfs-trace
12669@kindex set procfs-trace
12670@cindex @code{procfs} API calls
12671This command enables and disables tracing of @code{procfs} API calls.
12672
12673@item show procfs-trace
12674@kindex show procfs-trace
12675Show the current state of @code{procfs} API call tracing.
12676
12677@item set procfs-file @var{file}
12678@kindex set procfs-file
12679Tell @value{GDBN} to write @code{procfs} API trace to the named
12680@var{file}. @value{GDBN} appends the trace info to the previous
12681contents of the file. The default is to display the trace on the
12682standard output.
12683
12684@item show procfs-file
12685@kindex show procfs-file
12686Show the file to which @code{procfs} API trace is written.
12687
12688@item proc-trace-entry
12689@itemx proc-trace-exit
12690@itemx proc-untrace-entry
12691@itemx proc-untrace-exit
12692@kindex proc-trace-entry
12693@kindex proc-trace-exit
12694@kindex proc-untrace-entry
12695@kindex proc-untrace-exit
12696These commands enable and disable tracing of entries into and exits
12697from the @code{syscall} interface.
12698
12699@item info pidlist
12700@kindex info pidlist
12701@cindex process list, QNX Neutrino
12702For QNX Neutrino only, this command displays the list of all the
12703processes and all the threads within each process.
12704
12705@item info meminfo
12706@kindex info meminfo
12707@cindex mapinfo list, QNX Neutrino
12708For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12709@end table
104c1213 12710
8e04817f
AC
12711@node DJGPP Native
12712@subsection Features for Debugging @sc{djgpp} Programs
12713@cindex @sc{djgpp} debugging
12714@cindex native @sc{djgpp} debugging
12715@cindex MS-DOS-specific commands
104c1213 12716
514c4d71
EZ
12717@cindex DPMI
12718@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12719MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12720that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12721top of real-mode DOS systems and their emulations.
104c1213 12722
8e04817f
AC
12723@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12724defines a few commands specific to the @sc{djgpp} port. This
12725subsection describes those commands.
104c1213 12726
8e04817f
AC
12727@table @code
12728@kindex info dos
12729@item info dos
12730This is a prefix of @sc{djgpp}-specific commands which print
12731information about the target system and important OS structures.
f1251bdd 12732
8e04817f
AC
12733@kindex sysinfo
12734@cindex MS-DOS system info
12735@cindex free memory information (MS-DOS)
12736@item info dos sysinfo
12737This command displays assorted information about the underlying
12738platform: the CPU type and features, the OS version and flavor, the
12739DPMI version, and the available conventional and DPMI memory.
104c1213 12740
8e04817f
AC
12741@cindex GDT
12742@cindex LDT
12743@cindex IDT
12744@cindex segment descriptor tables
12745@cindex descriptor tables display
12746@item info dos gdt
12747@itemx info dos ldt
12748@itemx info dos idt
12749These 3 commands display entries from, respectively, Global, Local,
12750and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12751tables are data structures which store a descriptor for each segment
12752that is currently in use. The segment's selector is an index into a
12753descriptor table; the table entry for that index holds the
12754descriptor's base address and limit, and its attributes and access
12755rights.
104c1213 12756
8e04817f
AC
12757A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12758segment (used for both data and the stack), and a DOS segment (which
12759allows access to DOS/BIOS data structures and absolute addresses in
12760conventional memory). However, the DPMI host will usually define
12761additional segments in order to support the DPMI environment.
d4f3574e 12762
8e04817f
AC
12763@cindex garbled pointers
12764These commands allow to display entries from the descriptor tables.
12765Without an argument, all entries from the specified table are
12766displayed. An argument, which should be an integer expression, means
12767display a single entry whose index is given by the argument. For
12768example, here's a convenient way to display information about the
12769debugged program's data segment:
104c1213 12770
8e04817f
AC
12771@smallexample
12772@exdent @code{(@value{GDBP}) info dos ldt $ds}
12773@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12774@end smallexample
104c1213 12775
8e04817f
AC
12776@noindent
12777This comes in handy when you want to see whether a pointer is outside
12778the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12779
8e04817f
AC
12780@cindex page tables display (MS-DOS)
12781@item info dos pde
12782@itemx info dos pte
12783These two commands display entries from, respectively, the Page
12784Directory and the Page Tables. Page Directories and Page Tables are
12785data structures which control how virtual memory addresses are mapped
12786into physical addresses. A Page Table includes an entry for every
12787page of memory that is mapped into the program's address space; there
12788may be several Page Tables, each one holding up to 4096 entries. A
12789Page Directory has up to 4096 entries, one each for every Page Table
12790that is currently in use.
104c1213 12791
8e04817f
AC
12792Without an argument, @kbd{info dos pde} displays the entire Page
12793Directory, and @kbd{info dos pte} displays all the entries in all of
12794the Page Tables. An argument, an integer expression, given to the
12795@kbd{info dos pde} command means display only that entry from the Page
12796Directory table. An argument given to the @kbd{info dos pte} command
12797means display entries from a single Page Table, the one pointed to by
12798the specified entry in the Page Directory.
104c1213 12799
8e04817f
AC
12800@cindex direct memory access (DMA) on MS-DOS
12801These commands are useful when your program uses @dfn{DMA} (Direct
12802Memory Access), which needs physical addresses to program the DMA
12803controller.
104c1213 12804
8e04817f 12805These commands are supported only with some DPMI servers.
104c1213 12806
8e04817f
AC
12807@cindex physical address from linear address
12808@item info dos address-pte @var{addr}
12809This command displays the Page Table entry for a specified linear
514c4d71
EZ
12810address. The argument @var{addr} is a linear address which should
12811already have the appropriate segment's base address added to it,
12812because this command accepts addresses which may belong to @emph{any}
12813segment. For example, here's how to display the Page Table entry for
12814the page where a variable @code{i} is stored:
104c1213 12815
b383017d 12816@smallexample
8e04817f
AC
12817@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12818@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12819@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12820@end smallexample
104c1213 12821
8e04817f
AC
12822@noindent
12823This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12824whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12825attributes of that page.
104c1213 12826
8e04817f
AC
12827Note that you must cast the addresses of variables to a @code{char *},
12828since otherwise the value of @code{__djgpp_base_address}, the base
12829address of all variables and functions in a @sc{djgpp} program, will
12830be added using the rules of C pointer arithmetics: if @code{i} is
12831declared an @code{int}, @value{GDBN} will add 4 times the value of
12832@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12833
8e04817f
AC
12834Here's another example, it displays the Page Table entry for the
12835transfer buffer:
104c1213 12836
8e04817f
AC
12837@smallexample
12838@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12839@exdent @code{Page Table entry for address 0x29110:}
12840@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12841@end smallexample
104c1213 12842
8e04817f
AC
12843@noindent
12844(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128453rd member of the @code{_go32_info_block} structure.) The output
12846clearly shows that this DPMI server maps the addresses in conventional
12847memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12848linear (@code{0x29110}) addresses are identical.
104c1213 12849
8e04817f
AC
12850This command is supported only with some DPMI servers.
12851@end table
104c1213 12852
c45da7e6 12853@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12854In addition to native debugging, the DJGPP port supports remote
12855debugging via a serial data link. The following commands are specific
12856to remote serial debugging in the DJGPP port of @value{GDBN}.
12857
12858@table @code
12859@kindex set com1base
12860@kindex set com1irq
12861@kindex set com2base
12862@kindex set com2irq
12863@kindex set com3base
12864@kindex set com3irq
12865@kindex set com4base
12866@kindex set com4irq
12867@item set com1base @var{addr}
12868This command sets the base I/O port address of the @file{COM1} serial
12869port.
12870
12871@item set com1irq @var{irq}
12872This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12873for the @file{COM1} serial port.
12874
12875There are similar commands @samp{set com2base}, @samp{set com3irq},
12876etc.@: for setting the port address and the @code{IRQ} lines for the
12877other 3 COM ports.
12878
12879@kindex show com1base
12880@kindex show com1irq
12881@kindex show com2base
12882@kindex show com2irq
12883@kindex show com3base
12884@kindex show com3irq
12885@kindex show com4base
12886@kindex show com4irq
12887The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12888display the current settings of the base address and the @code{IRQ}
12889lines used by the COM ports.
c45da7e6
EZ
12890
12891@item info serial
12892@kindex info serial
12893@cindex DOS serial port status
12894This command prints the status of the 4 DOS serial ports. For each
12895port, it prints whether it's active or not, its I/O base address and
12896IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12897counts of various errors encountered so far.
a8f24a35
EZ
12898@end table
12899
12900
78c47bea
PM
12901@node Cygwin Native
12902@subsection Features for Debugging MS Windows PE executables
12903@cindex MS Windows debugging
12904@cindex native Cygwin debugging
12905@cindex Cygwin-specific commands
12906
be448670
CF
12907@value{GDBN} supports native debugging of MS Windows programs, including
12908DLLs with and without symbolic debugging information. There are various
12909additional Cygwin-specific commands, described in this subsection. The
12910subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12911that have no debugging symbols.
12912
78c47bea
PM
12913
12914@table @code
12915@kindex info w32
12916@item info w32
12917This is a prefix of MS Windows specific commands which print
12918information about the target system and important OS structures.
12919
12920@item info w32 selector
12921This command displays information returned by
12922the Win32 API @code{GetThreadSelectorEntry} function.
12923It takes an optional argument that is evaluated to
12924a long value to give the information about this given selector.
12925Without argument, this command displays information
12926about the the six segment registers.
12927
12928@kindex info dll
12929@item info dll
12930This is a Cygwin specific alias of info shared.
12931
12932@kindex dll-symbols
12933@item dll-symbols
12934This command loads symbols from a dll similarly to
12935add-sym command but without the need to specify a base address.
12936
b383017d 12937@kindex set new-console
78c47bea 12938@item set new-console @var{mode}
b383017d 12939If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12940be started in a new console on next start.
12941If @var{mode} is @code{off}i, the debuggee will
12942be started in the same console as the debugger.
12943
12944@kindex show new-console
12945@item show new-console
12946Displays whether a new console is used
12947when the debuggee is started.
12948
12949@kindex set new-group
12950@item set new-group @var{mode}
12951This boolean value controls whether the debuggee should
12952start a new group or stay in the same group as the debugger.
12953This affects the way the Windows OS handles
12954Ctrl-C.
12955
12956@kindex show new-group
12957@item show new-group
12958Displays current value of new-group boolean.
12959
12960@kindex set debugevents
12961@item set debugevents
12962This boolean value adds debug output concerning events seen by the debugger.
12963
12964@kindex set debugexec
12965@item set debugexec
b383017d 12966This boolean value adds debug output concerning execute events
78c47bea
PM
12967seen by the debugger.
12968
12969@kindex set debugexceptions
12970@item set debugexceptions
b383017d 12971This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12972seen by the debugger.
12973
12974@kindex set debugmemory
12975@item set debugmemory
b383017d 12976This boolean value adds debug ouptut concerning memory events
78c47bea
PM
12977seen by the debugger.
12978
12979@kindex set shell
12980@item set shell
12981This boolean values specifies whether the debuggee is called
12982via a shell or directly (default value is on).
12983
12984@kindex show shell
12985@item show shell
12986Displays if the debuggee will be started with a shell.
12987
12988@end table
12989
be448670
CF
12990@menu
12991* Non-debug DLL symbols:: Support for DLLs without debugging symbols
12992@end menu
12993
12994@node Non-debug DLL symbols
12995@subsubsection Support for DLLs without debugging symbols
12996@cindex DLLs with no debugging symbols
12997@cindex Minimal symbols and DLLs
12998
12999Very often on windows, some of the DLLs that your program relies on do
13000not include symbolic debugging information (for example,
13001@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13002symbols in a DLL, it relies on the minimal amount of symbolic
13003information contained in the DLL's export table. This subsubsection
13004describes working with such symbols, known internally to @value{GDBN} as
13005``minimal symbols''.
13006
13007Note that before the debugged program has started execution, no DLLs
13008will have been loaded. The easiest way around this problem is simply to
13009start the program --- either by setting a breakpoint or letting the
13010program run once to completion. It is also possible to force
13011@value{GDBN} to load a particular DLL before starting the executable ---
13012see the shared library information in @pxref{Files} or the
13013@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13014explicitly loading symbols from a DLL with no debugging information will
13015cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13016which may adversely affect symbol lookup performance.
13017
13018@subsubsection DLL name prefixes
13019
13020In keeping with the naming conventions used by the Microsoft debugging
13021tools, DLL export symbols are made available with a prefix based on the
13022DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13023also entered into the symbol table, so @code{CreateFileA} is often
13024sufficient. In some cases there will be name clashes within a program
13025(particularly if the executable itself includes full debugging symbols)
13026necessitating the use of the fully qualified name when referring to the
13027contents of the DLL. Use single-quotes around the name to avoid the
13028exclamation mark (``!'') being interpreted as a language operator.
13029
13030Note that the internal name of the DLL may be all upper-case, even
13031though the file name of the DLL is lower-case, or vice-versa. Since
13032symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13033some confusion. If in doubt, try the @code{info functions} and
13034@code{info variables} commands or even @code{maint print msymbols} (see
13035@pxref{Symbols}). Here's an example:
13036
13037@smallexample
f7dc1244 13038(@value{GDBP}) info function CreateFileA
be448670
CF
13039All functions matching regular expression "CreateFileA":
13040
13041Non-debugging symbols:
130420x77e885f4 CreateFileA
130430x77e885f4 KERNEL32!CreateFileA
13044@end smallexample
13045
13046@smallexample
f7dc1244 13047(@value{GDBP}) info function !
be448670
CF
13048All functions matching regular expression "!":
13049
13050Non-debugging symbols:
130510x6100114c cygwin1!__assert
130520x61004034 cygwin1!_dll_crt0@@0
130530x61004240 cygwin1!dll_crt0(per_process *)
13054[etc...]
13055@end smallexample
13056
13057@subsubsection Working with minimal symbols
13058
13059Symbols extracted from a DLL's export table do not contain very much
13060type information. All that @value{GDBN} can do is guess whether a symbol
13061refers to a function or variable depending on the linker section that
13062contains the symbol. Also note that the actual contents of the memory
13063contained in a DLL are not available unless the program is running. This
13064means that you cannot examine the contents of a variable or disassemble
13065a function within a DLL without a running program.
13066
13067Variables are generally treated as pointers and dereferenced
13068automatically. For this reason, it is often necessary to prefix a
13069variable name with the address-of operator (``&'') and provide explicit
13070type information in the command. Here's an example of the type of
13071problem:
13072
13073@smallexample
f7dc1244 13074(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13075$1 = 268572168
13076@end smallexample
13077
13078@smallexample
f7dc1244 13079(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
130800x10021610: "\230y\""
13081@end smallexample
13082
13083And two possible solutions:
13084
13085@smallexample
f7dc1244 13086(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13087$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13088@end smallexample
13089
13090@smallexample
f7dc1244 13091(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 130920x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13093(@value{GDBP}) x/x 0x10021608
be448670 130940x10021608: 0x0022fd98
f7dc1244 13095(@value{GDBP}) x/s 0x0022fd98
be448670
CF
130960x22fd98: "/cygdrive/c/mydirectory/myprogram"
13097@end smallexample
13098
13099Setting a break point within a DLL is possible even before the program
13100starts execution. However, under these circumstances, @value{GDBN} can't
13101examine the initial instructions of the function in order to skip the
13102function's frame set-up code. You can work around this by using ``*&''
13103to set the breakpoint at a raw memory address:
13104
13105@smallexample
f7dc1244 13106(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13107Breakpoint 1 at 0x1e04eff0
13108@end smallexample
13109
13110The author of these extensions is not entirely convinced that setting a
13111break point within a shared DLL like @file{kernel32.dll} is completely
13112safe.
13113
14d6dd68
EZ
13114@node Hurd Native
13115@subsection Commands specific to @sc{gnu} Hurd systems
13116@cindex @sc{gnu} Hurd debugging
13117
13118This subsection describes @value{GDBN} commands specific to the
13119@sc{gnu} Hurd native debugging.
13120
13121@table @code
13122@item set signals
13123@itemx set sigs
13124@kindex set signals@r{, Hurd command}
13125@kindex set sigs@r{, Hurd command}
13126This command toggles the state of inferior signal interception by
13127@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13128affected by this command. @code{sigs} is a shorthand alias for
13129@code{signals}.
13130
13131@item show signals
13132@itemx show sigs
13133@kindex show signals@r{, Hurd command}
13134@kindex show sigs@r{, Hurd command}
13135Show the current state of intercepting inferior's signals.
13136
13137@item set signal-thread
13138@itemx set sigthread
13139@kindex set signal-thread
13140@kindex set sigthread
13141This command tells @value{GDBN} which thread is the @code{libc} signal
13142thread. That thread is run when a signal is delivered to a running
13143process. @code{set sigthread} is the shorthand alias of @code{set
13144signal-thread}.
13145
13146@item show signal-thread
13147@itemx show sigthread
13148@kindex show signal-thread
13149@kindex show sigthread
13150These two commands show which thread will run when the inferior is
13151delivered a signal.
13152
13153@item set stopped
13154@kindex set stopped@r{, Hurd command}
13155This commands tells @value{GDBN} that the inferior process is stopped,
13156as with the @code{SIGSTOP} signal. The stopped process can be
13157continued by delivering a signal to it.
13158
13159@item show stopped
13160@kindex show stopped@r{, Hurd command}
13161This command shows whether @value{GDBN} thinks the debuggee is
13162stopped.
13163
13164@item set exceptions
13165@kindex set exceptions@r{, Hurd command}
13166Use this command to turn off trapping of exceptions in the inferior.
13167When exception trapping is off, neither breakpoints nor
13168single-stepping will work. To restore the default, set exception
13169trapping on.
13170
13171@item show exceptions
13172@kindex show exceptions@r{, Hurd command}
13173Show the current state of trapping exceptions in the inferior.
13174
13175@item set task pause
13176@kindex set task@r{, Hurd commands}
13177@cindex task attributes (@sc{gnu} Hurd)
13178@cindex pause current task (@sc{gnu} Hurd)
13179This command toggles task suspension when @value{GDBN} has control.
13180Setting it to on takes effect immediately, and the task is suspended
13181whenever @value{GDBN} gets control. Setting it to off will take
13182effect the next time the inferior is continued. If this option is set
13183to off, you can use @code{set thread default pause on} or @code{set
13184thread pause on} (see below) to pause individual threads.
13185
13186@item show task pause
13187@kindex show task@r{, Hurd commands}
13188Show the current state of task suspension.
13189
13190@item set task detach-suspend-count
13191@cindex task suspend count
13192@cindex detach from task, @sc{gnu} Hurd
13193This command sets the suspend count the task will be left with when
13194@value{GDBN} detaches from it.
13195
13196@item show task detach-suspend-count
13197Show the suspend count the task will be left with when detaching.
13198
13199@item set task exception-port
13200@itemx set task excp
13201@cindex task exception port, @sc{gnu} Hurd
13202This command sets the task exception port to which @value{GDBN} will
13203forward exceptions. The argument should be the value of the @dfn{send
13204rights} of the task. @code{set task excp} is a shorthand alias.
13205
13206@item set noninvasive
13207@cindex noninvasive task options
13208This command switches @value{GDBN} to a mode that is the least
13209invasive as far as interfering with the inferior is concerned. This
13210is the same as using @code{set task pause}, @code{set exceptions}, and
13211@code{set signals} to values opposite to the defaults.
13212
13213@item info send-rights
13214@itemx info receive-rights
13215@itemx info port-rights
13216@itemx info port-sets
13217@itemx info dead-names
13218@itemx info ports
13219@itemx info psets
13220@cindex send rights, @sc{gnu} Hurd
13221@cindex receive rights, @sc{gnu} Hurd
13222@cindex port rights, @sc{gnu} Hurd
13223@cindex port sets, @sc{gnu} Hurd
13224@cindex dead names, @sc{gnu} Hurd
13225These commands display information about, respectively, send rights,
13226receive rights, port rights, port sets, and dead names of a task.
13227There are also shorthand aliases: @code{info ports} for @code{info
13228port-rights} and @code{info psets} for @code{info port-sets}.
13229
13230@item set thread pause
13231@kindex set thread@r{, Hurd command}
13232@cindex thread properties, @sc{gnu} Hurd
13233@cindex pause current thread (@sc{gnu} Hurd)
13234This command toggles current thread suspension when @value{GDBN} has
13235control. Setting it to on takes effect immediately, and the current
13236thread is suspended whenever @value{GDBN} gets control. Setting it to
13237off will take effect the next time the inferior is continued.
13238Normally, this command has no effect, since when @value{GDBN} has
13239control, the whole task is suspended. However, if you used @code{set
13240task pause off} (see above), this command comes in handy to suspend
13241only the current thread.
13242
13243@item show thread pause
13244@kindex show thread@r{, Hurd command}
13245This command shows the state of current thread suspension.
13246
13247@item set thread run
13248This comamnd sets whether the current thread is allowed to run.
13249
13250@item show thread run
13251Show whether the current thread is allowed to run.
13252
13253@item set thread detach-suspend-count
13254@cindex thread suspend count, @sc{gnu} Hurd
13255@cindex detach from thread, @sc{gnu} Hurd
13256This command sets the suspend count @value{GDBN} will leave on a
13257thread when detaching. This number is relative to the suspend count
13258found by @value{GDBN} when it notices the thread; use @code{set thread
13259takeover-suspend-count} to force it to an absolute value.
13260
13261@item show thread detach-suspend-count
13262Show the suspend count @value{GDBN} will leave on the thread when
13263detaching.
13264
13265@item set thread exception-port
13266@itemx set thread excp
13267Set the thread exception port to which to forward exceptions. This
13268overrides the port set by @code{set task exception-port} (see above).
13269@code{set thread excp} is the shorthand alias.
13270
13271@item set thread takeover-suspend-count
13272Normally, @value{GDBN}'s thread suspend counts are relative to the
13273value @value{GDBN} finds when it notices each thread. This command
13274changes the suspend counts to be absolute instead.
13275
13276@item set thread default
13277@itemx show thread default
13278@cindex thread default settings, @sc{gnu} Hurd
13279Each of the above @code{set thread} commands has a @code{set thread
13280default} counterpart (e.g., @code{set thread default pause}, @code{set
13281thread default exception-port}, etc.). The @code{thread default}
13282variety of commands sets the default thread properties for all
13283threads; you can then change the properties of individual threads with
13284the non-default commands.
13285@end table
13286
13287
a64548ea
EZ
13288@node Neutrino
13289@subsection QNX Neutrino
13290@cindex QNX Neutrino
13291
13292@value{GDBN} provides the following commands specific to the QNX
13293Neutrino target:
13294
13295@table @code
13296@item set debug nto-debug
13297@kindex set debug nto-debug
13298When set to on, enables debugging messages specific to the QNX
13299Neutrino support.
13300
13301@item show debug nto-debug
13302@kindex show debug nto-debug
13303Show the current state of QNX Neutrino messages.
13304@end table
13305
13306
8e04817f
AC
13307@node Embedded OS
13308@section Embedded Operating Systems
104c1213 13309
8e04817f
AC
13310This section describes configurations involving the debugging of
13311embedded operating systems that are available for several different
13312architectures.
d4f3574e 13313
8e04817f
AC
13314@menu
13315* VxWorks:: Using @value{GDBN} with VxWorks
13316@end menu
104c1213 13317
8e04817f
AC
13318@value{GDBN} includes the ability to debug programs running on
13319various real-time operating systems.
104c1213 13320
8e04817f
AC
13321@node VxWorks
13322@subsection Using @value{GDBN} with VxWorks
104c1213 13323
8e04817f 13324@cindex VxWorks
104c1213 13325
8e04817f 13326@table @code
104c1213 13327
8e04817f
AC
13328@kindex target vxworks
13329@item target vxworks @var{machinename}
13330A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13331is the target system's machine name or IP address.
104c1213 13332
8e04817f 13333@end table
104c1213 13334
8e04817f
AC
13335On VxWorks, @code{load} links @var{filename} dynamically on the
13336current target system as well as adding its symbols in @value{GDBN}.
104c1213 13337
8e04817f
AC
13338@value{GDBN} enables developers to spawn and debug tasks running on networked
13339VxWorks targets from a Unix host. Already-running tasks spawned from
13340the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13341both the Unix host and on the VxWorks target. The program
13342@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13343installed with the name @code{vxgdb}, to distinguish it from a
13344@value{GDBN} for debugging programs on the host itself.)
104c1213 13345
8e04817f
AC
13346@table @code
13347@item VxWorks-timeout @var{args}
13348@kindex vxworks-timeout
13349All VxWorks-based targets now support the option @code{vxworks-timeout}.
13350This option is set by the user, and @var{args} represents the number of
13351seconds @value{GDBN} waits for responses to rpc's. You might use this if
13352your VxWorks target is a slow software simulator or is on the far side
13353of a thin network line.
13354@end table
104c1213 13355
8e04817f
AC
13356The following information on connecting to VxWorks was current when
13357this manual was produced; newer releases of VxWorks may use revised
13358procedures.
104c1213 13359
4644b6e3 13360@findex INCLUDE_RDB
8e04817f
AC
13361To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13362to include the remote debugging interface routines in the VxWorks
13363library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13364VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13365kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13366source debugging task @code{tRdbTask} when VxWorks is booted. For more
13367information on configuring and remaking VxWorks, see the manufacturer's
13368manual.
13369@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13370
8e04817f
AC
13371Once you have included @file{rdb.a} in your VxWorks system image and set
13372your Unix execution search path to find @value{GDBN}, you are ready to
13373run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13374@code{vxgdb}, depending on your installation).
104c1213 13375
8e04817f 13376@value{GDBN} comes up showing the prompt:
104c1213 13377
474c8240 13378@smallexample
8e04817f 13379(vxgdb)
474c8240 13380@end smallexample
104c1213 13381
8e04817f
AC
13382@menu
13383* VxWorks Connection:: Connecting to VxWorks
13384* VxWorks Download:: VxWorks download
13385* VxWorks Attach:: Running tasks
13386@end menu
104c1213 13387
8e04817f
AC
13388@node VxWorks Connection
13389@subsubsection Connecting to VxWorks
104c1213 13390
8e04817f
AC
13391The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13392network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13393
474c8240 13394@smallexample
8e04817f 13395(vxgdb) target vxworks tt
474c8240 13396@end smallexample
104c1213 13397
8e04817f
AC
13398@need 750
13399@value{GDBN} displays messages like these:
104c1213 13400
8e04817f
AC
13401@smallexample
13402Attaching remote machine across net...
13403Connected to tt.
13404@end smallexample
104c1213 13405
8e04817f
AC
13406@need 1000
13407@value{GDBN} then attempts to read the symbol tables of any object modules
13408loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13409these files by searching the directories listed in the command search
13410path (@pxref{Environment, ,Your program's environment}); if it fails
13411to find an object file, it displays a message such as:
5d161b24 13412
474c8240 13413@smallexample
8e04817f 13414prog.o: No such file or directory.
474c8240 13415@end smallexample
104c1213 13416
8e04817f
AC
13417When this happens, add the appropriate directory to the search path with
13418the @value{GDBN} command @code{path}, and execute the @code{target}
13419command again.
104c1213 13420
8e04817f
AC
13421@node VxWorks Download
13422@subsubsection VxWorks download
104c1213 13423
8e04817f
AC
13424@cindex download to VxWorks
13425If you have connected to the VxWorks target and you want to debug an
13426object that has not yet been loaded, you can use the @value{GDBN}
13427@code{load} command to download a file from Unix to VxWorks
13428incrementally. The object file given as an argument to the @code{load}
13429command is actually opened twice: first by the VxWorks target in order
13430to download the code, then by @value{GDBN} in order to read the symbol
13431table. This can lead to problems if the current working directories on
13432the two systems differ. If both systems have NFS mounted the same
13433filesystems, you can avoid these problems by using absolute paths.
13434Otherwise, it is simplest to set the working directory on both systems
13435to the directory in which the object file resides, and then to reference
13436the file by its name, without any path. For instance, a program
13437@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13438and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13439program, type this on VxWorks:
104c1213 13440
474c8240 13441@smallexample
8e04817f 13442-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13443@end smallexample
104c1213 13444
8e04817f
AC
13445@noindent
13446Then, in @value{GDBN}, type:
104c1213 13447
474c8240 13448@smallexample
8e04817f
AC
13449(vxgdb) cd @var{hostpath}/vw/demo/rdb
13450(vxgdb) load prog.o
474c8240 13451@end smallexample
104c1213 13452
8e04817f 13453@value{GDBN} displays a response similar to this:
104c1213 13454
8e04817f
AC
13455@smallexample
13456Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13457@end smallexample
104c1213 13458
8e04817f
AC
13459You can also use the @code{load} command to reload an object module
13460after editing and recompiling the corresponding source file. Note that
13461this makes @value{GDBN} delete all currently-defined breakpoints,
13462auto-displays, and convenience variables, and to clear the value
13463history. (This is necessary in order to preserve the integrity of
13464debugger's data structures that reference the target system's symbol
13465table.)
104c1213 13466
8e04817f
AC
13467@node VxWorks Attach
13468@subsubsection Running tasks
104c1213
JM
13469
13470@cindex running VxWorks tasks
13471You can also attach to an existing task using the @code{attach} command as
13472follows:
13473
474c8240 13474@smallexample
104c1213 13475(vxgdb) attach @var{task}
474c8240 13476@end smallexample
104c1213
JM
13477
13478@noindent
13479where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13480or suspended when you attach to it. Running tasks are suspended at
13481the time of attachment.
13482
6d2ebf8b 13483@node Embedded Processors
104c1213
JM
13484@section Embedded Processors
13485
13486This section goes into details specific to particular embedded
13487configurations.
13488
c45da7e6
EZ
13489@cindex send command to simulator
13490Whenever a specific embedded processor has a simulator, @value{GDBN}
13491allows to send an arbitrary command to the simulator.
13492
13493@table @code
13494@item sim @var{command}
13495@kindex sim@r{, a command}
13496Send an arbitrary @var{command} string to the simulator. Consult the
13497documentation for the specific simulator in use for information about
13498acceptable commands.
13499@end table
13500
7d86b5d5 13501
104c1213 13502@menu
c45da7e6 13503* ARM:: ARM RDI
172c2a43
KI
13504* H8/300:: Renesas H8/300
13505* H8/500:: Renesas H8/500
13506* M32R/D:: Renesas M32R/D
104c1213 13507* M68K:: Motorola M68K
104c1213 13508* MIPS Embedded:: MIPS Embedded
a37295f9 13509* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13510* PA:: HP PA Embedded
13511* PowerPC: PowerPC
172c2a43 13512* SH:: Renesas SH
104c1213
JM
13513* Sparclet:: Tsqware Sparclet
13514* Sparclite:: Fujitsu Sparclite
13515* ST2000:: Tandem ST2000
13516* Z8000:: Zilog Z8000
a64548ea
EZ
13517* AVR:: Atmel AVR
13518* CRIS:: CRIS
13519* Super-H:: Renesas Super-H
c45da7e6 13520* WinCE:: Windows CE child processes
104c1213
JM
13521@end menu
13522
6d2ebf8b 13523@node ARM
104c1213 13524@subsection ARM
c45da7e6 13525@cindex ARM RDI
104c1213
JM
13526
13527@table @code
8e04817f
AC
13528@kindex target rdi
13529@item target rdi @var{dev}
13530ARM Angel monitor, via RDI library interface to ADP protocol. You may
13531use this target to communicate with both boards running the Angel
13532monitor, or with the EmbeddedICE JTAG debug device.
13533
13534@kindex target rdp
13535@item target rdp @var{dev}
13536ARM Demon monitor.
13537
13538@end table
13539
e2f4edfd
EZ
13540@value{GDBN} provides the following ARM-specific commands:
13541
13542@table @code
13543@item set arm disassembler
13544@kindex set arm
13545This commands selects from a list of disassembly styles. The
13546@code{"std"} style is the standard style.
13547
13548@item show arm disassembler
13549@kindex show arm
13550Show the current disassembly style.
13551
13552@item set arm apcs32
13553@cindex ARM 32-bit mode
13554This command toggles ARM operation mode between 32-bit and 26-bit.
13555
13556@item show arm apcs32
13557Display the current usage of the ARM 32-bit mode.
13558
13559@item set arm fpu @var{fputype}
13560This command sets the ARM floating-point unit (FPU) type. The
13561argument @var{fputype} can be one of these:
13562
13563@table @code
13564@item auto
13565Determine the FPU type by querying the OS ABI.
13566@item softfpa
13567Software FPU, with mixed-endian doubles on little-endian ARM
13568processors.
13569@item fpa
13570GCC-compiled FPA co-processor.
13571@item softvfp
13572Software FPU with pure-endian doubles.
13573@item vfp
13574VFP co-processor.
13575@end table
13576
13577@item show arm fpu
13578Show the current type of the FPU.
13579
13580@item set arm abi
13581This command forces @value{GDBN} to use the specified ABI.
13582
13583@item show arm abi
13584Show the currently used ABI.
13585
13586@item set debug arm
13587Toggle whether to display ARM-specific debugging messages from the ARM
13588target support subsystem.
13589
13590@item show debug arm
13591Show whether ARM-specific debugging messages are enabled.
13592@end table
13593
c45da7e6
EZ
13594The following commands are available when an ARM target is debugged
13595using the RDI interface:
13596
13597@table @code
13598@item rdilogfile @r{[}@var{file}@r{]}
13599@kindex rdilogfile
13600@cindex ADP (Angel Debugger Protocol) logging
13601Set the filename for the ADP (Angel Debugger Protocol) packet log.
13602With an argument, sets the log file to the specified @var{file}. With
13603no argument, show the current log file name. The default log file is
13604@file{rdi.log}.
13605
13606@item rdilogenable @r{[}@var{arg}@r{]}
13607@kindex rdilogenable
13608Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13609enables logging, with an argument 0 or @code{"no"} disables it. With
13610no arguments displays the current setting. When logging is enabled,
13611ADP packets exchanged between @value{GDBN} and the RDI target device
13612are logged to a file.
13613
13614@item set rdiromatzero
13615@kindex set rdiromatzero
13616@cindex ROM at zero address, RDI
13617Tell @value{GDBN} whether the target has ROM at address 0. If on,
13618vector catching is disabled, so that zero address can be used. If off
13619(the default), vector catching is enabled. For this command to take
13620effect, it needs to be invoked prior to the @code{target rdi} command.
13621
13622@item show rdiromatzero
13623@kindex show rdiromatzero
13624Show the current setting of ROM at zero address.
13625
13626@item set rdiheartbeat
13627@kindex set rdiheartbeat
13628@cindex RDI heartbeat
13629Enable or disable RDI heartbeat packets. It is not recommended to
13630turn on this option, since it confuses ARM and EPI JTAG interface, as
13631well as the Angel monitor.
13632
13633@item show rdiheartbeat
13634@kindex show rdiheartbeat
13635Show the setting of RDI heartbeat packets.
13636@end table
13637
e2f4edfd 13638
8e04817f 13639@node H8/300
172c2a43 13640@subsection Renesas H8/300
8e04817f
AC
13641
13642@table @code
13643
13644@kindex target hms@r{, with H8/300}
13645@item target hms @var{dev}
172c2a43 13646A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13647Use special commands @code{device} and @code{speed} to control the serial
13648line and the communications speed used.
13649
13650@kindex target e7000@r{, with H8/300}
13651@item target e7000 @var{dev}
172c2a43 13652E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13653
13654@kindex target sh3@r{, with H8/300}
13655@kindex target sh3e@r{, with H8/300}
13656@item target sh3 @var{dev}
13657@itemx target sh3e @var{dev}
172c2a43 13658Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13659
13660@end table
13661
13662@cindex download to H8/300 or H8/500
13663@cindex H8/300 or H8/500 download
172c2a43
KI
13664@cindex download to Renesas SH
13665@cindex Renesas SH download
13666When you select remote debugging to a Renesas SH, H8/300, or H8/500
13667board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13668board and also opens it as the current executable target for
13669@value{GDBN} on your host (like the @code{file} command).
13670
13671@value{GDBN} needs to know these things to talk to your
172c2a43 13672Renesas SH, H8/300, or H8/500:
8e04817f
AC
13673
13674@enumerate
13675@item
13676that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13677for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13678emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13679the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13680H8/300, or H8/500.)
13681
13682@item
172c2a43 13683what serial device connects your host to your Renesas board (the first
8e04817f
AC
13684serial device available on your host is the default).
13685
13686@item
13687what speed to use over the serial device.
13688@end enumerate
13689
13690@menu
172c2a43
KI
13691* Renesas Boards:: Connecting to Renesas boards.
13692* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13693* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13694@end menu
13695
172c2a43
KI
13696@node Renesas Boards
13697@subsubsection Connecting to Renesas boards
8e04817f
AC
13698
13699@c only for Unix hosts
13700@kindex device
172c2a43 13701@cindex serial device, Renesas micros
8e04817f
AC
13702Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13703need to explicitly set the serial device. The default @var{port} is the
13704first available port on your host. This is only necessary on Unix
13705hosts, where it is typically something like @file{/dev/ttya}.
13706
13707@kindex speed
172c2a43 13708@cindex serial line speed, Renesas micros
8e04817f
AC
13709@code{@value{GDBN}} has another special command to set the communications
13710speed: @samp{speed @var{bps}}. This command also is only used from Unix
13711hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13712the DOS @code{mode} command (for instance,
13713@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13714
13715The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13716use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13717use a DOS host,
13718@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13719called @code{asynctsr} to communicate with the development board
13720through a PC serial port. You must also use the DOS @code{mode} command
13721to set up the serial port on the DOS side.
13722
13723The following sample session illustrates the steps needed to start a
13724program under @value{GDBN} control on an H8/300. The example uses a
13725sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13726the Renesas SH and the H8/500.
8e04817f
AC
13727
13728First hook up your development board. In this example, we use a
13729board attached to serial port @code{COM2}; if you use a different serial
13730port, substitute its name in the argument of the @code{mode} command.
13731When you call @code{asynctsr}, the auxiliary comms program used by the
13732debugger, you give it just the numeric part of the serial port's name;
13733for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13734@code{COM2}.
13735
474c8240 13736@smallexample
8e04817f
AC
13737C:\H8300\TEST> asynctsr 2
13738C:\H8300\TEST> mode com2:9600,n,8,1,p
13739
13740Resident portion of MODE loaded
13741
13742COM2: 9600, n, 8, 1, p
13743
474c8240 13744@end smallexample
8e04817f
AC
13745
13746@quotation
13747@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13748@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13749disable it, or even boot without it, to use @code{asynctsr} to control
13750your development board.
13751@end quotation
13752
13753@kindex target hms@r{, and serial protocol}
13754Now that serial communications are set up, and the development board is
9c16f35a 13755connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13756the name of your program as the argument. @code{@value{GDBN}} prompts
13757you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13758commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13759cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13760download your program to the board. @code{load} displays the names of
13761the program's sections, and a @samp{*} for each 2K of data downloaded.
13762(If you want to refresh @value{GDBN} data on symbols or on the
13763executable file without downloading, use the @value{GDBN} commands
13764@code{file} or @code{symbol-file}. These commands, and @code{load}
13765itself, are described in @ref{Files,,Commands to specify files}.)
13766
13767@smallexample
13768(eg-C:\H8300\TEST) @value{GDBP} t.x
13769@value{GDBN} is free software and you are welcome to distribute copies
13770 of it under certain conditions; type "show copying" to see
13771 the conditions.
13772There is absolutely no warranty for @value{GDBN}; type "show warranty"
13773for details.
13774@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13775(@value{GDBP}) target hms
13776Connected to remote H8/300 HMS system.
13777(@value{GDBP}) load t.x
13778.text : 0x8000 .. 0xabde ***********
13779.data : 0xabde .. 0xad30 *
13780.stack : 0xf000 .. 0xf014 *
13781@end smallexample
13782
13783At this point, you're ready to run or debug your program. From here on,
13784you can use all the usual @value{GDBN} commands. The @code{break} command
13785sets breakpoints; the @code{run} command starts your program;
13786@code{print} or @code{x} display data; the @code{continue} command
13787resumes execution after stopping at a breakpoint. You can use the
13788@code{help} command at any time to find out more about @value{GDBN} commands.
13789
13790Remember, however, that @emph{operating system} facilities aren't
13791available on your development board; for example, if your program hangs,
13792you can't send an interrupt---but you can press the @sc{reset} switch!
13793
13794Use the @sc{reset} button on the development board
13795@itemize @bullet
13796@item
13797to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13798no way to pass an interrupt signal to the development board); and
13799
13800@item
13801to return to the @value{GDBN} command prompt after your program finishes
13802normally. The communications protocol provides no other way for @value{GDBN}
13803to detect program completion.
13804@end itemize
13805
13806In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13807development board as a ``normal exit'' of your program.
13808
172c2a43 13809@node Renesas ICE
8e04817f
AC
13810@subsubsection Using the E7000 in-circuit emulator
13811
172c2a43 13812@kindex target e7000@r{, with Renesas ICE}
8e04817f 13813You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13814Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13815e7000} command to connect @value{GDBN} to your E7000:
13816
13817@table @code
13818@item target e7000 @var{port} @var{speed}
13819Use this form if your E7000 is connected to a serial port. The
13820@var{port} argument identifies what serial port to use (for example,
13821@samp{com2}). The third argument is the line speed in bits per second
13822(for example, @samp{9600}).
13823
13824@item target e7000 @var{hostname}
13825If your E7000 is installed as a host on a TCP/IP network, you can just
13826specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13827@end table
13828
ba04e063
EZ
13829The following special commands are available when debugging with the
13830Renesas E7000 ICE:
13831
13832@table @code
13833@item e7000 @var{command}
13834@kindex e7000
13835@cindex send command to E7000 monitor
13836This sends the specified @var{command} to the E7000 monitor.
13837
13838@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13839@kindex ftplogin@r{, E7000}
13840This command records information for subsequent interface with the
13841E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13842named @var{machine} using specified @var{username} and @var{password},
13843and then chdir to the named directory @var{dir}.
13844
13845@item ftpload @var{file}
13846@kindex ftpload@r{, E7000}
13847This command uses credentials recorded by @code{ftplogin} to fetch and
13848load the named @var{file} from the E7000 monitor.
13849
13850@item drain
13851@kindex drain@r{, E7000}
13852This command drains any pending text buffers stored on the E7000.
13853
13854@item set usehardbreakpoints
13855@itemx show usehardbreakpoints
13856@kindex set usehardbreakpoints@r{, E7000}
13857@kindex show usehardbreakpoints@r{, E7000}
13858@cindex hardware breakpoints, and E7000
13859These commands set and show the use of hardware breakpoints for all
13860breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13861more information about using hardware breakpoints selectively.
13862@end table
13863
172c2a43
KI
13864@node Renesas Special
13865@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13866
13867Some @value{GDBN} commands are available only for the H8/300:
13868
13869@table @code
13870
13871@kindex set machine
13872@kindex show machine
13873@item set machine h8300
13874@itemx set machine h8300h
13875Condition @value{GDBN} for one of the two variants of the H8/300
13876architecture with @samp{set machine}. You can use @samp{show machine}
13877to check which variant is currently in effect.
104c1213
JM
13878
13879@end table
13880
8e04817f
AC
13881@node H8/500
13882@subsection H8/500
104c1213
JM
13883
13884@table @code
13885
8e04817f
AC
13886@kindex set memory @var{mod}
13887@cindex memory models, H8/500
13888@item set memory @var{mod}
13889@itemx show memory
13890Specify which H8/500 memory model (@var{mod}) you are using with
13891@samp{set memory}; check which memory model is in effect with @samp{show
13892memory}. The accepted values for @var{mod} are @code{small},
13893@code{big}, @code{medium}, and @code{compact}.
104c1213 13894
8e04817f 13895@end table
104c1213 13896
8e04817f 13897@node M32R/D
ba04e063 13898@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13899
13900@table @code
8e04817f
AC
13901@kindex target m32r
13902@item target m32r @var{dev}
172c2a43 13903Renesas M32R/D ROM monitor.
8e04817f 13904
fb3e19c0
KI
13905@kindex target m32rsdi
13906@item target m32rsdi @var{dev}
13907Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13908@end table
13909
13910The following @value{GDBN} commands are specific to the M32R monitor:
13911
13912@table @code
13913@item set download-path @var{path}
13914@kindex set download-path
13915@cindex find downloadable @sc{srec} files (M32R)
13916Set the default path for finding donwloadable @sc{srec} files.
13917
13918@item show download-path
13919@kindex show download-path
13920Show the default path for downloadable @sc{srec} files.
fb3e19c0 13921
721c2651
EZ
13922@item set board-address @var{addr}
13923@kindex set board-address
13924@cindex M32-EVA target board address
13925Set the IP address for the M32R-EVA target board.
13926
13927@item show board-address
13928@kindex show board-address
13929Show the current IP address of the target board.
13930
13931@item set server-address @var{addr}
13932@kindex set server-address
13933@cindex download server address (M32R)
13934Set the IP address for the download server, which is the @value{GDBN}'s
13935host machine.
13936
13937@item show server-address
13938@kindex show server-address
13939Display the IP address of the download server.
13940
13941@item upload @r{[}@var{file}@r{]}
13942@kindex upload@r{, M32R}
13943Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13944upload capability. If no @var{file} argument is given, the current
13945executable file is uploaded.
13946
13947@item tload @r{[}@var{file}@r{]}
13948@kindex tload@r{, M32R}
13949Test the @code{upload} command.
8e04817f
AC
13950@end table
13951
ba04e063
EZ
13952The following commands are available for M32R/SDI:
13953
13954@table @code
13955@item sdireset
13956@kindex sdireset
13957@cindex reset SDI connection, M32R
13958This command resets the SDI connection.
13959
13960@item sdistatus
13961@kindex sdistatus
13962This command shows the SDI connection status.
13963
13964@item debug_chaos
13965@kindex debug_chaos
13966@cindex M32R/Chaos debugging
13967Instructs the remote that M32R/Chaos debugging is to be used.
13968
13969@item use_debug_dma
13970@kindex use_debug_dma
13971Instructs the remote to use the DEBUG_DMA method of accessing memory.
13972
13973@item use_mon_code
13974@kindex use_mon_code
13975Instructs the remote to use the MON_CODE method of accessing memory.
13976
13977@item use_ib_break
13978@kindex use_ib_break
13979Instructs the remote to set breakpoints by IB break.
13980
13981@item use_dbt_break
13982@kindex use_dbt_break
13983Instructs the remote to set breakpoints by DBT.
13984@end table
13985
8e04817f
AC
13986@node M68K
13987@subsection M68k
13988
13989The Motorola m68k configuration includes ColdFire support, and
13990target command for the following ROM monitors.
13991
13992@table @code
13993
13994@kindex target abug
13995@item target abug @var{dev}
13996ABug ROM monitor for M68K.
13997
13998@kindex target cpu32bug
13999@item target cpu32bug @var{dev}
14000CPU32BUG monitor, running on a CPU32 (M68K) board.
14001
14002@kindex target dbug
14003@item target dbug @var{dev}
14004dBUG ROM monitor for Motorola ColdFire.
14005
14006@kindex target est
14007@item target est @var{dev}
14008EST-300 ICE monitor, running on a CPU32 (M68K) board.
14009
14010@kindex target rom68k
14011@item target rom68k @var{dev}
14012ROM 68K monitor, running on an M68K IDP board.
14013
14014@end table
14015
8e04817f
AC
14016@table @code
14017
14018@kindex target rombug
14019@item target rombug @var{dev}
14020ROMBUG ROM monitor for OS/9000.
14021
14022@end table
14023
8e04817f
AC
14024@node MIPS Embedded
14025@subsection MIPS Embedded
14026
14027@cindex MIPS boards
14028@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14029MIPS board attached to a serial line. This is available when
14030you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14031
8e04817f
AC
14032@need 1000
14033Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14034
8e04817f
AC
14035@table @code
14036@item target mips @var{port}
14037@kindex target mips @var{port}
14038To run a program on the board, start up @code{@value{GDBP}} with the
14039name of your program as the argument. To connect to the board, use the
14040command @samp{target mips @var{port}}, where @var{port} is the name of
14041the serial port connected to the board. If the program has not already
14042been downloaded to the board, you may use the @code{load} command to
14043download it. You can then use all the usual @value{GDBN} commands.
104c1213 14044
8e04817f
AC
14045For example, this sequence connects to the target board through a serial
14046port, and loads and runs a program called @var{prog} through the
14047debugger:
104c1213 14048
474c8240 14049@smallexample
8e04817f
AC
14050host$ @value{GDBP} @var{prog}
14051@value{GDBN} is free software and @dots{}
14052(@value{GDBP}) target mips /dev/ttyb
14053(@value{GDBP}) load @var{prog}
14054(@value{GDBP}) run
474c8240 14055@end smallexample
104c1213 14056
8e04817f
AC
14057@item target mips @var{hostname}:@var{portnumber}
14058On some @value{GDBN} host configurations, you can specify a TCP
14059connection (for instance, to a serial line managed by a terminal
14060concentrator) instead of a serial port, using the syntax
14061@samp{@var{hostname}:@var{portnumber}}.
104c1213 14062
8e04817f
AC
14063@item target pmon @var{port}
14064@kindex target pmon @var{port}
14065PMON ROM monitor.
104c1213 14066
8e04817f
AC
14067@item target ddb @var{port}
14068@kindex target ddb @var{port}
14069NEC's DDB variant of PMON for Vr4300.
104c1213 14070
8e04817f
AC
14071@item target lsi @var{port}
14072@kindex target lsi @var{port}
14073LSI variant of PMON.
104c1213 14074
8e04817f
AC
14075@kindex target r3900
14076@item target r3900 @var{dev}
14077Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14078
8e04817f
AC
14079@kindex target array
14080@item target array @var{dev}
14081Array Tech LSI33K RAID controller board.
104c1213 14082
8e04817f 14083@end table
104c1213 14084
104c1213 14085
8e04817f
AC
14086@noindent
14087@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14088
8e04817f 14089@table @code
8e04817f
AC
14090@item set mipsfpu double
14091@itemx set mipsfpu single
14092@itemx set mipsfpu none
a64548ea 14093@itemx set mipsfpu auto
8e04817f
AC
14094@itemx show mipsfpu
14095@kindex set mipsfpu
14096@kindex show mipsfpu
14097@cindex MIPS remote floating point
14098@cindex floating point, MIPS remote
14099If your target board does not support the MIPS floating point
14100coprocessor, you should use the command @samp{set mipsfpu none} (if you
14101need this, you may wish to put the command in your @value{GDBN} init
14102file). This tells @value{GDBN} how to find the return value of
14103functions which return floating point values. It also allows
14104@value{GDBN} to avoid saving the floating point registers when calling
14105functions on the board. If you are using a floating point coprocessor
14106with only single precision floating point support, as on the @sc{r4650}
14107processor, use the command @samp{set mipsfpu single}. The default
14108double precision floating point coprocessor may be selected using
14109@samp{set mipsfpu double}.
104c1213 14110
8e04817f
AC
14111In previous versions the only choices were double precision or no
14112floating point, so @samp{set mipsfpu on} will select double precision
14113and @samp{set mipsfpu off} will select no floating point.
104c1213 14114
8e04817f
AC
14115As usual, you can inquire about the @code{mipsfpu} variable with
14116@samp{show mipsfpu}.
104c1213 14117
8e04817f
AC
14118@item set timeout @var{seconds}
14119@itemx set retransmit-timeout @var{seconds}
14120@itemx show timeout
14121@itemx show retransmit-timeout
14122@cindex @code{timeout}, MIPS protocol
14123@cindex @code{retransmit-timeout}, MIPS protocol
14124@kindex set timeout
14125@kindex show timeout
14126@kindex set retransmit-timeout
14127@kindex show retransmit-timeout
14128You can control the timeout used while waiting for a packet, in the MIPS
14129remote protocol, with the @code{set timeout @var{seconds}} command. The
14130default is 5 seconds. Similarly, you can control the timeout used while
14131waiting for an acknowledgement of a packet with the @code{set
14132retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14133You can inspect both values with @code{show timeout} and @code{show
14134retransmit-timeout}. (These commands are @emph{only} available when
14135@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14136
8e04817f
AC
14137The timeout set by @code{set timeout} does not apply when @value{GDBN}
14138is waiting for your program to stop. In that case, @value{GDBN} waits
14139forever because it has no way of knowing how long the program is going
14140to run before stopping.
ba04e063
EZ
14141
14142@item set syn-garbage-limit @var{num}
14143@kindex set syn-garbage-limit@r{, MIPS remote}
14144@cindex synchronize with remote MIPS target
14145Limit the maximum number of characters @value{GDBN} should ignore when
14146it tries to synchronize with the remote target. The default is 10
14147characters. Setting the limit to -1 means there's no limit.
14148
14149@item show syn-garbage-limit
14150@kindex show syn-garbage-limit@r{, MIPS remote}
14151Show the current limit on the number of characters to ignore when
14152trying to synchronize with the remote system.
14153
14154@item set monitor-prompt @var{prompt}
14155@kindex set monitor-prompt@r{, MIPS remote}
14156@cindex remote monitor prompt
14157Tell @value{GDBN} to expect the specified @var{prompt} string from the
14158remote monitor. The default depends on the target:
14159@table @asis
14160@item pmon target
14161@samp{PMON}
14162@item ddb target
14163@samp{NEC010}
14164@item lsi target
14165@samp{PMON>}
14166@end table
14167
14168@item show monitor-prompt
14169@kindex show monitor-prompt@r{, MIPS remote}
14170Show the current strings @value{GDBN} expects as the prompt from the
14171remote monitor.
14172
14173@item set monitor-warnings
14174@kindex set monitor-warnings@r{, MIPS remote}
14175Enable or disable monitor warnings about hardware breakpoints. This
14176has effect only for the @code{lsi} target. When on, @value{GDBN} will
14177display warning messages whose codes are returned by the @code{lsi}
14178PMON monitor for breakpoint commands.
14179
14180@item show monitor-warnings
14181@kindex show monitor-warnings@r{, MIPS remote}
14182Show the current setting of printing monitor warnings.
14183
14184@item pmon @var{command}
14185@kindex pmon@r{, MIPS remote}
14186@cindex send PMON command
14187This command allows sending an arbitrary @var{command} string to the
14188monitor. The monitor must be in debug mode for this to work.
8e04817f 14189@end table
104c1213 14190
a37295f9
MM
14191@node OpenRISC 1000
14192@subsection OpenRISC 1000
14193@cindex OpenRISC 1000
14194
14195@cindex or1k boards
14196See OR1k Architecture document (@uref{www.opencores.org}) for more information
14197about platform and commands.
14198
14199@table @code
14200
14201@kindex target jtag
14202@item target jtag jtag://@var{host}:@var{port}
14203
14204Connects to remote JTAG server.
14205JTAG remote server can be either an or1ksim or JTAG server,
14206connected via parallel port to the board.
14207
14208Example: @code{target jtag jtag://localhost:9999}
14209
14210@kindex or1ksim
14211@item or1ksim @var{command}
14212If connected to @code{or1ksim} OpenRISC 1000 Architectural
14213Simulator, proprietary commands can be executed.
14214
14215@kindex info or1k spr
14216@item info or1k spr
14217Displays spr groups.
14218
14219@item info or1k spr @var{group}
14220@itemx info or1k spr @var{groupno}
14221Displays register names in selected group.
14222
14223@item info or1k spr @var{group} @var{register}
14224@itemx info or1k spr @var{register}
14225@itemx info or1k spr @var{groupno} @var{registerno}
14226@itemx info or1k spr @var{registerno}
14227Shows information about specified spr register.
14228
14229@kindex spr
14230@item spr @var{group} @var{register} @var{value}
14231@itemx spr @var{register @var{value}}
14232@itemx spr @var{groupno} @var{registerno @var{value}}
14233@itemx spr @var{registerno @var{value}}
14234Writes @var{value} to specified spr register.
14235@end table
14236
14237Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14238It is very similar to @value{GDBN} trace, except it does not interfere with normal
14239program execution and is thus much faster. Hardware breakpoints/watchpoint
14240triggers can be set using:
14241@table @code
14242@item $LEA/$LDATA
14243Load effective address/data
14244@item $SEA/$SDATA
14245Store effective address/data
14246@item $AEA/$ADATA
14247Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14248@item $FETCH
14249Fetch data
14250@end table
14251
14252When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14253@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14254
14255@code{htrace} commands:
14256@cindex OpenRISC 1000 htrace
14257@table @code
14258@kindex hwatch
14259@item hwatch @var{conditional}
14260Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14261or Data. For example:
14262
14263@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14264
14265@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14266
4644b6e3 14267@kindex htrace
a37295f9
MM
14268@item htrace info
14269Display information about current HW trace configuration.
14270
a37295f9
MM
14271@item htrace trigger @var{conditional}
14272Set starting criteria for HW trace.
14273
a37295f9
MM
14274@item htrace qualifier @var{conditional}
14275Set acquisition qualifier for HW trace.
14276
a37295f9
MM
14277@item htrace stop @var{conditional}
14278Set HW trace stopping criteria.
14279
f153cc92 14280@item htrace record [@var{data}]*
a37295f9
MM
14281Selects the data to be recorded, when qualifier is met and HW trace was
14282triggered.
14283
a37295f9 14284@item htrace enable
a37295f9
MM
14285@itemx htrace disable
14286Enables/disables the HW trace.
14287
f153cc92 14288@item htrace rewind [@var{filename}]
a37295f9
MM
14289Clears currently recorded trace data.
14290
14291If filename is specified, new trace file is made and any newly collected data
14292will be written there.
14293
f153cc92 14294@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14295Prints trace buffer, using current record configuration.
14296
a37295f9
MM
14297@item htrace mode continuous
14298Set continuous trace mode.
14299
a37295f9
MM
14300@item htrace mode suspend
14301Set suspend trace mode.
14302
14303@end table
14304
8e04817f
AC
14305@node PowerPC
14306@subsection PowerPC
104c1213
JM
14307
14308@table @code
8e04817f
AC
14309@kindex target dink32
14310@item target dink32 @var{dev}
14311DINK32 ROM monitor.
104c1213 14312
8e04817f
AC
14313@kindex target ppcbug
14314@item target ppcbug @var{dev}
14315@kindex target ppcbug1
14316@item target ppcbug1 @var{dev}
14317PPCBUG ROM monitor for PowerPC.
104c1213 14318
8e04817f
AC
14319@kindex target sds
14320@item target sds @var{dev}
14321SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14322@end table
8e04817f 14323
c45da7e6
EZ
14324@cindex SDS protocol
14325The following commands specifi to the SDS protocol are supported
14326by@value{GDBN}:
14327
14328@table @code
14329@item set sdstimeout @var{nsec}
14330@kindex set sdstimeout
14331Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14332default is 2 seconds.
14333
14334@item show sdstimeout
14335@kindex show sdstimeout
14336Show the current value of the SDS timeout.
14337
14338@item sds @var{command}
14339@kindex sds@r{, a command}
14340Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14341@end table
14342
c45da7e6 14343
8e04817f
AC
14344@node PA
14345@subsection HP PA Embedded
104c1213
JM
14346
14347@table @code
14348
8e04817f
AC
14349@kindex target op50n
14350@item target op50n @var{dev}
14351OP50N monitor, running on an OKI HPPA board.
14352
14353@kindex target w89k
14354@item target w89k @var{dev}
14355W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14356
14357@end table
14358
8e04817f 14359@node SH
172c2a43 14360@subsection Renesas SH
104c1213
JM
14361
14362@table @code
14363
172c2a43 14364@kindex target hms@r{, with Renesas SH}
8e04817f 14365@item target hms @var{dev}
172c2a43 14366A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14367commands @code{device} and @code{speed} to control the serial line and
14368the communications speed used.
104c1213 14369
172c2a43 14370@kindex target e7000@r{, with Renesas SH}
8e04817f 14371@item target e7000 @var{dev}
172c2a43 14372E7000 emulator for Renesas SH.
104c1213 14373
8e04817f
AC
14374@kindex target sh3@r{, with SH}
14375@kindex target sh3e@r{, with SH}
14376@item target sh3 @var{dev}
14377@item target sh3e @var{dev}
172c2a43 14378Renesas SH-3 and SH-3E target systems.
104c1213 14379
8e04817f 14380@end table
104c1213 14381
8e04817f
AC
14382@node Sparclet
14383@subsection Tsqware Sparclet
104c1213 14384
8e04817f
AC
14385@cindex Sparclet
14386
14387@value{GDBN} enables developers to debug tasks running on
14388Sparclet targets from a Unix host.
14389@value{GDBN} uses code that runs on
14390both the Unix host and on the Sparclet target. The program
14391@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14392
8e04817f
AC
14393@table @code
14394@item remotetimeout @var{args}
14395@kindex remotetimeout
14396@value{GDBN} supports the option @code{remotetimeout}.
14397This option is set by the user, and @var{args} represents the number of
14398seconds @value{GDBN} waits for responses.
104c1213
JM
14399@end table
14400
8e04817f
AC
14401@cindex compiling, on Sparclet
14402When compiling for debugging, include the options @samp{-g} to get debug
14403information and @samp{-Ttext} to relocate the program to where you wish to
14404load it on the target. You may also want to add the options @samp{-n} or
14405@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14406
474c8240 14407@smallexample
8e04817f 14408sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14409@end smallexample
104c1213 14410
8e04817f 14411You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14412
474c8240 14413@smallexample
8e04817f 14414sparclet-aout-objdump --headers --syms prog
474c8240 14415@end smallexample
104c1213 14416
8e04817f
AC
14417@cindex running, on Sparclet
14418Once you have set
14419your Unix execution search path to find @value{GDBN}, you are ready to
14420run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14421(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14422
8e04817f
AC
14423@value{GDBN} comes up showing the prompt:
14424
474c8240 14425@smallexample
8e04817f 14426(gdbslet)
474c8240 14427@end smallexample
104c1213
JM
14428
14429@menu
8e04817f
AC
14430* Sparclet File:: Setting the file to debug
14431* Sparclet Connection:: Connecting to Sparclet
14432* Sparclet Download:: Sparclet download
14433* Sparclet Execution:: Running and debugging
104c1213
JM
14434@end menu
14435
8e04817f
AC
14436@node Sparclet File
14437@subsubsection Setting file to debug
104c1213 14438
8e04817f 14439The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14440
474c8240 14441@smallexample
8e04817f 14442(gdbslet) file prog
474c8240 14443@end smallexample
104c1213 14444
8e04817f
AC
14445@need 1000
14446@value{GDBN} then attempts to read the symbol table of @file{prog}.
14447@value{GDBN} locates
14448the file by searching the directories listed in the command search
14449path.
14450If the file was compiled with debug information (option "-g"), source
14451files will be searched as well.
14452@value{GDBN} locates
14453the source files by searching the directories listed in the directory search
14454path (@pxref{Environment, ,Your program's environment}).
14455If it fails
14456to find a file, it displays a message such as:
104c1213 14457
474c8240 14458@smallexample
8e04817f 14459prog: No such file or directory.
474c8240 14460@end smallexample
104c1213 14461
8e04817f
AC
14462When this happens, add the appropriate directories to the search paths with
14463the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14464@code{target} command again.
104c1213 14465
8e04817f
AC
14466@node Sparclet Connection
14467@subsubsection Connecting to Sparclet
104c1213 14468
8e04817f
AC
14469The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14470To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14471
474c8240 14472@smallexample
8e04817f
AC
14473(gdbslet) target sparclet /dev/ttya
14474Remote target sparclet connected to /dev/ttya
14475main () at ../prog.c:3
474c8240 14476@end smallexample
104c1213 14477
8e04817f
AC
14478@need 750
14479@value{GDBN} displays messages like these:
104c1213 14480
474c8240 14481@smallexample
8e04817f 14482Connected to ttya.
474c8240 14483@end smallexample
104c1213 14484
8e04817f
AC
14485@node Sparclet Download
14486@subsubsection Sparclet download
104c1213 14487
8e04817f
AC
14488@cindex download to Sparclet
14489Once connected to the Sparclet target,
14490you can use the @value{GDBN}
14491@code{load} command to download the file from the host to the target.
14492The file name and load offset should be given as arguments to the @code{load}
14493command.
14494Since the file format is aout, the program must be loaded to the starting
14495address. You can use @code{objdump} to find out what this value is. The load
14496offset is an offset which is added to the VMA (virtual memory address)
14497of each of the file's sections.
14498For instance, if the program
14499@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14500and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14501
474c8240 14502@smallexample
8e04817f
AC
14503(gdbslet) load prog 0x12010000
14504Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14505@end smallexample
104c1213 14506
8e04817f
AC
14507If the code is loaded at a different address then what the program was linked
14508to, you may need to use the @code{section} and @code{add-symbol-file} commands
14509to tell @value{GDBN} where to map the symbol table.
14510
14511@node Sparclet Execution
14512@subsubsection Running and debugging
14513
14514@cindex running and debugging Sparclet programs
14515You can now begin debugging the task using @value{GDBN}'s execution control
14516commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14517manual for the list of commands.
14518
474c8240 14519@smallexample
8e04817f
AC
14520(gdbslet) b main
14521Breakpoint 1 at 0x12010000: file prog.c, line 3.
14522(gdbslet) run
14523Starting program: prog
14524Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145253 char *symarg = 0;
14526(gdbslet) step
145274 char *execarg = "hello!";
14528(gdbslet)
474c8240 14529@end smallexample
8e04817f
AC
14530
14531@node Sparclite
14532@subsection Fujitsu Sparclite
104c1213
JM
14533
14534@table @code
14535
8e04817f
AC
14536@kindex target sparclite
14537@item target sparclite @var{dev}
14538Fujitsu sparclite boards, used only for the purpose of loading.
14539You must use an additional command to debug the program.
14540For example: target remote @var{dev} using @value{GDBN} standard
14541remote protocol.
104c1213
JM
14542
14543@end table
14544
8e04817f
AC
14545@node ST2000
14546@subsection Tandem ST2000
104c1213 14547
8e04817f
AC
14548@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14549STDBUG protocol.
104c1213 14550
8e04817f
AC
14551To connect your ST2000 to the host system, see the manufacturer's
14552manual. Once the ST2000 is physically attached, you can run:
104c1213 14553
474c8240 14554@smallexample
8e04817f 14555target st2000 @var{dev} @var{speed}
474c8240 14556@end smallexample
104c1213 14557
8e04817f
AC
14558@noindent
14559to establish it as your debugging environment. @var{dev} is normally
14560the name of a serial device, such as @file{/dev/ttya}, connected to the
14561ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14562connection (for example, to a serial line attached via a terminal
14563concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14564
8e04817f
AC
14565The @code{load} and @code{attach} commands are @emph{not} defined for
14566this target; you must load your program into the ST2000 as you normally
14567would for standalone operation. @value{GDBN} reads debugging information
14568(such as symbols) from a separate, debugging version of the program
14569available on your host computer.
14570@c FIXME!! This is terribly vague; what little content is here is
14571@c basically hearsay.
104c1213 14572
8e04817f
AC
14573@cindex ST2000 auxiliary commands
14574These auxiliary @value{GDBN} commands are available to help you with the ST2000
14575environment:
104c1213 14576
8e04817f
AC
14577@table @code
14578@item st2000 @var{command}
14579@kindex st2000 @var{cmd}
14580@cindex STDBUG commands (ST2000)
14581@cindex commands to STDBUG (ST2000)
14582Send a @var{command} to the STDBUG monitor. See the manufacturer's
14583manual for available commands.
104c1213 14584
8e04817f
AC
14585@item connect
14586@cindex connect (to STDBUG)
14587Connect the controlling terminal to the STDBUG command monitor. When
14588you are done interacting with STDBUG, typing either of two character
14589sequences gets you back to the @value{GDBN} command prompt:
14590@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14591@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14592@end table
14593
8e04817f
AC
14594@node Z8000
14595@subsection Zilog Z8000
104c1213 14596
8e04817f
AC
14597@cindex Z8000
14598@cindex simulator, Z8000
14599@cindex Zilog Z8000 simulator
104c1213 14600
8e04817f
AC
14601When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14602a Z8000 simulator.
14603
14604For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14605unsegmented variant of the Z8000 architecture) or the Z8001 (the
14606segmented variant). The simulator recognizes which architecture is
14607appropriate by inspecting the object code.
104c1213 14608
8e04817f
AC
14609@table @code
14610@item target sim @var{args}
14611@kindex sim
14612@kindex target sim@r{, with Z8000}
14613Debug programs on a simulated CPU. If the simulator supports setup
14614options, specify them via @var{args}.
104c1213
JM
14615@end table
14616
8e04817f
AC
14617@noindent
14618After specifying this target, you can debug programs for the simulated
14619CPU in the same style as programs for your host computer; use the
14620@code{file} command to load a new program image, the @code{run} command
14621to run your program, and so on.
14622
14623As well as making available all the usual machine registers
14624(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14625additional items of information as specially named registers:
104c1213
JM
14626
14627@table @code
14628
8e04817f
AC
14629@item cycles
14630Counts clock-ticks in the simulator.
104c1213 14631
8e04817f
AC
14632@item insts
14633Counts instructions run in the simulator.
104c1213 14634
8e04817f
AC
14635@item time
14636Execution time in 60ths of a second.
104c1213 14637
8e04817f 14638@end table
104c1213 14639
8e04817f
AC
14640You can refer to these values in @value{GDBN} expressions with the usual
14641conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14642conditional breakpoint that suspends only after at least 5000
14643simulated clock ticks.
104c1213 14644
a64548ea
EZ
14645@node AVR
14646@subsection Atmel AVR
14647@cindex AVR
14648
14649When configured for debugging the Atmel AVR, @value{GDBN} supports the
14650following AVR-specific commands:
14651
14652@table @code
14653@item info io_registers
14654@kindex info io_registers@r{, AVR}
14655@cindex I/O registers (Atmel AVR)
14656This command displays information about the AVR I/O registers. For
14657each register, @value{GDBN} prints its number and value.
14658@end table
14659
14660@node CRIS
14661@subsection CRIS
14662@cindex CRIS
14663
14664When configured for debugging CRIS, @value{GDBN} provides the
14665following CRIS-specific commands:
14666
14667@table @code
14668@item set cris-version @var{ver}
14669@cindex CRIS version
e22e55c9
OF
14670Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14671The CRIS version affects register names and sizes. This command is useful in
14672case autodetection of the CRIS version fails.
a64548ea
EZ
14673
14674@item show cris-version
14675Show the current CRIS version.
14676
14677@item set cris-dwarf2-cfi
14678@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14679Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14680Change to @samp{off} when using @code{gcc-cris} whose version is below
14681@code{R59}.
a64548ea
EZ
14682
14683@item show cris-dwarf2-cfi
14684Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14685
14686@item set cris-mode @var{mode}
14687@cindex CRIS mode
14688Set the current CRIS mode to @var{mode}. It should only be changed when
14689debugging in guru mode, in which case it should be set to
14690@samp{guru} (the default is @samp{normal}).
14691
14692@item show cris-mode
14693Show the current CRIS mode.
a64548ea
EZ
14694@end table
14695
14696@node Super-H
14697@subsection Renesas Super-H
14698@cindex Super-H
14699
14700For the Renesas Super-H processor, @value{GDBN} provides these
14701commands:
14702
14703@table @code
14704@item regs
14705@kindex regs@r{, Super-H}
14706Show the values of all Super-H registers.
14707@end table
14708
c45da7e6
EZ
14709@node WinCE
14710@subsection Windows CE
14711@cindex Windows CE
14712
14713The following commands are available for Windows CE:
14714
14715@table @code
14716@item set remotedirectory @var{dir}
14717@kindex set remotedirectory
14718Tell @value{GDBN} to upload files from the named directory @var{dir}.
14719The default is @file{/gdb}, i.e.@: the root directory on the current
14720drive.
14721
14722@item show remotedirectory
14723@kindex show remotedirectory
14724Show the current value of the upload directory.
14725
14726@item set remoteupload @var{method}
14727@kindex set remoteupload
14728Set the method used to upload files to remote device. Valid values
14729for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14730The default is @samp{newer}.
14731
14732@item show remoteupload
14733@kindex show remoteupload
14734Show the current setting of the upload method.
14735
14736@item set remoteaddhost
14737@kindex set remoteaddhost
14738Tell @value{GDBN} whether to add this host to the remote stub's
14739arguments when you debug over a network.
14740
14741@item show remoteaddhost
14742@kindex show remoteaddhost
14743Show whether to add this host to remote stub's arguments when
14744debugging over a network.
14745@end table
14746
a64548ea 14747
8e04817f
AC
14748@node Architectures
14749@section Architectures
104c1213 14750
8e04817f
AC
14751This section describes characteristics of architectures that affect
14752all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14753
8e04817f 14754@menu
9c16f35a 14755* i386::
8e04817f
AC
14756* A29K::
14757* Alpha::
14758* MIPS::
a64548ea 14759* HPPA:: HP PA architecture
8e04817f 14760@end menu
104c1213 14761
9c16f35a
EZ
14762@node i386
14763@subsection x86 Architecture-specific issues.
14764
14765@table @code
14766@item set struct-convention @var{mode}
14767@kindex set struct-convention
14768@cindex struct return convention
14769@cindex struct/union returned in registers
14770Set the convention used by the inferior to return @code{struct}s and
14771@code{union}s from functions to @var{mode}. Possible values of
14772@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14773default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14774are returned on the stack, while @code{"reg"} means that a
14775@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14776be returned in a register.
14777
14778@item show struct-convention
14779@kindex show struct-convention
14780Show the current setting of the convention to return @code{struct}s
14781from functions.
14782@end table
14783
8e04817f
AC
14784@node A29K
14785@subsection A29K
104c1213
JM
14786
14787@table @code
104c1213 14788
8e04817f
AC
14789@kindex set rstack_high_address
14790@cindex AMD 29K register stack
14791@cindex register stack, AMD29K
14792@item set rstack_high_address @var{address}
14793On AMD 29000 family processors, registers are saved in a separate
14794@dfn{register stack}. There is no way for @value{GDBN} to determine the
14795extent of this stack. Normally, @value{GDBN} just assumes that the
14796stack is ``large enough''. This may result in @value{GDBN} referencing
14797memory locations that do not exist. If necessary, you can get around
14798this problem by specifying the ending address of the register stack with
14799the @code{set rstack_high_address} command. The argument should be an
14800address, which you probably want to precede with @samp{0x} to specify in
14801hexadecimal.
104c1213 14802
8e04817f
AC
14803@kindex show rstack_high_address
14804@item show rstack_high_address
14805Display the current limit of the register stack, on AMD 29000 family
14806processors.
104c1213 14807
8e04817f 14808@end table
104c1213 14809
8e04817f
AC
14810@node Alpha
14811@subsection Alpha
104c1213 14812
8e04817f 14813See the following section.
104c1213 14814
8e04817f
AC
14815@node MIPS
14816@subsection MIPS
104c1213 14817
8e04817f
AC
14818@cindex stack on Alpha
14819@cindex stack on MIPS
14820@cindex Alpha stack
14821@cindex MIPS stack
14822Alpha- and MIPS-based computers use an unusual stack frame, which
14823sometimes requires @value{GDBN} to search backward in the object code to
14824find the beginning of a function.
104c1213 14825
8e04817f
AC
14826@cindex response time, MIPS debugging
14827To improve response time (especially for embedded applications, where
14828@value{GDBN} may be restricted to a slow serial line for this search)
14829you may want to limit the size of this search, using one of these
14830commands:
104c1213 14831
8e04817f
AC
14832@table @code
14833@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14834@item set heuristic-fence-post @var{limit}
14835Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14836search for the beginning of a function. A value of @var{0} (the
14837default) means there is no limit. However, except for @var{0}, the
14838larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14839and therefore the longer it takes to run. You should only need to use
14840this command when debugging a stripped executable.
104c1213 14841
8e04817f
AC
14842@item show heuristic-fence-post
14843Display the current limit.
14844@end table
104c1213
JM
14845
14846@noindent
8e04817f
AC
14847These commands are available @emph{only} when @value{GDBN} is configured
14848for debugging programs on Alpha or MIPS processors.
104c1213 14849
a64548ea
EZ
14850Several MIPS-specific commands are available when debugging MIPS
14851programs:
14852
14853@table @code
14854@item set mips saved-gpreg-size @var{size}
14855@kindex set mips saved-gpreg-size
14856@cindex MIPS GP register size on stack
14857Set the size of MIPS general-purpose registers saved on the stack.
14858The argument @var{size} can be one of the following:
14859
14860@table @samp
14861@item 32
1486232-bit GP registers
14863@item 64
1486464-bit GP registers
14865@item auto
14866Use the target's default setting or autodetect the saved size from the
14867information contained in the executable. This is the default
14868@end table
14869
14870@item show mips saved-gpreg-size
14871@kindex show mips saved-gpreg-size
14872Show the current size of MIPS GP registers on the stack.
14873
14874@item set mips stack-arg-size @var{size}
14875@kindex set mips stack-arg-size
14876@cindex MIPS stack space for arguments
14877Set the amount of stack space reserved for arguments to functions.
14878The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14879(the default).
14880
14881@item set mips abi @var{arg}
14882@kindex set mips abi
14883@cindex set ABI for MIPS
14884Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14885values of @var{arg} are:
14886
14887@table @samp
14888@item auto
14889The default ABI associated with the current binary (this is the
14890default).
14891@item o32
14892@item o64
14893@item n32
14894@item n64
14895@item eabi32
14896@item eabi64
14897@item auto
14898@end table
14899
14900@item show mips abi
14901@kindex show mips abi
14902Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14903
14904@item set mipsfpu
14905@itemx show mipsfpu
14906@xref{MIPS Embedded, set mipsfpu}.
14907
14908@item set mips mask-address @var{arg}
14909@kindex set mips mask-address
14910@cindex MIPS addresses, masking
14911This command determines whether the most-significant 32 bits of 64-bit
14912MIPS addresses are masked off. The argument @var{arg} can be
14913@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14914setting, which lets @value{GDBN} determine the correct value.
14915
14916@item show mips mask-address
14917@kindex show mips mask-address
14918Show whether the upper 32 bits of MIPS addresses are masked off or
14919not.
14920
14921@item set remote-mips64-transfers-32bit-regs
14922@kindex set remote-mips64-transfers-32bit-regs
14923This command controls compatibility with 64-bit MIPS targets that
14924transfer data in 32-bit quantities. If you have an old MIPS 64 target
14925that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14926and 64 bits for other registers, set this option to @samp{on}.
14927
14928@item show remote-mips64-transfers-32bit-regs
14929@kindex show remote-mips64-transfers-32bit-regs
14930Show the current setting of compatibility with older MIPS 64 targets.
14931
14932@item set debug mips
14933@kindex set debug mips
14934This command turns on and off debugging messages for the MIPS-specific
14935target code in @value{GDBN}.
14936
14937@item show debug mips
14938@kindex show debug mips
14939Show the current setting of MIPS debugging messages.
14940@end table
14941
14942
14943@node HPPA
14944@subsection HPPA
14945@cindex HPPA support
14946
14947When @value{GDBN} is debugging te HP PA architecture, it provides the
14948following special commands:
14949
14950@table @code
14951@item set debug hppa
14952@kindex set debug hppa
14953THis command determines whether HPPA architecture specific debugging
14954messages are to be displayed.
14955
14956@item show debug hppa
14957Show whether HPPA debugging messages are displayed.
14958
14959@item maint print unwind @var{address}
14960@kindex maint print unwind@r{, HPPA}
14961This command displays the contents of the unwind table entry at the
14962given @var{address}.
14963
14964@end table
14965
104c1213 14966
8e04817f
AC
14967@node Controlling GDB
14968@chapter Controlling @value{GDBN}
14969
14970You can alter the way @value{GDBN} interacts with you by using the
14971@code{set} command. For commands controlling how @value{GDBN} displays
14972data, see @ref{Print Settings, ,Print settings}. Other settings are
14973described here.
14974
14975@menu
14976* Prompt:: Prompt
14977* Editing:: Command editing
14978* History:: Command history
14979* Screen Size:: Screen size
14980* Numbers:: Numbers
1e698235 14981* ABI:: Configuring the current ABI
8e04817f
AC
14982* Messages/Warnings:: Optional warnings and messages
14983* Debugging Output:: Optional messages about internal happenings
14984@end menu
14985
14986@node Prompt
14987@section Prompt
104c1213 14988
8e04817f 14989@cindex prompt
104c1213 14990
8e04817f
AC
14991@value{GDBN} indicates its readiness to read a command by printing a string
14992called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
14993can change the prompt string with the @code{set prompt} command. For
14994instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
14995the prompt in one of the @value{GDBN} sessions so that you can always tell
14996which one you are talking to.
104c1213 14997
8e04817f
AC
14998@emph{Note:} @code{set prompt} does not add a space for you after the
14999prompt you set. This allows you to set a prompt which ends in a space
15000or a prompt that does not.
104c1213 15001
8e04817f
AC
15002@table @code
15003@kindex set prompt
15004@item set prompt @var{newprompt}
15005Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15006
8e04817f
AC
15007@kindex show prompt
15008@item show prompt
15009Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15010@end table
15011
8e04817f
AC
15012@node Editing
15013@section Command editing
15014@cindex readline
15015@cindex command line editing
104c1213 15016
703663ab 15017@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15018@sc{gnu} library provides consistent behavior for programs which provide a
15019command line interface to the user. Advantages are @sc{gnu} Emacs-style
15020or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15021substitution, and a storage and recall of command history across
15022debugging sessions.
104c1213 15023
8e04817f
AC
15024You may control the behavior of command line editing in @value{GDBN} with the
15025command @code{set}.
104c1213 15026
8e04817f
AC
15027@table @code
15028@kindex set editing
15029@cindex editing
15030@item set editing
15031@itemx set editing on
15032Enable command line editing (enabled by default).
104c1213 15033
8e04817f
AC
15034@item set editing off
15035Disable command line editing.
104c1213 15036
8e04817f
AC
15037@kindex show editing
15038@item show editing
15039Show whether command line editing is enabled.
104c1213
JM
15040@end table
15041
703663ab
EZ
15042@xref{Command Line Editing}, for more details about the Readline
15043interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15044encouraged to read that chapter.
15045
8e04817f
AC
15046@node History
15047@section Command history
703663ab 15048@cindex command history
8e04817f
AC
15049
15050@value{GDBN} can keep track of the commands you type during your
15051debugging sessions, so that you can be certain of precisely what
15052happened. Use these commands to manage the @value{GDBN} command
15053history facility.
104c1213 15054
703663ab
EZ
15055@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15056package, to provide the history facility. @xref{Using History
15057Interactively}, for the detailed description of the History library.
15058
15059Here is the description of @value{GDBN} commands related to command
15060history.
15061
104c1213 15062@table @code
8e04817f
AC
15063@cindex history substitution
15064@cindex history file
15065@kindex set history filename
4644b6e3 15066@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15067@item set history filename @var{fname}
15068Set the name of the @value{GDBN} command history file to @var{fname}.
15069This is the file where @value{GDBN} reads an initial command history
15070list, and where it writes the command history from this session when it
15071exits. You can access this list through history expansion or through
15072the history command editing characters listed below. This file defaults
15073to the value of the environment variable @code{GDBHISTFILE}, or to
15074@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15075is not set.
104c1213 15076
9c16f35a
EZ
15077@cindex save command history
15078@kindex set history save
8e04817f
AC
15079@item set history save
15080@itemx set history save on
15081Record command history in a file, whose name may be specified with the
15082@code{set history filename} command. By default, this option is disabled.
104c1213 15083
8e04817f
AC
15084@item set history save off
15085Stop recording command history in a file.
104c1213 15086
8e04817f 15087@cindex history size
9c16f35a 15088@kindex set history size
6fc08d32 15089@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15090@item set history size @var{size}
15091Set the number of commands which @value{GDBN} keeps in its history list.
15092This defaults to the value of the environment variable
15093@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15094@end table
15095
8e04817f 15096History expansion assigns special meaning to the character @kbd{!}.
703663ab 15097@xref{Event Designators}, for more details.
8e04817f 15098
703663ab 15099@cindex history expansion, turn on/off
8e04817f
AC
15100Since @kbd{!} is also the logical not operator in C, history expansion
15101is off by default. If you decide to enable history expansion with the
15102@code{set history expansion on} command, you may sometimes need to
15103follow @kbd{!} (when it is used as logical not, in an expression) with
15104a space or a tab to prevent it from being expanded. The readline
15105history facilities do not attempt substitution on the strings
15106@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15107
15108The commands to control history expansion are:
104c1213
JM
15109
15110@table @code
8e04817f
AC
15111@item set history expansion on
15112@itemx set history expansion
703663ab 15113@kindex set history expansion
8e04817f 15114Enable history expansion. History expansion is off by default.
104c1213 15115
8e04817f
AC
15116@item set history expansion off
15117Disable history expansion.
104c1213 15118
8e04817f
AC
15119@c @group
15120@kindex show history
15121@item show history
15122@itemx show history filename
15123@itemx show history save
15124@itemx show history size
15125@itemx show history expansion
15126These commands display the state of the @value{GDBN} history parameters.
15127@code{show history} by itself displays all four states.
15128@c @end group
15129@end table
15130
15131@table @code
9c16f35a
EZ
15132@kindex show commands
15133@cindex show last commands
15134@cindex display command history
8e04817f
AC
15135@item show commands
15136Display the last ten commands in the command history.
104c1213 15137
8e04817f
AC
15138@item show commands @var{n}
15139Print ten commands centered on command number @var{n}.
15140
15141@item show commands +
15142Print ten commands just after the commands last printed.
104c1213
JM
15143@end table
15144
8e04817f
AC
15145@node Screen Size
15146@section Screen size
15147@cindex size of screen
15148@cindex pauses in output
104c1213 15149
8e04817f
AC
15150Certain commands to @value{GDBN} may produce large amounts of
15151information output to the screen. To help you read all of it,
15152@value{GDBN} pauses and asks you for input at the end of each page of
15153output. Type @key{RET} when you want to continue the output, or @kbd{q}
15154to discard the remaining output. Also, the screen width setting
15155determines when to wrap lines of output. Depending on what is being
15156printed, @value{GDBN} tries to break the line at a readable place,
15157rather than simply letting it overflow onto the following line.
15158
15159Normally @value{GDBN} knows the size of the screen from the terminal
15160driver software. For example, on Unix @value{GDBN} uses the termcap data base
15161together with the value of the @code{TERM} environment variable and the
15162@code{stty rows} and @code{stty cols} settings. If this is not correct,
15163you can override it with the @code{set height} and @code{set
15164width} commands:
15165
15166@table @code
15167@kindex set height
15168@kindex set width
15169@kindex show width
15170@kindex show height
15171@item set height @var{lpp}
15172@itemx show height
15173@itemx set width @var{cpl}
15174@itemx show width
15175These @code{set} commands specify a screen height of @var{lpp} lines and
15176a screen width of @var{cpl} characters. The associated @code{show}
15177commands display the current settings.
104c1213 15178
8e04817f
AC
15179If you specify a height of zero lines, @value{GDBN} does not pause during
15180output no matter how long the output is. This is useful if output is to a
15181file or to an editor buffer.
104c1213 15182
8e04817f
AC
15183Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15184from wrapping its output.
9c16f35a
EZ
15185
15186@item set pagination on
15187@itemx set pagination off
15188@kindex set pagination
15189Turn the output pagination on or off; the default is on. Turning
15190pagination off is the alternative to @code{set height 0}.
15191
15192@item show pagination
15193@kindex show pagination
15194Show the current pagination mode.
104c1213
JM
15195@end table
15196
8e04817f
AC
15197@node Numbers
15198@section Numbers
15199@cindex number representation
15200@cindex entering numbers
104c1213 15201
8e04817f
AC
15202You can always enter numbers in octal, decimal, or hexadecimal in
15203@value{GDBN} by the usual conventions: octal numbers begin with
15204@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15205begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15206@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1520710; likewise, the default display for numbers---when no particular
15208format is specified---is base 10. You can change the default base for
15209both input and output with the commands described below.
104c1213 15210
8e04817f
AC
15211@table @code
15212@kindex set input-radix
15213@item set input-radix @var{base}
15214Set the default base for numeric input. Supported choices
15215for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15216specified either unambiguously or using the current input radix; for
8e04817f 15217example, any of
104c1213 15218
8e04817f 15219@smallexample
9c16f35a
EZ
15220set input-radix 012
15221set input-radix 10.
15222set input-radix 0xa
8e04817f 15223@end smallexample
104c1213 15224
8e04817f 15225@noindent
9c16f35a 15226sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15227leaves the input radix unchanged, no matter what it was, since
15228@samp{10}, being without any leading or trailing signs of its base, is
15229interpreted in the current radix. Thus, if the current radix is 16,
15230@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15231change the radix.
104c1213 15232
8e04817f
AC
15233@kindex set output-radix
15234@item set output-radix @var{base}
15235Set the default base for numeric display. Supported choices
15236for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15237specified either unambiguously or using the current input radix.
104c1213 15238
8e04817f
AC
15239@kindex show input-radix
15240@item show input-radix
15241Display the current default base for numeric input.
104c1213 15242
8e04817f
AC
15243@kindex show output-radix
15244@item show output-radix
15245Display the current default base for numeric display.
9c16f35a
EZ
15246
15247@item set radix @r{[}@var{base}@r{]}
15248@itemx show radix
15249@kindex set radix
15250@kindex show radix
15251These commands set and show the default base for both input and output
15252of numbers. @code{set radix} sets the radix of input and output to
15253the same base; without an argument, it resets the radix back to its
15254default value of 10.
15255
8e04817f 15256@end table
104c1213 15257
1e698235
DJ
15258@node ABI
15259@section Configuring the current ABI
15260
15261@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15262application automatically. However, sometimes you need to override its
15263conclusions. Use these commands to manage @value{GDBN}'s view of the
15264current ABI.
15265
98b45e30
DJ
15266@cindex OS ABI
15267@kindex set osabi
b4e9345d 15268@kindex show osabi
98b45e30
DJ
15269
15270One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15271system targets, either via remote debugging or native emulation.
98b45e30
DJ
15272@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15273but you can override its conclusion using the @code{set osabi} command.
15274One example where this is useful is in debugging of binaries which use
15275an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15276not have the same identifying marks that the standard C library for your
15277platform provides.
15278
15279@table @code
15280@item show osabi
15281Show the OS ABI currently in use.
15282
15283@item set osabi
15284With no argument, show the list of registered available OS ABI's.
15285
15286@item set osabi @var{abi}
15287Set the current OS ABI to @var{abi}.
15288@end table
15289
1e698235 15290@cindex float promotion
1e698235
DJ
15291
15292Generally, the way that an argument of type @code{float} is passed to a
15293function depends on whether the function is prototyped. For a prototyped
15294(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15295according to the architecture's convention for @code{float}. For unprototyped
15296(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15297@code{double} and then passed.
15298
15299Unfortunately, some forms of debug information do not reliably indicate whether
15300a function is prototyped. If @value{GDBN} calls a function that is not marked
15301as prototyped, it consults @kbd{set coerce-float-to-double}.
15302
15303@table @code
a8f24a35 15304@kindex set coerce-float-to-double
1e698235
DJ
15305@item set coerce-float-to-double
15306@itemx set coerce-float-to-double on
15307Arguments of type @code{float} will be promoted to @code{double} when passed
15308to an unprototyped function. This is the default setting.
15309
15310@item set coerce-float-to-double off
15311Arguments of type @code{float} will be passed directly to unprototyped
15312functions.
9c16f35a
EZ
15313
15314@kindex show coerce-float-to-double
15315@item show coerce-float-to-double
15316Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15317@end table
15318
f1212245
DJ
15319@kindex set cp-abi
15320@kindex show cp-abi
15321@value{GDBN} needs to know the ABI used for your program's C@t{++}
15322objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15323used to build your application. @value{GDBN} only fully supports
15324programs with a single C@t{++} ABI; if your program contains code using
15325multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15326program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15327Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15328before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15329``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15330use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15331``auto''.
15332
15333@table @code
15334@item show cp-abi
15335Show the C@t{++} ABI currently in use.
15336
15337@item set cp-abi
15338With no argument, show the list of supported C@t{++} ABI's.
15339
15340@item set cp-abi @var{abi}
15341@itemx set cp-abi auto
15342Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15343@end table
15344
8e04817f
AC
15345@node Messages/Warnings
15346@section Optional warnings and messages
104c1213 15347
9c16f35a
EZ
15348@cindex verbose operation
15349@cindex optional warnings
8e04817f
AC
15350By default, @value{GDBN} is silent about its inner workings. If you are
15351running on a slow machine, you may want to use the @code{set verbose}
15352command. This makes @value{GDBN} tell you when it does a lengthy
15353internal operation, so you will not think it has crashed.
104c1213 15354
8e04817f
AC
15355Currently, the messages controlled by @code{set verbose} are those
15356which announce that the symbol table for a source file is being read;
15357see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15358
8e04817f
AC
15359@table @code
15360@kindex set verbose
15361@item set verbose on
15362Enables @value{GDBN} output of certain informational messages.
104c1213 15363
8e04817f
AC
15364@item set verbose off
15365Disables @value{GDBN} output of certain informational messages.
104c1213 15366
8e04817f
AC
15367@kindex show verbose
15368@item show verbose
15369Displays whether @code{set verbose} is on or off.
15370@end table
104c1213 15371
8e04817f
AC
15372By default, if @value{GDBN} encounters bugs in the symbol table of an
15373object file, it is silent; but if you are debugging a compiler, you may
15374find this information useful (@pxref{Symbol Errors, ,Errors reading
15375symbol files}).
104c1213 15376
8e04817f 15377@table @code
104c1213 15378
8e04817f
AC
15379@kindex set complaints
15380@item set complaints @var{limit}
15381Permits @value{GDBN} to output @var{limit} complaints about each type of
15382unusual symbols before becoming silent about the problem. Set
15383@var{limit} to zero to suppress all complaints; set it to a large number
15384to prevent complaints from being suppressed.
104c1213 15385
8e04817f
AC
15386@kindex show complaints
15387@item show complaints
15388Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15389
8e04817f 15390@end table
104c1213 15391
8e04817f
AC
15392By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15393lot of stupid questions to confirm certain commands. For example, if
15394you try to run a program which is already running:
104c1213 15395
474c8240 15396@smallexample
8e04817f
AC
15397(@value{GDBP}) run
15398The program being debugged has been started already.
15399Start it from the beginning? (y or n)
474c8240 15400@end smallexample
104c1213 15401
8e04817f
AC
15402If you are willing to unflinchingly face the consequences of your own
15403commands, you can disable this ``feature'':
104c1213 15404
8e04817f 15405@table @code
104c1213 15406
8e04817f
AC
15407@kindex set confirm
15408@cindex flinching
15409@cindex confirmation
15410@cindex stupid questions
15411@item set confirm off
15412Disables confirmation requests.
104c1213 15413
8e04817f
AC
15414@item set confirm on
15415Enables confirmation requests (the default).
104c1213 15416
8e04817f
AC
15417@kindex show confirm
15418@item show confirm
15419Displays state of confirmation requests.
15420
15421@end table
104c1213 15422
8e04817f
AC
15423@node Debugging Output
15424@section Optional messages about internal happenings
4644b6e3
EZ
15425@cindex optional debugging messages
15426
da316a69
EZ
15427@value{GDBN} has commands that enable optional debugging messages from
15428various @value{GDBN} subsystems; normally these commands are of
15429interest to @value{GDBN} maintainers, or when reporting a bug. This
15430section documents those commands.
15431
104c1213 15432@table @code
a8f24a35
EZ
15433@kindex set exec-done-display
15434@item set exec-done-display
15435Turns on or off the notification of asynchronous commands'
15436completion. When on, @value{GDBN} will print a message when an
15437asynchronous command finishes its execution. The default is off.
15438@kindex show exec-done-display
15439@item show exec-done-display
15440Displays the current setting of asynchronous command completion
15441notification.
4644b6e3
EZ
15442@kindex set debug
15443@cindex gdbarch debugging info
a8f24a35 15444@cindex architecture debugging info
8e04817f 15445@item set debug arch
a8f24a35 15446Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15447@kindex show debug
8e04817f
AC
15448@item show debug arch
15449Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15450@item set debug aix-thread
15451@cindex AIX threads
15452Display debugging messages about inner workings of the AIX thread
15453module.
15454@item show debug aix-thread
15455Show the current state of AIX thread debugging info display.
8e04817f 15456@item set debug event
4644b6e3 15457@cindex event debugging info
a8f24a35 15458Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15459default is off.
8e04817f
AC
15460@item show debug event
15461Displays the current state of displaying @value{GDBN} event debugging
15462info.
8e04817f 15463@item set debug expression
4644b6e3 15464@cindex expression debugging info
721c2651
EZ
15465Turns on or off display of debugging info about @value{GDBN}
15466expression parsing. The default is off.
8e04817f 15467@item show debug expression
721c2651
EZ
15468Displays the current state of displaying debugging info about
15469@value{GDBN} expression parsing.
7453dc06 15470@item set debug frame
4644b6e3 15471@cindex frame debugging info
7453dc06
AC
15472Turns on or off display of @value{GDBN} frame debugging info. The
15473default is off.
7453dc06
AC
15474@item show debug frame
15475Displays the current state of displaying @value{GDBN} frame debugging
15476info.
30e91e0b
RC
15477@item set debug infrun
15478@cindex inferior debugging info
15479Turns on or off display of @value{GDBN} debugging info for running the inferior.
15480The default is off. @file{infrun.c} contains GDB's runtime state machine used
15481for implementing operations such as single-stepping the inferior.
15482@item show debug infrun
15483Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15484@item set debug lin-lwp
15485@cindex @sc{gnu}/Linux LWP debug messages
15486@cindex Linux lightweight processes
721c2651 15487Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15488@item show debug lin-lwp
15489Show the current state of Linux LWP debugging messages.
2b4855ab 15490@item set debug observer
4644b6e3 15491@cindex observer debugging info
2b4855ab
AC
15492Turns on or off display of @value{GDBN} observer debugging. This
15493includes info such as the notification of observable events.
2b4855ab
AC
15494@item show debug observer
15495Displays the current state of observer debugging.
8e04817f 15496@item set debug overload
4644b6e3 15497@cindex C@t{++} overload debugging info
8e04817f
AC
15498Turns on or off display of @value{GDBN} C@t{++} overload debugging
15499info. This includes info such as ranking of functions, etc. The default
15500is off.
8e04817f
AC
15501@item show debug overload
15502Displays the current state of displaying @value{GDBN} C@t{++} overload
15503debugging info.
8e04817f
AC
15504@cindex packets, reporting on stdout
15505@cindex serial connections, debugging
15506@item set debug remote
15507Turns on or off display of reports on all packets sent back and forth across
15508the serial line to the remote machine. The info is printed on the
15509@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15510@item show debug remote
15511Displays the state of display of remote packets.
8e04817f
AC
15512@item set debug serial
15513Turns on or off display of @value{GDBN} serial debugging info. The
15514default is off.
8e04817f
AC
15515@item show debug serial
15516Displays the current state of displaying @value{GDBN} serial debugging
15517info.
c45da7e6
EZ
15518@item set debug solib-frv
15519@cindex FR-V shared-library debugging
15520Turns on or off debugging messages for FR-V shared-library code.
15521@item show debug solib-frv
15522Display the current state of FR-V shared-library code debugging
15523messages.
8e04817f 15524@item set debug target
4644b6e3 15525@cindex target debugging info
8e04817f
AC
15526Turns on or off display of @value{GDBN} target debugging info. This info
15527includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15528default is 0. Set it to 1 to track events, and to 2 to also track the
15529value of large memory transfers. Changes to this flag do not take effect
15530until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15531@item show debug target
15532Displays the current state of displaying @value{GDBN} target debugging
15533info.
c45da7e6 15534@item set debugvarobj
4644b6e3 15535@cindex variable object debugging info
8e04817f
AC
15536Turns on or off display of @value{GDBN} variable object debugging
15537info. The default is off.
c45da7e6 15538@item show debugvarobj
8e04817f
AC
15539Displays the current state of displaying @value{GDBN} variable object
15540debugging info.
15541@end table
104c1213 15542
8e04817f
AC
15543@node Sequences
15544@chapter Canned Sequences of Commands
104c1213 15545
8e04817f
AC
15546Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15547command lists}), @value{GDBN} provides two ways to store sequences of
15548commands for execution as a unit: user-defined commands and command
15549files.
104c1213 15550
8e04817f
AC
15551@menu
15552* Define:: User-defined commands
15553* Hooks:: User-defined command hooks
15554* Command Files:: Command files
15555* Output:: Commands for controlled output
15556@end menu
104c1213 15557
8e04817f
AC
15558@node Define
15559@section User-defined commands
104c1213 15560
8e04817f
AC
15561@cindex user-defined command
15562A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15563which you assign a new name as a command. This is done with the
15564@code{define} command. User commands may accept up to 10 arguments
15565separated by whitespace. Arguments are accessed within the user command
15566via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15567
8e04817f
AC
15568@smallexample
15569define adder
15570 print $arg0 + $arg1 + $arg2
15571@end smallexample
104c1213
JM
15572
15573@noindent
8e04817f 15574To execute the command use:
104c1213 15575
8e04817f
AC
15576@smallexample
15577adder 1 2 3
15578@end smallexample
104c1213 15579
8e04817f
AC
15580@noindent
15581This defines the command @code{adder}, which prints the sum of
15582its three arguments. Note the arguments are text substitutions, so they may
15583reference variables, use complex expressions, or even perform inferior
15584functions calls.
104c1213
JM
15585
15586@table @code
104c1213 15587
8e04817f
AC
15588@kindex define
15589@item define @var{commandname}
15590Define a command named @var{commandname}. If there is already a command
15591by that name, you are asked to confirm that you want to redefine it.
104c1213 15592
8e04817f
AC
15593The definition of the command is made up of other @value{GDBN} command lines,
15594which are given following the @code{define} command. The end of these
15595commands is marked by a line containing @code{end}.
104c1213 15596
8e04817f
AC
15597@kindex if
15598@kindex else
15599@item if
09d4efe1 15600@itemx else
8e04817f
AC
15601Takes a single argument, which is an expression to evaluate.
15602It is followed by a series of commands that are executed
15603only if the expression is true (nonzero).
15604There can then optionally be a line @code{else}, followed
15605by a series of commands that are only executed if the expression
15606was false. The end of the list is marked by a line containing @code{end}.
104c1213 15607
8e04817f
AC
15608@kindex while
15609@item while
15610The syntax is similar to @code{if}: the command takes a single argument,
15611which is an expression to evaluate, and must be followed by the commands to
15612execute, one per line, terminated by an @code{end}.
15613The commands are executed repeatedly as long as the expression
15614evaluates to true.
104c1213 15615
8e04817f
AC
15616@kindex document
15617@item document @var{commandname}
15618Document the user-defined command @var{commandname}, so that it can be
15619accessed by @code{help}. The command @var{commandname} must already be
15620defined. This command reads lines of documentation just as @code{define}
15621reads the lines of the command definition, ending with @code{end}.
15622After the @code{document} command is finished, @code{help} on command
15623@var{commandname} displays the documentation you have written.
104c1213 15624
8e04817f
AC
15625You may use the @code{document} command again to change the
15626documentation of a command. Redefining the command with @code{define}
15627does not change the documentation.
104c1213 15628
c45da7e6
EZ
15629@kindex dont-repeat
15630@cindex don't repeat command
15631@item dont-repeat
15632Used inside a user-defined command, this tells @value{GDBN} that this
15633command should not be repeated when the user hits @key{RET}
15634(@pxref{Command Syntax, repeat last command}).
15635
8e04817f
AC
15636@kindex help user-defined
15637@item help user-defined
15638List all user-defined commands, with the first line of the documentation
15639(if any) for each.
104c1213 15640
8e04817f
AC
15641@kindex show user
15642@item show user
15643@itemx show user @var{commandname}
15644Display the @value{GDBN} commands used to define @var{commandname} (but
15645not its documentation). If no @var{commandname} is given, display the
15646definitions for all user-defined commands.
104c1213 15647
9c16f35a 15648@cindex infinite recusrion in user-defined commands
20f01a46
DH
15649@kindex show max-user-call-depth
15650@kindex set max-user-call-depth
15651@item show max-user-call-depth
5ca0cb28
DH
15652@itemx set max-user-call-depth
15653The value of @code{max-user-call-depth} controls how many recursion
15654levels are allowed in user-defined commands before GDB suspects an
15655infinite recursion and aborts the command.
20f01a46 15656
104c1213
JM
15657@end table
15658
8e04817f
AC
15659When user-defined commands are executed, the
15660commands of the definition are not printed. An error in any command
15661stops execution of the user-defined command.
104c1213 15662
8e04817f
AC
15663If used interactively, commands that would ask for confirmation proceed
15664without asking when used inside a user-defined command. Many @value{GDBN}
15665commands that normally print messages to say what they are doing omit the
15666messages when used in a user-defined command.
104c1213 15667
8e04817f
AC
15668@node Hooks
15669@section User-defined command hooks
15670@cindex command hooks
15671@cindex hooks, for commands
15672@cindex hooks, pre-command
104c1213 15673
8e04817f 15674@kindex hook
8e04817f
AC
15675You may define @dfn{hooks}, which are a special kind of user-defined
15676command. Whenever you run the command @samp{foo}, if the user-defined
15677command @samp{hook-foo} exists, it is executed (with no arguments)
15678before that command.
104c1213 15679
8e04817f
AC
15680@cindex hooks, post-command
15681@kindex hookpost
8e04817f
AC
15682A hook may also be defined which is run after the command you executed.
15683Whenever you run the command @samp{foo}, if the user-defined command
15684@samp{hookpost-foo} exists, it is executed (with no arguments) after
15685that command. Post-execution hooks may exist simultaneously with
15686pre-execution hooks, for the same command.
104c1213 15687
8e04817f 15688It is valid for a hook to call the command which it hooks. If this
9f1c6395 15689occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15690
8e04817f
AC
15691@c It would be nice if hookpost could be passed a parameter indicating
15692@c if the command it hooks executed properly or not. FIXME!
104c1213 15693
8e04817f
AC
15694@kindex stop@r{, a pseudo-command}
15695In addition, a pseudo-command, @samp{stop} exists. Defining
15696(@samp{hook-stop}) makes the associated commands execute every time
15697execution stops in your program: before breakpoint commands are run,
15698displays are printed, or the stack frame is printed.
104c1213 15699
8e04817f
AC
15700For example, to ignore @code{SIGALRM} signals while
15701single-stepping, but treat them normally during normal execution,
15702you could define:
104c1213 15703
474c8240 15704@smallexample
8e04817f
AC
15705define hook-stop
15706handle SIGALRM nopass
15707end
104c1213 15708
8e04817f
AC
15709define hook-run
15710handle SIGALRM pass
15711end
104c1213 15712
8e04817f
AC
15713define hook-continue
15714handle SIGLARM pass
15715end
474c8240 15716@end smallexample
104c1213 15717
8e04817f 15718As a further example, to hook at the begining and end of the @code{echo}
b383017d 15719command, and to add extra text to the beginning and end of the message,
8e04817f 15720you could define:
104c1213 15721
474c8240 15722@smallexample
8e04817f
AC
15723define hook-echo
15724echo <<<---
15725end
104c1213 15726
8e04817f
AC
15727define hookpost-echo
15728echo --->>>\n
15729end
104c1213 15730
8e04817f
AC
15731(@value{GDBP}) echo Hello World
15732<<<---Hello World--->>>
15733(@value{GDBP})
104c1213 15734
474c8240 15735@end smallexample
104c1213 15736
8e04817f
AC
15737You can define a hook for any single-word command in @value{GDBN}, but
15738not for command aliases; you should define a hook for the basic command
15739name, e.g. @code{backtrace} rather than @code{bt}.
15740@c FIXME! So how does Joe User discover whether a command is an alias
15741@c or not?
15742If an error occurs during the execution of your hook, execution of
15743@value{GDBN} commands stops and @value{GDBN} issues a prompt
15744(before the command that you actually typed had a chance to run).
104c1213 15745
8e04817f
AC
15746If you try to define a hook which does not match any known command, you
15747get a warning from the @code{define} command.
c906108c 15748
8e04817f
AC
15749@node Command Files
15750@section Command files
c906108c 15751
8e04817f 15752@cindex command files
6fc08d32
EZ
15753A command file for @value{GDBN} is a text file made of lines that are
15754@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15755also be included. An empty line in a command file does nothing; it
15756does not mean to repeat the last command, as it would from the
15757terminal.
c906108c 15758
6fc08d32
EZ
15759You can request the execution of a command file with the @code{source}
15760command:
c906108c 15761
8e04817f
AC
15762@table @code
15763@kindex source
15764@item source @var{filename}
15765Execute the command file @var{filename}.
c906108c
SS
15766@end table
15767
8e04817f 15768The lines in a command file are executed sequentially. They are not
a71ec265
DH
15769printed as they are executed. An error in any command terminates
15770execution of the command file and control is returned to the console.
c906108c 15771
8e04817f
AC
15772Commands that would ask for confirmation if used interactively proceed
15773without asking when used in a command file. Many @value{GDBN} commands that
15774normally print messages to say what they are doing omit the messages
15775when called from command files.
c906108c 15776
8e04817f
AC
15777@value{GDBN} also accepts command input from standard input. In this
15778mode, normal output goes to standard output and error output goes to
15779standard error. Errors in a command file supplied on standard input do
6fc08d32 15780not terminate execution of the command file---execution continues with
8e04817f 15781the next command.
c906108c 15782
474c8240 15783@smallexample
8e04817f 15784gdb < cmds > log 2>&1
474c8240 15785@end smallexample
c906108c 15786
8e04817f
AC
15787(The syntax above will vary depending on the shell used.) This example
15788will execute commands from the file @file{cmds}. All output and errors
15789would be directed to @file{log}.
c906108c 15790
8e04817f
AC
15791@node Output
15792@section Commands for controlled output
c906108c 15793
8e04817f
AC
15794During the execution of a command file or a user-defined command, normal
15795@value{GDBN} output is suppressed; the only output that appears is what is
15796explicitly printed by the commands in the definition. This section
15797describes three commands useful for generating exactly the output you
15798want.
c906108c
SS
15799
15800@table @code
8e04817f
AC
15801@kindex echo
15802@item echo @var{text}
15803@c I do not consider backslash-space a standard C escape sequence
15804@c because it is not in ANSI.
15805Print @var{text}. Nonprinting characters can be included in
15806@var{text} using C escape sequences, such as @samp{\n} to print a
15807newline. @strong{No newline is printed unless you specify one.}
15808In addition to the standard C escape sequences, a backslash followed
15809by a space stands for a space. This is useful for displaying a
15810string with spaces at the beginning or the end, since leading and
15811trailing spaces are otherwise trimmed from all arguments.
15812To print @samp{@w{ }and foo =@w{ }}, use the command
15813@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15814
8e04817f
AC
15815A backslash at the end of @var{text} can be used, as in C, to continue
15816the command onto subsequent lines. For example,
c906108c 15817
474c8240 15818@smallexample
8e04817f
AC
15819echo This is some text\n\
15820which is continued\n\
15821onto several lines.\n
474c8240 15822@end smallexample
c906108c 15823
8e04817f 15824produces the same output as
c906108c 15825
474c8240 15826@smallexample
8e04817f
AC
15827echo This is some text\n
15828echo which is continued\n
15829echo onto several lines.\n
474c8240 15830@end smallexample
c906108c 15831
8e04817f
AC
15832@kindex output
15833@item output @var{expression}
15834Print the value of @var{expression} and nothing but that value: no
15835newlines, no @samp{$@var{nn} = }. The value is not entered in the
15836value history either. @xref{Expressions, ,Expressions}, for more information
15837on expressions.
c906108c 15838
8e04817f
AC
15839@item output/@var{fmt} @var{expression}
15840Print the value of @var{expression} in format @var{fmt}. You can use
15841the same formats as for @code{print}. @xref{Output Formats,,Output
15842formats}, for more information.
c906108c 15843
8e04817f
AC
15844@kindex printf
15845@item printf @var{string}, @var{expressions}@dots{}
15846Print the values of the @var{expressions} under the control of
15847@var{string}. The @var{expressions} are separated by commas and may be
15848either numbers or pointers. Their values are printed as specified by
15849@var{string}, exactly as if your program were to execute the C
15850subroutine
15851@c FIXME: the above implies that at least all ANSI C formats are
15852@c supported, but it isn't true: %E and %G don't work (or so it seems).
15853@c Either this is a bug, or the manual should document what formats are
15854@c supported.
c906108c 15855
474c8240 15856@smallexample
8e04817f 15857printf (@var{string}, @var{expressions}@dots{});
474c8240 15858@end smallexample
c906108c 15859
8e04817f 15860For example, you can print two values in hex like this:
c906108c 15861
8e04817f
AC
15862@smallexample
15863printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15864@end smallexample
c906108c 15865
8e04817f
AC
15866The only backslash-escape sequences that you can use in the format
15867string are the simple ones that consist of backslash followed by a
15868letter.
c906108c
SS
15869@end table
15870
21c294e6
AC
15871@node Interpreters
15872@chapter Command Interpreters
15873@cindex command interpreters
15874
15875@value{GDBN} supports multiple command interpreters, and some command
15876infrastructure to allow users or user interface writers to switch
15877between interpreters or run commands in other interpreters.
15878
15879@value{GDBN} currently supports two command interpreters, the console
15880interpreter (sometimes called the command-line interpreter or @sc{cli})
15881and the machine interface interpreter (or @sc{gdb/mi}). This manual
15882describes both of these interfaces in great detail.
15883
15884By default, @value{GDBN} will start with the console interpreter.
15885However, the user may choose to start @value{GDBN} with another
15886interpreter by specifying the @option{-i} or @option{--interpreter}
15887startup options. Defined interpreters include:
15888
15889@table @code
15890@item console
15891@cindex console interpreter
15892The traditional console or command-line interpreter. This is the most often
15893used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15894@value{GDBN} will use this interpreter.
15895
15896@item mi
15897@cindex mi interpreter
15898The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15899by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15900or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15901Interface}.
15902
15903@item mi2
15904@cindex mi2 interpreter
15905The current @sc{gdb/mi} interface.
15906
15907@item mi1
15908@cindex mi1 interpreter
15909The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15910
15911@end table
15912
15913@cindex invoke another interpreter
15914The interpreter being used by @value{GDBN} may not be dynamically
15915switched at runtime. Although possible, this could lead to a very
15916precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15917enters the command "interpreter-set console" in a console view,
15918@value{GDBN} would switch to using the console interpreter, rendering
15919the IDE inoperable!
15920
15921@kindex interpreter-exec
15922Although you may only choose a single interpreter at startup, you may execute
15923commands in any interpreter from the current interpreter using the appropriate
15924command. If you are running the console interpreter, simply use the
15925@code{interpreter-exec} command:
15926
15927@smallexample
15928interpreter-exec mi "-data-list-register-names"
15929@end smallexample
15930
15931@sc{gdb/mi} has a similar command, although it is only available in versions of
15932@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15933
8e04817f
AC
15934@node TUI
15935@chapter @value{GDBN} Text User Interface
15936@cindex TUI
d0d5df6f 15937@cindex Text User Interface
c906108c 15938
8e04817f
AC
15939@menu
15940* TUI Overview:: TUI overview
15941* TUI Keys:: TUI key bindings
7cf36c78 15942* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
15943* TUI Commands:: TUI specific commands
15944* TUI Configuration:: TUI configuration variables
15945@end menu
c906108c 15946
d0d5df6f
AC
15947The @value{GDBN} Text User Interface, TUI in short, is a terminal
15948interface which uses the @code{curses} library to show the source
15949file, the assembly output, the program registers and @value{GDBN}
15950commands in separate text windows.
15951
15952The TUI is enabled by invoking @value{GDBN} using either
15953@pindex gdbtui
15954@samp{gdbtui} or @samp{gdb -tui}.
c906108c 15955
8e04817f
AC
15956@node TUI Overview
15957@section TUI overview
c906108c 15958
8e04817f
AC
15959The TUI has two display modes that can be switched while
15960@value{GDBN} runs:
c906108c 15961
8e04817f
AC
15962@itemize @bullet
15963@item
15964A curses (or TUI) mode in which it displays several text
15965windows on the terminal.
c906108c 15966
8e04817f
AC
15967@item
15968A standard mode which corresponds to the @value{GDBN} configured without
15969the TUI.
15970@end itemize
c906108c 15971
8e04817f
AC
15972In the TUI mode, @value{GDBN} can display several text window
15973on the terminal:
c906108c 15974
8e04817f
AC
15975@table @emph
15976@item command
15977This window is the @value{GDBN} command window with the @value{GDBN}
15978prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
15979managed using readline but through the TUI. The @emph{command}
15980window is always visible.
c906108c 15981
8e04817f
AC
15982@item source
15983The source window shows the source file of the program. The current
15984line as well as active breakpoints are displayed in this window.
c906108c 15985
8e04817f
AC
15986@item assembly
15987The assembly window shows the disassembly output of the program.
c906108c 15988
8e04817f
AC
15989@item register
15990This window shows the processor registers. It detects when
15991a register is changed and when this is the case, registers that have
6a1b180d 15992changed are highlighted.
c906108c 15993
c906108c
SS
15994@end table
15995
269c21fe
SC
15996The source and assembly windows show the current program position
15997by highlighting the current line and marking them with the @samp{>} marker.
15998Breakpoints are also indicated with two markers. A first one
15999indicates the breakpoint type:
16000
16001@table @code
16002@item B
16003Breakpoint which was hit at least once.
16004
16005@item b
16006Breakpoint which was never hit.
16007
16008@item H
16009Hardware breakpoint which was hit at least once.
16010
16011@item h
16012Hardware breakpoint which was never hit.
16013
16014@end table
16015
16016The second marker indicates whether the breakpoint is enabled or not:
16017
16018@table @code
16019@item +
16020Breakpoint is enabled.
16021
16022@item -
16023Breakpoint is disabled.
16024
16025@end table
16026
8e04817f
AC
16027The source, assembly and register windows are attached to the thread
16028and the frame position. They are updated when the current thread
16029changes, when the frame changes or when the program counter changes.
16030These three windows are arranged by the TUI according to several
16031layouts. The layout defines which of these three windows are visible.
16032The following layouts are available:
c906108c 16033
8e04817f
AC
16034@itemize @bullet
16035@item
16036source
2df3850c 16037
8e04817f
AC
16038@item
16039assembly
16040
16041@item
16042source and assembly
16043
16044@item
16045source and registers
c906108c 16046
8e04817f
AC
16047@item
16048assembly and registers
2df3850c 16049
8e04817f 16050@end itemize
c906108c 16051
b7bb15bc
SC
16052On top of the command window a status line gives various information
16053concerning the current process begin debugged. The status line is
16054updated when the information it shows changes. The following fields
16055are displayed:
16056
16057@table @emph
16058@item target
16059Indicates the current gdb target
16060(@pxref{Targets, ,Specifying a Debugging Target}).
16061
16062@item process
16063Gives information about the current process or thread number.
16064When no process is being debugged, this field is set to @code{No process}.
16065
16066@item function
16067Gives the current function name for the selected frame.
16068The name is demangled if demangling is turned on (@pxref{Print Settings}).
16069When there is no symbol corresponding to the current program counter
16070the string @code{??} is displayed.
16071
16072@item line
16073Indicates the current line number for the selected frame.
16074When the current line number is not known the string @code{??} is displayed.
16075
16076@item pc
16077Indicates the current program counter address.
16078
16079@end table
16080
8e04817f
AC
16081@node TUI Keys
16082@section TUI Key Bindings
16083@cindex TUI key bindings
c906108c 16084
8e04817f
AC
16085The TUI installs several key bindings in the readline keymaps
16086(@pxref{Command Line Editing}).
16087They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16088directly on the TUI layout and windows. The TUI also provides
16089a @emph{SingleKey} keymap which binds several keys directly to
16090@value{GDBN} commands. The following key bindings
8e04817f 16091are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16092
8e04817f
AC
16093@table @kbd
16094@kindex C-x C-a
16095@item C-x C-a
16096@kindex C-x a
16097@itemx C-x a
16098@kindex C-x A
16099@itemx C-x A
16100Enter or leave the TUI mode. When the TUI mode is left,
16101the curses window management is left and @value{GDBN} operates using
16102its standard mode writing on the terminal directly. When the TUI
16103mode is entered, the control is given back to the curses windows.
16104The screen is then refreshed.
c906108c 16105
8e04817f
AC
16106@kindex C-x 1
16107@item C-x 1
16108Use a TUI layout with only one window. The layout will
16109either be @samp{source} or @samp{assembly}. When the TUI mode
16110is not active, it will switch to the TUI mode.
2df3850c 16111
8e04817f 16112Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16113
8e04817f
AC
16114@kindex C-x 2
16115@item C-x 2
16116Use a TUI layout with at least two windows. When the current
16117layout shows already two windows, a next layout with two windows is used.
16118When a new layout is chosen, one window will always be common to the
16119previous layout and the new one.
c906108c 16120
8e04817f 16121Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16122
72ffddc9
SC
16123@kindex C-x o
16124@item C-x o
16125Change the active window. The TUI associates several key bindings
16126(like scrolling and arrow keys) to the active window. This command
16127gives the focus to the next TUI window.
16128
16129Think of it as the Emacs @kbd{C-x o} binding.
16130
7cf36c78
SC
16131@kindex C-x s
16132@item C-x s
16133Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16134(@pxref{TUI Single Key Mode}).
16135
c906108c
SS
16136@end table
16137
8e04817f 16138The following key bindings are handled only by the TUI mode:
5d161b24 16139
8e04817f
AC
16140@table @key
16141@kindex PgUp
16142@item PgUp
16143Scroll the active window one page up.
c906108c 16144
8e04817f
AC
16145@kindex PgDn
16146@item PgDn
16147Scroll the active window one page down.
c906108c 16148
8e04817f
AC
16149@kindex Up
16150@item Up
16151Scroll the active window one line up.
c906108c 16152
8e04817f
AC
16153@kindex Down
16154@item Down
16155Scroll the active window one line down.
c906108c 16156
8e04817f
AC
16157@kindex Left
16158@item Left
16159Scroll the active window one column left.
c906108c 16160
8e04817f
AC
16161@kindex Right
16162@item Right
16163Scroll the active window one column right.
c906108c 16164
8e04817f
AC
16165@kindex C-L
16166@item C-L
16167Refresh the screen.
c906108c 16168
8e04817f 16169@end table
c906108c 16170
8e04817f 16171In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16172for scrolling. This means they are available for readline when the
16173active window is the command window. When the command window
16174does not have the focus, it is necessary to use other readline
16175key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16176
7cf36c78
SC
16177@node TUI Single Key Mode
16178@section TUI Single Key Mode
16179@cindex TUI single key mode
16180
16181The TUI provides a @emph{SingleKey} mode in which it installs a particular
16182key binding in the readline keymaps to connect single keys to
b383017d 16183some gdb commands.
7cf36c78
SC
16184
16185@table @kbd
16186@kindex c @r{(SingleKey TUI key)}
16187@item c
16188continue
16189
16190@kindex d @r{(SingleKey TUI key)}
16191@item d
16192down
16193
16194@kindex f @r{(SingleKey TUI key)}
16195@item f
16196finish
16197
16198@kindex n @r{(SingleKey TUI key)}
16199@item n
16200next
16201
16202@kindex q @r{(SingleKey TUI key)}
16203@item q
16204exit the @emph{SingleKey} mode.
16205
16206@kindex r @r{(SingleKey TUI key)}
16207@item r
16208run
16209
16210@kindex s @r{(SingleKey TUI key)}
16211@item s
16212step
16213
16214@kindex u @r{(SingleKey TUI key)}
16215@item u
16216up
16217
16218@kindex v @r{(SingleKey TUI key)}
16219@item v
16220info locals
16221
16222@kindex w @r{(SingleKey TUI key)}
16223@item w
16224where
16225
16226@end table
16227
16228Other keys temporarily switch to the @value{GDBN} command prompt.
16229The key that was pressed is inserted in the editing buffer so that
16230it is possible to type most @value{GDBN} commands without interaction
16231with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16232@emph{SingleKey} mode is restored. The only way to permanently leave
16233this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16234
16235
8e04817f
AC
16236@node TUI Commands
16237@section TUI specific commands
16238@cindex TUI commands
16239
16240The TUI has specific commands to control the text windows.
16241These commands are always available, that is they do not depend on
16242the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16243is in the standard mode, using these commands will automatically switch
16244in the TUI mode.
c906108c
SS
16245
16246@table @code
3d757584
SC
16247@item info win
16248@kindex info win
16249List and give the size of all displayed windows.
16250
8e04817f 16251@item layout next
4644b6e3 16252@kindex layout
8e04817f 16253Display the next layout.
2df3850c 16254
8e04817f 16255@item layout prev
8e04817f 16256Display the previous layout.
c906108c 16257
8e04817f 16258@item layout src
8e04817f 16259Display the source window only.
c906108c 16260
8e04817f 16261@item layout asm
8e04817f 16262Display the assembly window only.
c906108c 16263
8e04817f 16264@item layout split
8e04817f 16265Display the source and assembly window.
c906108c 16266
8e04817f 16267@item layout regs
8e04817f
AC
16268Display the register window together with the source or assembly window.
16269
16270@item focus next | prev | src | asm | regs | split
16271@kindex focus
16272Set the focus to the named window.
16273This command allows to change the active window so that scrolling keys
16274can be affected to another window.
c906108c 16275
8e04817f
AC
16276@item refresh
16277@kindex refresh
16278Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16279
6a1b180d
SC
16280@item tui reg float
16281@kindex tui reg
16282Show the floating point registers in the register window.
16283
16284@item tui reg general
16285Show the general registers in the register window.
16286
16287@item tui reg next
16288Show the next register group. The list of register groups as well as
16289their order is target specific. The predefined register groups are the
16290following: @code{general}, @code{float}, @code{system}, @code{vector},
16291@code{all}, @code{save}, @code{restore}.
16292
16293@item tui reg system
16294Show the system registers in the register window.
16295
8e04817f
AC
16296@item update
16297@kindex update
16298Update the source window and the current execution point.
c906108c 16299
8e04817f
AC
16300@item winheight @var{name} +@var{count}
16301@itemx winheight @var{name} -@var{count}
16302@kindex winheight
16303Change the height of the window @var{name} by @var{count}
16304lines. Positive counts increase the height, while negative counts
16305decrease it.
2df3850c 16306
c45da7e6
EZ
16307@item tabset
16308@kindex tabset @var{nchars}
16309Set the width of tab stops to be @var{nchars} characters.
16310
c906108c
SS
16311@end table
16312
8e04817f
AC
16313@node TUI Configuration
16314@section TUI configuration variables
16315@cindex TUI configuration variables
c906108c 16316
8e04817f
AC
16317The TUI has several configuration variables that control the
16318appearance of windows on the terminal.
c906108c 16319
8e04817f
AC
16320@table @code
16321@item set tui border-kind @var{kind}
16322@kindex set tui border-kind
16323Select the border appearance for the source, assembly and register windows.
16324The possible values are the following:
16325@table @code
16326@item space
16327Use a space character to draw the border.
c906108c 16328
8e04817f
AC
16329@item ascii
16330Use ascii characters + - and | to draw the border.
c906108c 16331
8e04817f
AC
16332@item acs
16333Use the Alternate Character Set to draw the border. The border is
16334drawn using character line graphics if the terminal supports them.
c78b4128 16335
8e04817f 16336@end table
c78b4128 16337
8e04817f
AC
16338@item set tui active-border-mode @var{mode}
16339@kindex set tui active-border-mode
16340Select the attributes to display the border of the active window.
16341The possible values are @code{normal}, @code{standout}, @code{reverse},
16342@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16343
8e04817f
AC
16344@item set tui border-mode @var{mode}
16345@kindex set tui border-mode
16346Select the attributes to display the border of other windows.
16347The @var{mode} can be one of the following:
16348@table @code
16349@item normal
16350Use normal attributes to display the border.
c906108c 16351
8e04817f
AC
16352@item standout
16353Use standout mode.
c906108c 16354
8e04817f
AC
16355@item reverse
16356Use reverse video mode.
c906108c 16357
8e04817f
AC
16358@item half
16359Use half bright mode.
c906108c 16360
8e04817f
AC
16361@item half-standout
16362Use half bright and standout mode.
c906108c 16363
8e04817f
AC
16364@item bold
16365Use extra bright or bold mode.
c78b4128 16366
8e04817f
AC
16367@item bold-standout
16368Use extra bright or bold and standout mode.
c78b4128 16369
8e04817f 16370@end table
c78b4128 16371
8e04817f 16372@end table
c78b4128 16373
8e04817f
AC
16374@node Emacs
16375@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16376
8e04817f
AC
16377@cindex Emacs
16378@cindex @sc{gnu} Emacs
16379A special interface allows you to use @sc{gnu} Emacs to view (and
16380edit) the source files for the program you are debugging with
16381@value{GDBN}.
c906108c 16382
8e04817f
AC
16383To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16384executable file you want to debug as an argument. This command starts
16385@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16386created Emacs buffer.
16387@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16388
8e04817f
AC
16389Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16390things:
c906108c 16391
8e04817f
AC
16392@itemize @bullet
16393@item
16394All ``terminal'' input and output goes through the Emacs buffer.
16395@end itemize
c906108c 16396
8e04817f
AC
16397This applies both to @value{GDBN} commands and their output, and to the input
16398and output done by the program you are debugging.
bf0184be 16399
8e04817f
AC
16400This is useful because it means that you can copy the text of previous
16401commands and input them again; you can even use parts of the output
16402in this way.
bf0184be 16403
8e04817f
AC
16404All the facilities of Emacs' Shell mode are available for interacting
16405with your program. In particular, you can send signals the usual
16406way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16407stop.
bf0184be 16408
8e04817f 16409@itemize @bullet
bf0184be 16410@item
8e04817f
AC
16411@value{GDBN} displays source code through Emacs.
16412@end itemize
bf0184be 16413
8e04817f
AC
16414Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16415source file for that frame and puts an arrow (@samp{=>}) at the
16416left margin of the current line. Emacs uses a separate buffer for
16417source display, and splits the screen to show both your @value{GDBN} session
16418and the source.
bf0184be 16419
8e04817f
AC
16420Explicit @value{GDBN} @code{list} or search commands still produce output as
16421usual, but you probably have no reason to use them from Emacs.
c906108c 16422
64fabec2
AC
16423If you specify an absolute file name when prompted for the @kbd{M-x
16424gdb} argument, then Emacs sets your current working directory to where
16425your program resides. If you only specify the file name, then Emacs
16426sets your current working directory to to the directory associated
16427with the previous buffer. In this case, @value{GDBN} may find your
16428program by searching your environment's @code{PATH} variable, but on
16429some operating systems it might not find the source. So, although the
16430@value{GDBN} input and output session proceeds normally, the auxiliary
16431buffer does not display the current source and line of execution.
16432
16433The initial working directory of @value{GDBN} is printed on the top
16434line of the @value{GDBN} I/O buffer and this serves as a default for
16435the commands that specify files for @value{GDBN} to operate
16436on. @xref{Files, ,Commands to specify files}.
16437
16438By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16439need to call @value{GDBN} by a different name (for example, if you
16440keep several configurations around, with different names) you can
16441customize the Emacs variable @code{gud-gdb-command-name} to run the
16442one you want.
8e04817f
AC
16443
16444In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16445addition to the standard Shell mode commands:
c906108c 16446
8e04817f
AC
16447@table @kbd
16448@item C-h m
16449Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16450
64fabec2 16451@item C-c C-s
8e04817f
AC
16452Execute to another source line, like the @value{GDBN} @code{step} command; also
16453update the display window to show the current file and location.
c906108c 16454
64fabec2 16455@item C-c C-n
8e04817f
AC
16456Execute to next source line in this function, skipping all function
16457calls, like the @value{GDBN} @code{next} command. Then update the display window
16458to show the current file and location.
c906108c 16459
64fabec2 16460@item C-c C-i
8e04817f
AC
16461Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16462display window accordingly.
c906108c 16463
8e04817f
AC
16464@item C-c C-f
16465Execute until exit from the selected stack frame, like the @value{GDBN}
16466@code{finish} command.
c906108c 16467
64fabec2 16468@item C-c C-r
8e04817f
AC
16469Continue execution of your program, like the @value{GDBN} @code{continue}
16470command.
b433d00b 16471
64fabec2 16472@item C-c <
8e04817f
AC
16473Go up the number of frames indicated by the numeric argument
16474(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16475like the @value{GDBN} @code{up} command.
b433d00b 16476
64fabec2 16477@item C-c >
8e04817f
AC
16478Go down the number of frames indicated by the numeric argument, like the
16479@value{GDBN} @code{down} command.
8e04817f 16480@end table
c906108c 16481
64fabec2 16482In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16483tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16484
64fabec2
AC
16485If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16486shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16487point to any frame in the stack and type @key{RET} to make it become the
16488current frame and display the associated source in the source buffer.
16489Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16490current one.
16491
8e04817f
AC
16492If you accidentally delete the source-display buffer, an easy way to get
16493it back is to type the command @code{f} in the @value{GDBN} buffer, to
16494request a frame display; when you run under Emacs, this recreates
16495the source buffer if necessary to show you the context of the current
16496frame.
c906108c 16497
8e04817f
AC
16498The source files displayed in Emacs are in ordinary Emacs buffers
16499which are visiting the source files in the usual way. You can edit
16500the files with these buffers if you wish; but keep in mind that @value{GDBN}
16501communicates with Emacs in terms of line numbers. If you add or
16502delete lines from the text, the line numbers that @value{GDBN} knows cease
16503to correspond properly with the code.
b383017d 16504
64fabec2
AC
16505The description given here is for GNU Emacs version 21.3 and a more
16506detailed description of its interaction with @value{GDBN} is given in
16507the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16508
8e04817f
AC
16509@c The following dropped because Epoch is nonstandard. Reactivate
16510@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16511@ignore
16512@kindex Emacs Epoch environment
16513@kindex Epoch
16514@kindex inspect
c906108c 16515
8e04817f
AC
16516Version 18 of @sc{gnu} Emacs has a built-in window system
16517called the @code{epoch}
16518environment. Users of this environment can use a new command,
16519@code{inspect} which performs identically to @code{print} except that
16520each value is printed in its own window.
16521@end ignore
c906108c 16522
922fbb7b
AC
16523
16524@node GDB/MI
16525@chapter The @sc{gdb/mi} Interface
16526
16527@unnumberedsec Function and Purpose
16528
16529@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16530@sc{gdb/mi} is a line based machine oriented text interface to
16531@value{GDBN} and is activated by specifying using the
16532@option{--interpreter} command line option (@pxref{Mode Options}). It
16533is specifically intended to support the development of systems which
16534use the debugger as just one small component of a larger system.
922fbb7b
AC
16535
16536This chapter is a specification of the @sc{gdb/mi} interface. It is written
16537in the form of a reference manual.
16538
16539Note that @sc{gdb/mi} is still under construction, so some of the
16540features described below are incomplete and subject to change.
16541
16542@unnumberedsec Notation and Terminology
16543
16544@cindex notational conventions, for @sc{gdb/mi}
16545This chapter uses the following notation:
16546
16547@itemize @bullet
16548@item
16549@code{|} separates two alternatives.
16550
16551@item
16552@code{[ @var{something} ]} indicates that @var{something} is optional:
16553it may or may not be given.
16554
16555@item
16556@code{( @var{group} )*} means that @var{group} inside the parentheses
16557may repeat zero or more times.
16558
16559@item
16560@code{( @var{group} )+} means that @var{group} inside the parentheses
16561may repeat one or more times.
16562
16563@item
16564@code{"@var{string}"} means a literal @var{string}.
16565@end itemize
16566
16567@ignore
16568@heading Dependencies
16569@end ignore
16570
16571@heading Acknowledgments
16572
16573In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16574Elena Zannoni.
16575
16576@menu
16577* GDB/MI Command Syntax::
16578* GDB/MI Compatibility with CLI::
16579* GDB/MI Output Records::
16580* GDB/MI Command Description Format::
16581* GDB/MI Breakpoint Table Commands::
16582* GDB/MI Data Manipulation::
16583* GDB/MI Program Control::
16584* GDB/MI Miscellaneous Commands::
16585@ignore
16586* GDB/MI Kod Commands::
16587* GDB/MI Memory Overlay Commands::
16588* GDB/MI Signal Handling Commands::
16589@end ignore
16590* GDB/MI Stack Manipulation::
16591* GDB/MI Symbol Query::
16592* GDB/MI Target Manipulation::
16593* GDB/MI Thread Commands::
16594* GDB/MI Tracepoint Commands::
16595* GDB/MI Variable Objects::
16596@end menu
16597
16598@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16599@node GDB/MI Command Syntax
16600@section @sc{gdb/mi} Command Syntax
16601
16602@menu
16603* GDB/MI Input Syntax::
16604* GDB/MI Output Syntax::
16605* GDB/MI Simple Examples::
16606@end menu
16607
16608@node GDB/MI Input Syntax
16609@subsection @sc{gdb/mi} Input Syntax
16610
16611@cindex input syntax for @sc{gdb/mi}
16612@cindex @sc{gdb/mi}, input syntax
16613@table @code
16614@item @var{command} @expansion{}
16615@code{@var{cli-command} | @var{mi-command}}
16616
16617@item @var{cli-command} @expansion{}
16618@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16619@var{cli-command} is any existing @value{GDBN} CLI command.
16620
16621@item @var{mi-command} @expansion{}
16622@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16623@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16624
16625@item @var{token} @expansion{}
16626"any sequence of digits"
16627
16628@item @var{option} @expansion{}
16629@code{"-" @var{parameter} [ " " @var{parameter} ]}
16630
16631@item @var{parameter} @expansion{}
16632@code{@var{non-blank-sequence} | @var{c-string}}
16633
16634@item @var{operation} @expansion{}
16635@emph{any of the operations described in this chapter}
16636
16637@item @var{non-blank-sequence} @expansion{}
16638@emph{anything, provided it doesn't contain special characters such as
16639"-", @var{nl}, """ and of course " "}
16640
16641@item @var{c-string} @expansion{}
16642@code{""" @var{seven-bit-iso-c-string-content} """}
16643
16644@item @var{nl} @expansion{}
16645@code{CR | CR-LF}
16646@end table
16647
16648@noindent
16649Notes:
16650
16651@itemize @bullet
16652@item
16653The CLI commands are still handled by the @sc{mi} interpreter; their
16654output is described below.
16655
16656@item
16657The @code{@var{token}}, when present, is passed back when the command
16658finishes.
16659
16660@item
16661Some @sc{mi} commands accept optional arguments as part of the parameter
16662list. Each option is identified by a leading @samp{-} (dash) and may be
16663followed by an optional argument parameter. Options occur first in the
16664parameter list and can be delimited from normal parameters using
16665@samp{--} (this is useful when some parameters begin with a dash).
16666@end itemize
16667
16668Pragmatics:
16669
16670@itemize @bullet
16671@item
16672We want easy access to the existing CLI syntax (for debugging).
16673
16674@item
16675We want it to be easy to spot a @sc{mi} operation.
16676@end itemize
16677
16678@node GDB/MI Output Syntax
16679@subsection @sc{gdb/mi} Output Syntax
16680
16681@cindex output syntax of @sc{gdb/mi}
16682@cindex @sc{gdb/mi}, output syntax
16683The output from @sc{gdb/mi} consists of zero or more out-of-band records
16684followed, optionally, by a single result record. This result record
16685is for the most recent command. The sequence of output records is
16686terminated by @samp{(@value{GDBP})}.
16687
16688If an input command was prefixed with a @code{@var{token}} then the
16689corresponding output for that command will also be prefixed by that same
16690@var{token}.
16691
16692@table @code
16693@item @var{output} @expansion{}
f7dc1244 16694@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16695
16696@item @var{result-record} @expansion{}
16697@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16698
16699@item @var{out-of-band-record} @expansion{}
16700@code{@var{async-record} | @var{stream-record}}
16701
16702@item @var{async-record} @expansion{}
16703@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16704
16705@item @var{exec-async-output} @expansion{}
16706@code{[ @var{token} ] "*" @var{async-output}}
16707
16708@item @var{status-async-output} @expansion{}
16709@code{[ @var{token} ] "+" @var{async-output}}
16710
16711@item @var{notify-async-output} @expansion{}
16712@code{[ @var{token} ] "=" @var{async-output}}
16713
16714@item @var{async-output} @expansion{}
16715@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16716
16717@item @var{result-class} @expansion{}
16718@code{"done" | "running" | "connected" | "error" | "exit"}
16719
16720@item @var{async-class} @expansion{}
16721@code{"stopped" | @var{others}} (where @var{others} will be added
16722depending on the needs---this is still in development).
16723
16724@item @var{result} @expansion{}
16725@code{ @var{variable} "=" @var{value}}
16726
16727@item @var{variable} @expansion{}
16728@code{ @var{string} }
16729
16730@item @var{value} @expansion{}
16731@code{ @var{const} | @var{tuple} | @var{list} }
16732
16733@item @var{const} @expansion{}
16734@code{@var{c-string}}
16735
16736@item @var{tuple} @expansion{}
16737@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16738
16739@item @var{list} @expansion{}
16740@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16741@var{result} ( "," @var{result} )* "]" }
16742
16743@item @var{stream-record} @expansion{}
16744@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16745
16746@item @var{console-stream-output} @expansion{}
16747@code{"~" @var{c-string}}
16748
16749@item @var{target-stream-output} @expansion{}
16750@code{"@@" @var{c-string}}
16751
16752@item @var{log-stream-output} @expansion{}
16753@code{"&" @var{c-string}}
16754
16755@item @var{nl} @expansion{}
16756@code{CR | CR-LF}
16757
16758@item @var{token} @expansion{}
16759@emph{any sequence of digits}.
16760@end table
16761
16762@noindent
16763Notes:
16764
16765@itemize @bullet
16766@item
16767All output sequences end in a single line containing a period.
16768
16769@item
16770The @code{@var{token}} is from the corresponding request. If an execution
16771command is interrupted by the @samp{-exec-interrupt} command, the
16772@var{token} associated with the @samp{*stopped} message is the one of the
16773original execution command, not the one of the interrupt command.
16774
16775@item
16776@cindex status output in @sc{gdb/mi}
16777@var{status-async-output} contains on-going status information about the
16778progress of a slow operation. It can be discarded. All status output is
16779prefixed by @samp{+}.
16780
16781@item
16782@cindex async output in @sc{gdb/mi}
16783@var{exec-async-output} contains asynchronous state change on the target
16784(stopped, started, disappeared). All async output is prefixed by
16785@samp{*}.
16786
16787@item
16788@cindex notify output in @sc{gdb/mi}
16789@var{notify-async-output} contains supplementary information that the
16790client should handle (e.g., a new breakpoint information). All notify
16791output is prefixed by @samp{=}.
16792
16793@item
16794@cindex console output in @sc{gdb/mi}
16795@var{console-stream-output} is output that should be displayed as is in the
16796console. It is the textual response to a CLI command. All the console
16797output is prefixed by @samp{~}.
16798
16799@item
16800@cindex target output in @sc{gdb/mi}
16801@var{target-stream-output} is the output produced by the target program.
16802All the target output is prefixed by @samp{@@}.
16803
16804@item
16805@cindex log output in @sc{gdb/mi}
16806@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16807instance messages that should be displayed as part of an error log. All
16808the log output is prefixed by @samp{&}.
16809
16810@item
16811@cindex list output in @sc{gdb/mi}
16812New @sc{gdb/mi} commands should only output @var{lists} containing
16813@var{values}.
16814
16815
16816@end itemize
16817
16818@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16819details about the various output records.
16820
16821@node GDB/MI Simple Examples
16822@subsection Simple Examples of @sc{gdb/mi} Interaction
16823@cindex @sc{gdb/mi}, simple examples
16824
16825This subsection presents several simple examples of interaction using
16826the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16827following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16828the output received from @sc{gdb/mi}.
16829
16830@subsubheading Target Stop
16831@c Ummm... There is no "-stop" command. This assumes async, no?
16832Here's an example of stopping the inferior process:
16833
16834@smallexample
16835-> -stop
16836<- (@value{GDBP})
16837@end smallexample
16838
16839@noindent
16840and later:
16841
16842@smallexample
16843<- *stop,reason="stop",address="0x123",source="a.c:123"
16844<- (@value{GDBP})
16845@end smallexample
16846
16847@subsubheading Simple CLI Command
16848
16849Here's an example of a simple CLI command being passed through
16850@sc{gdb/mi} and on to the CLI.
16851
16852@smallexample
16853-> print 1+2
16854<- &"print 1+2\n"
16855<- ~"$1 = 3\n"
16856<- ^done
16857<- (@value{GDBP})
16858@end smallexample
16859
16860@subsubheading Command With Side Effects
16861
16862@smallexample
16863-> -symbol-file xyz.exe
16864<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16865<- (@value{GDBP})
16866@end smallexample
16867
16868@subsubheading A Bad Command
16869
16870Here's what happens if you pass a non-existent command:
16871
16872@smallexample
16873-> -rubbish
16874<- ^error,msg="Undefined MI command: rubbish"
16875<- (@value{GDBP})
16876@end smallexample
16877
16878@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16879@node GDB/MI Compatibility with CLI
16880@section @sc{gdb/mi} Compatibility with CLI
16881
16882@cindex compatibility, @sc{gdb/mi} and CLI
16883@cindex @sc{gdb/mi}, compatibility with CLI
16884To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16885accepts existing CLI commands. As specified by the syntax, such
16886commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16887respond.
16888
16889This mechanism is provided as an aid to developers of @sc{gdb/mi}
16890clients and not as a reliable interface into the CLI. Since the command
16891is being interpreteted in an environment that assumes @sc{gdb/mi}
16892behaviour, the exact output of such commands is likely to end up being
16893an un-supported hybrid of @sc{gdb/mi} and CLI output.
16894
16895@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16896@node GDB/MI Output Records
16897@section @sc{gdb/mi} Output Records
16898
16899@menu
16900* GDB/MI Result Records::
16901* GDB/MI Stream Records::
16902* GDB/MI Out-of-band Records::
16903@end menu
16904
16905@node GDB/MI Result Records
16906@subsection @sc{gdb/mi} Result Records
16907
16908@cindex result records in @sc{gdb/mi}
16909@cindex @sc{gdb/mi}, result records
16910In addition to a number of out-of-band notifications, the response to a
16911@sc{gdb/mi} command includes one of the following result indications:
16912
16913@table @code
16914@findex ^done
16915@item "^done" [ "," @var{results} ]
16916The synchronous operation was successful, @code{@var{results}} are the return
16917values.
16918
16919@item "^running"
16920@findex ^running
16921@c Is this one correct? Should it be an out-of-band notification?
16922The asynchronous operation was successfully started. The target is
16923running.
16924
16925@item "^error" "," @var{c-string}
16926@findex ^error
16927The operation failed. The @code{@var{c-string}} contains the corresponding
16928error message.
16929@end table
16930
16931@node GDB/MI Stream Records
16932@subsection @sc{gdb/mi} Stream Records
16933
16934@cindex @sc{gdb/mi}, stream records
16935@cindex stream records in @sc{gdb/mi}
16936@value{GDBN} internally maintains a number of output streams: the console, the
16937target, and the log. The output intended for each of these streams is
16938funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16939
16940Each stream record begins with a unique @dfn{prefix character} which
16941identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16942Syntax}). In addition to the prefix, each stream record contains a
16943@code{@var{string-output}}. This is either raw text (with an implicit new
16944line) or a quoted C string (which does not contain an implicit newline).
16945
16946@table @code
16947@item "~" @var{string-output}
16948The console output stream contains text that should be displayed in the
16949CLI console window. It contains the textual responses to CLI commands.
16950
16951@item "@@" @var{string-output}
16952The target output stream contains any textual output from the running
16953target.
16954
16955@item "&" @var{string-output}
16956The log stream contains debugging messages being produced by @value{GDBN}'s
16957internals.
16958@end table
16959
16960@node GDB/MI Out-of-band Records
16961@subsection @sc{gdb/mi} Out-of-band Records
16962
16963@cindex out-of-band records in @sc{gdb/mi}
16964@cindex @sc{gdb/mi}, out-of-band records
16965@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
16966additional changes that have occurred. Those changes can either be a
16967consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
16968target activity (e.g., target stopped).
16969
16970The following is a preliminary list of possible out-of-band records.
034dad6f 16971In particular, the @var{exec-async-output} records.
922fbb7b
AC
16972
16973@table @code
034dad6f
BR
16974@item *stopped,reason="@var{reason}"
16975@end table
16976
16977@var{reason} can be one of the following:
16978
16979@table @code
16980@item breakpoint-hit
16981A breakpoint was reached.
16982@item watchpoint-trigger
16983A watchpoint was triggered.
16984@item read-watchpoint-trigger
16985A read watchpoint was triggered.
16986@item access-watchpoint-trigger
16987An access watchpoint was triggered.
16988@item function-finished
16989An -exec-finish or similar CLI command was accomplished.
16990@item location-reached
16991An -exec-until or similar CLI command was accomplished.
16992@item watchpoint-scope
16993A watchpoint has gone out of scope.
16994@item end-stepping-range
16995An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
16996similar CLI command was accomplished.
16997@item exited-signalled
16998The inferior exited because of a signal.
16999@item exited
17000The inferior exited.
17001@item exited-normally
17002The inferior exited normally.
17003@item signal-received
17004A signal was received by the inferior.
922fbb7b
AC
17005@end table
17006
17007
17008@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17009@node GDB/MI Command Description Format
17010@section @sc{gdb/mi} Command Description Format
17011
17012The remaining sections describe blocks of commands. Each block of
17013commands is laid out in a fashion similar to this section.
17014
17015Note the the line breaks shown in the examples are here only for
17016readability. They don't appear in the real output.
17017Also note that the commands with a non-available example (N.A.@:) are
17018not yet implemented.
17019
17020@subheading Motivation
17021
17022The motivation for this collection of commands.
17023
17024@subheading Introduction
17025
17026A brief introduction to this collection of commands as a whole.
17027
17028@subheading Commands
17029
17030For each command in the block, the following is described:
17031
17032@subsubheading Synopsis
17033
17034@smallexample
17035 -command @var{args}@dots{}
17036@end smallexample
17037
17038@subsubheading @value{GDBN} Command
17039
17040The corresponding @value{GDBN} CLI command.
17041
17042@subsubheading Result
17043
17044@subsubheading Out-of-band
17045
17046@subsubheading Notes
17047
17048@subsubheading Example
17049
17050
17051@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17052@node GDB/MI Breakpoint Table Commands
17053@section @sc{gdb/mi} Breakpoint table commands
17054
17055@cindex breakpoint commands for @sc{gdb/mi}
17056@cindex @sc{gdb/mi}, breakpoint commands
17057This section documents @sc{gdb/mi} commands for manipulating
17058breakpoints.
17059
17060@subheading The @code{-break-after} Command
17061@findex -break-after
17062
17063@subsubheading Synopsis
17064
17065@smallexample
17066 -break-after @var{number} @var{count}
17067@end smallexample
17068
17069The breakpoint number @var{number} is not in effect until it has been
17070hit @var{count} times. To see how this is reflected in the output of
17071the @samp{-break-list} command, see the description of the
17072@samp{-break-list} command below.
17073
17074@subsubheading @value{GDBN} Command
17075
17076The corresponding @value{GDBN} command is @samp{ignore}.
17077
17078@subsubheading Example
17079
17080@smallexample
17081(@value{GDBP})
17082-break-insert main
17083^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17084(@value{GDBP})
17085-break-after 1 3
17086~
17087^done
17088(@value{GDBP})
17089-break-list
17090^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17091hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17092@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17093@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17094@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17095@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17096@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17097body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17098addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17099ignore="3"@}]@}
17100(@value{GDBP})
17101@end smallexample
17102
17103@ignore
17104@subheading The @code{-break-catch} Command
17105@findex -break-catch
17106
17107@subheading The @code{-break-commands} Command
17108@findex -break-commands
17109@end ignore
17110
17111
17112@subheading The @code{-break-condition} Command
17113@findex -break-condition
17114
17115@subsubheading Synopsis
17116
17117@smallexample
17118 -break-condition @var{number} @var{expr}
17119@end smallexample
17120
17121Breakpoint @var{number} will stop the program only if the condition in
17122@var{expr} is true. The condition becomes part of the
17123@samp{-break-list} output (see the description of the @samp{-break-list}
17124command below).
17125
17126@subsubheading @value{GDBN} Command
17127
17128The corresponding @value{GDBN} command is @samp{condition}.
17129
17130@subsubheading Example
17131
17132@smallexample
17133(@value{GDBP})
17134-break-condition 1 1
17135^done
17136(@value{GDBP})
17137-break-list
17138^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17139hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17140@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17141@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17142@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17143@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17144@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17145body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17146addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17147times="0",ignore="3"@}]@}
17148(@value{GDBP})
17149@end smallexample
17150
17151@subheading The @code{-break-delete} Command
17152@findex -break-delete
17153
17154@subsubheading Synopsis
17155
17156@smallexample
17157 -break-delete ( @var{breakpoint} )+
17158@end smallexample
17159
17160Delete the breakpoint(s) whose number(s) are specified in the argument
17161list. This is obviously reflected in the breakpoint list.
17162
17163@subsubheading @value{GDBN} command
17164
17165The corresponding @value{GDBN} command is @samp{delete}.
17166
17167@subsubheading Example
17168
17169@smallexample
17170(@value{GDBP})
17171-break-delete 1
17172^done
17173(@value{GDBP})
17174-break-list
17175^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17176hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17177@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17178@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17179@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17180@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17181@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17182body=[]@}
17183(@value{GDBP})
17184@end smallexample
17185
17186@subheading The @code{-break-disable} Command
17187@findex -break-disable
17188
17189@subsubheading Synopsis
17190
17191@smallexample
17192 -break-disable ( @var{breakpoint} )+
17193@end smallexample
17194
17195Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17196break list is now set to @samp{n} for the named @var{breakpoint}(s).
17197
17198@subsubheading @value{GDBN} Command
17199
17200The corresponding @value{GDBN} command is @samp{disable}.
17201
17202@subsubheading Example
17203
17204@smallexample
17205(@value{GDBP})
17206-break-disable 2
17207^done
17208(@value{GDBP})
17209-break-list
17210^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17211hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17212@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17213@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17214@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17215@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17216@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17217body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17218addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17219(@value{GDBP})
17220@end smallexample
17221
17222@subheading The @code{-break-enable} Command
17223@findex -break-enable
17224
17225@subsubheading Synopsis
17226
17227@smallexample
17228 -break-enable ( @var{breakpoint} )+
17229@end smallexample
17230
17231Enable (previously disabled) @var{breakpoint}(s).
17232
17233@subsubheading @value{GDBN} Command
17234
17235The corresponding @value{GDBN} command is @samp{enable}.
17236
17237@subsubheading Example
17238
17239@smallexample
17240(@value{GDBP})
17241-break-enable 2
17242^done
17243(@value{GDBP})
17244-break-list
17245^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17246hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17247@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17248@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17249@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17250@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17251@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17252body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17253addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17254(@value{GDBP})
17255@end smallexample
17256
17257@subheading The @code{-break-info} Command
17258@findex -break-info
17259
17260@subsubheading Synopsis
17261
17262@smallexample
17263 -break-info @var{breakpoint}
17264@end smallexample
17265
17266@c REDUNDANT???
17267Get information about a single breakpoint.
17268
17269@subsubheading @value{GDBN} command
17270
17271The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17272
17273@subsubheading Example
17274N.A.
17275
17276@subheading The @code{-break-insert} Command
17277@findex -break-insert
17278
17279@subsubheading Synopsis
17280
17281@smallexample
17282 -break-insert [ -t ] [ -h ] [ -r ]
17283 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17284 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17285@end smallexample
17286
17287@noindent
17288If specified, @var{line}, can be one of:
17289
17290@itemize @bullet
17291@item function
17292@c @item +offset
17293@c @item -offset
17294@c @item linenum
17295@item filename:linenum
17296@item filename:function
17297@item *address
17298@end itemize
17299
17300The possible optional parameters of this command are:
17301
17302@table @samp
17303@item -t
17304Insert a tempoary breakpoint.
17305@item -h
17306Insert a hardware breakpoint.
17307@item -c @var{condition}
17308Make the breakpoint conditional on @var{condition}.
17309@item -i @var{ignore-count}
17310Initialize the @var{ignore-count}.
17311@item -r
17312Insert a regular breakpoint in all the functions whose names match the
17313given regular expression. Other flags are not applicable to regular
17314expresson.
17315@end table
17316
17317@subsubheading Result
17318
17319The result is in the form:
17320
17321@smallexample
17322 ^done,bkptno="@var{number}",func="@var{funcname}",
17323 file="@var{filename}",line="@var{lineno}"
17324@end smallexample
17325
17326@noindent
17327where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17328is the name of the function where the breakpoint was inserted,
17329@var{filename} is the name of the source file which contains this
17330function, and @var{lineno} is the source line number within that file.
17331
17332Note: this format is open to change.
17333@c An out-of-band breakpoint instead of part of the result?
17334
17335@subsubheading @value{GDBN} Command
17336
17337The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17338@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17339
17340@subsubheading Example
17341
17342@smallexample
17343(@value{GDBP})
17344-break-insert main
17345^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17346(@value{GDBP})
17347-break-insert -t foo
17348^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17349(@value{GDBP})
17350-break-list
17351^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17352hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17353@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17354@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17355@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17356@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17357@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17358body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17359addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17360bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17361addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17362(@value{GDBP})
17363-break-insert -r foo.*
17364~int foo(int, int);
17365^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17366(@value{GDBP})
17367@end smallexample
17368
17369@subheading The @code{-break-list} Command
17370@findex -break-list
17371
17372@subsubheading Synopsis
17373
17374@smallexample
17375 -break-list
17376@end smallexample
17377
17378Displays the list of inserted breakpoints, showing the following fields:
17379
17380@table @samp
17381@item Number
17382number of the breakpoint
17383@item Type
17384type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17385@item Disposition
17386should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17387or @samp{nokeep}
17388@item Enabled
17389is the breakpoint enabled or no: @samp{y} or @samp{n}
17390@item Address
17391memory location at which the breakpoint is set
17392@item What
17393logical location of the breakpoint, expressed by function name, file
17394name, line number
17395@item Times
17396number of times the breakpoint has been hit
17397@end table
17398
17399If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17400@code{body} field is an empty list.
17401
17402@subsubheading @value{GDBN} Command
17403
17404The corresponding @value{GDBN} command is @samp{info break}.
17405
17406@subsubheading Example
17407
17408@smallexample
17409(@value{GDBP})
17410-break-list
17411^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17412hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17413@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17414@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17415@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17416@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17417@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17418body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17419addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17420bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17421addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17422(@value{GDBP})
17423@end smallexample
17424
17425Here's an example of the result when there are no breakpoints:
17426
17427@smallexample
17428(@value{GDBP})
17429-break-list
17430^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17431hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17432@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17433@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17434@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17435@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17436@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17437body=[]@}
17438(@value{GDBP})
17439@end smallexample
17440
17441@subheading The @code{-break-watch} Command
17442@findex -break-watch
17443
17444@subsubheading Synopsis
17445
17446@smallexample
17447 -break-watch [ -a | -r ]
17448@end smallexample
17449
17450Create a watchpoint. With the @samp{-a} option it will create an
17451@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17452read from or on a write to the memory location. With the @samp{-r}
17453option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17454trigger only when the memory location is accessed for reading. Without
17455either of the options, the watchpoint created is a regular watchpoint,
17456i.e. it will trigger when the memory location is accessed for writing.
17457@xref{Set Watchpoints, , Setting watchpoints}.
17458
17459Note that @samp{-break-list} will report a single list of watchpoints and
17460breakpoints inserted.
17461
17462@subsubheading @value{GDBN} Command
17463
17464The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17465@samp{rwatch}.
17466
17467@subsubheading Example
17468
17469Setting a watchpoint on a variable in the @code{main} function:
17470
17471@smallexample
17472(@value{GDBP})
17473-break-watch x
17474^done,wpt=@{number="2",exp="x"@}
17475(@value{GDBP})
17476-exec-continue
17477^running
17478^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17479value=@{old="-268439212",new="55"@},
76ff342d
DJ
17480frame=@{func="main",args=[],file="recursive2.c",
17481fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17482(@value{GDBP})
17483@end smallexample
17484
17485Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17486the program execution twice: first for the variable changing value, then
17487for the watchpoint going out of scope.
17488
17489@smallexample
17490(@value{GDBP})
17491-break-watch C
17492^done,wpt=@{number="5",exp="C"@}
17493(@value{GDBP})
17494-exec-continue
17495^running
17496^done,reason="watchpoint-trigger",
17497wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17498frame=@{func="callee4",args=[],
76ff342d
DJ
17499file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17500fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17501(@value{GDBP})
17502-exec-continue
17503^running
17504^done,reason="watchpoint-scope",wpnum="5",
17505frame=@{func="callee3",args=[@{name="strarg",
17506value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17507file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17508fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17509(@value{GDBP})
17510@end smallexample
17511
17512Listing breakpoints and watchpoints, at different points in the program
17513execution. Note that once the watchpoint goes out of scope, it is
17514deleted.
17515
17516@smallexample
17517(@value{GDBP})
17518-break-watch C
17519^done,wpt=@{number="2",exp="C"@}
17520(@value{GDBP})
17521-break-list
17522^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17523hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17524@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17525@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17526@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17527@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17528@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17529body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17530addr="0x00010734",func="callee4",
17531file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17532bkpt=@{number="2",type="watchpoint",disp="keep",
17533enabled="y",addr="",what="C",times="0"@}]@}
17534(@value{GDBP})
17535-exec-continue
17536^running
17537^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17538value=@{old="-276895068",new="3"@},
17539frame=@{func="callee4",args=[],
76ff342d
DJ
17540file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17541fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17542(@value{GDBP})
17543-break-list
17544^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17545hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17546@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17547@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17548@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17549@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17550@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17551body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17552addr="0x00010734",func="callee4",
17553file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17554bkpt=@{number="2",type="watchpoint",disp="keep",
17555enabled="y",addr="",what="C",times="-5"@}]@}
17556(@value{GDBP})
17557-exec-continue
17558^running
17559^done,reason="watchpoint-scope",wpnum="2",
17560frame=@{func="callee3",args=[@{name="strarg",
17561value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17562file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17563fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17564(@value{GDBP})
17565-break-list
17566^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17567hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17568@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17569@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17570@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17571@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17572@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17573body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17574addr="0x00010734",func="callee4",
17575file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17576(@value{GDBP})
17577@end smallexample
17578
17579@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17580@node GDB/MI Data Manipulation
17581@section @sc{gdb/mi} Data Manipulation
17582
17583@cindex data manipulation, in @sc{gdb/mi}
17584@cindex @sc{gdb/mi}, data manipulation
17585This section describes the @sc{gdb/mi} commands that manipulate data:
17586examine memory and registers, evaluate expressions, etc.
17587
17588@c REMOVED FROM THE INTERFACE.
17589@c @subheading -data-assign
17590@c Change the value of a program variable. Plenty of side effects.
17591@c @subsubheading GDB command
17592@c set variable
17593@c @subsubheading Example
17594@c N.A.
17595
17596@subheading The @code{-data-disassemble} Command
17597@findex -data-disassemble
17598
17599@subsubheading Synopsis
17600
17601@smallexample
17602 -data-disassemble
17603 [ -s @var{start-addr} -e @var{end-addr} ]
17604 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17605 -- @var{mode}
17606@end smallexample
17607
17608@noindent
17609Where:
17610
17611@table @samp
17612@item @var{start-addr}
17613is the beginning address (or @code{$pc})
17614@item @var{end-addr}
17615is the end address
17616@item @var{filename}
17617is the name of the file to disassemble
17618@item @var{linenum}
17619is the line number to disassemble around
17620@item @var{lines}
17621is the the number of disassembly lines to be produced. If it is -1,
17622the whole function will be disassembled, in case no @var{end-addr} is
17623specified. If @var{end-addr} is specified as a non-zero value, and
17624@var{lines} is lower than the number of disassembly lines between
17625@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17626displayed; if @var{lines} is higher than the number of lines between
17627@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17628are displayed.
17629@item @var{mode}
17630is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17631disassembly).
17632@end table
17633
17634@subsubheading Result
17635
17636The output for each instruction is composed of four fields:
17637
17638@itemize @bullet
17639@item Address
17640@item Func-name
17641@item Offset
17642@item Instruction
17643@end itemize
17644
17645Note that whatever included in the instruction field, is not manipulated
17646directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17647
17648@subsubheading @value{GDBN} Command
17649
17650There's no direct mapping from this command to the CLI.
17651
17652@subsubheading Example
17653
17654Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17655
17656@smallexample
17657(@value{GDBP})
17658-data-disassemble -s $pc -e "$pc + 20" -- 0
17659^done,
17660asm_insns=[
17661@{address="0x000107c0",func-name="main",offset="4",
17662inst="mov 2, %o0"@},
17663@{address="0x000107c4",func-name="main",offset="8",
17664inst="sethi %hi(0x11800), %o2"@},
17665@{address="0x000107c8",func-name="main",offset="12",
17666inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17667@{address="0x000107cc",func-name="main",offset="16",
17668inst="sethi %hi(0x11800), %o2"@},
17669@{address="0x000107d0",func-name="main",offset="20",
17670inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17671(@value{GDBP})
17672@end smallexample
17673
17674Disassemble the whole @code{main} function. Line 32 is part of
17675@code{main}.
17676
17677@smallexample
17678-data-disassemble -f basics.c -l 32 -- 0
17679^done,asm_insns=[
17680@{address="0x000107bc",func-name="main",offset="0",
17681inst="save %sp, -112, %sp"@},
17682@{address="0x000107c0",func-name="main",offset="4",
17683inst="mov 2, %o0"@},
17684@{address="0x000107c4",func-name="main",offset="8",
17685inst="sethi %hi(0x11800), %o2"@},
17686[@dots{}]
17687@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17688@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17689(@value{GDBP})
17690@end smallexample
17691
17692Disassemble 3 instructions from the start of @code{main}:
17693
17694@smallexample
17695(@value{GDBP})
17696-data-disassemble -f basics.c -l 32 -n 3 -- 0
17697^done,asm_insns=[
17698@{address="0x000107bc",func-name="main",offset="0",
17699inst="save %sp, -112, %sp"@},
17700@{address="0x000107c0",func-name="main",offset="4",
17701inst="mov 2, %o0"@},
17702@{address="0x000107c4",func-name="main",offset="8",
17703inst="sethi %hi(0x11800), %o2"@}]
17704(@value{GDBP})
17705@end smallexample
17706
17707Disassemble 3 instructions from the start of @code{main} in mixed mode:
17708
17709@smallexample
17710(@value{GDBP})
17711-data-disassemble -f basics.c -l 32 -n 3 -- 1
17712^done,asm_insns=[
17713src_and_asm_line=@{line="31",
17714file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17715 testsuite/gdb.mi/basics.c",line_asm_insn=[
17716@{address="0x000107bc",func-name="main",offset="0",
17717inst="save %sp, -112, %sp"@}]@},
17718src_and_asm_line=@{line="32",
17719file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17720 testsuite/gdb.mi/basics.c",line_asm_insn=[
17721@{address="0x000107c0",func-name="main",offset="4",
17722inst="mov 2, %o0"@},
17723@{address="0x000107c4",func-name="main",offset="8",
17724inst="sethi %hi(0x11800), %o2"@}]@}]
17725(@value{GDBP})
17726@end smallexample
17727
17728
17729@subheading The @code{-data-evaluate-expression} Command
17730@findex -data-evaluate-expression
17731
17732@subsubheading Synopsis
17733
17734@smallexample
17735 -data-evaluate-expression @var{expr}
17736@end smallexample
17737
17738Evaluate @var{expr} as an expression. The expression could contain an
17739inferior function call. The function call will execute synchronously.
17740If the expression contains spaces, it must be enclosed in double quotes.
17741
17742@subsubheading @value{GDBN} Command
17743
17744The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17745@samp{call}. In @code{gdbtk} only, there's a corresponding
17746@samp{gdb_eval} command.
17747
17748@subsubheading Example
17749
17750In the following example, the numbers that precede the commands are the
17751@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17752Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17753output.
17754
17755@smallexample
17756211-data-evaluate-expression A
17757211^done,value="1"
17758(@value{GDBP})
17759311-data-evaluate-expression &A
17760311^done,value="0xefffeb7c"
17761(@value{GDBP})
17762411-data-evaluate-expression A+3
17763411^done,value="4"
17764(@value{GDBP})
17765511-data-evaluate-expression "A + 3"
17766511^done,value="4"
17767(@value{GDBP})
17768@end smallexample
17769
17770
17771@subheading The @code{-data-list-changed-registers} Command
17772@findex -data-list-changed-registers
17773
17774@subsubheading Synopsis
17775
17776@smallexample
17777 -data-list-changed-registers
17778@end smallexample
17779
17780Display a list of the registers that have changed.
17781
17782@subsubheading @value{GDBN} Command
17783
17784@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17785has the corresponding command @samp{gdb_changed_register_list}.
17786
17787@subsubheading Example
17788
17789On a PPC MBX board:
17790
17791@smallexample
17792(@value{GDBP})
17793-exec-continue
17794^running
17795
17796(@value{GDBP})
17797*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17798args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17799(@value{GDBP})
17800-data-list-changed-registers
17801^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17802"10","11","13","14","15","16","17","18","19","20","21","22","23",
17803"24","25","26","27","28","30","31","64","65","66","67","69"]
17804(@value{GDBP})
17805@end smallexample
17806
17807
17808@subheading The @code{-data-list-register-names} Command
17809@findex -data-list-register-names
17810
17811@subsubheading Synopsis
17812
17813@smallexample
17814 -data-list-register-names [ ( @var{regno} )+ ]
17815@end smallexample
17816
17817Show a list of register names for the current target. If no arguments
17818are given, it shows a list of the names of all the registers. If
17819integer numbers are given as arguments, it will print a list of the
17820names of the registers corresponding to the arguments. To ensure
17821consistency between a register name and its number, the output list may
17822include empty register names.
17823
17824@subsubheading @value{GDBN} Command
17825
17826@value{GDBN} does not have a command which corresponds to
17827@samp{-data-list-register-names}. In @code{gdbtk} there is a
17828corresponding command @samp{gdb_regnames}.
17829
17830@subsubheading Example
17831
17832For the PPC MBX board:
17833@smallexample
17834(@value{GDBP})
17835-data-list-register-names
17836^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17837"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17838"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17839"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17840"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17841"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17842"", "pc","ps","cr","lr","ctr","xer"]
17843(@value{GDBP})
17844-data-list-register-names 1 2 3
17845^done,register-names=["r1","r2","r3"]
17846(@value{GDBP})
17847@end smallexample
17848
17849@subheading The @code{-data-list-register-values} Command
17850@findex -data-list-register-values
17851
17852@subsubheading Synopsis
17853
17854@smallexample
17855 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17856@end smallexample
17857
17858Display the registers' contents. @var{fmt} is the format according to
17859which the registers' contents are to be returned, followed by an optional
17860list of numbers specifying the registers to display. A missing list of
17861numbers indicates that the contents of all the registers must be returned.
17862
17863Allowed formats for @var{fmt} are:
17864
17865@table @code
17866@item x
17867Hexadecimal
17868@item o
17869Octal
17870@item t
17871Binary
17872@item d
17873Decimal
17874@item r
17875Raw
17876@item N
17877Natural
17878@end table
17879
17880@subsubheading @value{GDBN} Command
17881
17882The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17883all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17884
17885@subsubheading Example
17886
17887For a PPC MBX board (note: line breaks are for readability only, they
17888don't appear in the actual output):
17889
17890@smallexample
17891(@value{GDBP})
17892-data-list-register-values r 64 65
17893^done,register-values=[@{number="64",value="0xfe00a300"@},
17894@{number="65",value="0x00029002"@}]
17895(@value{GDBP})
17896-data-list-register-values x
17897^done,register-values=[@{number="0",value="0xfe0043c8"@},
17898@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17899@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17900@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17901@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17902@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17903@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17904@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17905@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17906@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17907@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17908@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17909@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17910@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17911@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17912@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17913@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17914@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17915@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17916@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17917@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17918@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17919@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17920@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17921@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17922@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17923@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17924@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17925@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17926@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17927@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17928@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17929@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17930@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17931@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17932@{number="69",value="0x20002b03"@}]
17933(@value{GDBP})
17934@end smallexample
17935
17936
17937@subheading The @code{-data-read-memory} Command
17938@findex -data-read-memory
17939
17940@subsubheading Synopsis
17941
17942@smallexample
17943 -data-read-memory [ -o @var{byte-offset} ]
17944 @var{address} @var{word-format} @var{word-size}
17945 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17946@end smallexample
17947
17948@noindent
17949where:
17950
17951@table @samp
17952@item @var{address}
17953An expression specifying the address of the first memory word to be
17954read. Complex expressions containing embedded white space should be
17955quoted using the C convention.
17956
17957@item @var{word-format}
17958The format to be used to print the memory words. The notation is the
17959same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
17960,Output formats}).
17961
17962@item @var{word-size}
17963The size of each memory word in bytes.
17964
17965@item @var{nr-rows}
17966The number of rows in the output table.
17967
17968@item @var{nr-cols}
17969The number of columns in the output table.
17970
17971@item @var{aschar}
17972If present, indicates that each row should include an @sc{ascii} dump. The
17973value of @var{aschar} is used as a padding character when a byte is not a
17974member of the printable @sc{ascii} character set (printable @sc{ascii}
17975characters are those whose code is between 32 and 126, inclusively).
17976
17977@item @var{byte-offset}
17978An offset to add to the @var{address} before fetching memory.
17979@end table
17980
17981This command displays memory contents as a table of @var{nr-rows} by
17982@var{nr-cols} words, each word being @var{word-size} bytes. In total,
17983@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
17984(returned as @samp{total-bytes}). Should less than the requested number
17985of bytes be returned by the target, the missing words are identified
17986using @samp{N/A}. The number of bytes read from the target is returned
17987in @samp{nr-bytes} and the starting address used to read memory in
17988@samp{addr}.
17989
17990The address of the next/previous row or page is available in
17991@samp{next-row} and @samp{prev-row}, @samp{next-page} and
17992@samp{prev-page}.
17993
17994@subsubheading @value{GDBN} Command
17995
17996The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
17997@samp{gdb_get_mem} memory read command.
17998
17999@subsubheading Example
18000
18001Read six bytes of memory starting at @code{bytes+6} but then offset by
18002@code{-6} bytes. Format as three rows of two columns. One byte per
18003word. Display each word in hex.
18004
18005@smallexample
18006(@value{GDBP})
180079-data-read-memory -o -6 -- bytes+6 x 1 3 2
180089^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18009next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18010prev-page="0x0000138a",memory=[
18011@{addr="0x00001390",data=["0x00","0x01"]@},
18012@{addr="0x00001392",data=["0x02","0x03"]@},
18013@{addr="0x00001394",data=["0x04","0x05"]@}]
18014(@value{GDBP})
18015@end smallexample
18016
18017Read two bytes of memory starting at address @code{shorts + 64} and
18018display as a single word formatted in decimal.
18019
18020@smallexample
18021(@value{GDBP})
180225-data-read-memory shorts+64 d 2 1 1
180235^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18024next-row="0x00001512",prev-row="0x0000150e",
18025next-page="0x00001512",prev-page="0x0000150e",memory=[
18026@{addr="0x00001510",data=["128"]@}]
18027(@value{GDBP})
18028@end smallexample
18029
18030Read thirty two bytes of memory starting at @code{bytes+16} and format
18031as eight rows of four columns. Include a string encoding with @samp{x}
18032used as the non-printable character.
18033
18034@smallexample
18035(@value{GDBP})
180364-data-read-memory bytes+16 x 1 8 4 x
180374^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18038next-row="0x000013c0",prev-row="0x0000139c",
18039next-page="0x000013c0",prev-page="0x00001380",memory=[
18040@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18041@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18042@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18043@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18044@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18045@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18046@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18047@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18048(@value{GDBP})
18049@end smallexample
18050
18051@subheading The @code{-display-delete} Command
18052@findex -display-delete
18053
18054@subsubheading Synopsis
18055
18056@smallexample
18057 -display-delete @var{number}
18058@end smallexample
18059
18060Delete the display @var{number}.
18061
18062@subsubheading @value{GDBN} Command
18063
18064The corresponding @value{GDBN} command is @samp{delete display}.
18065
18066@subsubheading Example
18067N.A.
18068
18069
18070@subheading The @code{-display-disable} Command
18071@findex -display-disable
18072
18073@subsubheading Synopsis
18074
18075@smallexample
18076 -display-disable @var{number}
18077@end smallexample
18078
18079Disable display @var{number}.
18080
18081@subsubheading @value{GDBN} Command
18082
18083The corresponding @value{GDBN} command is @samp{disable display}.
18084
18085@subsubheading Example
18086N.A.
18087
18088
18089@subheading The @code{-display-enable} Command
18090@findex -display-enable
18091
18092@subsubheading Synopsis
18093
18094@smallexample
18095 -display-enable @var{number}
18096@end smallexample
18097
18098Enable display @var{number}.
18099
18100@subsubheading @value{GDBN} Command
18101
18102The corresponding @value{GDBN} command is @samp{enable display}.
18103
18104@subsubheading Example
18105N.A.
18106
18107
18108@subheading The @code{-display-insert} Command
18109@findex -display-insert
18110
18111@subsubheading Synopsis
18112
18113@smallexample
18114 -display-insert @var{expression}
18115@end smallexample
18116
18117Display @var{expression} every time the program stops.
18118
18119@subsubheading @value{GDBN} Command
18120
18121The corresponding @value{GDBN} command is @samp{display}.
18122
18123@subsubheading Example
18124N.A.
18125
18126
18127@subheading The @code{-display-list} Command
18128@findex -display-list
18129
18130@subsubheading Synopsis
18131
18132@smallexample
18133 -display-list
18134@end smallexample
18135
18136List the displays. Do not show the current values.
18137
18138@subsubheading @value{GDBN} Command
18139
18140The corresponding @value{GDBN} command is @samp{info display}.
18141
18142@subsubheading Example
18143N.A.
18144
18145
18146@subheading The @code{-environment-cd} Command
18147@findex -environment-cd
18148
18149@subsubheading Synopsis
18150
18151@smallexample
18152 -environment-cd @var{pathdir}
18153@end smallexample
18154
18155Set @value{GDBN}'s working directory.
18156
18157@subsubheading @value{GDBN} Command
18158
18159The corresponding @value{GDBN} command is @samp{cd}.
18160
18161@subsubheading Example
18162
18163@smallexample
18164(@value{GDBP})
18165-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18166^done
18167(@value{GDBP})
18168@end smallexample
18169
18170
18171@subheading The @code{-environment-directory} Command
18172@findex -environment-directory
18173
18174@subsubheading Synopsis
18175
18176@smallexample
18177 -environment-directory [ -r ] [ @var{pathdir} ]+
18178@end smallexample
18179
18180Add directories @var{pathdir} to beginning of search path for source files.
18181If the @samp{-r} option is used, the search path is reset to the default
b383017d 18182search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18183@samp{-r} option, the search path is first reset and then addition
18184occurs as normal.
b383017d 18185Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18186multiple directories in a single command
18187results in the directories added to the beginning of the
18188search path in the same order they were presented in the command.
18189If blanks are needed as
18190part of a directory name, double-quotes should be used around
18191the name. In the command output, the path will show up separated
b383017d 18192by the system directory-separator character. The directory-seperator
922fbb7b
AC
18193character must not be used
18194in any directory name.
18195If no directories are specified, the current search path is displayed.
18196
18197@subsubheading @value{GDBN} Command
18198
18199The corresponding @value{GDBN} command is @samp{dir}.
18200
18201@subsubheading Example
18202
18203@smallexample
18204(@value{GDBP})
18205-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18206^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18207(@value{GDBP})
18208-environment-directory ""
18209^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18210(@value{GDBP})
18211-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18212^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18213(@value{GDBP})
18214-environment-directory -r
18215^done,source-path="$cdir:$cwd"
18216(@value{GDBP})
18217@end smallexample
18218
18219
18220@subheading The @code{-environment-path} Command
18221@findex -environment-path
18222
18223@subsubheading Synopsis
18224
18225@smallexample
18226 -environment-path [ -r ] [ @var{pathdir} ]+
18227@end smallexample
18228
18229Add directories @var{pathdir} to beginning of search path for object files.
18230If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18231search path that existed at gdb start-up. If directories @var{pathdir} are
18232supplied in addition to the
922fbb7b
AC
18233@samp{-r} option, the search path is first reset and then addition
18234occurs as normal.
b383017d 18235Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18236multiple directories in a single command
18237results in the directories added to the beginning of the
18238search path in the same order they were presented in the command.
18239If blanks are needed as
18240part of a directory name, double-quotes should be used around
18241the name. In the command output, the path will show up separated
b383017d 18242by the system directory-separator character. The directory-seperator
922fbb7b
AC
18243character must not be used
18244in any directory name.
18245If no directories are specified, the current path is displayed.
18246
18247
18248@subsubheading @value{GDBN} Command
18249
18250The corresponding @value{GDBN} command is @samp{path}.
18251
18252@subsubheading Example
18253
18254@smallexample
18255(@value{GDBP})
b383017d 18256-environment-path
922fbb7b
AC
18257^done,path="/usr/bin"
18258(@value{GDBP})
18259-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18260^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18261(@value{GDBP})
18262-environment-path -r /usr/local/bin
18263^done,path="/usr/local/bin:/usr/bin"
18264(@value{GDBP})
18265@end smallexample
18266
18267
18268@subheading The @code{-environment-pwd} Command
18269@findex -environment-pwd
18270
18271@subsubheading Synopsis
18272
18273@smallexample
18274 -environment-pwd
18275@end smallexample
18276
18277Show the current working directory.
18278
18279@subsubheading @value{GDBN} command
18280
18281The corresponding @value{GDBN} command is @samp{pwd}.
18282
18283@subsubheading Example
18284
18285@smallexample
18286(@value{GDBP})
18287-environment-pwd
18288^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18289(@value{GDBP})
18290@end smallexample
18291
18292@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18293@node GDB/MI Program Control
18294@section @sc{gdb/mi} Program control
18295
18296@subsubheading Program termination
18297
18298As a result of execution, the inferior program can run to completion, if
18299it doesn't encounter any breakpoints. In this case the output will
18300include an exit code, if the program has exited exceptionally.
18301
18302@subsubheading Examples
18303
18304@noindent
18305Program exited normally:
18306
18307@smallexample
18308(@value{GDBP})
18309-exec-run
18310^running
18311(@value{GDBP})
18312x = 55
18313*stopped,reason="exited-normally"
18314(@value{GDBP})
18315@end smallexample
18316
18317@noindent
18318Program exited exceptionally:
18319
18320@smallexample
18321(@value{GDBP})
18322-exec-run
18323^running
18324(@value{GDBP})
18325x = 55
18326*stopped,reason="exited",exit-code="01"
18327(@value{GDBP})
18328@end smallexample
18329
18330Another way the program can terminate is if it receives a signal such as
18331@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18332
18333@smallexample
18334(@value{GDBP})
18335*stopped,reason="exited-signalled",signal-name="SIGINT",
18336signal-meaning="Interrupt"
18337@end smallexample
18338
18339
18340@subheading The @code{-exec-abort} Command
18341@findex -exec-abort
18342
18343@subsubheading Synopsis
18344
18345@smallexample
18346 -exec-abort
18347@end smallexample
18348
18349Kill the inferior running program.
18350
18351@subsubheading @value{GDBN} Command
18352
18353The corresponding @value{GDBN} command is @samp{kill}.
18354
18355@subsubheading Example
18356N.A.
18357
18358
18359@subheading The @code{-exec-arguments} Command
18360@findex -exec-arguments
18361
18362@subsubheading Synopsis
18363
18364@smallexample
18365 -exec-arguments @var{args}
18366@end smallexample
18367
18368Set the inferior program arguments, to be used in the next
18369@samp{-exec-run}.
18370
18371@subsubheading @value{GDBN} Command
18372
18373The corresponding @value{GDBN} command is @samp{set args}.
18374
18375@subsubheading Example
18376
18377@c FIXME!
18378Don't have one around.
18379
18380
18381@subheading The @code{-exec-continue} Command
18382@findex -exec-continue
18383
18384@subsubheading Synopsis
18385
18386@smallexample
18387 -exec-continue
18388@end smallexample
18389
18390Asynchronous command. Resumes the execution of the inferior program
18391until a breakpoint is encountered, or until the inferior exits.
18392
18393@subsubheading @value{GDBN} Command
18394
18395The corresponding @value{GDBN} corresponding is @samp{continue}.
18396
18397@subsubheading Example
18398
18399@smallexample
18400-exec-continue
18401^running
18402(@value{GDBP})
18403@@Hello world
18404*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18405file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18406(@value{GDBP})
18407@end smallexample
18408
18409
18410@subheading The @code{-exec-finish} Command
18411@findex -exec-finish
18412
18413@subsubheading Synopsis
18414
18415@smallexample
18416 -exec-finish
18417@end smallexample
18418
18419Asynchronous command. Resumes the execution of the inferior program
18420until the current function is exited. Displays the results returned by
18421the function.
18422
18423@subsubheading @value{GDBN} Command
18424
18425The corresponding @value{GDBN} command is @samp{finish}.
18426
18427@subsubheading Example
18428
18429Function returning @code{void}.
18430
18431@smallexample
18432-exec-finish
18433^running
18434(@value{GDBP})
18435@@hello from foo
18436*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18437file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18438(@value{GDBP})
18439@end smallexample
18440
18441Function returning other than @code{void}. The name of the internal
18442@value{GDBN} variable storing the result is printed, together with the
18443value itself.
18444
18445@smallexample
18446-exec-finish
18447^running
18448(@value{GDBP})
18449*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18450args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18451file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18452gdb-result-var="$1",return-value="0"
18453(@value{GDBP})
18454@end smallexample
18455
18456
18457@subheading The @code{-exec-interrupt} Command
18458@findex -exec-interrupt
18459
18460@subsubheading Synopsis
18461
18462@smallexample
18463 -exec-interrupt
18464@end smallexample
18465
18466Asynchronous command. Interrupts the background execution of the target.
18467Note how the token associated with the stop message is the one for the
18468execution command that has been interrupted. The token for the interrupt
18469itself only appears in the @samp{^done} output. If the user is trying to
18470interrupt a non-running program, an error message will be printed.
18471
18472@subsubheading @value{GDBN} Command
18473
18474The corresponding @value{GDBN} command is @samp{interrupt}.
18475
18476@subsubheading Example
18477
18478@smallexample
18479(@value{GDBP})
18480111-exec-continue
18481111^running
18482
18483(@value{GDBP})
18484222-exec-interrupt
18485222^done
18486(@value{GDBP})
18487111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18488frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18489fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18490(@value{GDBP})
18491
18492(@value{GDBP})
18493-exec-interrupt
18494^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18495(@value{GDBP})
18496@end smallexample
18497
18498
18499@subheading The @code{-exec-next} Command
18500@findex -exec-next
18501
18502@subsubheading Synopsis
18503
18504@smallexample
18505 -exec-next
18506@end smallexample
18507
18508Asynchronous command. Resumes execution of the inferior program, stopping
18509when the beginning of the next source line is reached.
18510
18511@subsubheading @value{GDBN} Command
18512
18513The corresponding @value{GDBN} command is @samp{next}.
18514
18515@subsubheading Example
18516
18517@smallexample
18518-exec-next
18519^running
18520(@value{GDBP})
18521*stopped,reason="end-stepping-range",line="8",file="hello.c"
18522(@value{GDBP})
18523@end smallexample
18524
18525
18526@subheading The @code{-exec-next-instruction} Command
18527@findex -exec-next-instruction
18528
18529@subsubheading Synopsis
18530
18531@smallexample
18532 -exec-next-instruction
18533@end smallexample
18534
18535Asynchronous command. Executes one machine instruction. If the
18536instruction is a function call continues until the function returns. If
18537the program stops at an instruction in the middle of a source line, the
18538address will be printed as well.
18539
18540@subsubheading @value{GDBN} Command
18541
18542The corresponding @value{GDBN} command is @samp{nexti}.
18543
18544@subsubheading Example
18545
18546@smallexample
18547(@value{GDBP})
18548-exec-next-instruction
18549^running
18550
18551(@value{GDBP})
18552*stopped,reason="end-stepping-range",
18553addr="0x000100d4",line="5",file="hello.c"
18554(@value{GDBP})
18555@end smallexample
18556
18557
18558@subheading The @code{-exec-return} Command
18559@findex -exec-return
18560
18561@subsubheading Synopsis
18562
18563@smallexample
18564 -exec-return
18565@end smallexample
18566
18567Makes current function return immediately. Doesn't execute the inferior.
18568Displays the new current frame.
18569
18570@subsubheading @value{GDBN} Command
18571
18572The corresponding @value{GDBN} command is @samp{return}.
18573
18574@subsubheading Example
18575
18576@smallexample
18577(@value{GDBP})
18578200-break-insert callee4
18579200^done,bkpt=@{number="1",addr="0x00010734",
18580file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18581(@value{GDBP})
18582000-exec-run
18583000^running
18584(@value{GDBP})
18585000*stopped,reason="breakpoint-hit",bkptno="1",
18586frame=@{func="callee4",args=[],
76ff342d
DJ
18587file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18588fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18589(@value{GDBP})
18590205-break-delete
18591205^done
18592(@value{GDBP})
18593111-exec-return
18594111^done,frame=@{level="0",func="callee3",
18595args=[@{name="strarg",
18596value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18597file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18598fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18599(@value{GDBP})
18600@end smallexample
18601
18602
18603@subheading The @code{-exec-run} Command
18604@findex -exec-run
18605
18606@subsubheading Synopsis
18607
18608@smallexample
18609 -exec-run
18610@end smallexample
18611
18612Asynchronous command. Starts execution of the inferior from the
18613beginning. The inferior executes until either a breakpoint is
18614encountered or the program exits.
18615
18616@subsubheading @value{GDBN} Command
18617
18618The corresponding @value{GDBN} command is @samp{run}.
18619
18620@subsubheading Example
18621
18622@smallexample
18623(@value{GDBP})
18624-break-insert main
18625^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18626(@value{GDBP})
18627-exec-run
18628^running
18629(@value{GDBP})
18630*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18631frame=@{func="main",args=[],file="recursive2.c",
18632fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18633(@value{GDBP})
18634@end smallexample
18635
18636
18637@subheading The @code{-exec-show-arguments} Command
18638@findex -exec-show-arguments
18639
18640@subsubheading Synopsis
18641
18642@smallexample
18643 -exec-show-arguments
18644@end smallexample
18645
18646Print the arguments of the program.
18647
18648@subsubheading @value{GDBN} Command
18649
18650The corresponding @value{GDBN} command is @samp{show args}.
18651
18652@subsubheading Example
18653N.A.
18654
18655@c @subheading -exec-signal
18656
18657@subheading The @code{-exec-step} Command
18658@findex -exec-step
18659
18660@subsubheading Synopsis
18661
18662@smallexample
18663 -exec-step
18664@end smallexample
18665
18666Asynchronous command. Resumes execution of the inferior program, stopping
18667when the beginning of the next source line is reached, if the next
18668source line is not a function call. If it is, stop at the first
18669instruction of the called function.
18670
18671@subsubheading @value{GDBN} Command
18672
18673The corresponding @value{GDBN} command is @samp{step}.
18674
18675@subsubheading Example
18676
18677Stepping into a function:
18678
18679@smallexample
18680-exec-step
18681^running
18682(@value{GDBP})
18683*stopped,reason="end-stepping-range",
18684frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18685@{name="b",value="0"@}],file="recursive2.c",
18686fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18687(@value{GDBP})
18688@end smallexample
18689
18690Regular stepping:
18691
18692@smallexample
18693-exec-step
18694^running
18695(@value{GDBP})
18696*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18697(@value{GDBP})
18698@end smallexample
18699
18700
18701@subheading The @code{-exec-step-instruction} Command
18702@findex -exec-step-instruction
18703
18704@subsubheading Synopsis
18705
18706@smallexample
18707 -exec-step-instruction
18708@end smallexample
18709
18710Asynchronous command. Resumes the inferior which executes one machine
18711instruction. The output, once @value{GDBN} has stopped, will vary depending on
18712whether we have stopped in the middle of a source line or not. In the
18713former case, the address at which the program stopped will be printed as
18714well.
18715
18716@subsubheading @value{GDBN} Command
18717
18718The corresponding @value{GDBN} command is @samp{stepi}.
18719
18720@subsubheading Example
18721
18722@smallexample
18723(@value{GDBP})
18724-exec-step-instruction
18725^running
18726
18727(@value{GDBP})
18728*stopped,reason="end-stepping-range",
76ff342d
DJ
18729frame=@{func="foo",args=[],file="try.c",
18730fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18731(@value{GDBP})
18732-exec-step-instruction
18733^running
18734
18735(@value{GDBP})
18736*stopped,reason="end-stepping-range",
76ff342d
DJ
18737frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18738fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18739(@value{GDBP})
18740@end smallexample
18741
18742
18743@subheading The @code{-exec-until} Command
18744@findex -exec-until
18745
18746@subsubheading Synopsis
18747
18748@smallexample
18749 -exec-until [ @var{location} ]
18750@end smallexample
18751
18752Asynchronous command. Executes the inferior until the @var{location}
18753specified in the argument is reached. If there is no argument, the inferior
18754executes until a source line greater than the current one is reached.
18755The reason for stopping in this case will be @samp{location-reached}.
18756
18757@subsubheading @value{GDBN} Command
18758
18759The corresponding @value{GDBN} command is @samp{until}.
18760
18761@subsubheading Example
18762
18763@smallexample
18764(@value{GDBP})
18765-exec-until recursive2.c:6
18766^running
18767(@value{GDBP})
18768x = 55
18769*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18770file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18771(@value{GDBP})
18772@end smallexample
18773
18774@ignore
18775@subheading -file-clear
18776Is this going away????
18777@end ignore
18778
18779
18780@subheading The @code{-file-exec-and-symbols} Command
18781@findex -file-exec-and-symbols
18782
18783@subsubheading Synopsis
18784
18785@smallexample
18786 -file-exec-and-symbols @var{file}
18787@end smallexample
18788
18789Specify the executable file to be debugged. This file is the one from
18790which the symbol table is also read. If no file is specified, the
18791command clears the executable and symbol information. If breakpoints
18792are set when using this command with no arguments, @value{GDBN} will produce
18793error messages. Otherwise, no output is produced, except a completion
18794notification.
18795
18796@subsubheading @value{GDBN} Command
18797
18798The corresponding @value{GDBN} command is @samp{file}.
18799
18800@subsubheading Example
18801
18802@smallexample
18803(@value{GDBP})
18804-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18805^done
18806(@value{GDBP})
18807@end smallexample
18808
18809
18810@subheading The @code{-file-exec-file} Command
18811@findex -file-exec-file
18812
18813@subsubheading Synopsis
18814
18815@smallexample
18816 -file-exec-file @var{file}
18817@end smallexample
18818
18819Specify the executable file to be debugged. Unlike
18820@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18821from this file. If used without argument, @value{GDBN} clears the information
18822about the executable file. No output is produced, except a completion
18823notification.
18824
18825@subsubheading @value{GDBN} Command
18826
18827The corresponding @value{GDBN} command is @samp{exec-file}.
18828
18829@subsubheading Example
18830
18831@smallexample
18832(@value{GDBP})
18833-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18834^done
18835(@value{GDBP})
18836@end smallexample
18837
18838
18839@subheading The @code{-file-list-exec-sections} Command
18840@findex -file-list-exec-sections
18841
18842@subsubheading Synopsis
18843
18844@smallexample
18845 -file-list-exec-sections
18846@end smallexample
18847
18848List the sections of the current executable file.
18849
18850@subsubheading @value{GDBN} Command
18851
18852The @value{GDBN} command @samp{info file} shows, among the rest, the same
18853information as this command. @code{gdbtk} has a corresponding command
18854@samp{gdb_load_info}.
18855
18856@subsubheading Example
18857N.A.
18858
18859
1abaf70c
BR
18860@subheading The @code{-file-list-exec-source-file} Command
18861@findex -file-list-exec-source-file
18862
18863@subsubheading Synopsis
18864
18865@smallexample
18866 -file-list-exec-source-file
18867@end smallexample
18868
b383017d 18869List the line number, the current source file, and the absolute path
1abaf70c
BR
18870to the current source file for the current executable.
18871
18872@subsubheading @value{GDBN} Command
18873
18874There's no @value{GDBN} command which directly corresponds to this one.
18875
18876@subsubheading Example
18877
18878@smallexample
18879(@value{GDBP})
18880123-file-list-exec-source-file
18881123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18882(@value{GDBP})
18883@end smallexample
18884
18885
922fbb7b
AC
18886@subheading The @code{-file-list-exec-source-files} Command
18887@findex -file-list-exec-source-files
18888
18889@subsubheading Synopsis
18890
18891@smallexample
18892 -file-list-exec-source-files
18893@end smallexample
18894
18895List the source files for the current executable.
18896
57c22c6c
BR
18897It will always output the filename, but only when GDB can find the absolute
18898file name of a source file, will it output the fullname.
18899
922fbb7b
AC
18900@subsubheading @value{GDBN} Command
18901
18902There's no @value{GDBN} command which directly corresponds to this one.
18903@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18904
18905@subsubheading Example
57c22c6c
BR
18906@smallexample
18907(@value{GDBP})
18908-file-list-exec-source-files
18909^done,files=[
18910@{file=foo.c,fullname=/home/foo.c@},
18911@{file=/home/bar.c,fullname=/home/bar.c@},
18912@{file=gdb_could_not_find_fullpath.c@}]
18913(@value{GDBP})
18914@end smallexample
922fbb7b
AC
18915
18916@subheading The @code{-file-list-shared-libraries} Command
18917@findex -file-list-shared-libraries
18918
18919@subsubheading Synopsis
18920
18921@smallexample
18922 -file-list-shared-libraries
18923@end smallexample
18924
18925List the shared libraries in the program.
18926
18927@subsubheading @value{GDBN} Command
18928
18929The corresponding @value{GDBN} command is @samp{info shared}.
18930
18931@subsubheading Example
18932N.A.
18933
18934
18935@subheading The @code{-file-list-symbol-files} Command
18936@findex -file-list-symbol-files
18937
18938@subsubheading Synopsis
18939
18940@smallexample
18941 -file-list-symbol-files
18942@end smallexample
18943
18944List symbol files.
18945
18946@subsubheading @value{GDBN} Command
18947
18948The corresponding @value{GDBN} command is @samp{info file} (part of it).
18949
18950@subsubheading Example
18951N.A.
18952
18953
18954@subheading The @code{-file-symbol-file} Command
18955@findex -file-symbol-file
18956
18957@subsubheading Synopsis
18958
18959@smallexample
18960 -file-symbol-file @var{file}
18961@end smallexample
18962
18963Read symbol table info from the specified @var{file} argument. When
18964used without arguments, clears @value{GDBN}'s symbol table info. No output is
18965produced, except for a completion notification.
18966
18967@subsubheading @value{GDBN} Command
18968
18969The corresponding @value{GDBN} command is @samp{symbol-file}.
18970
18971@subsubheading Example
18972
18973@smallexample
18974(@value{GDBP})
18975-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18976^done
18977(@value{GDBP})
18978@end smallexample
18979
18980@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18981@node GDB/MI Miscellaneous Commands
18982@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
18983
18984@c @subheading -gdb-complete
18985
18986@subheading The @code{-gdb-exit} Command
18987@findex -gdb-exit
18988
18989@subsubheading Synopsis
18990
18991@smallexample
18992 -gdb-exit
18993@end smallexample
18994
18995Exit @value{GDBN} immediately.
18996
18997@subsubheading @value{GDBN} Command
18998
18999Approximately corresponds to @samp{quit}.
19000
19001@subsubheading Example
19002
19003@smallexample
19004(@value{GDBP})
19005-gdb-exit
19006@end smallexample
19007
19008@subheading The @code{-gdb-set} Command
19009@findex -gdb-set
19010
19011@subsubheading Synopsis
19012
19013@smallexample
19014 -gdb-set
19015@end smallexample
19016
19017Set an internal @value{GDBN} variable.
19018@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19019
19020@subsubheading @value{GDBN} Command
19021
19022The corresponding @value{GDBN} command is @samp{set}.
19023
19024@subsubheading Example
19025
19026@smallexample
19027(@value{GDBP})
19028-gdb-set $foo=3
19029^done
19030(@value{GDBP})
19031@end smallexample
19032
19033
19034@subheading The @code{-gdb-show} Command
19035@findex -gdb-show
19036
19037@subsubheading Synopsis
19038
19039@smallexample
19040 -gdb-show
19041@end smallexample
19042
19043Show the current value of a @value{GDBN} variable.
19044
19045@subsubheading @value{GDBN} command
19046
19047The corresponding @value{GDBN} command is @samp{show}.
19048
19049@subsubheading Example
19050
19051@smallexample
19052(@value{GDBP})
19053-gdb-show annotate
19054^done,value="0"
19055(@value{GDBP})
19056@end smallexample
19057
19058@c @subheading -gdb-source
19059
19060
19061@subheading The @code{-gdb-version} Command
19062@findex -gdb-version
19063
19064@subsubheading Synopsis
19065
19066@smallexample
19067 -gdb-version
19068@end smallexample
19069
19070Show version information for @value{GDBN}. Used mostly in testing.
19071
19072@subsubheading @value{GDBN} Command
19073
19074There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19075information when you start an interactive session.
19076
19077@subsubheading Example
19078
19079@c This example modifies the actual output from GDB to avoid overfull
19080@c box in TeX.
19081@smallexample
19082(@value{GDBP})
19083-gdb-version
19084~GNU gdb 5.2.1
19085~Copyright 2000 Free Software Foundation, Inc.
19086~GDB is free software, covered by the GNU General Public License, and
19087~you are welcome to change it and/or distribute copies of it under
19088~ certain conditions.
19089~Type "show copying" to see the conditions.
19090~There is absolutely no warranty for GDB. Type "show warranty" for
19091~ details.
b383017d 19092~This GDB was configured as
922fbb7b
AC
19093 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19094^done
19095(@value{GDBP})
19096@end smallexample
19097
19098@subheading The @code{-interpreter-exec} Command
19099@findex -interpreter-exec
19100
19101@subheading Synopsis
19102
19103@smallexample
19104-interpreter-exec @var{interpreter} @var{command}
19105@end smallexample
19106
19107Execute the specified @var{command} in the given @var{interpreter}.
19108
19109@subheading @value{GDBN} Command
19110
19111The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19112
19113@subheading Example
19114
19115@smallexample
19116(@value{GDBP})
19117-interpreter-exec console "break main"
19118&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19119&"During symbol reading, bad structure-type format.\n"
19120~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19121^done
19122(@value{GDBP})
19123@end smallexample
19124
19125@ignore
19126@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19127@node GDB/MI Kod Commands
19128@section @sc{gdb/mi} Kod Commands
19129
19130The Kod commands are not implemented.
19131
19132@c @subheading -kod-info
19133
19134@c @subheading -kod-list
19135
19136@c @subheading -kod-list-object-types
19137
19138@c @subheading -kod-show
19139
19140@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19141@node GDB/MI Memory Overlay Commands
19142@section @sc{gdb/mi} Memory Overlay Commands
19143
19144The memory overlay commands are not implemented.
19145
19146@c @subheading -overlay-auto
19147
19148@c @subheading -overlay-list-mapping-state
19149
19150@c @subheading -overlay-list-overlays
19151
19152@c @subheading -overlay-map
19153
19154@c @subheading -overlay-off
19155
19156@c @subheading -overlay-on
19157
19158@c @subheading -overlay-unmap
19159
19160@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19161@node GDB/MI Signal Handling Commands
19162@section @sc{gdb/mi} Signal Handling Commands
19163
19164Signal handling commands are not implemented.
19165
19166@c @subheading -signal-handle
19167
19168@c @subheading -signal-list-handle-actions
19169
19170@c @subheading -signal-list-signal-types
19171@end ignore
19172
19173
19174@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19175@node GDB/MI Stack Manipulation
19176@section @sc{gdb/mi} Stack Manipulation Commands
19177
19178
19179@subheading The @code{-stack-info-frame} Command
19180@findex -stack-info-frame
19181
19182@subsubheading Synopsis
19183
19184@smallexample
19185 -stack-info-frame
19186@end smallexample
19187
19188Get info on the current frame.
19189
19190@subsubheading @value{GDBN} Command
19191
19192The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19193(without arguments).
19194
19195@subsubheading Example
19196N.A.
19197
19198@subheading The @code{-stack-info-depth} Command
19199@findex -stack-info-depth
19200
19201@subsubheading Synopsis
19202
19203@smallexample
19204 -stack-info-depth [ @var{max-depth} ]
19205@end smallexample
19206
19207Return the depth of the stack. If the integer argument @var{max-depth}
19208is specified, do not count beyond @var{max-depth} frames.
19209
19210@subsubheading @value{GDBN} Command
19211
19212There's no equivalent @value{GDBN} command.
19213
19214@subsubheading Example
19215
19216For a stack with frame levels 0 through 11:
19217
19218@smallexample
19219(@value{GDBP})
19220-stack-info-depth
19221^done,depth="12"
19222(@value{GDBP})
19223-stack-info-depth 4
19224^done,depth="4"
19225(@value{GDBP})
19226-stack-info-depth 12
19227^done,depth="12"
19228(@value{GDBP})
19229-stack-info-depth 11
19230^done,depth="11"
19231(@value{GDBP})
19232-stack-info-depth 13
19233^done,depth="12"
19234(@value{GDBP})
19235@end smallexample
19236
19237@subheading The @code{-stack-list-arguments} Command
19238@findex -stack-list-arguments
19239
19240@subsubheading Synopsis
19241
19242@smallexample
19243 -stack-list-arguments @var{show-values}
19244 [ @var{low-frame} @var{high-frame} ]
19245@end smallexample
19246
19247Display a list of the arguments for the frames between @var{low-frame}
19248and @var{high-frame} (inclusive). If @var{low-frame} and
19249@var{high-frame} are not provided, list the arguments for the whole call
19250stack.
19251
19252The @var{show-values} argument must have a value of 0 or 1. A value of
192530 means that only the names of the arguments are listed, a value of 1
19254means that both names and values of the arguments are printed.
19255
19256@subsubheading @value{GDBN} Command
19257
19258@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19259@samp{gdb_get_args} command which partially overlaps with the
19260functionality of @samp{-stack-list-arguments}.
19261
19262@subsubheading Example
19263
19264@smallexample
19265(@value{GDBP})
19266-stack-list-frames
19267^done,
19268stack=[
19269frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19270file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19271fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19272frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19273file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19274fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19275frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19276file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19277fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19278frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19279file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19280fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19281frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19282file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19283fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19284(@value{GDBP})
19285-stack-list-arguments 0
19286^done,
19287stack-args=[
19288frame=@{level="0",args=[]@},
19289frame=@{level="1",args=[name="strarg"]@},
19290frame=@{level="2",args=[name="intarg",name="strarg"]@},
19291frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19292frame=@{level="4",args=[]@}]
19293(@value{GDBP})
19294-stack-list-arguments 1
19295^done,
19296stack-args=[
19297frame=@{level="0",args=[]@},
19298frame=@{level="1",
19299 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19300frame=@{level="2",args=[
19301@{name="intarg",value="2"@},
19302@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19303@{frame=@{level="3",args=[
19304@{name="intarg",value="2"@},
19305@{name="strarg",value="0x11940 \"A string argument.\""@},
19306@{name="fltarg",value="3.5"@}]@},
19307frame=@{level="4",args=[]@}]
19308(@value{GDBP})
19309-stack-list-arguments 0 2 2
19310^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19311(@value{GDBP})
19312-stack-list-arguments 1 2 2
19313^done,stack-args=[frame=@{level="2",
19314args=[@{name="intarg",value="2"@},
19315@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19316(@value{GDBP})
19317@end smallexample
19318
19319@c @subheading -stack-list-exception-handlers
19320
19321
19322@subheading The @code{-stack-list-frames} Command
19323@findex -stack-list-frames
19324
19325@subsubheading Synopsis
19326
19327@smallexample
19328 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19329@end smallexample
19330
19331List the frames currently on the stack. For each frame it displays the
19332following info:
19333
19334@table @samp
19335@item @var{level}
19336The frame number, 0 being the topmost frame, i.e. the innermost function.
19337@item @var{addr}
19338The @code{$pc} value for that frame.
19339@item @var{func}
19340Function name.
19341@item @var{file}
19342File name of the source file where the function lives.
19343@item @var{line}
19344Line number corresponding to the @code{$pc}.
19345@end table
19346
19347If invoked without arguments, this command prints a backtrace for the
19348whole stack. If given two integer arguments, it shows the frames whose
19349levels are between the two arguments (inclusive). If the two arguments
19350are equal, it shows the single frame at the corresponding level.
19351
19352@subsubheading @value{GDBN} Command
19353
19354The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19355
19356@subsubheading Example
19357
19358Full stack backtrace:
19359
19360@smallexample
19361(@value{GDBP})
19362-stack-list-frames
19363^done,stack=
19364[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19365 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19366frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19367 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19368frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19369 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19370frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19371 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19372frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19373 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19374frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19375 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19376frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19377 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19378frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19379 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19380frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19381 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19382frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19383 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19384frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19385 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19386frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19387 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19388(@value{GDBP})
19389@end smallexample
19390
19391Show frames between @var{low_frame} and @var{high_frame}:
19392
19393@smallexample
19394(@value{GDBP})
19395-stack-list-frames 3 5
19396^done,stack=
19397[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19398 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19399frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19400 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19401frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19402 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19403(@value{GDBP})
19404@end smallexample
19405
19406Show a single frame:
19407
19408@smallexample
19409(@value{GDBP})
19410-stack-list-frames 3 3
19411^done,stack=
19412[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19413 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19414(@value{GDBP})
19415@end smallexample
19416
19417
19418@subheading The @code{-stack-list-locals} Command
19419@findex -stack-list-locals
19420
19421@subsubheading Synopsis
19422
19423@smallexample
19424 -stack-list-locals @var{print-values}
19425@end smallexample
19426
19427Display the local variable names for the current frame. With an
bc8ced35
NR
19428argument of 0 or @code{--no-values}, prints only the names of the variables.
19429With argument of 1 or @code{--all-values}, prints also their values. With
19430argument of 2 or @code{--simple-values}, prints the name, type and value for
19431simple data types and the name and type for arrays, structures and
19432unions. In this last case, the idea is that the user can see the
19433value of simple data types immediately and he can create variable
19434objects for other data types if he wishes to explore their values in
19435more detail.
922fbb7b
AC
19436
19437@subsubheading @value{GDBN} Command
19438
19439@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19440
19441@subsubheading Example
19442
19443@smallexample
19444(@value{GDBP})
19445-stack-list-locals 0
19446^done,locals=[name="A",name="B",name="C"]
19447(@value{GDBP})
bc8ced35 19448-stack-list-locals --all-values
922fbb7b 19449^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19450 @{name="C",value="@{1, 2, 3@}"@}]
19451-stack-list-locals --simple-values
19452^done,locals=[@{name="A",type="int",value="1"@},
19453 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19454(@value{GDBP})
19455@end smallexample
19456
19457
19458@subheading The @code{-stack-select-frame} Command
19459@findex -stack-select-frame
19460
19461@subsubheading Synopsis
19462
19463@smallexample
19464 -stack-select-frame @var{framenum}
19465@end smallexample
19466
19467Change the current frame. Select a different frame @var{framenum} on
19468the stack.
19469
19470@subsubheading @value{GDBN} Command
19471
19472The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19473@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19474
19475@subsubheading Example
19476
19477@smallexample
19478(@value{GDBP})
19479-stack-select-frame 2
19480^done
19481(@value{GDBP})
19482@end smallexample
19483
19484@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19485@node GDB/MI Symbol Query
19486@section @sc{gdb/mi} Symbol Query Commands
19487
19488
19489@subheading The @code{-symbol-info-address} Command
19490@findex -symbol-info-address
19491
19492@subsubheading Synopsis
19493
19494@smallexample
19495 -symbol-info-address @var{symbol}
19496@end smallexample
19497
19498Describe where @var{symbol} is stored.
19499
19500@subsubheading @value{GDBN} Command
19501
19502The corresponding @value{GDBN} command is @samp{info address}.
19503
19504@subsubheading Example
19505N.A.
19506
19507
19508@subheading The @code{-symbol-info-file} Command
19509@findex -symbol-info-file
19510
19511@subsubheading Synopsis
19512
19513@smallexample
19514 -symbol-info-file
19515@end smallexample
19516
19517Show the file for the symbol.
19518
19519@subsubheading @value{GDBN} Command
19520
19521There's no equivalent @value{GDBN} command. @code{gdbtk} has
19522@samp{gdb_find_file}.
19523
19524@subsubheading Example
19525N.A.
19526
19527
19528@subheading The @code{-symbol-info-function} Command
19529@findex -symbol-info-function
19530
19531@subsubheading Synopsis
19532
19533@smallexample
19534 -symbol-info-function
19535@end smallexample
19536
19537Show which function the symbol lives in.
19538
19539@subsubheading @value{GDBN} Command
19540
19541@samp{gdb_get_function} in @code{gdbtk}.
19542
19543@subsubheading Example
19544N.A.
19545
19546
19547@subheading The @code{-symbol-info-line} Command
19548@findex -symbol-info-line
19549
19550@subsubheading Synopsis
19551
19552@smallexample
19553 -symbol-info-line
19554@end smallexample
19555
19556Show the core addresses of the code for a source line.
19557
19558@subsubheading @value{GDBN} Command
19559
71952f4c 19560The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19561@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19562
19563@subsubheading Example
19564N.A.
19565
19566
19567@subheading The @code{-symbol-info-symbol} Command
19568@findex -symbol-info-symbol
19569
19570@subsubheading Synopsis
19571
19572@smallexample
19573 -symbol-info-symbol @var{addr}
19574@end smallexample
19575
19576Describe what symbol is at location @var{addr}.
19577
19578@subsubheading @value{GDBN} Command
19579
19580The corresponding @value{GDBN} command is @samp{info symbol}.
19581
19582@subsubheading Example
19583N.A.
19584
19585
19586@subheading The @code{-symbol-list-functions} Command
19587@findex -symbol-list-functions
19588
19589@subsubheading Synopsis
19590
19591@smallexample
19592 -symbol-list-functions
19593@end smallexample
19594
19595List the functions in the executable.
19596
19597@subsubheading @value{GDBN} Command
19598
19599@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19600@samp{gdb_search} in @code{gdbtk}.
19601
19602@subsubheading Example
19603N.A.
19604
19605
32e7087d
JB
19606@subheading The @code{-symbol-list-lines} Command
19607@findex -symbol-list-lines
19608
19609@subsubheading Synopsis
19610
19611@smallexample
19612 -symbol-list-lines @var{filename}
19613@end smallexample
19614
19615Print the list of lines that contain code and their associated program
19616addresses for the given source filename. The entries are sorted in
19617ascending PC order.
19618
19619@subsubheading @value{GDBN} Command
19620
19621There is no corresponding @value{GDBN} command.
19622
19623@subsubheading Example
19624@smallexample
19625(@value{GDBP})
19626-symbol-list-lines basics.c
54ff5908 19627^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19628(@value{GDBP})
19629@end smallexample
19630
19631
922fbb7b
AC
19632@subheading The @code{-symbol-list-types} Command
19633@findex -symbol-list-types
19634
19635@subsubheading Synopsis
19636
19637@smallexample
19638 -symbol-list-types
19639@end smallexample
19640
19641List all the type names.
19642
19643@subsubheading @value{GDBN} Command
19644
19645The corresponding commands are @samp{info types} in @value{GDBN},
19646@samp{gdb_search} in @code{gdbtk}.
19647
19648@subsubheading Example
19649N.A.
19650
19651
19652@subheading The @code{-symbol-list-variables} Command
19653@findex -symbol-list-variables
19654
19655@subsubheading Synopsis
19656
19657@smallexample
19658 -symbol-list-variables
19659@end smallexample
19660
19661List all the global and static variable names.
19662
19663@subsubheading @value{GDBN} Command
19664
19665@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19666
19667@subsubheading Example
19668N.A.
19669
19670
19671@subheading The @code{-symbol-locate} Command
19672@findex -symbol-locate
19673
19674@subsubheading Synopsis
19675
19676@smallexample
19677 -symbol-locate
19678@end smallexample
19679
19680@subsubheading @value{GDBN} Command
19681
19682@samp{gdb_loc} in @code{gdbtk}.
19683
19684@subsubheading Example
19685N.A.
19686
19687
19688@subheading The @code{-symbol-type} Command
19689@findex -symbol-type
19690
19691@subsubheading Synopsis
19692
19693@smallexample
19694 -symbol-type @var{variable}
19695@end smallexample
19696
19697Show type of @var{variable}.
19698
19699@subsubheading @value{GDBN} Command
19700
19701The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19702@samp{gdb_obj_variable}.
19703
19704@subsubheading Example
19705N.A.
19706
19707
19708@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19709@node GDB/MI Target Manipulation
19710@section @sc{gdb/mi} Target Manipulation Commands
19711
19712
19713@subheading The @code{-target-attach} Command
19714@findex -target-attach
19715
19716@subsubheading Synopsis
19717
19718@smallexample
19719 -target-attach @var{pid} | @var{file}
19720@end smallexample
19721
19722Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19723
19724@subsubheading @value{GDBN} command
19725
19726The corresponding @value{GDBN} command is @samp{attach}.
19727
19728@subsubheading Example
19729N.A.
19730
19731
19732@subheading The @code{-target-compare-sections} Command
19733@findex -target-compare-sections
19734
19735@subsubheading Synopsis
19736
19737@smallexample
19738 -target-compare-sections [ @var{section} ]
19739@end smallexample
19740
19741Compare data of section @var{section} on target to the exec file.
19742Without the argument, all sections are compared.
19743
19744@subsubheading @value{GDBN} Command
19745
19746The @value{GDBN} equivalent is @samp{compare-sections}.
19747
19748@subsubheading Example
19749N.A.
19750
19751
19752@subheading The @code{-target-detach} Command
19753@findex -target-detach
19754
19755@subsubheading Synopsis
19756
19757@smallexample
19758 -target-detach
19759@end smallexample
19760
19761Disconnect from the remote target. There's no output.
19762
19763@subsubheading @value{GDBN} command
19764
19765The corresponding @value{GDBN} command is @samp{detach}.
19766
19767@subsubheading Example
19768
19769@smallexample
19770(@value{GDBP})
19771-target-detach
19772^done
19773(@value{GDBP})
19774@end smallexample
19775
19776
07f31aa6
DJ
19777@subheading The @code{-target-disconnect} Command
19778@findex -target-disconnect
19779
19780@subsubheading Synopsis
19781
19782@example
19783 -target-disconnect
19784@end example
19785
19786Disconnect from the remote target. There's no output.
19787
19788@subsubheading @value{GDBN} command
19789
19790The corresponding @value{GDBN} command is @samp{disconnect}.
19791
19792@subsubheading Example
19793
19794@smallexample
19795(@value{GDBP})
19796-target-disconnect
19797^done
19798(@value{GDBP})
19799@end smallexample
19800
19801
922fbb7b
AC
19802@subheading The @code{-target-download} Command
19803@findex -target-download
19804
19805@subsubheading Synopsis
19806
19807@smallexample
19808 -target-download
19809@end smallexample
19810
19811Loads the executable onto the remote target.
19812It prints out an update message every half second, which includes the fields:
19813
19814@table @samp
19815@item section
19816The name of the section.
19817@item section-sent
19818The size of what has been sent so far for that section.
19819@item section-size
19820The size of the section.
19821@item total-sent
19822The total size of what was sent so far (the current and the previous sections).
19823@item total-size
19824The size of the overall executable to download.
19825@end table
19826
19827@noindent
19828Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19829@sc{gdb/mi} Output Syntax}).
19830
19831In addition, it prints the name and size of the sections, as they are
19832downloaded. These messages include the following fields:
19833
19834@table @samp
19835@item section
19836The name of the section.
19837@item section-size
19838The size of the section.
19839@item total-size
19840The size of the overall executable to download.
19841@end table
19842
19843@noindent
19844At the end, a summary is printed.
19845
19846@subsubheading @value{GDBN} Command
19847
19848The corresponding @value{GDBN} command is @samp{load}.
19849
19850@subsubheading Example
19851
19852Note: each status message appears on a single line. Here the messages
19853have been broken down so that they can fit onto a page.
19854
19855@smallexample
19856(@value{GDBP})
19857-target-download
19858+download,@{section=".text",section-size="6668",total-size="9880"@}
19859+download,@{section=".text",section-sent="512",section-size="6668",
19860total-sent="512",total-size="9880"@}
19861+download,@{section=".text",section-sent="1024",section-size="6668",
19862total-sent="1024",total-size="9880"@}
19863+download,@{section=".text",section-sent="1536",section-size="6668",
19864total-sent="1536",total-size="9880"@}
19865+download,@{section=".text",section-sent="2048",section-size="6668",
19866total-sent="2048",total-size="9880"@}
19867+download,@{section=".text",section-sent="2560",section-size="6668",
19868total-sent="2560",total-size="9880"@}
19869+download,@{section=".text",section-sent="3072",section-size="6668",
19870total-sent="3072",total-size="9880"@}
19871+download,@{section=".text",section-sent="3584",section-size="6668",
19872total-sent="3584",total-size="9880"@}
19873+download,@{section=".text",section-sent="4096",section-size="6668",
19874total-sent="4096",total-size="9880"@}
19875+download,@{section=".text",section-sent="4608",section-size="6668",
19876total-sent="4608",total-size="9880"@}
19877+download,@{section=".text",section-sent="5120",section-size="6668",
19878total-sent="5120",total-size="9880"@}
19879+download,@{section=".text",section-sent="5632",section-size="6668",
19880total-sent="5632",total-size="9880"@}
19881+download,@{section=".text",section-sent="6144",section-size="6668",
19882total-sent="6144",total-size="9880"@}
19883+download,@{section=".text",section-sent="6656",section-size="6668",
19884total-sent="6656",total-size="9880"@}
19885+download,@{section=".init",section-size="28",total-size="9880"@}
19886+download,@{section=".fini",section-size="28",total-size="9880"@}
19887+download,@{section=".data",section-size="3156",total-size="9880"@}
19888+download,@{section=".data",section-sent="512",section-size="3156",
19889total-sent="7236",total-size="9880"@}
19890+download,@{section=".data",section-sent="1024",section-size="3156",
19891total-sent="7748",total-size="9880"@}
19892+download,@{section=".data",section-sent="1536",section-size="3156",
19893total-sent="8260",total-size="9880"@}
19894+download,@{section=".data",section-sent="2048",section-size="3156",
19895total-sent="8772",total-size="9880"@}
19896+download,@{section=".data",section-sent="2560",section-size="3156",
19897total-sent="9284",total-size="9880"@}
19898+download,@{section=".data",section-sent="3072",section-size="3156",
19899total-sent="9796",total-size="9880"@}
19900^done,address="0x10004",load-size="9880",transfer-rate="6586",
19901write-rate="429"
19902(@value{GDBP})
19903@end smallexample
19904
19905
19906@subheading The @code{-target-exec-status} Command
19907@findex -target-exec-status
19908
19909@subsubheading Synopsis
19910
19911@smallexample
19912 -target-exec-status
19913@end smallexample
19914
19915Provide information on the state of the target (whether it is running or
19916not, for instance).
19917
19918@subsubheading @value{GDBN} Command
19919
19920There's no equivalent @value{GDBN} command.
19921
19922@subsubheading Example
19923N.A.
19924
19925
19926@subheading The @code{-target-list-available-targets} Command
19927@findex -target-list-available-targets
19928
19929@subsubheading Synopsis
19930
19931@smallexample
19932 -target-list-available-targets
19933@end smallexample
19934
19935List the possible targets to connect to.
19936
19937@subsubheading @value{GDBN} Command
19938
19939The corresponding @value{GDBN} command is @samp{help target}.
19940
19941@subsubheading Example
19942N.A.
19943
19944
19945@subheading The @code{-target-list-current-targets} Command
19946@findex -target-list-current-targets
19947
19948@subsubheading Synopsis
19949
19950@smallexample
19951 -target-list-current-targets
19952@end smallexample
19953
19954Describe the current target.
19955
19956@subsubheading @value{GDBN} Command
19957
19958The corresponding information is printed by @samp{info file} (among
19959other things).
19960
19961@subsubheading Example
19962N.A.
19963
19964
19965@subheading The @code{-target-list-parameters} Command
19966@findex -target-list-parameters
19967
19968@subsubheading Synopsis
19969
19970@smallexample
19971 -target-list-parameters
19972@end smallexample
19973
19974@c ????
19975
19976@subsubheading @value{GDBN} Command
19977
19978No equivalent.
19979
19980@subsubheading Example
19981N.A.
19982
19983
19984@subheading The @code{-target-select} Command
19985@findex -target-select
19986
19987@subsubheading Synopsis
19988
19989@smallexample
19990 -target-select @var{type} @var{parameters @dots{}}
19991@end smallexample
19992
19993Connect @value{GDBN} to the remote target. This command takes two args:
19994
19995@table @samp
19996@item @var{type}
19997The type of target, for instance @samp{async}, @samp{remote}, etc.
19998@item @var{parameters}
19999Device names, host names and the like. @xref{Target Commands, ,
20000Commands for managing targets}, for more details.
20001@end table
20002
20003The output is a connection notification, followed by the address at
20004which the target program is, in the following form:
20005
20006@smallexample
20007^connected,addr="@var{address}",func="@var{function name}",
20008 args=[@var{arg list}]
20009@end smallexample
20010
20011@subsubheading @value{GDBN} Command
20012
20013The corresponding @value{GDBN} command is @samp{target}.
20014
20015@subsubheading Example
20016
20017@smallexample
20018(@value{GDBP})
20019-target-select async /dev/ttya
20020^connected,addr="0xfe00a300",func="??",args=[]
20021(@value{GDBP})
20022@end smallexample
20023
20024@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20025@node GDB/MI Thread Commands
20026@section @sc{gdb/mi} Thread Commands
20027
20028
20029@subheading The @code{-thread-info} Command
20030@findex -thread-info
20031
20032@subsubheading Synopsis
20033
20034@smallexample
20035 -thread-info
20036@end smallexample
20037
20038@subsubheading @value{GDBN} command
20039
20040No equivalent.
20041
20042@subsubheading Example
20043N.A.
20044
20045
20046@subheading The @code{-thread-list-all-threads} Command
20047@findex -thread-list-all-threads
20048
20049@subsubheading Synopsis
20050
20051@smallexample
20052 -thread-list-all-threads
20053@end smallexample
20054
20055@subsubheading @value{GDBN} Command
20056
20057The equivalent @value{GDBN} command is @samp{info threads}.
20058
20059@subsubheading Example
20060N.A.
20061
20062
20063@subheading The @code{-thread-list-ids} Command
20064@findex -thread-list-ids
20065
20066@subsubheading Synopsis
20067
20068@smallexample
20069 -thread-list-ids
20070@end smallexample
20071
20072Produces a list of the currently known @value{GDBN} thread ids. At the
20073end of the list it also prints the total number of such threads.
20074
20075@subsubheading @value{GDBN} Command
20076
20077Part of @samp{info threads} supplies the same information.
20078
20079@subsubheading Example
20080
20081No threads present, besides the main process:
20082
20083@smallexample
20084(@value{GDBP})
20085-thread-list-ids
20086^done,thread-ids=@{@},number-of-threads="0"
20087(@value{GDBP})
20088@end smallexample
20089
20090
20091Several threads:
20092
20093@smallexample
20094(@value{GDBP})
20095-thread-list-ids
20096^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20097number-of-threads="3"
20098(@value{GDBP})
20099@end smallexample
20100
20101
20102@subheading The @code{-thread-select} Command
20103@findex -thread-select
20104
20105@subsubheading Synopsis
20106
20107@smallexample
20108 -thread-select @var{threadnum}
20109@end smallexample
20110
20111Make @var{threadnum} the current thread. It prints the number of the new
20112current thread, and the topmost frame for that thread.
20113
20114@subsubheading @value{GDBN} Command
20115
20116The corresponding @value{GDBN} command is @samp{thread}.
20117
20118@subsubheading Example
20119
20120@smallexample
20121(@value{GDBP})
20122-exec-next
20123^running
20124(@value{GDBP})
20125*stopped,reason="end-stepping-range",thread-id="2",line="187",
20126file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20127(@value{GDBP})
20128-thread-list-ids
20129^done,
20130thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20131number-of-threads="3"
20132(@value{GDBP})
20133-thread-select 3
20134^done,new-thread-id="3",
20135frame=@{level="0",func="vprintf",
20136args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20137@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20138(@value{GDBP})
20139@end smallexample
20140
20141@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20142@node GDB/MI Tracepoint Commands
20143@section @sc{gdb/mi} Tracepoint Commands
20144
20145The tracepoint commands are not yet implemented.
20146
20147@c @subheading -trace-actions
20148
20149@c @subheading -trace-delete
20150
20151@c @subheading -trace-disable
20152
20153@c @subheading -trace-dump
20154
20155@c @subheading -trace-enable
20156
20157@c @subheading -trace-exists
20158
20159@c @subheading -trace-find
20160
20161@c @subheading -trace-frame-number
20162
20163@c @subheading -trace-info
20164
20165@c @subheading -trace-insert
20166
20167@c @subheading -trace-list
20168
20169@c @subheading -trace-pass-count
20170
20171@c @subheading -trace-save
20172
20173@c @subheading -trace-start
20174
20175@c @subheading -trace-stop
20176
20177
20178@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20179@node GDB/MI Variable Objects
20180@section @sc{gdb/mi} Variable Objects
20181
20182
20183@subheading Motivation for Variable Objects in @sc{gdb/mi}
20184
20185For the implementation of a variable debugger window (locals, watched
20186expressions, etc.), we are proposing the adaptation of the existing code
20187used by @code{Insight}.
20188
20189The two main reasons for that are:
20190
20191@enumerate 1
20192@item
20193It has been proven in practice (it is already on its second generation).
20194
20195@item
20196It will shorten development time (needless to say how important it is
20197now).
20198@end enumerate
20199
20200The original interface was designed to be used by Tcl code, so it was
20201slightly changed so it could be used through @sc{gdb/mi}. This section
20202describes the @sc{gdb/mi} operations that will be available and gives some
20203hints about their use.
20204
20205@emph{Note}: In addition to the set of operations described here, we
20206expect the @sc{gui} implementation of a variable window to require, at
20207least, the following operations:
20208
20209@itemize @bullet
20210@item @code{-gdb-show} @code{output-radix}
20211@item @code{-stack-list-arguments}
20212@item @code{-stack-list-locals}
20213@item @code{-stack-select-frame}
20214@end itemize
20215
20216@subheading Introduction to Variable Objects in @sc{gdb/mi}
20217
20218@cindex variable objects in @sc{gdb/mi}
20219The basic idea behind variable objects is the creation of a named object
20220to represent a variable, an expression, a memory location or even a CPU
20221register. For each object created, a set of operations is available for
20222examining or changing its properties.
20223
20224Furthermore, complex data types, such as C structures, are represented
20225in a tree format. For instance, the @code{struct} type variable is the
20226root and the children will represent the struct members. If a child
20227is itself of a complex type, it will also have children of its own.
20228Appropriate language differences are handled for C, C@t{++} and Java.
20229
20230When returning the actual values of the objects, this facility allows
20231for the individual selection of the display format used in the result
20232creation. It can be chosen among: binary, decimal, hexadecimal, octal
20233and natural. Natural refers to a default format automatically
20234chosen based on the variable type (like decimal for an @code{int}, hex
20235for pointers, etc.).
20236
20237The following is the complete set of @sc{gdb/mi} operations defined to
20238access this functionality:
20239
20240@multitable @columnfractions .4 .6
20241@item @strong{Operation}
20242@tab @strong{Description}
20243
20244@item @code{-var-create}
20245@tab create a variable object
20246@item @code{-var-delete}
20247@tab delete the variable object and its children
20248@item @code{-var-set-format}
20249@tab set the display format of this variable
20250@item @code{-var-show-format}
20251@tab show the display format of this variable
20252@item @code{-var-info-num-children}
20253@tab tells how many children this object has
20254@item @code{-var-list-children}
20255@tab return a list of the object's children
20256@item @code{-var-info-type}
20257@tab show the type of this variable object
20258@item @code{-var-info-expression}
20259@tab print what this variable object represents
20260@item @code{-var-show-attributes}
20261@tab is this variable editable? does it exist here?
20262@item @code{-var-evaluate-expression}
20263@tab get the value of this variable
20264@item @code{-var-assign}
20265@tab set the value of this variable
20266@item @code{-var-update}
20267@tab update the variable and its children
20268@end multitable
20269
20270In the next subsection we describe each operation in detail and suggest
20271how it can be used.
20272
20273@subheading Description And Use of Operations on Variable Objects
20274
20275@subheading The @code{-var-create} Command
20276@findex -var-create
20277
20278@subsubheading Synopsis
20279
20280@smallexample
20281 -var-create @{@var{name} | "-"@}
20282 @{@var{frame-addr} | "*"@} @var{expression}
20283@end smallexample
20284
20285This operation creates a variable object, which allows the monitoring of
20286a variable, the result of an expression, a memory cell or a CPU
20287register.
20288
20289The @var{name} parameter is the string by which the object can be
20290referenced. It must be unique. If @samp{-} is specified, the varobj
20291system will generate a string ``varNNNNNN'' automatically. It will be
20292unique provided that one does not specify @var{name} on that format.
20293The command fails if a duplicate name is found.
20294
20295The frame under which the expression should be evaluated can be
20296specified by @var{frame-addr}. A @samp{*} indicates that the current
20297frame should be used.
20298
20299@var{expression} is any expression valid on the current language set (must not
20300begin with a @samp{*}), or one of the following:
20301
20302@itemize @bullet
20303@item
20304@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20305
20306@item
20307@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20308
20309@item
20310@samp{$@var{regname}} --- a CPU register name
20311@end itemize
20312
20313@subsubheading Result
20314
20315This operation returns the name, number of children and the type of the
20316object created. Type is returned as a string as the ones generated by
20317the @value{GDBN} CLI:
20318
20319@smallexample
20320 name="@var{name}",numchild="N",type="@var{type}"
20321@end smallexample
20322
20323
20324@subheading The @code{-var-delete} Command
20325@findex -var-delete
20326
20327@subsubheading Synopsis
20328
20329@smallexample
20330 -var-delete @var{name}
20331@end smallexample
20332
20333Deletes a previously created variable object and all of its children.
20334
20335Returns an error if the object @var{name} is not found.
20336
20337
20338@subheading The @code{-var-set-format} Command
20339@findex -var-set-format
20340
20341@subsubheading Synopsis
20342
20343@smallexample
20344 -var-set-format @var{name} @var{format-spec}
20345@end smallexample
20346
20347Sets the output format for the value of the object @var{name} to be
20348@var{format-spec}.
20349
20350The syntax for the @var{format-spec} is as follows:
20351
20352@smallexample
20353 @var{format-spec} @expansion{}
20354 @{binary | decimal | hexadecimal | octal | natural@}
20355@end smallexample
20356
20357
20358@subheading The @code{-var-show-format} Command
20359@findex -var-show-format
20360
20361@subsubheading Synopsis
20362
20363@smallexample
20364 -var-show-format @var{name}
20365@end smallexample
20366
20367Returns the format used to display the value of the object @var{name}.
20368
20369@smallexample
20370 @var{format} @expansion{}
20371 @var{format-spec}
20372@end smallexample
20373
20374
20375@subheading The @code{-var-info-num-children} Command
20376@findex -var-info-num-children
20377
20378@subsubheading Synopsis
20379
20380@smallexample
20381 -var-info-num-children @var{name}
20382@end smallexample
20383
20384Returns the number of children of a variable object @var{name}:
20385
20386@smallexample
20387 numchild=@var{n}
20388@end smallexample
20389
20390
20391@subheading The @code{-var-list-children} Command
20392@findex -var-list-children
20393
20394@subsubheading Synopsis
20395
20396@smallexample
bc8ced35 20397 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
20398@end smallexample
20399
bc8ced35
NR
20400Returns a list of the children of the specified variable object. With
20401just the variable object name as an argument or with an optional
20402preceding argument of 0 or @code{--no-values}, prints only the names of the
20403variables. With an optional preceding argument of 1 or @code{--all-values},
20404also prints their values.
20405
20406@subsubheading Example
922fbb7b
AC
20407
20408@smallexample
bc8ced35
NR
20409(@value{GDBP})
20410 -var-list-children n
922fbb7b
AC
20411 numchild=@var{n},children=[@{name=@var{name},
20412 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20413(@value{GDBP})
20414 -var-list-children --all-values n
20415 numchild=@var{n},children=[@{name=@var{name},
20416 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20417@end smallexample
20418
20419
20420@subheading The @code{-var-info-type} Command
20421@findex -var-info-type
20422
20423@subsubheading Synopsis
20424
20425@smallexample
20426 -var-info-type @var{name}
20427@end smallexample
20428
20429Returns the type of the specified variable @var{name}. The type is
20430returned as a string in the same format as it is output by the
20431@value{GDBN} CLI:
20432
20433@smallexample
20434 type=@var{typename}
20435@end smallexample
20436
20437
20438@subheading The @code{-var-info-expression} Command
20439@findex -var-info-expression
20440
20441@subsubheading Synopsis
20442
20443@smallexample
20444 -var-info-expression @var{name}
20445@end smallexample
20446
20447Returns what is represented by the variable object @var{name}:
20448
20449@smallexample
20450 lang=@var{lang-spec},exp=@var{expression}
20451@end smallexample
20452
20453@noindent
20454where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20455
20456@subheading The @code{-var-show-attributes} Command
20457@findex -var-show-attributes
20458
20459@subsubheading Synopsis
20460
20461@smallexample
20462 -var-show-attributes @var{name}
20463@end smallexample
20464
20465List attributes of the specified variable object @var{name}:
20466
20467@smallexample
20468 status=@var{attr} [ ( ,@var{attr} )* ]
20469@end smallexample
20470
20471@noindent
20472where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20473
20474@subheading The @code{-var-evaluate-expression} Command
20475@findex -var-evaluate-expression
20476
20477@subsubheading Synopsis
20478
20479@smallexample
20480 -var-evaluate-expression @var{name}
20481@end smallexample
20482
20483Evaluates the expression that is represented by the specified variable
20484object and returns its value as a string in the current format specified
20485for the object:
20486
20487@smallexample
20488 value=@var{value}
20489@end smallexample
20490
20491Note that one must invoke @code{-var-list-children} for a variable
20492before the value of a child variable can be evaluated.
20493
20494@subheading The @code{-var-assign} Command
20495@findex -var-assign
20496
20497@subsubheading Synopsis
20498
20499@smallexample
20500 -var-assign @var{name} @var{expression}
20501@end smallexample
20502
20503Assigns the value of @var{expression} to the variable object specified
20504by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20505value is altered by the assign, the variable will show up in any
922fbb7b
AC
20506subsequent @code{-var-update} list.
20507
20508@subsubheading Example
20509
20510@smallexample
20511(@value{GDBP})
20512-var-assign var1 3
20513^done,value="3"
20514(@value{GDBP})
20515-var-update *
20516^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20517(@value{GDBP})
20518@end smallexample
20519
20520@subheading The @code{-var-update} Command
20521@findex -var-update
20522
20523@subsubheading Synopsis
20524
20525@smallexample
20526 -var-update @{@var{name} | "*"@}
20527@end smallexample
20528
20529Update the value of the variable object @var{name} by evaluating its
20530expression after fetching all the new values from memory or registers.
20531A @samp{*} causes all existing variable objects to be updated.
20532
20533
20534@node Annotations
20535@chapter @value{GDBN} Annotations
20536
086432e2
AC
20537This chapter describes annotations in @value{GDBN}. Annotations were
20538designed to interface @value{GDBN} to graphical user interfaces or other
20539similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20540relatively high level.
20541
086432e2
AC
20542The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20543(@pxref{GDB/MI}).
20544
922fbb7b
AC
20545@ignore
20546This is Edition @value{EDITION}, @value{DATE}.
20547@end ignore
20548
20549@menu
20550* Annotations Overview:: What annotations are; the general syntax.
20551* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
20552* Prompting:: Annotations marking @value{GDBN}'s need for input.
20553* Errors:: Annotations for error messages.
922fbb7b
AC
20554* Invalidation:: Some annotations describe things now invalid.
20555* Annotations for Running::
20556 Whether the program is running, how it stopped, etc.
20557* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20558@end menu
20559
20560@node Annotations Overview
20561@section What is an Annotation?
20562@cindex annotations
20563
922fbb7b
AC
20564Annotations start with a newline character, two @samp{control-z}
20565characters, and the name of the annotation. If there is no additional
20566information associated with this annotation, the name of the annotation
20567is followed immediately by a newline. If there is additional
20568information, the name of the annotation is followed by a space, the
20569additional information, and a newline. The additional information
20570cannot contain newline characters.
20571
20572Any output not beginning with a newline and two @samp{control-z}
20573characters denotes literal output from @value{GDBN}. Currently there is
20574no need for @value{GDBN} to output a newline followed by two
20575@samp{control-z} characters, but if there was such a need, the
20576annotations could be extended with an @samp{escape} annotation which
20577means those three characters as output.
20578
086432e2
AC
20579The annotation @var{level}, which is specified using the
20580@option{--annotate} command line option (@pxref{Mode Options}), controls
20581how much information @value{GDBN} prints together with its prompt,
20582values of expressions, source lines, and other types of output. Level 0
20583is for no anntations, level 1 is for use when @value{GDBN} is run as a
20584subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20585for programs that control @value{GDBN}, and level 2 annotations have
20586been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20587Interface, annotate, GDB's Obsolete Annotations}).
20588
20589@table @code
20590@kindex set annotate
20591@item set annotate @var{level}
20592The @value{GDB} command @code{set annotate} sets the level of
20593annotations to the specified @var{level}.
9c16f35a
EZ
20594
20595@item show annotate
20596@kindex show annotate
20597Show the current annotation level.
09d4efe1
EZ
20598@end table
20599
20600This chapter describes level 3 annotations.
086432e2 20601
922fbb7b
AC
20602A simple example of starting up @value{GDBN} with annotations is:
20603
20604@smallexample
086432e2
AC
20605$ @kbd{gdb --annotate=3}
20606GNU gdb 6.0
20607Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20608GDB is free software, covered by the GNU General Public License,
20609and you are welcome to change it and/or distribute copies of it
20610under certain conditions.
20611Type "show copying" to see the conditions.
20612There is absolutely no warranty for GDB. Type "show warranty"
20613for details.
086432e2 20614This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20615
20616^Z^Zpre-prompt
f7dc1244 20617(@value{GDBP})
922fbb7b 20618^Z^Zprompt
086432e2 20619@kbd{quit}
922fbb7b
AC
20620
20621^Z^Zpost-prompt
b383017d 20622$
922fbb7b
AC
20623@end smallexample
20624
20625Here @samp{quit} is input to @value{GDBN}; the rest is output from
20626@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20627denotes a @samp{control-z} character) are annotations; the rest is
20628output from @value{GDBN}.
20629
20630@node Server Prefix
20631@section The Server Prefix
20632@cindex server prefix for annotations
20633
20634To issue a command to @value{GDBN} without affecting certain aspects of
20635the state which is seen by users, prefix it with @samp{server }. This
20636means that this command will not affect the command history, nor will it
20637affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
20638pressed on a line by itself.
20639
20640The server prefix does not affect the recording of values into the value
20641history; to print a value without recording it into the value history,
20642use the @code{output} command instead of the @code{print} command.
20643
922fbb7b
AC
20644@node Prompting
20645@section Annotation for @value{GDBN} Input
20646
20647@cindex annotations for prompts
20648When @value{GDBN} prompts for input, it annotates this fact so it is possible
20649to know when to send output, when the output from a given command is
20650over, etc.
20651
20652Different kinds of input each have a different @dfn{input type}. Each
20653input type has three annotations: a @code{pre-} annotation, which
20654denotes the beginning of any prompt which is being output, a plain
20655annotation, which denotes the end of the prompt, and then a @code{post-}
20656annotation which denotes the end of any echo which may (or may not) be
20657associated with the input. For example, the @code{prompt} input type
20658features the following annotations:
20659
20660@smallexample
20661^Z^Zpre-prompt
20662^Z^Zprompt
20663^Z^Zpost-prompt
20664@end smallexample
20665
20666The input types are
20667
20668@table @code
20669@findex pre-prompt
20670@findex prompt
20671@findex post-prompt
20672@item prompt
20673When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20674
20675@findex pre-commands
20676@findex commands
20677@findex post-commands
20678@item commands
20679When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20680command. The annotations are repeated for each command which is input.
20681
20682@findex pre-overload-choice
20683@findex overload-choice
20684@findex post-overload-choice
20685@item overload-choice
20686When @value{GDBN} wants the user to select between various overloaded functions.
20687
20688@findex pre-query
20689@findex query
20690@findex post-query
20691@item query
20692When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20693
20694@findex pre-prompt-for-continue
20695@findex prompt-for-continue
20696@findex post-prompt-for-continue
20697@item prompt-for-continue
20698When @value{GDBN} is asking the user to press return to continue. Note: Don't
20699expect this to work well; instead use @code{set height 0} to disable
20700prompting. This is because the counting of lines is buggy in the
20701presence of annotations.
20702@end table
20703
20704@node Errors
20705@section Errors
20706@cindex annotations for errors, warnings and interrupts
20707
20708@findex quit
20709@smallexample
20710^Z^Zquit
20711@end smallexample
20712
20713This annotation occurs right before @value{GDBN} responds to an interrupt.
20714
20715@findex error
20716@smallexample
20717^Z^Zerror
20718@end smallexample
20719
20720This annotation occurs right before @value{GDBN} responds to an error.
20721
20722Quit and error annotations indicate that any annotations which @value{GDBN} was
20723in the middle of may end abruptly. For example, if a
20724@code{value-history-begin} annotation is followed by a @code{error}, one
20725cannot expect to receive the matching @code{value-history-end}. One
20726cannot expect not to receive it either, however; an error annotation
20727does not necessarily mean that @value{GDBN} is immediately returning all the way
20728to the top level.
20729
20730@findex error-begin
20731A quit or error annotation may be preceded by
20732
20733@smallexample
20734^Z^Zerror-begin
20735@end smallexample
20736
20737Any output between that and the quit or error annotation is the error
20738message.
20739
20740Warning messages are not yet annotated.
20741@c If we want to change that, need to fix warning(), type_error(),
20742@c range_error(), and possibly other places.
20743
922fbb7b
AC
20744@node Invalidation
20745@section Invalidation Notices
20746
20747@cindex annotations for invalidation messages
20748The following annotations say that certain pieces of state may have
20749changed.
20750
20751@table @code
20752@findex frames-invalid
20753@item ^Z^Zframes-invalid
20754
20755The frames (for example, output from the @code{backtrace} command) may
20756have changed.
20757
20758@findex breakpoints-invalid
20759@item ^Z^Zbreakpoints-invalid
20760
20761The breakpoints may have changed. For example, the user just added or
20762deleted a breakpoint.
20763@end table
20764
20765@node Annotations for Running
20766@section Running the Program
20767@cindex annotations for running programs
20768
20769@findex starting
20770@findex stopping
20771When the program starts executing due to a @value{GDBN} command such as
b383017d 20772@code{step} or @code{continue},
922fbb7b
AC
20773
20774@smallexample
20775^Z^Zstarting
20776@end smallexample
20777
b383017d 20778is output. When the program stops,
922fbb7b
AC
20779
20780@smallexample
20781^Z^Zstopped
20782@end smallexample
20783
20784is output. Before the @code{stopped} annotation, a variety of
20785annotations describe how the program stopped.
20786
20787@table @code
20788@findex exited
20789@item ^Z^Zexited @var{exit-status}
20790The program exited, and @var{exit-status} is the exit status (zero for
20791successful exit, otherwise nonzero).
20792
20793@findex signalled
20794@findex signal-name
20795@findex signal-name-end
20796@findex signal-string
20797@findex signal-string-end
20798@item ^Z^Zsignalled
20799The program exited with a signal. After the @code{^Z^Zsignalled}, the
20800annotation continues:
20801
20802@smallexample
20803@var{intro-text}
20804^Z^Zsignal-name
20805@var{name}
20806^Z^Zsignal-name-end
20807@var{middle-text}
20808^Z^Zsignal-string
20809@var{string}
20810^Z^Zsignal-string-end
20811@var{end-text}
20812@end smallexample
20813
20814@noindent
20815where @var{name} is the name of the signal, such as @code{SIGILL} or
20816@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20817as @code{Illegal Instruction} or @code{Segmentation fault}.
20818@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20819user's benefit and have no particular format.
20820
20821@findex signal
20822@item ^Z^Zsignal
20823The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20824just saying that the program received the signal, not that it was
20825terminated with it.
20826
20827@findex breakpoint
20828@item ^Z^Zbreakpoint @var{number}
20829The program hit breakpoint number @var{number}.
20830
20831@findex watchpoint
20832@item ^Z^Zwatchpoint @var{number}
20833The program hit watchpoint number @var{number}.
20834@end table
20835
20836@node Source Annotations
20837@section Displaying Source
20838@cindex annotations for source display
20839
20840@findex source
20841The following annotation is used instead of displaying source code:
20842
20843@smallexample
20844^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20845@end smallexample
20846
20847where @var{filename} is an absolute file name indicating which source
20848file, @var{line} is the line number within that file (where 1 is the
20849first line in the file), @var{character} is the character position
20850within the file (where 0 is the first character in the file) (for most
20851debug formats this will necessarily point to the beginning of a line),
20852@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20853line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20854@var{addr} is the address in the target program associated with the
20855source which is being displayed. @var{addr} is in the form @samp{0x}
20856followed by one or more lowercase hex digits (note that this does not
20857depend on the language).
20858
8e04817f
AC
20859@node GDB Bugs
20860@chapter Reporting Bugs in @value{GDBN}
20861@cindex bugs in @value{GDBN}
20862@cindex reporting bugs in @value{GDBN}
c906108c 20863
8e04817f 20864Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20865
8e04817f
AC
20866Reporting a bug may help you by bringing a solution to your problem, or it
20867may not. But in any case the principal function of a bug report is to help
20868the entire community by making the next version of @value{GDBN} work better. Bug
20869reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20870
8e04817f
AC
20871In order for a bug report to serve its purpose, you must include the
20872information that enables us to fix the bug.
c4555f82
SC
20873
20874@menu
8e04817f
AC
20875* Bug Criteria:: Have you found a bug?
20876* Bug Reporting:: How to report bugs
c4555f82
SC
20877@end menu
20878
8e04817f
AC
20879@node Bug Criteria
20880@section Have you found a bug?
20881@cindex bug criteria
c4555f82 20882
8e04817f 20883If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20884
20885@itemize @bullet
8e04817f
AC
20886@cindex fatal signal
20887@cindex debugger crash
20888@cindex crash of debugger
c4555f82 20889@item
8e04817f
AC
20890If the debugger gets a fatal signal, for any input whatever, that is a
20891@value{GDBN} bug. Reliable debuggers never crash.
20892
20893@cindex error on valid input
20894@item
20895If @value{GDBN} produces an error message for valid input, that is a
20896bug. (Note that if you're cross debugging, the problem may also be
20897somewhere in the connection to the target.)
c4555f82 20898
8e04817f 20899@cindex invalid input
c4555f82 20900@item
8e04817f
AC
20901If @value{GDBN} does not produce an error message for invalid input,
20902that is a bug. However, you should note that your idea of
20903``invalid input'' might be our idea of ``an extension'' or ``support
20904for traditional practice''.
20905
20906@item
20907If you are an experienced user of debugging tools, your suggestions
20908for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
20909@end itemize
20910
8e04817f
AC
20911@node Bug Reporting
20912@section How to report bugs
20913@cindex bug reports
20914@cindex @value{GDBN} bugs, reporting
20915
20916A number of companies and individuals offer support for @sc{gnu} products.
20917If you obtained @value{GDBN} from a support organization, we recommend you
20918contact that organization first.
20919
20920You can find contact information for many support companies and
20921individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
20922distribution.
20923@c should add a web page ref...
20924
129188f6
AC
20925In any event, we also recommend that you submit bug reports for
20926@value{GDBN}. The prefered method is to submit them directly using
20927@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
20928page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
20929be used.
8e04817f
AC
20930
20931@strong{Do not send bug reports to @samp{info-gdb}, or to
20932@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
20933not want to receive bug reports. Those that do have arranged to receive
20934@samp{bug-gdb}.
20935
20936The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
20937serves as a repeater. The mailing list and the newsgroup carry exactly
20938the same messages. Often people think of posting bug reports to the
20939newsgroup instead of mailing them. This appears to work, but it has one
20940problem which can be crucial: a newsgroup posting often lacks a mail
20941path back to the sender. Thus, if we need to ask for more information,
20942we may be unable to reach you. For this reason, it is better to send
20943bug reports to the mailing list.
c4555f82 20944
8e04817f
AC
20945The fundamental principle of reporting bugs usefully is this:
20946@strong{report all the facts}. If you are not sure whether to state a
20947fact or leave it out, state it!
c4555f82 20948
8e04817f
AC
20949Often people omit facts because they think they know what causes the
20950problem and assume that some details do not matter. Thus, you might
20951assume that the name of the variable you use in an example does not matter.
20952Well, probably it does not, but one cannot be sure. Perhaps the bug is a
20953stray memory reference which happens to fetch from the location where that
20954name is stored in memory; perhaps, if the name were different, the contents
20955of that location would fool the debugger into doing the right thing despite
20956the bug. Play it safe and give a specific, complete example. That is the
20957easiest thing for you to do, and the most helpful.
c4555f82 20958
8e04817f
AC
20959Keep in mind that the purpose of a bug report is to enable us to fix the
20960bug. It may be that the bug has been reported previously, but neither
20961you nor we can know that unless your bug report is complete and
20962self-contained.
c4555f82 20963
8e04817f
AC
20964Sometimes people give a few sketchy facts and ask, ``Does this ring a
20965bell?'' Those bug reports are useless, and we urge everyone to
20966@emph{refuse to respond to them} except to chide the sender to report
20967bugs properly.
20968
20969To enable us to fix the bug, you should include all these things:
c4555f82
SC
20970
20971@itemize @bullet
20972@item
8e04817f
AC
20973The version of @value{GDBN}. @value{GDBN} announces it if you start
20974with no arguments; you can also print it at any time using @code{show
20975version}.
c4555f82 20976
8e04817f
AC
20977Without this, we will not know whether there is any point in looking for
20978the bug in the current version of @value{GDBN}.
c4555f82
SC
20979
20980@item
8e04817f
AC
20981The type of machine you are using, and the operating system name and
20982version number.
c4555f82
SC
20983
20984@item
8e04817f
AC
20985What compiler (and its version) was used to compile @value{GDBN}---e.g.
20986``@value{GCC}--2.8.1''.
c4555f82
SC
20987
20988@item
8e04817f
AC
20989What compiler (and its version) was used to compile the program you are
20990debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
20991C Compiler''. For GCC, you can say @code{gcc --version} to get this
20992information; for other compilers, see the documentation for those
20993compilers.
c4555f82 20994
8e04817f
AC
20995@item
20996The command arguments you gave the compiler to compile your example and
20997observe the bug. For example, did you use @samp{-O}? To guarantee
20998you will not omit something important, list them all. A copy of the
20999Makefile (or the output from make) is sufficient.
c4555f82 21000
8e04817f
AC
21001If we were to try to guess the arguments, we would probably guess wrong
21002and then we might not encounter the bug.
c4555f82 21003
8e04817f
AC
21004@item
21005A complete input script, and all necessary source files, that will
21006reproduce the bug.
c4555f82 21007
8e04817f
AC
21008@item
21009A description of what behavior you observe that you believe is
21010incorrect. For example, ``It gets a fatal signal.''
c4555f82 21011
8e04817f
AC
21012Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21013will certainly notice it. But if the bug is incorrect output, we might
21014not notice unless it is glaringly wrong. You might as well not give us
21015a chance to make a mistake.
c4555f82 21016
8e04817f
AC
21017Even if the problem you experience is a fatal signal, you should still
21018say so explicitly. Suppose something strange is going on, such as, your
21019copy of @value{GDBN} is out of synch, or you have encountered a bug in
21020the C library on your system. (This has happened!) Your copy might
21021crash and ours would not. If you told us to expect a crash, then when
21022ours fails to crash, we would know that the bug was not happening for
21023us. If you had not told us to expect a crash, then we would not be able
21024to draw any conclusion from our observations.
c4555f82 21025
e0c07bf0
MC
21026@pindex script
21027@cindex recording a session script
21028To collect all this information, you can use a session recording program
21029such as @command{script}, which is available on many Unix systems.
21030Just run your @value{GDBN} session inside @command{script} and then
21031include the @file{typescript} file with your bug report.
21032
21033Another way to record a @value{GDBN} session is to run @value{GDBN}
21034inside Emacs and then save the entire buffer to a file.
21035
8e04817f
AC
21036@item
21037If you wish to suggest changes to the @value{GDBN} source, send us context
21038diffs. If you even discuss something in the @value{GDBN} source, refer to
21039it by context, not by line number.
c4555f82 21040
8e04817f
AC
21041The line numbers in our development sources will not match those in your
21042sources. Your line numbers would convey no useful information to us.
c4555f82 21043
8e04817f 21044@end itemize
c4555f82 21045
8e04817f 21046Here are some things that are not necessary:
c4555f82 21047
8e04817f
AC
21048@itemize @bullet
21049@item
21050A description of the envelope of the bug.
c4555f82 21051
8e04817f
AC
21052Often people who encounter a bug spend a lot of time investigating
21053which changes to the input file will make the bug go away and which
21054changes will not affect it.
c4555f82 21055
8e04817f
AC
21056This is often time consuming and not very useful, because the way we
21057will find the bug is by running a single example under the debugger
21058with breakpoints, not by pure deduction from a series of examples.
21059We recommend that you save your time for something else.
c4555f82 21060
8e04817f
AC
21061Of course, if you can find a simpler example to report @emph{instead}
21062of the original one, that is a convenience for us. Errors in the
21063output will be easier to spot, running under the debugger will take
21064less time, and so on.
c4555f82 21065
8e04817f
AC
21066However, simplification is not vital; if you do not want to do this,
21067report the bug anyway and send us the entire test case you used.
c4555f82 21068
8e04817f
AC
21069@item
21070A patch for the bug.
c4555f82 21071
8e04817f
AC
21072A patch for the bug does help us if it is a good one. But do not omit
21073the necessary information, such as the test case, on the assumption that
21074a patch is all we need. We might see problems with your patch and decide
21075to fix the problem another way, or we might not understand it at all.
c4555f82 21076
8e04817f
AC
21077Sometimes with a program as complicated as @value{GDBN} it is very hard to
21078construct an example that will make the program follow a certain path
21079through the code. If you do not send us the example, we will not be able
21080to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21081
8e04817f
AC
21082And if we cannot understand what bug you are trying to fix, or why your
21083patch should be an improvement, we will not install it. A test case will
21084help us to understand.
c4555f82 21085
8e04817f
AC
21086@item
21087A guess about what the bug is or what it depends on.
c4555f82 21088
8e04817f
AC
21089Such guesses are usually wrong. Even we cannot guess right about such
21090things without first using the debugger to find the facts.
21091@end itemize
c4555f82 21092
8e04817f
AC
21093@c The readline documentation is distributed with the readline code
21094@c and consists of the two following files:
21095@c rluser.texinfo
21096@c inc-hist.texinfo
21097@c Use -I with makeinfo to point to the appropriate directory,
21098@c environment var TEXINPUTS with TeX.
21099@include rluser.texinfo
21100@include inc-hist.texinfo
c4555f82 21101
c4555f82 21102
8e04817f
AC
21103@node Formatting Documentation
21104@appendix Formatting Documentation
c4555f82 21105
8e04817f
AC
21106@cindex @value{GDBN} reference card
21107@cindex reference card
21108The @value{GDBN} 4 release includes an already-formatted reference card, ready
21109for printing with PostScript or Ghostscript, in the @file{gdb}
21110subdirectory of the main source directory@footnote{In
21111@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21112release.}. If you can use PostScript or Ghostscript with your printer,
21113you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21114
8e04817f
AC
21115The release also includes the source for the reference card. You
21116can format it, using @TeX{}, by typing:
c4555f82 21117
474c8240 21118@smallexample
8e04817f 21119make refcard.dvi
474c8240 21120@end smallexample
c4555f82 21121
8e04817f
AC
21122The @value{GDBN} reference card is designed to print in @dfn{landscape}
21123mode on US ``letter'' size paper;
21124that is, on a sheet 11 inches wide by 8.5 inches
21125high. You will need to specify this form of printing as an option to
21126your @sc{dvi} output program.
c4555f82 21127
8e04817f 21128@cindex documentation
c4555f82 21129
8e04817f
AC
21130All the documentation for @value{GDBN} comes as part of the machine-readable
21131distribution. The documentation is written in Texinfo format, which is
21132a documentation system that uses a single source file to produce both
21133on-line information and a printed manual. You can use one of the Info
21134formatting commands to create the on-line version of the documentation
21135and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21136
8e04817f
AC
21137@value{GDBN} includes an already formatted copy of the on-line Info
21138version of this manual in the @file{gdb} subdirectory. The main Info
21139file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21140subordinate files matching @samp{gdb.info*} in the same directory. If
21141necessary, you can print out these files, or read them with any editor;
21142but they are easier to read using the @code{info} subsystem in @sc{gnu}
21143Emacs or the standalone @code{info} program, available as part of the
21144@sc{gnu} Texinfo distribution.
c4555f82 21145
8e04817f
AC
21146If you want to format these Info files yourself, you need one of the
21147Info formatting programs, such as @code{texinfo-format-buffer} or
21148@code{makeinfo}.
c4555f82 21149
8e04817f
AC
21150If you have @code{makeinfo} installed, and are in the top level
21151@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21152version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21153
474c8240 21154@smallexample
8e04817f
AC
21155cd gdb
21156make gdb.info
474c8240 21157@end smallexample
c4555f82 21158
8e04817f
AC
21159If you want to typeset and print copies of this manual, you need @TeX{},
21160a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21161Texinfo definitions file.
c4555f82 21162
8e04817f
AC
21163@TeX{} is a typesetting program; it does not print files directly, but
21164produces output files called @sc{dvi} files. To print a typeset
21165document, you need a program to print @sc{dvi} files. If your system
21166has @TeX{} installed, chances are it has such a program. The precise
21167command to use depends on your system; @kbd{lpr -d} is common; another
21168(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21169require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21170
8e04817f
AC
21171@TeX{} also requires a macro definitions file called
21172@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21173written in Texinfo format. On its own, @TeX{} cannot either read or
21174typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21175and is located in the @file{gdb-@var{version-number}/texinfo}
21176directory.
c4555f82 21177
8e04817f
AC
21178If you have @TeX{} and a @sc{dvi} printer program installed, you can
21179typeset and print this manual. First switch to the the @file{gdb}
21180subdirectory of the main source directory (for example, to
21181@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21182
474c8240 21183@smallexample
8e04817f 21184make gdb.dvi
474c8240 21185@end smallexample
c4555f82 21186
8e04817f 21187Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21188
8e04817f
AC
21189@node Installing GDB
21190@appendix Installing @value{GDBN}
21191@cindex configuring @value{GDBN}
21192@cindex installation
94e91d6d 21193@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21194
8e04817f
AC
21195@value{GDBN} comes with a @code{configure} script that automates the process
21196of preparing @value{GDBN} for installation; you can then use @code{make} to
21197build the @code{gdb} program.
21198@iftex
21199@c irrelevant in info file; it's as current as the code it lives with.
21200@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21201look at the @file{README} file in the sources; we may have improved the
21202installation procedures since publishing this manual.}
21203@end iftex
c4555f82 21204
8e04817f
AC
21205The @value{GDBN} distribution includes all the source code you need for
21206@value{GDBN} in a single directory, whose name is usually composed by
21207appending the version number to @samp{gdb}.
c4555f82 21208
8e04817f
AC
21209For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21210@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21211
8e04817f
AC
21212@table @code
21213@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21214script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21215
8e04817f
AC
21216@item gdb-@value{GDBVN}/gdb
21217the source specific to @value{GDBN} itself
c4555f82 21218
8e04817f
AC
21219@item gdb-@value{GDBVN}/bfd
21220source for the Binary File Descriptor library
c906108c 21221
8e04817f
AC
21222@item gdb-@value{GDBVN}/include
21223@sc{gnu} include files
c906108c 21224
8e04817f
AC
21225@item gdb-@value{GDBVN}/libiberty
21226source for the @samp{-liberty} free software library
c906108c 21227
8e04817f
AC
21228@item gdb-@value{GDBVN}/opcodes
21229source for the library of opcode tables and disassemblers
c906108c 21230
8e04817f
AC
21231@item gdb-@value{GDBVN}/readline
21232source for the @sc{gnu} command-line interface
c906108c 21233
8e04817f
AC
21234@item gdb-@value{GDBVN}/glob
21235source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21236
8e04817f
AC
21237@item gdb-@value{GDBVN}/mmalloc
21238source for the @sc{gnu} memory-mapped malloc package
21239@end table
c906108c 21240
8e04817f
AC
21241The simplest way to configure and build @value{GDBN} is to run @code{configure}
21242from the @file{gdb-@var{version-number}} source directory, which in
21243this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21244
8e04817f
AC
21245First switch to the @file{gdb-@var{version-number}} source directory
21246if you are not already in it; then run @code{configure}. Pass the
21247identifier for the platform on which @value{GDBN} will run as an
21248argument.
c906108c 21249
8e04817f 21250For example:
c906108c 21251
474c8240 21252@smallexample
8e04817f
AC
21253cd gdb-@value{GDBVN}
21254./configure @var{host}
21255make
474c8240 21256@end smallexample
c906108c 21257
8e04817f
AC
21258@noindent
21259where @var{host} is an identifier such as @samp{sun4} or
21260@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21261(You can often leave off @var{host}; @code{configure} tries to guess the
21262correct value by examining your system.)
c906108c 21263
8e04817f
AC
21264Running @samp{configure @var{host}} and then running @code{make} builds the
21265@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21266libraries, then @code{gdb} itself. The configured source files, and the
21267binaries, are left in the corresponding source directories.
c906108c 21268
8e04817f
AC
21269@need 750
21270@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21271system does not recognize this automatically when you run a different
21272shell, you may need to run @code{sh} on it explicitly:
c906108c 21273
474c8240 21274@smallexample
8e04817f 21275sh configure @var{host}
474c8240 21276@end smallexample
c906108c 21277
8e04817f
AC
21278If you run @code{configure} from a directory that contains source
21279directories for multiple libraries or programs, such as the
21280@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21281creates configuration files for every directory level underneath (unless
21282you tell it not to, with the @samp{--norecursion} option).
21283
94e91d6d
MC
21284You should run the @code{configure} script from the top directory in the
21285source tree, the @file{gdb-@var{version-number}} directory. If you run
21286@code{configure} from one of the subdirectories, you will configure only
21287that subdirectory. That is usually not what you want. In particular,
21288if you run the first @code{configure} from the @file{gdb} subdirectory
21289of the @file{gdb-@var{version-number}} directory, you will omit the
21290configuration of @file{bfd}, @file{readline}, and other sibling
21291directories of the @file{gdb} subdirectory. This leads to build errors
21292about missing include files such as @file{bfd/bfd.h}.
c906108c 21293
8e04817f
AC
21294You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21295However, you should make sure that the shell on your path (named by
21296the @samp{SHELL} environment variable) is publicly readable. Remember
21297that @value{GDBN} uses the shell to start your program---some systems refuse to
21298let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21299
8e04817f
AC
21300@menu
21301* Separate Objdir:: Compiling @value{GDBN} in another directory
21302* Config Names:: Specifying names for hosts and targets
21303* Configure Options:: Summary of options for configure
21304@end menu
c906108c 21305
8e04817f
AC
21306@node Separate Objdir
21307@section Compiling @value{GDBN} in another directory
c906108c 21308
8e04817f
AC
21309If you want to run @value{GDBN} versions for several host or target machines,
21310you need a different @code{gdb} compiled for each combination of
21311host and target. @code{configure} is designed to make this easy by
21312allowing you to generate each configuration in a separate subdirectory,
21313rather than in the source directory. If your @code{make} program
21314handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21315@code{make} in each of these directories builds the @code{gdb}
21316program specified there.
c906108c 21317
8e04817f
AC
21318To build @code{gdb} in a separate directory, run @code{configure}
21319with the @samp{--srcdir} option to specify where to find the source.
21320(You also need to specify a path to find @code{configure}
21321itself from your working directory. If the path to @code{configure}
21322would be the same as the argument to @samp{--srcdir}, you can leave out
21323the @samp{--srcdir} option; it is assumed.)
c906108c 21324
8e04817f
AC
21325For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21326separate directory for a Sun 4 like this:
c906108c 21327
474c8240 21328@smallexample
8e04817f
AC
21329@group
21330cd gdb-@value{GDBVN}
21331mkdir ../gdb-sun4
21332cd ../gdb-sun4
21333../gdb-@value{GDBVN}/configure sun4
21334make
21335@end group
474c8240 21336@end smallexample
c906108c 21337
8e04817f
AC
21338When @code{configure} builds a configuration using a remote source
21339directory, it creates a tree for the binaries with the same structure
21340(and using the same names) as the tree under the source directory. In
21341the example, you'd find the Sun 4 library @file{libiberty.a} in the
21342directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21343@file{gdb-sun4/gdb}.
c906108c 21344
94e91d6d
MC
21345Make sure that your path to the @file{configure} script has just one
21346instance of @file{gdb} in it. If your path to @file{configure} looks
21347like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21348one subdirectory of @value{GDBN}, not the whole package. This leads to
21349build errors about missing include files such as @file{bfd/bfd.h}.
21350
8e04817f
AC
21351One popular reason to build several @value{GDBN} configurations in separate
21352directories is to configure @value{GDBN} for cross-compiling (where
21353@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21354programs that run on another machine---the @dfn{target}).
21355You specify a cross-debugging target by
21356giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21357
8e04817f
AC
21358When you run @code{make} to build a program or library, you must run
21359it in a configured directory---whatever directory you were in when you
21360called @code{configure} (or one of its subdirectories).
c906108c 21361
8e04817f
AC
21362The @code{Makefile} that @code{configure} generates in each source
21363directory also runs recursively. If you type @code{make} in a source
21364directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21365directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21366will build all the required libraries, and then build GDB.
c906108c 21367
8e04817f
AC
21368When you have multiple hosts or targets configured in separate
21369directories, you can run @code{make} on them in parallel (for example,
21370if they are NFS-mounted on each of the hosts); they will not interfere
21371with each other.
c906108c 21372
8e04817f
AC
21373@node Config Names
21374@section Specifying names for hosts and targets
c906108c 21375
8e04817f
AC
21376The specifications used for hosts and targets in the @code{configure}
21377script are based on a three-part naming scheme, but some short predefined
21378aliases are also supported. The full naming scheme encodes three pieces
21379of information in the following pattern:
c906108c 21380
474c8240 21381@smallexample
8e04817f 21382@var{architecture}-@var{vendor}-@var{os}
474c8240 21383@end smallexample
c906108c 21384
8e04817f
AC
21385For example, you can use the alias @code{sun4} as a @var{host} argument,
21386or as the value for @var{target} in a @code{--target=@var{target}}
21387option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21388
8e04817f
AC
21389The @code{configure} script accompanying @value{GDBN} does not provide
21390any query facility to list all supported host and target names or
21391aliases. @code{configure} calls the Bourne shell script
21392@code{config.sub} to map abbreviations to full names; you can read the
21393script, if you wish, or you can use it to test your guesses on
21394abbreviations---for example:
c906108c 21395
8e04817f
AC
21396@smallexample
21397% sh config.sub i386-linux
21398i386-pc-linux-gnu
21399% sh config.sub alpha-linux
21400alpha-unknown-linux-gnu
21401% sh config.sub hp9k700
21402hppa1.1-hp-hpux
21403% sh config.sub sun4
21404sparc-sun-sunos4.1.1
21405% sh config.sub sun3
21406m68k-sun-sunos4.1.1
21407% sh config.sub i986v
21408Invalid configuration `i986v': machine `i986v' not recognized
21409@end smallexample
c906108c 21410
8e04817f
AC
21411@noindent
21412@code{config.sub} is also distributed in the @value{GDBN} source
21413directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21414
8e04817f
AC
21415@node Configure Options
21416@section @code{configure} options
c906108c 21417
8e04817f
AC
21418Here is a summary of the @code{configure} options and arguments that
21419are most often useful for building @value{GDBN}. @code{configure} also has
21420several other options not listed here. @inforef{What Configure
21421Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21422
474c8240 21423@smallexample
8e04817f
AC
21424configure @r{[}--help@r{]}
21425 @r{[}--prefix=@var{dir}@r{]}
21426 @r{[}--exec-prefix=@var{dir}@r{]}
21427 @r{[}--srcdir=@var{dirname}@r{]}
21428 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21429 @r{[}--target=@var{target}@r{]}
21430 @var{host}
474c8240 21431@end smallexample
c906108c 21432
8e04817f
AC
21433@noindent
21434You may introduce options with a single @samp{-} rather than
21435@samp{--} if you prefer; but you may abbreviate option names if you use
21436@samp{--}.
c906108c 21437
8e04817f
AC
21438@table @code
21439@item --help
21440Display a quick summary of how to invoke @code{configure}.
c906108c 21441
8e04817f
AC
21442@item --prefix=@var{dir}
21443Configure the source to install programs and files under directory
21444@file{@var{dir}}.
c906108c 21445
8e04817f
AC
21446@item --exec-prefix=@var{dir}
21447Configure the source to install programs under directory
21448@file{@var{dir}}.
c906108c 21449
8e04817f
AC
21450@c avoid splitting the warning from the explanation:
21451@need 2000
21452@item --srcdir=@var{dirname}
21453@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21454@code{make} that implements the @code{VPATH} feature.}@*
21455Use this option to make configurations in directories separate from the
21456@value{GDBN} source directories. Among other things, you can use this to
21457build (or maintain) several configurations simultaneously, in separate
21458directories. @code{configure} writes configuration specific files in
21459the current directory, but arranges for them to use the source in the
21460directory @var{dirname}. @code{configure} creates directories under
21461the working directory in parallel to the source directories below
21462@var{dirname}.
c906108c 21463
8e04817f
AC
21464@item --norecursion
21465Configure only the directory level where @code{configure} is executed; do not
21466propagate configuration to subdirectories.
c906108c 21467
8e04817f
AC
21468@item --target=@var{target}
21469Configure @value{GDBN} for cross-debugging programs running on the specified
21470@var{target}. Without this option, @value{GDBN} is configured to debug
21471programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21472
8e04817f 21473There is no convenient way to generate a list of all available targets.
c906108c 21474
8e04817f
AC
21475@item @var{host} @dots{}
21476Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21477
8e04817f
AC
21478There is no convenient way to generate a list of all available hosts.
21479@end table
c906108c 21480
8e04817f
AC
21481There are many other options available as well, but they are generally
21482needed for special purposes only.
c906108c 21483
8e04817f
AC
21484@node Maintenance Commands
21485@appendix Maintenance Commands
21486@cindex maintenance commands
21487@cindex internal commands
c906108c 21488
8e04817f 21489In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21490includes a number of commands intended for @value{GDBN} developers,
21491that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21492provided here for reference. (For commands that turn on debugging
21493messages, see @ref{Debugging Output}.)
c906108c 21494
8e04817f 21495@table @code
09d4efe1
EZ
21496@kindex maint agent
21497@item maint agent @var{expression}
21498Translate the given @var{expression} into remote agent bytecodes.
21499This command is useful for debugging the Agent Expression mechanism
21500(@pxref{Agent Expressions}).
21501
8e04817f
AC
21502@kindex maint info breakpoints
21503@item @anchor{maint info breakpoints}maint info breakpoints
21504Using the same format as @samp{info breakpoints}, display both the
21505breakpoints you've set explicitly, and those @value{GDBN} is using for
21506internal purposes. Internal breakpoints are shown with negative
21507breakpoint numbers. The type column identifies what kind of breakpoint
21508is shown:
c906108c 21509
8e04817f
AC
21510@table @code
21511@item breakpoint
21512Normal, explicitly set breakpoint.
c906108c 21513
8e04817f
AC
21514@item watchpoint
21515Normal, explicitly set watchpoint.
c906108c 21516
8e04817f
AC
21517@item longjmp
21518Internal breakpoint, used to handle correctly stepping through
21519@code{longjmp} calls.
c906108c 21520
8e04817f
AC
21521@item longjmp resume
21522Internal breakpoint at the target of a @code{longjmp}.
c906108c 21523
8e04817f
AC
21524@item until
21525Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21526
8e04817f
AC
21527@item finish
21528Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21529
8e04817f
AC
21530@item shlib events
21531Shared library events.
c906108c 21532
8e04817f 21533@end table
c906108c 21534
09d4efe1
EZ
21535@kindex maint check-symtabs
21536@item maint check-symtabs
21537Check the consistency of psymtabs and symtabs.
21538
21539@kindex maint cplus first_component
21540@item maint cplus first_component @var{name}
21541Print the first C@t{++} class/namespace component of @var{name}.
21542
21543@kindex maint cplus namespace
21544@item maint cplus namespace
21545Print the list of possible C@t{++} namespaces.
21546
21547@kindex maint demangle
21548@item maint demangle @var{name}
21549Demangle a C@t{++} or Objective-C manled @var{name}.
21550
21551@kindex maint deprecate
21552@kindex maint undeprecate
21553@cindex deprecated commands
21554@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21555@itemx maint undeprecate @var{command}
21556Deprecate or undeprecate the named @var{command}. Deprecated commands
21557cause @value{GDBN} to issue a warning when you use them. The optional
21558argument @var{replacement} says which newer command should be used in
21559favor of the deprecated one; if it is given, @value{GDBN} will mention
21560the replacement as part of the warning.
21561
21562@kindex maint dump-me
21563@item maint dump-me
721c2651 21564@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21565Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21566This is supported only on systems which support aborting a program
21567with the @code{SIGQUIT} signal.
09d4efe1 21568
8d30a00d
AC
21569@kindex maint internal-error
21570@kindex maint internal-warning
09d4efe1
EZ
21571@item maint internal-error @r{[}@var{message-text}@r{]}
21572@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21573Cause @value{GDBN} to call the internal function @code{internal_error}
21574or @code{internal_warning} and hence behave as though an internal error
21575or internal warning has been detected. In addition to reporting the
21576internal problem, these functions give the user the opportunity to
21577either quit @value{GDBN} or create a core file of the current
21578@value{GDBN} session.
21579
09d4efe1
EZ
21580These commands take an optional parameter @var{message-text} that is
21581used as the text of the error or warning message.
21582
21583Here's an example of using @code{indernal-error}:
21584
8d30a00d 21585@smallexample
f7dc1244 21586(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21587@dots{}/maint.c:121: internal-error: testing, 1, 2
21588A problem internal to GDB has been detected. Further
21589debugging may prove unreliable.
21590Quit this debugging session? (y or n) @kbd{n}
21591Create a core file? (y or n) @kbd{n}
f7dc1244 21592(@value{GDBP})
8d30a00d
AC
21593@end smallexample
21594
09d4efe1
EZ
21595@kindex maint packet
21596@item maint packet @var{text}
21597If @value{GDBN} is talking to an inferior via the serial protocol,
21598then this command sends the string @var{text} to the inferior, and
21599displays the response packet. @value{GDBN} supplies the initial
21600@samp{$} character, the terminating @samp{#} character, and the
21601checksum.
21602
21603@kindex maint print architecture
21604@item maint print architecture @r{[}@var{file}@r{]}
21605Print the entire architecture configuration. The optional argument
21606@var{file} names the file where the output goes.
8d30a00d 21607
00905d52
AC
21608@kindex maint print dummy-frames
21609@item maint print dummy-frames
00905d52
AC
21610Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21611
21612@smallexample
f7dc1244 21613(@value{GDBP}) @kbd{b add}
00905d52 21614@dots{}
f7dc1244 21615(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21616Breakpoint 2, add (a=2, b=3) at @dots{}
2161758 return (a + b);
21618The program being debugged stopped while in a function called from GDB.
21619@dots{}
f7dc1244 21620(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
216210x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21622 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21623 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21624(@value{GDBP})
00905d52
AC
21625@end smallexample
21626
21627Takes an optional file parameter.
21628
0680b120
AC
21629@kindex maint print registers
21630@kindex maint print raw-registers
21631@kindex maint print cooked-registers
617073a9 21632@kindex maint print register-groups
09d4efe1
EZ
21633@item maint print registers @r{[}@var{file}@r{]}
21634@itemx maint print raw-registers @r{[}@var{file}@r{]}
21635@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21636@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21637Print @value{GDBN}'s internal register data structures.
21638
617073a9
AC
21639The command @code{maint print raw-registers} includes the contents of
21640the raw register cache; the command @code{maint print cooked-registers}
21641includes the (cooked) value of all registers; and the command
21642@code{maint print register-groups} includes the groups that each
21643register is a member of. @xref{Registers,, Registers, gdbint,
21644@value{GDBN} Internals}.
0680b120 21645
09d4efe1
EZ
21646These commands take an optional parameter, a file name to which to
21647write the information.
0680b120 21648
617073a9 21649@kindex maint print reggroups
09d4efe1
EZ
21650@item maint print reggroups @r{[}@var{file}@r{]}
21651Print @value{GDBN}'s internal register group data structures. The
21652optional argument @var{file} tells to what file to write the
21653information.
617073a9 21654
09d4efe1 21655The register groups info looks like this:
617073a9
AC
21656
21657@smallexample
f7dc1244 21658(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21659 Group Type
21660 general user
21661 float user
21662 all user
21663 vector user
21664 system user
21665 save internal
21666 restore internal
617073a9
AC
21667@end smallexample
21668
09d4efe1
EZ
21669@kindex flushregs
21670@item flushregs
21671This command forces @value{GDBN} to flush its internal register cache.
21672
21673@kindex maint print objfiles
21674@cindex info for known object files
21675@item maint print objfiles
21676Print a dump of all known object files. For each object file, this
21677command prints its name, address in memory, and all of its psymtabs
21678and symtabs.
21679
21680@kindex maint print statistics
21681@cindex bcache statistics
21682@item maint print statistics
21683This command prints, for each object file in the program, various data
21684about that object file followed by the byte cache (@dfn{bcache})
21685statistics for the object file. The objfile data includes the number
21686of minimal, partical, full, and stabs symbols, the number of types
21687defined by the objfile, the number of as yet unexpanded psym tables,
21688the number of line tables and string tables, and the amount of memory
21689used by the various tables. The bcache statistics include the counts,
21690sizes, and counts of duplicates of all and unique objects, max,
21691average, and median entry size, total memory used and its overhead and
21692savings, and various measures of the hash table size and chain
21693lengths.
21694
21695@kindex maint print type
21696@cindex type chain of a data type
21697@item maint print type @var{expr}
21698Print the type chain for a type specified by @var{expr}. The argument
21699can be either a type name or a symbol. If it is a symbol, the type of
21700that symbol is described. The type chain produced by this command is
21701a recursive definition of the data type as stored in @value{GDBN}'s
21702data structures, including its flags and contained types.
21703
21704@kindex maint set dwarf2 max-cache-age
21705@kindex maint show dwarf2 max-cache-age
21706@item maint set dwarf2 max-cache-age
21707@itemx maint show dwarf2 max-cache-age
21708Control the DWARF 2 compilation unit cache.
21709
21710@cindex DWARF 2 compilation units cache
21711In object files with inter-compilation-unit references, such as those
21712produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21713reader needs to frequently refer to previously read compilation units.
21714This setting controls how long a compilation unit will remain in the
21715cache if it is not referenced. A higher limit means that cached
21716compilation units will be stored in memory longer, and more total
21717memory will be used. Setting it to zero disables caching, which will
21718slow down @value{GDBN} startup, but reduce memory consumption.
21719
e7ba9c65
DJ
21720@kindex maint set profile
21721@kindex maint show profile
21722@cindex profiling GDB
21723@item maint set profile
21724@itemx maint show profile
21725Control profiling of @value{GDBN}.
21726
21727Profiling will be disabled until you use the @samp{maint set profile}
21728command to enable it. When you enable profiling, the system will begin
21729collecting timing and execution count data; when you disable profiling or
21730exit @value{GDBN}, the results will be written to a log file. Remember that
21731if you use profiling, @value{GDBN} will overwrite the profiling log file
21732(often called @file{gmon.out}). If you have a record of important profiling
21733data in a @file{gmon.out} file, be sure to move it to a safe location.
21734
21735Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21736compiled with the @samp{-pg} compiler option.
e7ba9c65 21737
09d4efe1
EZ
21738@kindex maint show-debug-regs
21739@cindex x86 hardware debug registers
21740@item maint show-debug-regs
21741Control whether to show variables that mirror the x86 hardware debug
21742registers. Use @code{ON} to enable, @code{OFF} to disable. If
21743enabled, the debug registers values are shown when GDB inserts or
21744removes a hardware breakpoint or watchpoint, and when the inferior
21745triggers a hardware-assisted breakpoint or watchpoint.
21746
21747@kindex maint space
21748@cindex memory used by commands
21749@item maint space
21750Control whether to display memory usage for each command. If set to a
21751nonzero value, @value{GDBN} will display how much memory each command
21752took, following the command's own output. This can also be requested
21753by invoking @value{GDBN} with the @option{--statistics} command-line
21754switch (@pxref{Mode Options}).
21755
21756@kindex maint time
21757@cindex time of command execution
21758@item maint time
21759Control whether to display the execution time for each command. If
21760set to a nonzero value, @value{GDBN} will display how much time it
21761took to execute each command, following the command's own output.
21762This can also be requested by invoking @value{GDBN} with the
21763@option{--statistics} command-line switch (@pxref{Mode Options}).
21764
21765@kindex maint translate-address
21766@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21767Find the symbol stored at the location specified by the address
21768@var{addr} and an optional section name @var{section}. If found,
21769@value{GDBN} prints the name of the closest symbol and an offset from
21770the symbol's location to the specified address. This is similar to
21771the @code{info address} command (@pxref{Symbols}), except that this
21772command also allows to find symbols in other sections.
ae038cb0 21773
8e04817f 21774@end table
c906108c 21775
9c16f35a
EZ
21776The following command is useful for non-interactive invocations of
21777@value{GDBN}, such as in the test suite.
21778
21779@table @code
21780@item set watchdog @var{nsec}
21781@kindex set watchdog
21782@cindex watchdog timer
21783@cindex timeout for commands
21784Set the maximum number of seconds @value{GDBN} will wait for the
21785target operation to finish. If this time expires, @value{GDBN}
21786reports and error and the command is aborted.
21787
21788@item show watchdog
21789Show the current setting of the target wait timeout.
21790@end table
c906108c 21791
e0ce93ac 21792@node Remote Protocol
8e04817f 21793@appendix @value{GDBN} Remote Serial Protocol
c906108c 21794
ee2d5c50
AC
21795@menu
21796* Overview::
21797* Packets::
21798* Stop Reply Packets::
21799* General Query Packets::
21800* Register Packet Format::
21801* Examples::
0ce1b118 21802* File-I/O remote protocol extension::
ee2d5c50
AC
21803@end menu
21804
21805@node Overview
21806@section Overview
21807
8e04817f
AC
21808There may be occasions when you need to know something about the
21809protocol---for example, if there is only one serial port to your target
21810machine, you might want your program to do something special if it
21811recognizes a packet meant for @value{GDBN}.
c906108c 21812
d2c6833e 21813In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21814transmitted and received data respectfully.
c906108c 21815
8e04817f
AC
21816@cindex protocol, @value{GDBN} remote serial
21817@cindex serial protocol, @value{GDBN} remote
21818@cindex remote serial protocol
21819All @value{GDBN} commands and responses (other than acknowledgments) are
21820sent as a @var{packet}. A @var{packet} is introduced with the character
21821@samp{$}, the actual @var{packet-data}, and the terminating character
21822@samp{#} followed by a two-digit @var{checksum}:
c906108c 21823
474c8240 21824@smallexample
8e04817f 21825@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21826@end smallexample
8e04817f 21827@noindent
c906108c 21828
8e04817f
AC
21829@cindex checksum, for @value{GDBN} remote
21830@noindent
21831The two-digit @var{checksum} is computed as the modulo 256 sum of all
21832characters between the leading @samp{$} and the trailing @samp{#} (an
21833eight bit unsigned checksum).
c906108c 21834
8e04817f
AC
21835Implementors should note that prior to @value{GDBN} 5.0 the protocol
21836specification also included an optional two-digit @var{sequence-id}:
c906108c 21837
474c8240 21838@smallexample
8e04817f 21839@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21840@end smallexample
c906108c 21841
8e04817f
AC
21842@cindex sequence-id, for @value{GDBN} remote
21843@noindent
21844That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21845has never output @var{sequence-id}s. Stubs that handle packets added
21846since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21847
8e04817f
AC
21848@cindex acknowledgment, for @value{GDBN} remote
21849When either the host or the target machine receives a packet, the first
21850response expected is an acknowledgment: either @samp{+} (to indicate
21851the package was received correctly) or @samp{-} (to request
21852retransmission):
c906108c 21853
474c8240 21854@smallexample
d2c6833e
AC
21855-> @code{$}@var{packet-data}@code{#}@var{checksum}
21856<- @code{+}
474c8240 21857@end smallexample
8e04817f 21858@noindent
53a5351d 21859
8e04817f
AC
21860The host (@value{GDBN}) sends @var{command}s, and the target (the
21861debugging stub incorporated in your program) sends a @var{response}. In
21862the case of step and continue @var{command}s, the response is only sent
21863when the operation has completed (the target has again stopped).
c906108c 21864
8e04817f
AC
21865@var{packet-data} consists of a sequence of characters with the
21866exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21867exceptions).
c906108c 21868
8e04817f 21869Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21870@cindex remote protocol, field separator
8e04817f 21871@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21872@sc{hex} with leading zeros suppressed.
c906108c 21873
8e04817f
AC
21874Implementors should note that prior to @value{GDBN} 5.0, the character
21875@samp{:} could not appear as the third character in a packet (as it
21876would potentially conflict with the @var{sequence-id}).
c906108c 21877
8e04817f
AC
21878Response @var{data} can be run-length encoded to save space. A @samp{*}
21879means that the next character is an @sc{ascii} encoding giving a repeat count
21880which stands for that many repetitions of the character preceding the
21881@samp{*}. The encoding is @code{n+29}, yielding a printable character
21882where @code{n >=3} (which is where rle starts to win). The printable
21883characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21884value greater than 126 should not be used.
c906108c 21885
8e04817f 21886So:
474c8240 21887@smallexample
8e04817f 21888"@code{0* }"
474c8240 21889@end smallexample
8e04817f
AC
21890@noindent
21891means the same as "0000".
c906108c 21892
8e04817f
AC
21893The error response returned for some packets includes a two character
21894error number. That number is not well defined.
c906108c 21895
8e04817f
AC
21896For any @var{command} not supported by the stub, an empty response
21897(@samp{$#00}) should be returned. That way it is possible to extend the
21898protocol. A newer @value{GDBN} can tell if a packet is supported based
21899on that response.
c906108c 21900
b383017d
RM
21901A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21902@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 21903optional.
c906108c 21904
ee2d5c50
AC
21905@node Packets
21906@section Packets
21907
21908The following table provides a complete list of all currently defined
21909@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
21910@xref{File-I/O remote protocol extension}, for details about the File
21911I/O extension of the remote protocol.
ee2d5c50
AC
21912
21913@table @r
21914
21915@item @code{!} --- extended mode
21916@cindex @code{!} packet
21917
8e04817f
AC
21918Enable extended mode. In extended mode, the remote server is made
21919persistent. The @samp{R} packet is used to restart the program being
21920debugged.
ee2d5c50
AC
21921
21922Reply:
21923@table @samp
21924@item OK
8e04817f 21925The remote target both supports and has enabled extended mode.
ee2d5c50 21926@end table
c906108c 21927
ee2d5c50
AC
21928@item @code{?} --- last signal
21929@cindex @code{?} packet
c906108c 21930
ee2d5c50
AC
21931Indicate the reason the target halted. The reply is the same as for
21932step and continue.
c906108c 21933
ee2d5c50
AC
21934Reply:
21935@xref{Stop Reply Packets}, for the reply specifications.
21936
21937@item @code{a} --- reserved
21938
21939Reserved for future use.
21940
21941@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
21942@cindex @code{A} packet
c906108c 21943
8e04817f
AC
21944Initialized @samp{argv[]} array passed into program. @var{arglen}
21945specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
21946See @code{gdbserver} for more details.
21947
21948Reply:
21949@table @samp
21950@item OK
21951@item E@var{NN}
21952@end table
21953
21954@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
21955@cindex @code{b} packet
21956
21957Change the serial line speed to @var{baud}.
21958
21959JTC: @emph{When does the transport layer state change? When it's
21960received, or after the ACK is transmitted. In either case, there are
21961problems if the command or the acknowledgment packet is dropped.}
21962
21963Stan: @emph{If people really wanted to add something like this, and get
21964it working for the first time, they ought to modify ser-unix.c to send
21965some kind of out-of-band message to a specially-setup stub and have the
21966switch happen "in between" packets, so that from remote protocol's point
21967of view, nothing actually happened.}
21968
21969@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
21970@cindex @code{B} packet
21971
8e04817f 21972Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
21973breakpoint at @var{addr}.
21974
21975This packet has been replaced by the @samp{Z} and @samp{z} packets
21976(@pxref{insert breakpoint or watchpoint packet}).
c906108c 21977
ee2d5c50
AC
21978@item @code{c}@var{addr} --- continue
21979@cindex @code{c} packet
21980
21981@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 21982current address.
c906108c 21983
ee2d5c50
AC
21984Reply:
21985@xref{Stop Reply Packets}, for the reply specifications.
21986
21987@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
21988@cindex @code{C} packet
21989
8e04817f
AC
21990Continue with signal @var{sig} (hex signal number). If
21991@code{;}@var{addr} is omitted, resume at same address.
c906108c 21992
ee2d5c50
AC
21993Reply:
21994@xref{Stop Reply Packets}, for the reply specifications.
c906108c 21995
ee2d5c50
AC
21996@item @code{d} --- toggle debug @strong{(deprecated)}
21997@cindex @code{d} packet
21998
21999Toggle debug flag.
22000
22001@item @code{D} --- detach
22002@cindex @code{D} packet
22003
22004Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22005before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22006
22007Reply:
22008@table @samp
22009@item @emph{no response}
8e04817f 22010@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 22011@end table
c906108c 22012
ee2d5c50 22013@item @code{e} --- reserved
c906108c 22014
ee2d5c50 22015Reserved for future use.
c906108c 22016
ee2d5c50 22017@item @code{E} --- reserved
c906108c 22018
ee2d5c50 22019Reserved for future use.
c906108c 22020
ee2d5c50
AC
22021@item @code{f} --- reserved
22022
22023Reserved for future use.
22024
0ce1b118
CV
22025@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22026@cindex @code{F} packet
ee2d5c50 22027
0ce1b118
CV
22028This packet is send by @value{GDBN} as reply to a @code{F} request packet
22029sent by the target. This is part of the File-I/O protocol extension.
22030@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22031
22032@item @code{g} --- read registers
22033@anchor{read registers packet}
22034@cindex @code{g} packet
22035
22036Read general registers.
22037
22038Reply:
22039@table @samp
22040@item @var{XX@dots{}}
8e04817f
AC
22041Each byte of register data is described by two hex digits. The bytes
22042with the register are transmitted in target byte order. The size of
22043each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22044determined by the @value{GDBN} internal macros
22045@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22046specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22047@item E@var{NN}
22048for an error.
22049@end table
c906108c 22050
ee2d5c50
AC
22051@item @code{G}@var{XX@dots{}} --- write regs
22052@cindex @code{G} packet
c906108c 22053
ee2d5c50
AC
22054@xref{read registers packet}, for a description of the @var{XX@dots{}}
22055data.
22056
22057Reply:
22058@table @samp
22059@item OK
22060for success
22061@item E@var{NN}
22062for an error
22063@end table
22064
22065@item @code{h} --- reserved
22066
22067Reserved for future use.
22068
b383017d 22069@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22070@cindex @code{H} packet
c906108c 22071
8e04817f 22072Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22073@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22074should be @samp{c} for step and continue operations, @samp{g} for other
22075operations. The thread designator @var{t@dots{}} may be -1, meaning all
22076the threads, a thread number, or zero which means pick any thread.
22077
22078Reply:
22079@table @samp
22080@item OK
22081for success
22082@item E@var{NN}
22083for an error
22084@end table
c906108c 22085
8e04817f
AC
22086@c FIXME: JTC:
22087@c 'H': How restrictive (or permissive) is the thread model. If a
22088@c thread is selected and stopped, are other threads allowed
22089@c to continue to execute? As I mentioned above, I think the
22090@c semantics of each command when a thread is selected must be
22091@c described. For example:
22092@c
22093@c 'g': If the stub supports threads and a specific thread is
22094@c selected, returns the register block from that thread;
22095@c otherwise returns current registers.
22096@c
22097@c 'G' If the stub supports threads and a specific thread is
22098@c selected, sets the registers of the register block of
22099@c that thread; otherwise sets current registers.
c906108c 22100
ee2d5c50
AC
22101@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22102@anchor{cycle step packet}
22103@cindex @code{i} packet
22104
8e04817f
AC
22105Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22106present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22107step starting at that address.
c906108c 22108
ee2d5c50
AC
22109@item @code{I} --- signal then cycle step @strong{(reserved)}
22110@cindex @code{I} packet
22111
22112@xref{step with signal packet}. @xref{cycle step packet}.
22113
22114@item @code{j} --- reserved
22115
22116Reserved for future use.
22117
22118@item @code{J} --- reserved
c906108c 22119
ee2d5c50 22120Reserved for future use.
c906108c 22121
ee2d5c50
AC
22122@item @code{k} --- kill request
22123@cindex @code{k} packet
c906108c 22124
ac282366 22125FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22126thread context has been selected (i.e.@: does 'k' kill only that
22127thread?)}.
c906108c 22128
ee2d5c50 22129@item @code{K} --- reserved
c906108c 22130
ee2d5c50
AC
22131Reserved for future use.
22132
22133@item @code{l} --- reserved
22134
22135Reserved for future use.
22136
22137@item @code{L} --- reserved
22138
22139Reserved for future use.
22140
22141@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22142@cindex @code{m} packet
c906108c 22143
8e04817f 22144Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22145Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22146assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22147transfer mechanism is needed.}
c906108c 22148
ee2d5c50
AC
22149Reply:
22150@table @samp
22151@item @var{XX@dots{}}
22152@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22153to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22154that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22155accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22156needed.}
22157@item E@var{NN}
22158@var{NN} is errno
22159@end table
22160
22161@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22162@cindex @code{M} packet
22163
8e04817f 22164Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22165@var{XX@dots{}} is the data.
22166
22167Reply:
22168@table @samp
22169@item OK
22170for success
22171@item E@var{NN}
8e04817f
AC
22172for an error (this includes the case where only part of the data was
22173written).
ee2d5c50 22174@end table
c906108c 22175
ee2d5c50 22176@item @code{n} --- reserved
c906108c 22177
ee2d5c50 22178Reserved for future use.
c906108c 22179
ee2d5c50 22180@item @code{N} --- reserved
c906108c 22181
ee2d5c50 22182Reserved for future use.
c906108c 22183
ee2d5c50
AC
22184@item @code{o} --- reserved
22185
22186Reserved for future use.
22187
22188@item @code{O} --- reserved
22189
2e868123 22190@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22191@cindex @code{p} packet
22192
2e868123
AC
22193@xref{read registers packet}, for a description of how the returned
22194register value is encoded.
ee2d5c50
AC
22195
22196Reply:
22197@table @samp
2e868123
AC
22198@item @var{XX@dots{}}
22199the register's value
22200@item E@var{NN}
22201for an error
22202@item
22203Indicating an unrecognized @var{query}.
ee2d5c50
AC
22204@end table
22205
22206@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22207@anchor{write register packet}
22208@cindex @code{P} packet
22209
22210Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22211digits for each byte in the register (target byte order).
c906108c 22212
ee2d5c50
AC
22213Reply:
22214@table @samp
22215@item OK
22216for success
22217@item E@var{NN}
22218for an error
22219@end table
22220
22221@item @code{q}@var{query} --- general query
22222@anchor{general query packet}
22223@cindex @code{q} packet
22224
22225Request info about @var{query}. In general @value{GDBN} queries have a
22226leading upper case letter. Custom vendor queries should use a company
22227prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22228be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22229that they match the full @var{query} name.
22230
22231Reply:
22232@table @samp
22233@item @var{XX@dots{}}
22234Hex encoded data from query. The reply can not be empty.
22235@item E@var{NN}
22236error reply
8e04817f 22237@item
ee2d5c50
AC
22238Indicating an unrecognized @var{query}.
22239@end table
22240
22241@item @code{Q}@var{var}@code{=}@var{val} --- general set
22242@cindex @code{Q} packet
22243
22244Set value of @var{var} to @var{val}.
22245
22246@xref{general query packet}, for a discussion of naming conventions.
c906108c 22247
ee2d5c50
AC
22248@item @code{r} --- reset @strong{(deprecated)}
22249@cindex @code{r} packet
c906108c 22250
8e04817f 22251Reset the entire system.
c906108c 22252
ee2d5c50
AC
22253@item @code{R}@var{XX} --- remote restart
22254@cindex @code{R} packet
22255
8e04817f
AC
22256Restart the program being debugged. @var{XX}, while needed, is ignored.
22257This packet is only available in extended mode.
ee2d5c50
AC
22258
22259Reply:
22260@table @samp
22261@item @emph{no reply}
8e04817f 22262The @samp{R} packet has no reply.
ee2d5c50
AC
22263@end table
22264
22265@item @code{s}@var{addr} --- step
22266@cindex @code{s} packet
c906108c 22267
8e04817f
AC
22268@var{addr} is address to resume. If @var{addr} is omitted, resume at
22269same address.
c906108c 22270
ee2d5c50
AC
22271Reply:
22272@xref{Stop Reply Packets}, for the reply specifications.
22273
22274@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22275@anchor{step with signal packet}
22276@cindex @code{S} packet
22277
8e04817f 22278Like @samp{C} but step not continue.
c906108c 22279
ee2d5c50
AC
22280Reply:
22281@xref{Stop Reply Packets}, for the reply specifications.
22282
b383017d 22283@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22284@cindex @code{t} packet
22285
8e04817f 22286Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22287@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22288@var{addr} must be at least 3 digits.
c906108c 22289
ee2d5c50
AC
22290@item @code{T}@var{XX} --- thread alive
22291@cindex @code{T} packet
c906108c 22292
ee2d5c50 22293Find out if the thread XX is alive.
c906108c 22294
ee2d5c50
AC
22295Reply:
22296@table @samp
22297@item OK
22298thread is still alive
22299@item E@var{NN}
22300thread is dead
22301@end table
22302
22303@item @code{u} --- reserved
22304
22305Reserved for future use.
22306
22307@item @code{U} --- reserved
22308
22309Reserved for future use.
22310
86d30acc 22311@item @code{v} --- verbose packet prefix
ee2d5c50 22312
86d30acc
DJ
22313Packets starting with @code{v} are identified by a multi-letter name,
22314up to the first @code{;} or @code{?} (or the end of the packet).
22315
22316@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22317@cindex @code{vCont} packet
22318
22319Resume the inferior. Different actions may be specified for each thread.
22320If an action is specified with no @var{tid}, then it is applied to any
22321threads that don't have a specific action specified; if no default action is
22322specified then other threads should remain stopped. Specifying multiple
22323default actions is an error; specifying no actions is also an error.
22324Thread IDs are specified in hexadecimal. Currently supported actions are:
22325
22326@table @code
22327@item c
22328Continue.
22329@item C@var{sig}
22330Continue with signal @var{sig}. @var{sig} should be two hex digits.
22331@item s
22332Step.
22333@item S@var{sig}
22334Step with signal @var{sig}. @var{sig} should be two hex digits.
22335@end table
22336
22337The optional @var{addr} argument normally associated with these packets is
22338not supported in @code{vCont}.
22339
22340Reply:
22341@xref{Stop Reply Packets}, for the reply specifications.
22342
22343@item @code{vCont?} --- extended resume query
22344@cindex @code{vCont?} packet
22345
22346Query support for the @code{vCont} packet.
22347
22348Reply:
22349@table @samp
22350@item @code{vCont}[;@var{action}]...
22351The @code{vCont} packet is supported. Each @var{action} is a supported
22352command in the @code{vCont} packet.
22353@item
22354The @code{vCont} packet is not supported.
22355@end table
ee2d5c50
AC
22356
22357@item @code{V} --- reserved
c906108c 22358
ee2d5c50 22359Reserved for future use.
c906108c 22360
ee2d5c50 22361@item @code{w} --- reserved
c906108c 22362
ee2d5c50 22363Reserved for future use.
c906108c 22364
ee2d5c50 22365@item @code{W} --- reserved
c906108c 22366
ee2d5c50 22367Reserved for future use.
c906108c 22368
ee2d5c50
AC
22369@item @code{x} --- reserved
22370
22371Reserved for future use.
22372
22373@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22374@cindex @code{X} packet
22375
22376@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22377is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22378escaped using @code{0x7d}, and then XORed with @code{0x20}.
22379For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22380
ee2d5c50
AC
22381Reply:
22382@table @samp
22383@item OK
22384for success
22385@item E@var{NN}
22386for an error
22387@end table
22388
22389@item @code{y} --- reserved
c906108c 22390
ee2d5c50 22391Reserved for future use.
c906108c 22392
ee2d5c50
AC
22393@item @code{Y} reserved
22394
22395Reserved for future use.
22396
2f870471
AC
22397@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22398@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22399@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22400@cindex @code{z} packet
2f870471 22401@cindex @code{Z} packets
ee2d5c50 22402
2f870471
AC
22403Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22404watchpoint starting at address @var{address} and covering the next
22405@var{length} bytes.
ee2d5c50 22406
2f870471
AC
22407Each breakpoint and watchpoint packet @var{type} is documented
22408separately.
22409
512217c7
AC
22410@emph{Implementation notes: A remote target shall return an empty string
22411for an unrecognized breakpoint or watchpoint packet @var{type}. A
22412remote target shall support either both or neither of a given
2f870471
AC
22413@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22414avoid potential problems with duplicate packets, the operations should
22415be implemented in an idempotent way.}
22416
22417@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22418@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22419@cindex @code{z0} packet
22420@cindex @code{Z0} packet
22421
22422Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22423@code{addr} of size @code{length}.
22424
22425A memory breakpoint is implemented by replacing the instruction at
22426@var{addr} with a software breakpoint or trap instruction. The
22427@code{length} is used by targets that indicates the size of the
22428breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22429@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22430
2f870471
AC
22431@emph{Implementation note: It is possible for a target to copy or move
22432code that contains memory breakpoints (e.g., when implementing
22433overlays). The behavior of this packet, in the presence of such a
22434target, is not defined.}
c906108c 22435
ee2d5c50
AC
22436Reply:
22437@table @samp
2f870471
AC
22438@item OK
22439success
22440@item
22441not supported
ee2d5c50
AC
22442@item E@var{NN}
22443for an error
2f870471
AC
22444@end table
22445
22446@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22447@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22448@cindex @code{z1} packet
22449@cindex @code{Z1} packet
22450
22451Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22452address @code{addr} of size @code{length}.
22453
22454A hardware breakpoint is implemented using a mechanism that is not
22455dependant on being able to modify the target's memory.
22456
22457@emph{Implementation note: A hardware breakpoint is not affected by code
22458movement.}
22459
22460Reply:
22461@table @samp
ee2d5c50 22462@item OK
2f870471
AC
22463success
22464@item
22465not supported
22466@item E@var{NN}
22467for an error
22468@end table
22469
22470@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22471@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22472@cindex @code{z2} packet
22473@cindex @code{Z2} packet
22474
22475Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22476
22477Reply:
22478@table @samp
22479@item OK
22480success
22481@item
22482not supported
22483@item E@var{NN}
22484for an error
22485@end table
22486
22487@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22488@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22489@cindex @code{z3} packet
22490@cindex @code{Z3} packet
22491
2e834e49 22492Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22493
22494Reply:
22495@table @samp
22496@item OK
22497success
22498@item
22499not supported
22500@item E@var{NN}
22501for an error
22502@end table
22503
2e834e49
HPN
22504@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22505@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22506@cindex @code{z4} packet
22507@cindex @code{Z4} packet
22508
22509Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22510
22511Reply:
22512@table @samp
22513@item OK
22514success
22515@item
22516not supported
22517@item E@var{NN}
22518for an error
ee2d5c50
AC
22519@end table
22520
22521@end table
c906108c 22522
ee2d5c50
AC
22523@node Stop Reply Packets
22524@section Stop Reply Packets
22525@cindex stop reply packets
c906108c 22526
8e04817f
AC
22527The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22528receive any of the below as a reply. In the case of the @samp{C},
22529@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22530when the target halts. In the below the exact meaning of @samp{signal
22531number} is poorly defined. In general one of the UNIX signal numbering
22532conventions is used.
c906108c 22533
ee2d5c50 22534@table @samp
c906108c 22535
ee2d5c50
AC
22536@item S@var{AA}
22537@var{AA} is the signal number
c906108c 22538
8e04817f 22539@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
22540@cindex @code{T} packet reply
22541
8e04817f
AC
22542@var{AA} = two hex digit signal number; @var{n...} = register number
22543(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22544by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22545@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22546(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22547address, this is a hex integer; @var{n...} = other string not starting
22548with valid hex digit. @value{GDBN} should ignore this @var{n...},
22549@var{r...} pair and go on to the next. This way we can extend the
22550protocol.
c906108c 22551
ee2d5c50
AC
22552@item W@var{AA}
22553
8e04817f 22554The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22555applicable to certain targets.
22556
22557@item X@var{AA}
c906108c 22558
8e04817f 22559The process terminated with signal @var{AA}.
c906108c 22560
ee2d5c50 22561@item O@var{XX@dots{}}
c906108c 22562
ee2d5c50
AC
22563@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22564any time while the program is running and the debugger should continue
22565to wait for @samp{W}, @samp{T}, etc.
22566
0ce1b118
CV
22567@item F@var{call-id}@code{,}@var{parameter@dots{}}
22568
22569@var{call-id} is the identifier which says which host system call should
22570be called. This is just the name of the function. Translation into the
22571correct system call is only applicable as it's defined in @value{GDBN}.
22572@xref{File-I/O remote protocol extension}, for a list of implemented
22573system calls.
22574
22575@var{parameter@dots{}} is a list of parameters as defined for this very
22576system call.
22577
22578The target replies with this packet when it expects @value{GDBN} to call
22579a host system call on behalf of the target. @value{GDBN} replies with
22580an appropriate @code{F} packet and keeps up waiting for the next reply
22581packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22582@samp{s} action is expected to be continued.
22583@xref{File-I/O remote protocol extension}, for more details.
22584
ee2d5c50
AC
22585@end table
22586
22587@node General Query Packets
22588@section General Query Packets
9c16f35a 22589@cindex remote query requests
c906108c 22590
8e04817f 22591The following set and query packets have already been defined.
c906108c 22592
ee2d5c50 22593@table @r
c906108c 22594
ee2d5c50 22595@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22596@cindex current thread, remote request
22597@cindex @code{qC} packet
ee2d5c50
AC
22598Return the current thread id.
22599
22600Reply:
22601@table @samp
22602@item @code{QC}@var{pid}
e1aac25b 22603Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22604@item *
22605Any other reply implies the old pid.
22606@end table
22607
22608@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22609@cindex list active threads, remote request
22610@cindex @code{qfThreadInfo} packet
ee2d5c50 22611@code{q}@code{sThreadInfo}
c906108c 22612
8e04817f
AC
22613Obtain a list of active thread ids from the target (OS). Since there
22614may be too many active threads to fit into one reply packet, this query
22615works iteratively: it may require more than one query/reply sequence to
22616obtain the entire list of threads. The first query of the sequence will
22617be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22618sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22619
22620NOTE: replaces the @code{qL} query (see below).
22621
22622Reply:
22623@table @samp
22624@item @code{m}@var{id}
22625A single thread id
22626@item @code{m}@var{id},@var{id}@dots{}
22627a comma-separated list of thread ids
22628@item @code{l}
22629(lower case 'el') denotes end of list.
22630@end table
22631
22632In response to each query, the target will reply with a list of one or
e1aac25b
JB
22633more thread ids, in big-endian unsigned hex, separated by commas.
22634@value{GDBN} will respond to each reply with a request for more thread
22635ids (using the @code{qs} form of the query), until the target responds
22636with @code{l} (lower-case el, for @code{'last'}).
c906108c 22637
ee2d5c50 22638@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22639@cindex thread attributes info, remote request
22640@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22641Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22642string description of a thread's attributes from the target OS. This
22643string may contain anything that the target OS thinks is interesting for
22644@value{GDBN} to tell the user about the thread. The string is displayed
22645in @value{GDBN}'s @samp{info threads} display. Some examples of
22646possible thread extra info strings are ``Runnable'', or ``Blocked on
22647Mutex''.
22648
22649Reply:
22650@table @samp
22651@item @var{XX@dots{}}
22652Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22653the printable string containing the extra information about the thread's
8e04817f 22654attributes.
ee2d5c50
AC
22655@end table
22656
22657@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22658
8e04817f
AC
22659Obtain thread information from RTOS. Where: @var{startflag} (one hex
22660digit) is one to indicate the first query and zero to indicate a
22661subsequent query; @var{threadcount} (two hex digits) is the maximum
22662number of threads the response packet can contain; and @var{nextthread}
22663(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22664returned in the response as @var{argthread}.
ee2d5c50
AC
22665
22666NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22667(see above).
22668
22669Reply:
22670@table @samp
22671@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22672Where: @var{count} (two hex digits) is the number of threads being
22673returned; @var{done} (one hex digit) is zero to indicate more threads
22674and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22675digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22676is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22677digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22678@end table
c906108c 22679
ee2d5c50 22680@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22681@cindex CRC of memory block, remote request
22682@cindex @code{qCRC} packet
ee2d5c50
AC
22683Reply:
22684@table @samp
22685@item @code{E}@var{NN}
22686An error (such as memory fault)
22687@item @code{C}@var{CRC32}
22688A 32 bit cyclic redundancy check of the specified memory region.
22689@end table
22690
22691@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22692@cindex section offsets, remote request
22693@cindex @code{qOffsets} packet
8e04817f
AC
22694Get section offsets that the target used when re-locating the downloaded
22695image. @emph{Note: while a @code{Bss} offset is included in the
22696response, @value{GDBN} ignores this and instead applies the @code{Data}
22697offset to the @code{Bss} section.}
c906108c 22698
ee2d5c50
AC
22699Reply:
22700@table @samp
22701@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22702@end table
22703
22704@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22705@cindex thread information, remote request
22706@cindex @code{qP} packet
8e04817f
AC
22707Returns information on @var{threadid}. Where: @var{mode} is a hex
22708encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22709
22710Reply:
22711@table @samp
22712@item *
22713@end table
22714
8e04817f 22715See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22716
ee2d5c50 22717@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22718@cindex execute remote command, remote request
22719@cindex @code{qRcmd} packet
ee2d5c50 22720@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22721execution. Invalid commands should be reported using the output string.
22722Before the final result packet, the target may also respond with a
ee2d5c50
AC
22723number of intermediate @code{O}@var{output} console output packets.
22724@emph{Implementors should note that providing access to a stubs's
22725interpreter may have security implications}.
22726
22727Reply:
22728@table @samp
22729@item OK
8e04817f 22730A command response with no output.
ee2d5c50 22731@item @var{OUTPUT}
8e04817f 22732A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22733@item @code{E}@var{NN}
8e04817f 22734Indicate a badly formed request.
ee2d5c50 22735@item @samp{}
8e04817f 22736When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22737@end table
9c16f35a 22738z
ee2d5c50 22739@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22740@cindex symbol lookup, remote request
22741@cindex @code{qSymbol} packet
8e04817f
AC
22742Notify the target that @value{GDBN} is prepared to serve symbol lookup
22743requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22744
22745Reply:
22746@table @samp
22747@item @code{OK}
8e04817f 22748The target does not need to look up any (more) symbols.
ee2d5c50
AC
22749@item @code{qSymbol:}@var{sym_name}
22750The target requests the value of symbol @var{sym_name} (hex encoded).
22751@value{GDBN} may provide the value by using the
22752@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22753@end table
22754
22755@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22756
22757Set the value of @var{sym_name} to @var{sym_value}.
22758
22759@var{sym_name} (hex encoded) is the name of a symbol whose value the
22760target has previously requested.
22761
22762@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22763@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22764will be empty.
22765
22766Reply:
22767@table @samp
22768@item @code{OK}
8e04817f 22769The target does not need to look up any (more) symbols.
ee2d5c50
AC
22770@item @code{qSymbol:}@var{sym_name}
22771The target requests the value of a new symbol @var{sym_name} (hex
22772encoded). @value{GDBN} will continue to supply the values of symbols
22773(if available), until the target ceases to request them.
22774@end table
eb12ee30 22775
649e03f6 22776@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22777@cindex read special object, remote request
22778@cindex @code{qPart} packet
649e03f6
RM
22779Read uninterpreted bytes from the target's special data area
22780identified by the keyword @code{object}.
22781Request @var{length} bytes starting at @var{offset} bytes into the data.
22782The content and encoding of @var{annex} is specific to the object;
22783it can supply additional details about what data to access.
22784
22785Here are the specific requests of this form defined so far.
22786All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22787requests use the same reply formats, listed below.
22788
22789@table @asis
22790@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22791Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22792auxiliary vector}, and see @ref{Remote configuration,
22793read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22794@end table
22795
22796Reply:
22797@table @asis
22798@item @code{OK}
22799The @var{offset} in the request is at the end of the data.
22800There is no more data to be read.
22801
22802@item @var{XX@dots{}}
22803Hex encoded data bytes read.
22804This may be fewer bytes than the @var{length} in the request.
22805
22806@item @code{E00}
22807The request was malformed, or @var{annex} was invalid.
22808
22809@item @code{E}@var{nn}
22810The offset was invalid, or there was an error encountered reading the data.
22811@var{nn} is a hex-encoded @code{errno} value.
22812
22813@item @code{""} (empty)
22814An empty reply indicates the @var{object} or @var{annex} string was not
22815recognized by the stub.
22816@end table
22817
22818@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22819@cindex write data into object, remote request
649e03f6
RM
22820Write uninterpreted bytes into the target's special data area
22821identified by the keyword @code{object},
22822starting at @var{offset} bytes into the data.
22823@var{data@dots{}} is the hex-encoded data to be written.
22824The content and encoding of @var{annex} is specific to the object;
22825it can supply additional details about what data to access.
22826
22827No requests of this form are presently in use. This specification
22828serves as a placeholder to document the common format that new
22829specific request specifications ought to use.
22830
22831Reply:
22832@table @asis
22833@item @var{nn}
22834@var{nn} (hex encoded) is the number of bytes written.
22835This may be fewer bytes than supplied in the request.
22836
22837@item @code{E00}
22838The request was malformed, or @var{annex} was invalid.
22839
22840@item @code{E}@var{nn}
22841The offset was invalid, or there was an error encountered writing the data.
22842@var{nn} is a hex-encoded @code{errno} value.
22843
22844@item @code{""} (empty)
22845An empty reply indicates the @var{object} or @var{annex} string was not
22846recognized by the stub, or that the object does not support writing.
22847@end table
22848
22849@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22850Requests of this form may be added in the future. When a stub does
22851not recognize the @var{object} keyword, or its support for
22852@var{object} does not recognize the @var{operation} keyword,
22853the stub must respond with an empty packet.
83761cbd
KB
22854
22855@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22856@cindex get thread-local storage address, remote request
22857@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22858Fetch the address associated with thread local storage specified
22859by @var{thread-id}, @var{offset}, and @var{lm}.
22860
22861@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22862thread for which to fetch the TLS address.
22863
22864@var{offset} is the (big endian, hex encoded) offset associated with the
22865thread local variable. (This offset is obtained from the debug
22866information associated with the variable.)
22867
22868@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22869the load module associated with the thread local storage. For example,
22870a @sc{gnu}/Linux system will pass the link map address of the shared
22871object associated with the thread local storage under consideration.
22872Other operating environments may choose to represent the load module
22873differently, so the precise meaning of this parameter will vary.
22874
22875Reply:
22876@table @asis
68c71a2e 22877@item @var{XX@dots{}}
83761cbd
KB
22878Hex encoded (big endian) bytes representing the address of the thread
22879local storage requested.
22880
22881@item @code{E}@var{nn} (where @var{nn} are hex digits)
22882An error occurred.
22883
22884@item @code{""} (empty)
22885An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22886@end table
22887
0abb7bc7
EZ
22888Use of this request packet is controlled by the @code{set remote
22889get-thread-local-storage-address} command (@pxref{Remote
22890configuration, set remote get-thread-local-storage-address}).
22891
ee2d5c50
AC
22892@end table
22893
22894@node Register Packet Format
22895@section Register Packet Format
eb12ee30 22896
8e04817f 22897The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
22898In the below, some thirty-two bit registers are transferred as
22899sixty-four bits. Those registers should be zero/sign extended (which?)
22900to fill the space allocated. Register bytes are transfered in target
22901byte order. The two nibbles within a register byte are transfered
22902most-significant - least-significant.
eb12ee30 22903
ee2d5c50 22904@table @r
eb12ee30 22905
8e04817f 22906@item MIPS32
ee2d5c50 22907
8e04817f
AC
22908All registers are transfered as thirty-two bit quantities in the order:
2290932 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
22910registers; fsr; fir; fp.
eb12ee30 22911
8e04817f 22912@item MIPS64
ee2d5c50 22913
8e04817f
AC
22914All registers are transfered as sixty-four bit quantities (including
22915thirty-two bit registers such as @code{sr}). The ordering is the same
22916as @code{MIPS32}.
eb12ee30 22917
ee2d5c50
AC
22918@end table
22919
22920@node Examples
22921@section Examples
eb12ee30 22922
8e04817f
AC
22923Example sequence of a target being re-started. Notice how the restart
22924does not get any direct output:
eb12ee30 22925
474c8240 22926@smallexample
d2c6833e
AC
22927-> @code{R00}
22928<- @code{+}
8e04817f 22929@emph{target restarts}
d2c6833e 22930-> @code{?}
8e04817f 22931<- @code{+}
d2c6833e
AC
22932<- @code{T001:1234123412341234}
22933-> @code{+}
474c8240 22934@end smallexample
eb12ee30 22935
8e04817f 22936Example sequence of a target being stepped by a single instruction:
eb12ee30 22937
474c8240 22938@smallexample
d2c6833e 22939-> @code{G1445@dots{}}
8e04817f 22940<- @code{+}
d2c6833e
AC
22941-> @code{s}
22942<- @code{+}
22943@emph{time passes}
22944<- @code{T001:1234123412341234}
8e04817f 22945-> @code{+}
d2c6833e 22946-> @code{g}
8e04817f 22947<- @code{+}
d2c6833e
AC
22948<- @code{1455@dots{}}
22949-> @code{+}
474c8240 22950@end smallexample
eb12ee30 22951
0ce1b118
CV
22952@node File-I/O remote protocol extension
22953@section File-I/O remote protocol extension
22954@cindex File-I/O remote protocol extension
22955
22956@menu
22957* File-I/O Overview::
22958* Protocol basics::
1d8b2f28
JB
22959* The F request packet::
22960* The F reply packet::
0ce1b118
CV
22961* Memory transfer::
22962* The Ctrl-C message::
22963* Console I/O::
22964* The isatty call::
22965* The system call::
22966* List of supported calls::
22967* Protocol specific representation of datatypes::
22968* Constants::
22969* File-I/O Examples::
22970@end menu
22971
22972@node File-I/O Overview
22973@subsection File-I/O Overview
22974@cindex file-i/o overview
22975
9c16f35a
EZ
22976The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
22977target to use the host's file system and console I/O when calling various
0ce1b118
CV
22978system calls. System calls on the target system are translated into a
22979remote protocol packet to the host system which then performs the needed
22980actions and returns with an adequate response packet to the target system.
22981This simulates file system operations even on targets that lack file systems.
22982
22983The protocol is defined host- and target-system independent. It uses
9c16f35a 22984its own independent representation of datatypes and values. Both,
0ce1b118
CV
22985@value{GDBN} and the target's @value{GDBN} stub are responsible for
22986translating the system dependent values into the unified protocol values
22987when data is transmitted.
22988
22989The communication is synchronous. A system call is possible only
22990when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
22991packets. While @value{GDBN} handles the request for a system call,
22992the target is stopped to allow deterministic access to the target's
22993memory. Therefore File-I/O is not interuptible by target signals. It
22994is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
22995
22996The target's request to perform a host system call does not finish
22997the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
22998after finishing the system call, the target returns to continuing the
22999previous activity (continue, step). No additional continue or step
23000request from @value{GDBN} is required.
23001
23002@smallexample
f7dc1244 23003(@value{GDBP}) continue
0ce1b118
CV
23004 <- target requests 'system call X'
23005 target is stopped, @value{GDBN} executes system call
23006 -> GDB returns result
23007 ... target continues, GDB returns to wait for the target
23008 <- target hits breakpoint and sends a Txx packet
23009@end smallexample
23010
23011The protocol is only used for files on the host file system and
23012for I/O on the console. Character or block special devices, pipes,
23013named pipes or sockets or any other communication method on the host
23014system are not supported by this protocol.
23015
23016@node Protocol basics
23017@subsection Protocol basics
23018@cindex protocol basics, file-i/o
23019
23020The File-I/O protocol uses the @code{F} packet, as request as well
23021as as reply packet. Since a File-I/O system call can only occur when
b383017d 23022@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23023File-I/O request is a reply that @value{GDBN} has to expect as a result
23024of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23025This @code{F} packet contains all information needed to allow @value{GDBN}
23026to call the appropriate host system call:
23027
23028@itemize @bullet
b383017d 23029@item
0ce1b118
CV
23030A unique identifier for the requested system call.
23031
23032@item
23033All parameters to the system call. Pointers are given as addresses
23034in the target memory address space. Pointers to strings are given as
b383017d 23035pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23036Numerical control values are given in a protocol specific representation.
23037
23038@end itemize
23039
23040At that point @value{GDBN} has to perform the following actions.
23041
23042@itemize @bullet
b383017d 23043@item
0ce1b118
CV
23044If parameter pointer values are given, which point to data needed as input
23045to a system call, @value{GDBN} requests this data from the target with a
23046standard @code{m} packet request. This additional communication has to be
23047expected by the target implementation and is handled as any other @code{m}
23048packet.
23049
23050@item
23051@value{GDBN} translates all value from protocol representation to host
23052representation as needed. Datatypes are coerced into the host types.
23053
23054@item
23055@value{GDBN} calls the system call
23056
23057@item
23058It then coerces datatypes back to protocol representation.
23059
23060@item
23061If pointer parameters in the request packet point to buffer space in which
23062a system call is expected to copy data to, the data is transmitted to the
23063target using a @code{M} or @code{X} packet. This packet has to be expected
23064by the target implementation and is handled as any other @code{M} or @code{X}
23065packet.
23066
23067@end itemize
23068
23069Eventually @value{GDBN} replies with another @code{F} packet which contains all
23070necessary information for the target to continue. This at least contains
23071
23072@itemize @bullet
23073@item
23074Return value.
23075
23076@item
23077@code{errno}, if has been changed by the system call.
23078
23079@item
23080``Ctrl-C'' flag.
23081
23082@end itemize
23083
23084After having done the needed type and value coercion, the target continues
23085the latest continue or step action.
23086
1d8b2f28 23087@node The F request packet
0ce1b118
CV
23088@subsection The @code{F} request packet
23089@cindex file-i/o request packet
23090@cindex @code{F} request packet
23091
23092The @code{F} request packet has the following format:
23093
23094@table @samp
23095
23096@smallexample
23097@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23098@end smallexample
23099
23100@var{call-id} is the identifier to indicate the host system call to be called.
23101This is just the name of the function.
23102
23103@var{parameter@dots{}} are the parameters to the system call.
23104
b383017d 23105@end table
0ce1b118
CV
23106
23107Parameters are hexadecimal integer values, either the real values in case
23108of scalar datatypes, as pointers to target buffer space in case of compound
23109datatypes and unspecified memory areas or as pointer/length pairs in case
23110of string parameters. These are appended to the call-id, each separated
23111from its predecessor by a comma. All values are transmitted in ASCII
23112string representation, pointer/length pairs separated by a slash.
23113
1d8b2f28 23114@node The F reply packet
0ce1b118
CV
23115@subsection The @code{F} reply packet
23116@cindex file-i/o reply packet
23117@cindex @code{F} reply packet
23118
23119The @code{F} reply packet has the following format:
23120
23121@table @samp
23122
23123@smallexample
23124@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23125@end smallexample
23126
23127@var{retcode} is the return code of the system call as hexadecimal value.
23128
23129@var{errno} is the errno set by the call, in protocol specific representation.
23130This parameter can be omitted if the call was successful.
23131
23132@var{Ctrl-C flag} is only send if the user requested a break. In this
23133case, @var{errno} must be send as well, even if the call was successful.
23134The @var{Ctrl-C flag} itself consists of the character 'C':
23135
23136@smallexample
23137F0,0,C
23138@end smallexample
23139
23140@noindent
23141or, if the call was interupted before the host call has been performed:
23142
23143@smallexample
23144F-1,4,C
23145@end smallexample
23146
23147@noindent
23148assuming 4 is the protocol specific representation of @code{EINTR}.
23149
23150@end table
23151
23152@node Memory transfer
23153@subsection Memory transfer
23154@cindex memory transfer, in file-i/o protocol
23155
23156Structured data which is transferred using a memory read or write as e.g.@:
23157a @code{struct stat} is expected to be in a protocol specific format with
23158all scalar multibyte datatypes being big endian. This should be done by
23159the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23160it transfers memory to the target. Transferred pointers to structured
23161data should point to the already coerced data at any time.
23162
23163@node The Ctrl-C message
23164@subsection The Ctrl-C message
23165@cindex ctrl-c message, in file-i/o protocol
23166
23167A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23168reply packet. In this case the target should behave, as if it had
23169gotten a break message. The meaning for the target is ``system call
23170interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23171(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23172packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23173state the system call was interrupted. Since this action is by design
23174not an atomic operation, we have to differ between two cases:
23175
23176@itemize @bullet
23177@item
23178The system call hasn't been performed on the host yet.
23179
23180@item
23181The system call on the host has been finished.
23182
23183@end itemize
23184
23185These two states can be distinguished by the target by the value of the
23186returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23187call hasn't been performed. This is equivalent to the @code{EINTR} handling
23188on POSIX systems. In any other case, the target may presume that the
23189system call has been finished --- successful or not --- and should behave
23190as if the break message arrived right after the system call.
23191
23192@value{GDBN} must behave reliable. If the system call has not been called
23193yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23194@code{errno} in the packet. If the system call on the host has been finished
23195before the user requests a break, the full action must be finshed by
23196@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23197The @code{F} packet may only be send when either nothing has happened
23198or the full action has been completed.
23199
23200@node Console I/O
23201@subsection Console I/O
23202@cindex console i/o as part of file-i/o
23203
23204By default and if not explicitely closed by the target system, the file
23205descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23206on the @value{GDBN} console is handled as any other file output operation
23207(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23208by @value{GDBN} so that after the target read request from file descriptor
232090 all following typing is buffered until either one of the following
23210conditions is met:
23211
23212@itemize @bullet
23213@item
23214The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23215@code{read}
23216system call is treated as finished.
23217
23218@item
23219The user presses @kbd{Enter}. This is treated as end of input with a trailing
23220line feed.
23221
23222@item
23223The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23224character, especially no Ctrl-D is appended to the input.
23225
23226@end itemize
23227
23228If the user has typed more characters as fit in the buffer given to
23229the read call, the trailing characters are buffered in @value{GDBN} until
23230either another @code{read(0, @dots{})} is requested by the target or debugging
23231is stopped on users request.
23232
23233@node The isatty call
2eecc4ab 23234@subsection The @samp{isatty} function call
0ce1b118
CV
23235@cindex isatty call, file-i/o protocol
23236
23237A special case in this protocol is the library call @code{isatty} which
9c16f35a 23238is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
232391 to the target if the file descriptor given as parameter is attached
23240to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23241would require implementing @code{ioctl} and would be more complex than
23242needed.
23243
23244@node The system call
2eecc4ab 23245@subsection The @samp{system} function call
0ce1b118
CV
23246@cindex system call, file-i/o protocol
23247
23248The other special case in this protocol is the @code{system} call which
9c16f35a 23249is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23250task of calling the necessary host calls to perform the @code{system}
23251call. The return value of @code{system} is simplified before it's returned
23252to the target. Basically, the only signal transmitted back is @code{EINTR}
23253in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23254entirely of the exit status of the called command.
23255
9c16f35a
EZ
23256Due to security concerns, the @code{system} call is by default refused
23257by @value{GDBN}. The user has to allow this call explicitly with the
23258@kbd{set remote system-call-allowed 1} command.
0ce1b118 23259
9c16f35a
EZ
23260@table @code
23261@item set remote system-call-allowed
23262@kindex set remote system-call-allowed
23263Control whether to allow the @code{system} calls in the File I/O
23264protocol for the remote target. The default is zero (disabled).
0ce1b118 23265
9c16f35a 23266@item show remote system-call-allowed
0ce1b118 23267@kindex show remote system-call-allowed
9c16f35a
EZ
23268Show the current setting of system calls for the remote File I/O
23269protocol.
0ce1b118
CV
23270@end table
23271
23272@node List of supported calls
23273@subsection List of supported calls
23274@cindex list of supported file-i/o calls
23275
23276@menu
23277* open::
23278* close::
23279* read::
23280* write::
23281* lseek::
23282* rename::
23283* unlink::
23284* stat/fstat::
23285* gettimeofday::
23286* isatty::
23287* system::
23288@end menu
23289
23290@node open
23291@unnumberedsubsubsec open
23292@cindex open, file-i/o system call
23293
23294@smallexample
23295@exdent Synopsis:
23296int open(const char *pathname, int flags);
23297int open(const char *pathname, int flags, mode_t mode);
23298
b383017d 23299@exdent Request:
0ce1b118
CV
23300Fopen,pathptr/len,flags,mode
23301@end smallexample
23302
23303@noindent
23304@code{flags} is the bitwise or of the following values:
23305
23306@table @code
b383017d 23307@item O_CREAT
0ce1b118
CV
23308If the file does not exist it will be created. The host
23309rules apply as far as file ownership and time stamps
23310are concerned.
23311
b383017d 23312@item O_EXCL
0ce1b118
CV
23313When used with O_CREAT, if the file already exists it is
23314an error and open() fails.
23315
b383017d 23316@item O_TRUNC
0ce1b118
CV
23317If the file already exists and the open mode allows
23318writing (O_RDWR or O_WRONLY is given) it will be
23319truncated to length 0.
23320
b383017d 23321@item O_APPEND
0ce1b118
CV
23322The file is opened in append mode.
23323
b383017d 23324@item O_RDONLY
0ce1b118
CV
23325The file is opened for reading only.
23326
b383017d 23327@item O_WRONLY
0ce1b118
CV
23328The file is opened for writing only.
23329
b383017d 23330@item O_RDWR
0ce1b118
CV
23331The file is opened for reading and writing.
23332
23333@noindent
23334Each other bit is silently ignored.
23335
23336@end table
23337
23338@noindent
23339@code{mode} is the bitwise or of the following values:
23340
23341@table @code
b383017d 23342@item S_IRUSR
0ce1b118
CV
23343User has read permission.
23344
b383017d 23345@item S_IWUSR
0ce1b118
CV
23346User has write permission.
23347
b383017d 23348@item S_IRGRP
0ce1b118
CV
23349Group has read permission.
23350
b383017d 23351@item S_IWGRP
0ce1b118
CV
23352Group has write permission.
23353
b383017d 23354@item S_IROTH
0ce1b118
CV
23355Others have read permission.
23356
b383017d 23357@item S_IWOTH
0ce1b118
CV
23358Others have write permission.
23359
23360@noindent
23361Each other bit is silently ignored.
23362
23363@end table
23364
23365@smallexample
23366@exdent Return value:
23367open returns the new file descriptor or -1 if an error
23368occured.
23369
23370@exdent Errors:
23371@end smallexample
23372
23373@table @code
b383017d 23374@item EEXIST
0ce1b118
CV
23375pathname already exists and O_CREAT and O_EXCL were used.
23376
b383017d 23377@item EISDIR
0ce1b118
CV
23378pathname refers to a directory.
23379
b383017d 23380@item EACCES
0ce1b118
CV
23381The requested access is not allowed.
23382
23383@item ENAMETOOLONG
23384pathname was too long.
23385
b383017d 23386@item ENOENT
0ce1b118
CV
23387A directory component in pathname does not exist.
23388
b383017d 23389@item ENODEV
0ce1b118
CV
23390pathname refers to a device, pipe, named pipe or socket.
23391
b383017d 23392@item EROFS
0ce1b118
CV
23393pathname refers to a file on a read-only filesystem and
23394write access was requested.
23395
b383017d 23396@item EFAULT
0ce1b118
CV
23397pathname is an invalid pointer value.
23398
b383017d 23399@item ENOSPC
0ce1b118
CV
23400No space on device to create the file.
23401
b383017d 23402@item EMFILE
0ce1b118
CV
23403The process already has the maximum number of files open.
23404
b383017d 23405@item ENFILE
0ce1b118
CV
23406The limit on the total number of files open on the system
23407has been reached.
23408
b383017d 23409@item EINTR
0ce1b118
CV
23410The call was interrupted by the user.
23411@end table
23412
23413@node close
23414@unnumberedsubsubsec close
23415@cindex close, file-i/o system call
23416
23417@smallexample
b383017d 23418@exdent Synopsis:
0ce1b118
CV
23419int close(int fd);
23420
b383017d 23421@exdent Request:
0ce1b118
CV
23422Fclose,fd
23423
23424@exdent Return value:
23425close returns zero on success, or -1 if an error occurred.
23426
23427@exdent Errors:
23428@end smallexample
23429
23430@table @code
b383017d 23431@item EBADF
0ce1b118
CV
23432fd isn't a valid open file descriptor.
23433
b383017d 23434@item EINTR
0ce1b118
CV
23435The call was interrupted by the user.
23436@end table
23437
23438@node read
23439@unnumberedsubsubsec read
23440@cindex read, file-i/o system call
23441
23442@smallexample
b383017d 23443@exdent Synopsis:
0ce1b118
CV
23444int read(int fd, void *buf, unsigned int count);
23445
b383017d 23446@exdent Request:
0ce1b118
CV
23447Fread,fd,bufptr,count
23448
23449@exdent Return value:
23450On success, the number of bytes read is returned.
23451Zero indicates end of file. If count is zero, read
b383017d 23452returns zero as well. On error, -1 is returned.
0ce1b118
CV
23453
23454@exdent Errors:
23455@end smallexample
23456
23457@table @code
b383017d 23458@item EBADF
0ce1b118
CV
23459fd is not a valid file descriptor or is not open for
23460reading.
23461
b383017d 23462@item EFAULT
0ce1b118
CV
23463buf is an invalid pointer value.
23464
b383017d 23465@item EINTR
0ce1b118
CV
23466The call was interrupted by the user.
23467@end table
23468
23469@node write
23470@unnumberedsubsubsec write
23471@cindex write, file-i/o system call
23472
23473@smallexample
b383017d 23474@exdent Synopsis:
0ce1b118
CV
23475int write(int fd, const void *buf, unsigned int count);
23476
b383017d 23477@exdent Request:
0ce1b118
CV
23478Fwrite,fd,bufptr,count
23479
23480@exdent Return value:
23481On success, the number of bytes written are returned.
23482Zero indicates nothing was written. On error, -1
23483is returned.
23484
23485@exdent Errors:
23486@end smallexample
23487
23488@table @code
b383017d 23489@item EBADF
0ce1b118
CV
23490fd is not a valid file descriptor or is not open for
23491writing.
23492
b383017d 23493@item EFAULT
0ce1b118
CV
23494buf is an invalid pointer value.
23495
b383017d 23496@item EFBIG
0ce1b118
CV
23497An attempt was made to write a file that exceeds the
23498host specific maximum file size allowed.
23499
b383017d 23500@item ENOSPC
0ce1b118
CV
23501No space on device to write the data.
23502
b383017d 23503@item EINTR
0ce1b118
CV
23504The call was interrupted by the user.
23505@end table
23506
23507@node lseek
23508@unnumberedsubsubsec lseek
23509@cindex lseek, file-i/o system call
23510
23511@smallexample
b383017d 23512@exdent Synopsis:
0ce1b118
CV
23513long lseek (int fd, long offset, int flag);
23514
b383017d 23515@exdent Request:
0ce1b118
CV
23516Flseek,fd,offset,flag
23517@end smallexample
23518
23519@code{flag} is one of:
23520
23521@table @code
b383017d 23522@item SEEK_SET
0ce1b118
CV
23523The offset is set to offset bytes.
23524
b383017d 23525@item SEEK_CUR
0ce1b118
CV
23526The offset is set to its current location plus offset
23527bytes.
23528
b383017d 23529@item SEEK_END
0ce1b118
CV
23530The offset is set to the size of the file plus offset
23531bytes.
23532@end table
23533
23534@smallexample
23535@exdent Return value:
23536On success, the resulting unsigned offset in bytes from
23537the beginning of the file is returned. Otherwise, a
23538value of -1 is returned.
23539
23540@exdent Errors:
23541@end smallexample
23542
23543@table @code
b383017d 23544@item EBADF
0ce1b118
CV
23545fd is not a valid open file descriptor.
23546
b383017d 23547@item ESPIPE
0ce1b118
CV
23548fd is associated with the @value{GDBN} console.
23549
b383017d 23550@item EINVAL
0ce1b118
CV
23551flag is not a proper value.
23552
b383017d 23553@item EINTR
0ce1b118
CV
23554The call was interrupted by the user.
23555@end table
23556
23557@node rename
23558@unnumberedsubsubsec rename
23559@cindex rename, file-i/o system call
23560
23561@smallexample
b383017d 23562@exdent Synopsis:
0ce1b118
CV
23563int rename(const char *oldpath, const char *newpath);
23564
b383017d 23565@exdent Request:
0ce1b118
CV
23566Frename,oldpathptr/len,newpathptr/len
23567
23568@exdent Return value:
23569On success, zero is returned. On error, -1 is returned.
23570
23571@exdent Errors:
23572@end smallexample
23573
23574@table @code
b383017d 23575@item EISDIR
0ce1b118
CV
23576newpath is an existing directory, but oldpath is not a
23577directory.
23578
b383017d 23579@item EEXIST
0ce1b118
CV
23580newpath is a non-empty directory.
23581
b383017d 23582@item EBUSY
0ce1b118
CV
23583oldpath or newpath is a directory that is in use by some
23584process.
23585
b383017d 23586@item EINVAL
0ce1b118
CV
23587An attempt was made to make a directory a subdirectory
23588of itself.
23589
b383017d 23590@item ENOTDIR
0ce1b118
CV
23591A component used as a directory in oldpath or new
23592path is not a directory. Or oldpath is a directory
23593and newpath exists but is not a directory.
23594
b383017d 23595@item EFAULT
0ce1b118
CV
23596oldpathptr or newpathptr are invalid pointer values.
23597
b383017d 23598@item EACCES
0ce1b118
CV
23599No access to the file or the path of the file.
23600
23601@item ENAMETOOLONG
b383017d 23602
0ce1b118
CV
23603oldpath or newpath was too long.
23604
b383017d 23605@item ENOENT
0ce1b118
CV
23606A directory component in oldpath or newpath does not exist.
23607
b383017d 23608@item EROFS
0ce1b118
CV
23609The file is on a read-only filesystem.
23610
b383017d 23611@item ENOSPC
0ce1b118
CV
23612The device containing the file has no room for the new
23613directory entry.
23614
b383017d 23615@item EINTR
0ce1b118
CV
23616The call was interrupted by the user.
23617@end table
23618
23619@node unlink
23620@unnumberedsubsubsec unlink
23621@cindex unlink, file-i/o system call
23622
23623@smallexample
b383017d 23624@exdent Synopsis:
0ce1b118
CV
23625int unlink(const char *pathname);
23626
b383017d 23627@exdent Request:
0ce1b118
CV
23628Funlink,pathnameptr/len
23629
23630@exdent Return value:
23631On success, zero is returned. On error, -1 is returned.
23632
23633@exdent Errors:
23634@end smallexample
23635
23636@table @code
b383017d 23637@item EACCES
0ce1b118
CV
23638No access to the file or the path of the file.
23639
b383017d 23640@item EPERM
0ce1b118
CV
23641The system does not allow unlinking of directories.
23642
b383017d 23643@item EBUSY
0ce1b118
CV
23644The file pathname cannot be unlinked because it's
23645being used by another process.
23646
b383017d 23647@item EFAULT
0ce1b118
CV
23648pathnameptr is an invalid pointer value.
23649
23650@item ENAMETOOLONG
23651pathname was too long.
23652
b383017d 23653@item ENOENT
0ce1b118
CV
23654A directory component in pathname does not exist.
23655
b383017d 23656@item ENOTDIR
0ce1b118
CV
23657A component of the path is not a directory.
23658
b383017d 23659@item EROFS
0ce1b118
CV
23660The file is on a read-only filesystem.
23661
b383017d 23662@item EINTR
0ce1b118
CV
23663The call was interrupted by the user.
23664@end table
23665
23666@node stat/fstat
23667@unnumberedsubsubsec stat/fstat
23668@cindex fstat, file-i/o system call
23669@cindex stat, file-i/o system call
23670
23671@smallexample
b383017d 23672@exdent Synopsis:
0ce1b118
CV
23673int stat(const char *pathname, struct stat *buf);
23674int fstat(int fd, struct stat *buf);
23675
b383017d 23676@exdent Request:
0ce1b118
CV
23677Fstat,pathnameptr/len,bufptr
23678Ffstat,fd,bufptr
23679
23680@exdent Return value:
23681On success, zero is returned. On error, -1 is returned.
23682
23683@exdent Errors:
23684@end smallexample
23685
23686@table @code
b383017d 23687@item EBADF
0ce1b118
CV
23688fd is not a valid open file.
23689
b383017d 23690@item ENOENT
0ce1b118
CV
23691A directory component in pathname does not exist or the
23692path is an empty string.
23693
b383017d 23694@item ENOTDIR
0ce1b118
CV
23695A component of the path is not a directory.
23696
b383017d 23697@item EFAULT
0ce1b118
CV
23698pathnameptr is an invalid pointer value.
23699
b383017d 23700@item EACCES
0ce1b118
CV
23701No access to the file or the path of the file.
23702
23703@item ENAMETOOLONG
23704pathname was too long.
23705
b383017d 23706@item EINTR
0ce1b118
CV
23707The call was interrupted by the user.
23708@end table
23709
23710@node gettimeofday
23711@unnumberedsubsubsec gettimeofday
23712@cindex gettimeofday, file-i/o system call
23713
23714@smallexample
b383017d 23715@exdent Synopsis:
0ce1b118
CV
23716int gettimeofday(struct timeval *tv, void *tz);
23717
b383017d 23718@exdent Request:
0ce1b118
CV
23719Fgettimeofday,tvptr,tzptr
23720
23721@exdent Return value:
23722On success, 0 is returned, -1 otherwise.
23723
23724@exdent Errors:
23725@end smallexample
23726
23727@table @code
b383017d 23728@item EINVAL
0ce1b118
CV
23729tz is a non-NULL pointer.
23730
b383017d 23731@item EFAULT
0ce1b118
CV
23732tvptr and/or tzptr is an invalid pointer value.
23733@end table
23734
23735@node isatty
23736@unnumberedsubsubsec isatty
23737@cindex isatty, file-i/o system call
23738
23739@smallexample
b383017d 23740@exdent Synopsis:
0ce1b118
CV
23741int isatty(int fd);
23742
b383017d 23743@exdent Request:
0ce1b118
CV
23744Fisatty,fd
23745
23746@exdent Return value:
23747Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23748
23749@exdent Errors:
23750@end smallexample
23751
23752@table @code
b383017d 23753@item EINTR
0ce1b118
CV
23754The call was interrupted by the user.
23755@end table
23756
23757@node system
23758@unnumberedsubsubsec system
23759@cindex system, file-i/o system call
23760
23761@smallexample
b383017d 23762@exdent Synopsis:
0ce1b118
CV
23763int system(const char *command);
23764
b383017d 23765@exdent Request:
0ce1b118
CV
23766Fsystem,commandptr/len
23767
23768@exdent Return value:
23769The value returned is -1 on error and the return status
23770of the command otherwise. Only the exit status of the
23771command is returned, which is extracted from the hosts
23772system return value by calling WEXITSTATUS(retval).
23773In case /bin/sh could not be executed, 127 is returned.
23774
23775@exdent Errors:
23776@end smallexample
23777
23778@table @code
b383017d 23779@item EINTR
0ce1b118
CV
23780The call was interrupted by the user.
23781@end table
23782
23783@node Protocol specific representation of datatypes
23784@subsection Protocol specific representation of datatypes
23785@cindex protocol specific representation of datatypes, in file-i/o protocol
23786
23787@menu
23788* Integral datatypes::
23789* Pointer values::
23790* struct stat::
23791* struct timeval::
23792@end menu
23793
23794@node Integral datatypes
23795@unnumberedsubsubsec Integral datatypes
23796@cindex integral datatypes, in file-i/o protocol
23797
23798The integral datatypes used in the system calls are
23799
23800@smallexample
23801int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23802@end smallexample
23803
23804@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23805implemented as 32 bit values in this protocol.
23806
b383017d
RM
23807@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23808
0ce1b118
CV
23809@xref{Limits}, for corresponding MIN and MAX values (similar to those
23810in @file{limits.h}) to allow range checking on host and target.
23811
23812@code{time_t} datatypes are defined as seconds since the Epoch.
23813
23814All integral datatypes transferred as part of a memory read or write of a
23815structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23816byte order.
23817
23818@node Pointer values
23819@unnumberedsubsubsec Pointer values
23820@cindex pointer values, in file-i/o protocol
23821
23822Pointers to target data are transmitted as they are. An exception
23823is made for pointers to buffers for which the length isn't
23824transmitted as part of the function call, namely strings. Strings
23825are transmitted as a pointer/length pair, both as hex values, e.g.@:
23826
23827@smallexample
23828@code{1aaf/12}
23829@end smallexample
23830
23831@noindent
23832which is a pointer to data of length 18 bytes at position 0x1aaf.
23833The length is defined as the full string length in bytes, including
23834the trailing null byte. Example:
23835
23836@smallexample
23837``hello, world'' at address 0x123456
23838@end smallexample
23839
23840@noindent
23841is transmitted as
23842
23843@smallexample
23844@code{123456/d}
23845@end smallexample
23846
23847@node struct stat
23848@unnumberedsubsubsec struct stat
23849@cindex struct stat, in file-i/o protocol
23850
23851The buffer of type struct stat used by the target and @value{GDBN} is defined
23852as follows:
23853
23854@smallexample
23855struct stat @{
23856 unsigned int st_dev; /* device */
23857 unsigned int st_ino; /* inode */
23858 mode_t st_mode; /* protection */
23859 unsigned int st_nlink; /* number of hard links */
23860 unsigned int st_uid; /* user ID of owner */
23861 unsigned int st_gid; /* group ID of owner */
23862 unsigned int st_rdev; /* device type (if inode device) */
23863 unsigned long st_size; /* total size, in bytes */
23864 unsigned long st_blksize; /* blocksize for filesystem I/O */
23865 unsigned long st_blocks; /* number of blocks allocated */
23866 time_t st_atime; /* time of last access */
23867 time_t st_mtime; /* time of last modification */
23868 time_t st_ctime; /* time of last change */
23869@};
23870@end smallexample
23871
23872The integral datatypes are conforming to the definitions given in the
23873approriate section (see @ref{Integral datatypes}, for details) so this
23874structure is of size 64 bytes.
23875
23876The values of several fields have a restricted meaning and/or
23877range of values.
23878
23879@smallexample
23880st_dev: 0 file
23881 1 console
23882
23883st_ino: No valid meaning for the target. Transmitted unchanged.
23884
23885st_mode: Valid mode bits are described in Appendix C. Any other
23886 bits have currently no meaning for the target.
23887
23888st_uid: No valid meaning for the target. Transmitted unchanged.
23889
23890st_gid: No valid meaning for the target. Transmitted unchanged.
23891
23892st_rdev: No valid meaning for the target. Transmitted unchanged.
23893
23894st_atime, st_mtime, st_ctime:
23895 These values have a host and file system dependent
23896 accuracy. Especially on Windows hosts the file systems
23897 don't support exact timing values.
23898@end smallexample
23899
23900The target gets a struct stat of the above representation and is
23901responsible to coerce it to the target representation before
23902continuing.
23903
23904Note that due to size differences between the host and target
23905representation of stat members, these members could eventually
23906get truncated on the target.
23907
23908@node struct timeval
23909@unnumberedsubsubsec struct timeval
23910@cindex struct timeval, in file-i/o protocol
23911
23912The buffer of type struct timeval used by the target and @value{GDBN}
23913is defined as follows:
23914
23915@smallexample
b383017d 23916struct timeval @{
0ce1b118
CV
23917 time_t tv_sec; /* second */
23918 long tv_usec; /* microsecond */
23919@};
23920@end smallexample
23921
23922The integral datatypes are conforming to the definitions given in the
23923approriate section (see @ref{Integral datatypes}, for details) so this
23924structure is of size 8 bytes.
23925
23926@node Constants
23927@subsection Constants
23928@cindex constants, in file-i/o protocol
23929
23930The following values are used for the constants inside of the
23931protocol. @value{GDBN} and target are resposible to translate these
23932values before and after the call as needed.
23933
23934@menu
23935* Open flags::
23936* mode_t values::
23937* Errno values::
23938* Lseek flags::
23939* Limits::
23940@end menu
23941
23942@node Open flags
23943@unnumberedsubsubsec Open flags
23944@cindex open flags, in file-i/o protocol
23945
23946All values are given in hexadecimal representation.
23947
23948@smallexample
23949 O_RDONLY 0x0
23950 O_WRONLY 0x1
23951 O_RDWR 0x2
23952 O_APPEND 0x8
23953 O_CREAT 0x200
23954 O_TRUNC 0x400
23955 O_EXCL 0x800
23956@end smallexample
23957
23958@node mode_t values
23959@unnumberedsubsubsec mode_t values
23960@cindex mode_t values, in file-i/o protocol
23961
23962All values are given in octal representation.
23963
23964@smallexample
23965 S_IFREG 0100000
23966 S_IFDIR 040000
23967 S_IRUSR 0400
23968 S_IWUSR 0200
23969 S_IXUSR 0100
23970 S_IRGRP 040
23971 S_IWGRP 020
23972 S_IXGRP 010
23973 S_IROTH 04
23974 S_IWOTH 02
23975 S_IXOTH 01
23976@end smallexample
23977
23978@node Errno values
23979@unnumberedsubsubsec Errno values
23980@cindex errno values, in file-i/o protocol
23981
23982All values are given in decimal representation.
23983
23984@smallexample
23985 EPERM 1
23986 ENOENT 2
23987 EINTR 4
23988 EBADF 9
23989 EACCES 13
23990 EFAULT 14
23991 EBUSY 16
23992 EEXIST 17
23993 ENODEV 19
23994 ENOTDIR 20
23995 EISDIR 21
23996 EINVAL 22
23997 ENFILE 23
23998 EMFILE 24
23999 EFBIG 27
24000 ENOSPC 28
24001 ESPIPE 29
24002 EROFS 30
24003 ENAMETOOLONG 91
24004 EUNKNOWN 9999
24005@end smallexample
24006
24007 EUNKNOWN is used as a fallback error value if a host system returns
24008 any error value not in the list of supported error numbers.
24009
24010@node Lseek flags
24011@unnumberedsubsubsec Lseek flags
24012@cindex lseek flags, in file-i/o protocol
24013
24014@smallexample
24015 SEEK_SET 0
24016 SEEK_CUR 1
24017 SEEK_END 2
24018@end smallexample
24019
24020@node Limits
24021@unnumberedsubsubsec Limits
24022@cindex limits, in file-i/o protocol
24023
24024All values are given in decimal representation.
24025
24026@smallexample
24027 INT_MIN -2147483648
24028 INT_MAX 2147483647
24029 UINT_MAX 4294967295
24030 LONG_MIN -9223372036854775808
24031 LONG_MAX 9223372036854775807
24032 ULONG_MAX 18446744073709551615
24033@end smallexample
24034
24035@node File-I/O Examples
24036@subsection File-I/O Examples
24037@cindex file-i/o examples
24038
24039Example sequence of a write call, file descriptor 3, buffer is at target
24040address 0x1234, 6 bytes should be written:
24041
24042@smallexample
24043<- @code{Fwrite,3,1234,6}
24044@emph{request memory read from target}
24045-> @code{m1234,6}
24046<- XXXXXX
24047@emph{return "6 bytes written"}
24048-> @code{F6}
24049@end smallexample
24050
24051Example sequence of a read call, file descriptor 3, buffer is at target
24052address 0x1234, 6 bytes should be read:
24053
24054@smallexample
24055<- @code{Fread,3,1234,6}
24056@emph{request memory write to target}
24057-> @code{X1234,6:XXXXXX}
24058@emph{return "6 bytes read"}
24059-> @code{F6}
24060@end smallexample
24061
24062Example sequence of a read call, call fails on the host due to invalid
24063file descriptor (EBADF):
24064
24065@smallexample
24066<- @code{Fread,3,1234,6}
24067-> @code{F-1,9}
24068@end smallexample
24069
24070Example sequence of a read call, user presses Ctrl-C before syscall on
24071host is called:
24072
24073@smallexample
24074<- @code{Fread,3,1234,6}
24075-> @code{F-1,4,C}
24076<- @code{T02}
24077@end smallexample
24078
24079Example sequence of a read call, user presses Ctrl-C after syscall on
24080host is called:
24081
24082@smallexample
24083<- @code{Fread,3,1234,6}
24084-> @code{X1234,6:XXXXXX}
24085<- @code{T02}
24086@end smallexample
24087
f418dd93
DJ
24088@include agentexpr.texi
24089
aab4e0ec 24090@include gpl.texi
eb12ee30 24091
2154891a 24092@raisesections
6826cf00 24093@include fdl.texi
2154891a 24094@lowersections
6826cf00 24095
6d2ebf8b 24096@node Index
c906108c
SS
24097@unnumbered Index
24098
24099@printindex cp
24100
24101@tex
24102% I think something like @colophon should be in texinfo. In the
24103% meantime:
24104\long\def\colophon{\hbox to0pt{}\vfill
24105\centerline{The body of this manual is set in}
24106\centerline{\fontname\tenrm,}
24107\centerline{with headings in {\bf\fontname\tenbf}}
24108\centerline{and examples in {\tt\fontname\tentt}.}
24109\centerline{{\it\fontname\tenit\/},}
24110\centerline{{\bf\fontname\tenbf}, and}
24111\centerline{{\sl\fontname\tensl\/}}
24112\centerline{are used for emphasis.}\vfill}
24113\page\colophon
24114% Blame: doc@cygnus.com, 1991.
24115@end tex
24116
c906108c 24117@bye
This page took 1.847667 seconds and 4 git commands to generate.