(Breakpoints): Fix a typo.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
c02a867d 2@c Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
b620eb07 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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,@*
b620eb07 55 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006@*
7d51c7de 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,
b620eb07 881996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
7d51c7de 89Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c 91Published by the Free Software Foundation @*
c02a867d
EZ
9251 Franklin Street, Fifth Floor,
93Boston, MA 02110-1301, 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
b620eb07 120Copyright (C) 1988-2006 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:
7ba3cf9c 352Andrew Cagney (releases 6.3, 6.2, 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
a9967aef
AC
480Andrew Cagney designed @value{GDBN}'s architecture vector. Many
481people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
482Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
483Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
484Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
485with the migration of old architectures to this new framework.
486
c5e30d01
AC
487Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
488unwinder framework, this consisting of a fresh new design featuring
489frame IDs, independent frame sniffers, and the sentinel frame. Mark
490Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
491libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
492trad unwinders. The architecture specific changes, each involving a
493complete rewrite of the architecture's frame code, were carried out by
494Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
495Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
496Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
497Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
498Weigand.
499
6d2ebf8b 500@node Sample Session
c906108c
SS
501@chapter A Sample @value{GDBN} Session
502
503You can use this manual at your leisure to read all about @value{GDBN}.
504However, a handful of commands are enough to get started using the
505debugger. This chapter illustrates those commands.
506
507@iftex
508In this sample session, we emphasize user input like this: @b{input},
509to make it easier to pick out from the surrounding output.
510@end iftex
511
512@c FIXME: this example may not be appropriate for some configs, where
513@c FIXME...primary interest is in remote use.
514
515One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
516processor) exhibits the following bug: sometimes, when we change its
517quote strings from the default, the commands used to capture one macro
518definition within another stop working. In the following short @code{m4}
519session, we define a macro @code{foo} which expands to @code{0000}; we
520then use the @code{m4} built-in @code{defn} to define @code{bar} as the
521same thing. However, when we change the open quote string to
522@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
523procedure fails to define a new synonym @code{baz}:
524
525@smallexample
526$ @b{cd gnu/m4}
527$ @b{./m4}
528@b{define(foo,0000)}
529
530@b{foo}
5310000
532@b{define(bar,defn(`foo'))}
533
534@b{bar}
5350000
536@b{changequote(<QUOTE>,<UNQUOTE>)}
537
538@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
539@b{baz}
c8aa23ab 540@b{Ctrl-d}
c906108c
SS
541m4: End of input: 0: fatal error: EOF in string
542@end smallexample
543
544@noindent
545Let us use @value{GDBN} to try to see what is going on.
546
c906108c
SS
547@smallexample
548$ @b{@value{GDBP} m4}
549@c FIXME: this falsifies the exact text played out, to permit smallbook
550@c FIXME... format to come out better.
551@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 552 of it under certain conditions; type "show copying" to see
c906108c 553 the conditions.
5d161b24 554There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
555 for details.
556
557@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
558(@value{GDBP})
559@end smallexample
c906108c
SS
560
561@noindent
562@value{GDBN} reads only enough symbol data to know where to find the
563rest when needed; as a result, the first prompt comes up very quickly.
564We now tell @value{GDBN} to use a narrower display width than usual, so
565that examples fit in this manual.
566
567@smallexample
568(@value{GDBP}) @b{set width 70}
569@end smallexample
570
571@noindent
572We need to see how the @code{m4} built-in @code{changequote} works.
573Having looked at the source, we know the relevant subroutine is
574@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
575@code{break} command.
576
577@smallexample
578(@value{GDBP}) @b{break m4_changequote}
579Breakpoint 1 at 0x62f4: file builtin.c, line 879.
580@end smallexample
581
582@noindent
583Using the @code{run} command, we start @code{m4} running under @value{GDBN}
584control; as long as control does not reach the @code{m4_changequote}
585subroutine, the program runs as usual:
586
587@smallexample
588(@value{GDBP}) @b{run}
589Starting program: /work/Editorial/gdb/gnu/m4/m4
590@b{define(foo,0000)}
591
592@b{foo}
5930000
594@end smallexample
595
596@noindent
597To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
598suspends execution of @code{m4}, displaying information about the
599context where it stops.
600
601@smallexample
602@b{changequote(<QUOTE>,<UNQUOTE>)}
603
5d161b24 604Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
605 at builtin.c:879
606879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
607@end smallexample
608
609@noindent
610Now we use the command @code{n} (@code{next}) to advance execution to
611the next line of the current function.
612
613@smallexample
614(@value{GDBP}) @b{n}
615882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
616 : nil,
617@end smallexample
618
619@noindent
620@code{set_quotes} looks like a promising subroutine. We can go into it
621by using the command @code{s} (@code{step}) instead of @code{next}.
622@code{step} goes to the next line to be executed in @emph{any}
623subroutine, so it steps into @code{set_quotes}.
624
625@smallexample
626(@value{GDBP}) @b{s}
627set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
628 at input.c:530
629530 if (lquote != def_lquote)
630@end smallexample
631
632@noindent
633The display that shows the subroutine where @code{m4} is now
634suspended (and its arguments) is called a stack frame display. It
635shows a summary of the stack. We can use the @code{backtrace}
636command (which can also be spelled @code{bt}), to see where we are
637in the stack as a whole: the @code{backtrace} command displays a
638stack frame for each active subroutine.
639
640@smallexample
641(@value{GDBP}) @b{bt}
642#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
643 at input.c:530
5d161b24 644#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
645 at builtin.c:882
646#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
647#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
648 at macro.c:71
649#4 0x79dc in expand_input () at macro.c:40
650#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
651@end smallexample
652
653@noindent
654We step through a few more lines to see what happens. The first two
655times, we can use @samp{s}; the next two times we use @code{n} to avoid
656falling into the @code{xstrdup} subroutine.
657
658@smallexample
659(@value{GDBP}) @b{s}
6600x3b5c 532 if (rquote != def_rquote)
661(@value{GDBP}) @b{s}
6620x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
663def_lquote : xstrdup(lq);
664(@value{GDBP}) @b{n}
665536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
666 : xstrdup(rq);
667(@value{GDBP}) @b{n}
668538 len_lquote = strlen(rquote);
669@end smallexample
670
671@noindent
672The last line displayed looks a little odd; we can examine the variables
673@code{lquote} and @code{rquote} to see if they are in fact the new left
674and right quotes we specified. We use the command @code{p}
675(@code{print}) to see their values.
676
677@smallexample
678(@value{GDBP}) @b{p lquote}
679$1 = 0x35d40 "<QUOTE>"
680(@value{GDBP}) @b{p rquote}
681$2 = 0x35d50 "<UNQUOTE>"
682@end smallexample
683
684@noindent
685@code{lquote} and @code{rquote} are indeed the new left and right quotes.
686To look at some context, we can display ten lines of source
687surrounding the current line with the @code{l} (@code{list}) command.
688
689@smallexample
690(@value{GDBP}) @b{l}
691533 xfree(rquote);
692534
693535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
694 : xstrdup (lq);
695536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
696 : xstrdup (rq);
697537
698538 len_lquote = strlen(rquote);
699539 len_rquote = strlen(lquote);
700540 @}
701541
702542 void
703@end smallexample
704
705@noindent
706Let us step past the two lines that set @code{len_lquote} and
707@code{len_rquote}, and then examine the values of those variables.
708
709@smallexample
710(@value{GDBP}) @b{n}
711539 len_rquote = strlen(lquote);
712(@value{GDBP}) @b{n}
713540 @}
714(@value{GDBP}) @b{p len_lquote}
715$3 = 9
716(@value{GDBP}) @b{p len_rquote}
717$4 = 7
718@end smallexample
719
720@noindent
721That certainly looks wrong, assuming @code{len_lquote} and
722@code{len_rquote} are meant to be the lengths of @code{lquote} and
723@code{rquote} respectively. We can set them to better values using
724the @code{p} command, since it can print the value of
725any expression---and that expression can include subroutine calls and
726assignments.
727
728@smallexample
729(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
730$5 = 7
731(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
732$6 = 9
733@end smallexample
734
735@noindent
736Is that enough to fix the problem of using the new quotes with the
737@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
738executing with the @code{c} (@code{continue}) command, and then try the
739example that caused trouble initially:
740
741@smallexample
742(@value{GDBP}) @b{c}
743Continuing.
744
745@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
746
747baz
7480000
749@end smallexample
750
751@noindent
752Success! The new quotes now work just as well as the default ones. The
753problem seems to have been just the two typos defining the wrong
754lengths. We allow @code{m4} exit by giving it an EOF as input:
755
756@smallexample
c8aa23ab 757@b{Ctrl-d}
c906108c
SS
758Program exited normally.
759@end smallexample
760
761@noindent
762The message @samp{Program exited normally.} is from @value{GDBN}; it
763indicates @code{m4} has finished executing. We can end our @value{GDBN}
764session with the @value{GDBN} @code{quit} command.
765
766@smallexample
767(@value{GDBP}) @b{quit}
768@end smallexample
c906108c 769
6d2ebf8b 770@node Invocation
c906108c
SS
771@chapter Getting In and Out of @value{GDBN}
772
773This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 774The essentials are:
c906108c 775@itemize @bullet
5d161b24 776@item
53a5351d 777type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 778@item
c8aa23ab 779type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
780@end itemize
781
782@menu
783* Invoking GDB:: How to start @value{GDBN}
784* Quitting GDB:: How to quit @value{GDBN}
785* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 786* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
787@end menu
788
6d2ebf8b 789@node Invoking GDB
c906108c
SS
790@section Invoking @value{GDBN}
791
c906108c
SS
792Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
793@value{GDBN} reads commands from the terminal until you tell it to exit.
794
795You can also run @code{@value{GDBP}} with a variety of arguments and options,
796to specify more of your debugging environment at the outset.
797
c906108c
SS
798The command-line options described here are designed
799to cover a variety of situations; in some environments, some of these
5d161b24 800options may effectively be unavailable.
c906108c
SS
801
802The most usual way to start @value{GDBN} is with one argument,
803specifying an executable program:
804
474c8240 805@smallexample
c906108c 806@value{GDBP} @var{program}
474c8240 807@end smallexample
c906108c 808
c906108c
SS
809@noindent
810You can also start with both an executable program and a core file
811specified:
812
474c8240 813@smallexample
c906108c 814@value{GDBP} @var{program} @var{core}
474c8240 815@end smallexample
c906108c
SS
816
817You can, instead, specify a process ID as a second argument, if you want
818to debug a running process:
819
474c8240 820@smallexample
c906108c 821@value{GDBP} @var{program} 1234
474c8240 822@end smallexample
c906108c
SS
823
824@noindent
825would attach @value{GDBN} to process @code{1234} (unless you also have a file
826named @file{1234}; @value{GDBN} does check for a core file first).
827
c906108c 828Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
829complete operating system; when you use @value{GDBN} as a remote
830debugger attached to a bare board, there may not be any notion of
831``process'', and there is often no way to get a core dump. @value{GDBN}
832will warn you if it is unable to attach or to read core dumps.
c906108c 833
aa26fa3a
TT
834You can optionally have @code{@value{GDBP}} pass any arguments after the
835executable file to the inferior using @code{--args}. This option stops
836option processing.
474c8240 837@smallexample
aa26fa3a 838gdb --args gcc -O2 -c foo.c
474c8240 839@end smallexample
aa26fa3a
TT
840This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
841@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
842
96a2c332 843You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
844@value{GDBN}'s non-warranty, by specifying @code{-silent}:
845
846@smallexample
847@value{GDBP} -silent
848@end smallexample
849
850@noindent
851You can further control how @value{GDBN} starts up by using command-line
852options. @value{GDBN} itself can remind you of the options available.
853
854@noindent
855Type
856
474c8240 857@smallexample
c906108c 858@value{GDBP} -help
474c8240 859@end smallexample
c906108c
SS
860
861@noindent
862to display all available options and briefly describe their use
863(@samp{@value{GDBP} -h} is a shorter equivalent).
864
865All options and command line arguments you give are processed
866in sequential order. The order makes a difference when the
867@samp{-x} option is used.
868
869
870@menu
c906108c
SS
871* File Options:: Choosing files
872* Mode Options:: Choosing modes
6fc08d32 873* Startup:: What @value{GDBN} does during startup
c906108c
SS
874@end menu
875
6d2ebf8b 876@node File Options
c906108c
SS
877@subsection Choosing files
878
2df3850c 879When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
880specifying an executable file and core file (or process ID). This is
881the same as if the arguments were specified by the @samp{-se} and
19837790
MS
882@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
883first argument that does not have an associated option flag as
884equivalent to the @samp{-se} option followed by that argument; and the
885second argument that does not have an associated option flag, if any, as
886equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
887If the second argument begins with a decimal digit, @value{GDBN} will
888first attempt to attach to it as a process, and if that fails, attempt
889to open it as a corefile. If you have a corefile whose name begins with
b383017d 890a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 891prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
892
893If @value{GDBN} has not been configured to included core file support,
894such as for most embedded targets, then it will complain about a second
895argument and ignore it.
c906108c
SS
896
897Many options have both long and short forms; both are shown in the
898following list. @value{GDBN} also recognizes the long forms if you truncate
899them, so long as enough of the option is present to be unambiguous.
900(If you prefer, you can flag option arguments with @samp{--} rather
901than @samp{-}, though we illustrate the more usual convention.)
902
d700128c
EZ
903@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
904@c way, both those who look for -foo and --foo in the index, will find
905@c it.
906
c906108c
SS
907@table @code
908@item -symbols @var{file}
909@itemx -s @var{file}
d700128c
EZ
910@cindex @code{--symbols}
911@cindex @code{-s}
c906108c
SS
912Read symbol table from file @var{file}.
913
914@item -exec @var{file}
915@itemx -e @var{file}
d700128c
EZ
916@cindex @code{--exec}
917@cindex @code{-e}
7a292a7a
SS
918Use file @var{file} as the executable file to execute when appropriate,
919and for examining pure data in conjunction with a core dump.
c906108c
SS
920
921@item -se @var{file}
d700128c 922@cindex @code{--se}
c906108c
SS
923Read symbol table from file @var{file} and use it as the executable
924file.
925
c906108c
SS
926@item -core @var{file}
927@itemx -c @var{file}
d700128c
EZ
928@cindex @code{--core}
929@cindex @code{-c}
b383017d 930Use file @var{file} as a core dump to examine.
c906108c
SS
931
932@item -c @var{number}
19837790
MS
933@item -pid @var{number}
934@itemx -p @var{number}
935@cindex @code{--pid}
936@cindex @code{-p}
937Connect to process ID @var{number}, as with the @code{attach} command.
938If there is no such process, @value{GDBN} will attempt to open a core
939file named @var{number}.
c906108c
SS
940
941@item -command @var{file}
942@itemx -x @var{file}
d700128c
EZ
943@cindex @code{--command}
944@cindex @code{-x}
c906108c
SS
945Execute @value{GDBN} commands from file @var{file}. @xref{Command
946Files,, Command files}.
947
8a5a3c82
AS
948@item -eval-command @var{command}
949@itemx -ex @var{command}
950@cindex @code{--eval-command}
951@cindex @code{-ex}
952Execute a single @value{GDBN} command.
953
954This option may be used multiple times to call multiple commands. It may
955also be interleaved with @samp{-command} as required.
956
957@smallexample
958@value{GDBP} -ex 'target sim' -ex 'load' \
959 -x setbreakpoints -ex 'run' a.out
960@end smallexample
961
c906108c
SS
962@item -directory @var{directory}
963@itemx -d @var{directory}
d700128c
EZ
964@cindex @code{--directory}
965@cindex @code{-d}
4b505b12 966Add @var{directory} to the path to search for source and script files.
c906108c 967
c906108c
SS
968@item -r
969@itemx -readnow
d700128c
EZ
970@cindex @code{--readnow}
971@cindex @code{-r}
c906108c
SS
972Read each symbol file's entire symbol table immediately, rather than
973the default, which is to read it incrementally as it is needed.
974This makes startup slower, but makes future operations faster.
53a5351d 975
c906108c
SS
976@end table
977
6d2ebf8b 978@node Mode Options
c906108c
SS
979@subsection Choosing modes
980
981You can run @value{GDBN} in various alternative modes---for example, in
982batch mode or quiet mode.
983
984@table @code
985@item -nx
986@itemx -n
d700128c
EZ
987@cindex @code{--nx}
988@cindex @code{-n}
96565e91 989Do not execute commands found in any initialization files. Normally,
2df3850c
JM
990@value{GDBN} executes the commands in these files after all the command
991options and arguments have been processed. @xref{Command Files,,Command
992files}.
c906108c
SS
993
994@item -quiet
d700128c 995@itemx -silent
c906108c 996@itemx -q
d700128c
EZ
997@cindex @code{--quiet}
998@cindex @code{--silent}
999@cindex @code{-q}
c906108c
SS
1000``Quiet''. Do not print the introductory and copyright messages. These
1001messages are also suppressed in batch mode.
1002
1003@item -batch
d700128c 1004@cindex @code{--batch}
c906108c
SS
1005Run in batch mode. Exit with status @code{0} after processing all the
1006command files specified with @samp{-x} (and all commands from
1007initialization files, if not inhibited with @samp{-n}). Exit with
1008nonzero status if an error occurs in executing the @value{GDBN} commands
1009in the command files.
1010
2df3850c
JM
1011Batch mode may be useful for running @value{GDBN} as a filter, for
1012example to download and run a program on another computer; in order to
1013make this more useful, the message
c906108c 1014
474c8240 1015@smallexample
c906108c 1016Program exited normally.
474c8240 1017@end smallexample
c906108c
SS
1018
1019@noindent
2df3850c
JM
1020(which is ordinarily issued whenever a program running under
1021@value{GDBN} control terminates) is not issued when running in batch
1022mode.
1023
1a088d06
AS
1024@item -batch-silent
1025@cindex @code{--batch-silent}
1026Run in batch mode exactly like @samp{-batch}, but totally silently. All
1027@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1028unaffected). This is much quieter than @samp{-silent} and would be useless
1029for an interactive session.
1030
1031This is particularly useful when using targets that give @samp{Loading section}
1032messages, for example.
1033
1034Note that targets that give their output via @value{GDBN}, as opposed to
1035writing directly to @code{stdout}, will also be made silent.
1036
4b0ad762
AS
1037@item -return-child-result
1038@cindex @code{--return-child-result}
1039The return code from @value{GDBN} will be the return code from the child
1040process (the process being debugged), with the following exceptions:
1041
1042@itemize @bullet
1043@item
1044@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1045internal error. In this case the exit code is the same as it would have been
1046without @samp{-return-child-result}.
1047@item
1048The user quits with an explicit value. E.g., @samp{quit 1}.
1049@item
1050The child process never runs, or is not allowed to terminate, in which case
1051the exit code will be -1.
1052@end itemize
1053
1054This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1055when @value{GDBN} is being used as a remote program loader or simulator
1056interface.
1057
2df3850c
JM
1058@item -nowindows
1059@itemx -nw
d700128c
EZ
1060@cindex @code{--nowindows}
1061@cindex @code{-nw}
2df3850c 1062``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1063(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1064interface. If no GUI is available, this option has no effect.
1065
1066@item -windows
1067@itemx -w
d700128c
EZ
1068@cindex @code{--windows}
1069@cindex @code{-w}
2df3850c
JM
1070If @value{GDBN} includes a GUI, then this option requires it to be
1071used if possible.
c906108c
SS
1072
1073@item -cd @var{directory}
d700128c 1074@cindex @code{--cd}
c906108c
SS
1075Run @value{GDBN} using @var{directory} as its working directory,
1076instead of the current directory.
1077
c906108c
SS
1078@item -fullname
1079@itemx -f
d700128c
EZ
1080@cindex @code{--fullname}
1081@cindex @code{-f}
7a292a7a
SS
1082@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1083subprocess. It tells @value{GDBN} to output the full file name and line
1084number in a standard, recognizable fashion each time a stack frame is
1085displayed (which includes each time your program stops). This
1086recognizable format looks like two @samp{\032} characters, followed by
1087the file name, line number and character position separated by colons,
1088and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1089@samp{\032} characters as a signal to display the source code for the
1090frame.
c906108c 1091
d700128c
EZ
1092@item -epoch
1093@cindex @code{--epoch}
1094The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1095@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1096routines so as to allow Epoch to display values of expressions in a
1097separate window.
1098
1099@item -annotate @var{level}
1100@cindex @code{--annotate}
1101This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1102effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1103(@pxref{Annotations}). The annotation @var{level} controls how much
1104information @value{GDBN} prints together with its prompt, values of
1105expressions, source lines, and other types of output. Level 0 is the
1106normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1107@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1108that control @value{GDBN}, and level 2 has been deprecated.
1109
265eeb58 1110The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1111(@pxref{GDB/MI}).
d700128c 1112
aa26fa3a
TT
1113@item --args
1114@cindex @code{--args}
1115Change interpretation of command line so that arguments following the
1116executable file are passed as command line arguments to the inferior.
1117This option stops option processing.
1118
2df3850c
JM
1119@item -baud @var{bps}
1120@itemx -b @var{bps}
d700128c
EZ
1121@cindex @code{--baud}
1122@cindex @code{-b}
c906108c
SS
1123Set the line speed (baud rate or bits per second) of any serial
1124interface used by @value{GDBN} for remote debugging.
c906108c 1125
f47b1503
AS
1126@item -l @var{timeout}
1127@cindex @code{-l}
1128Set the timeout (in seconds) of any communication used by @value{GDBN}
1129for remote debugging.
1130
c906108c 1131@item -tty @var{device}
d700128c
EZ
1132@itemx -t @var{device}
1133@cindex @code{--tty}
1134@cindex @code{-t}
c906108c
SS
1135Run using @var{device} for your program's standard input and output.
1136@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1137
53a5351d 1138@c resolve the situation of these eventually
c4555f82
SC
1139@item -tui
1140@cindex @code{--tui}
d0d5df6f
AC
1141Activate the @dfn{Text User Interface} when starting. The Text User
1142Interface manages several text windows on the terminal, showing
1143source, assembly, registers and @value{GDBN} command outputs
1144(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1145Text User Interface can be enabled by invoking the program
1146@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1147Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1148
1149@c @item -xdb
d700128c 1150@c @cindex @code{--xdb}
53a5351d
JM
1151@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1152@c For information, see the file @file{xdb_trans.html}, which is usually
1153@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1154@c systems.
1155
d700128c
EZ
1156@item -interpreter @var{interp}
1157@cindex @code{--interpreter}
1158Use the interpreter @var{interp} for interface with the controlling
1159program or device. This option is meant to be set by programs which
94bbb2c0 1160communicate with @value{GDBN} using it as a back end.
21c294e6 1161@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1162
da0f9dcd 1163@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1164@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1165The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1166previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1167selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1168@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1169
1170@item -write
1171@cindex @code{--write}
1172Open the executable and core files for both reading and writing. This
1173is equivalent to the @samp{set write on} command inside @value{GDBN}
1174(@pxref{Patching}).
1175
1176@item -statistics
1177@cindex @code{--statistics}
1178This option causes @value{GDBN} to print statistics about time and
1179memory usage after it completes each command and returns to the prompt.
1180
1181@item -version
1182@cindex @code{--version}
1183This option causes @value{GDBN} to print its version number and
1184no-warranty blurb, and exit.
1185
c906108c
SS
1186@end table
1187
6fc08d32
EZ
1188@node Startup
1189@subsection What @value{GDBN} does during startup
1190@cindex @value{GDBN} startup
1191
1192Here's the description of what @value{GDBN} does during session startup:
1193
1194@enumerate
1195@item
1196Sets up the command interpreter as specified by the command line
1197(@pxref{Mode Options, interpreter}).
1198
1199@item
1200@cindex init file
1201Reads the @dfn{init file} (if any) in your home directory@footnote{On
1202DOS/Windows systems, the home directory is the one pointed to by the
1203@code{HOME} environment variable.} and executes all the commands in
1204that file.
1205
1206@item
1207Processes command line options and operands.
1208
1209@item
1210Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1211working directory. This is only done if the current directory is
1212different from your home directory. Thus, you can have more than one
1213init file, one generic in your home directory, and another, specific
1214to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1215@value{GDBN}.
1216
1217@item
1218Reads command files specified by the @samp{-x} option. @xref{Command
1219Files}, for more details about @value{GDBN} command files.
1220
1221@item
1222Reads the command history recorded in the @dfn{history file}.
d620b259 1223@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1224files where @value{GDBN} records it.
1225@end enumerate
1226
1227Init files use the same syntax as @dfn{command files} (@pxref{Command
1228Files}) and are processed by @value{GDBN} in the same way. The init
1229file in your home directory can set options (such as @samp{set
1230complaints}) that affect subsequent processing of command line options
1231and operands. Init files are not executed if you use the @samp{-nx}
1232option (@pxref{Mode Options, ,Choosing modes}).
1233
1234@cindex init file name
1235@cindex @file{.gdbinit}
119b882a 1236The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1237On some configurations of @value{GDBN}, the init file is known by a
1238different name (these are typically environments where a specialized
1239form of @value{GDBN} may need to coexist with other forms, hence a
1240different name for the specialized version's init file). These are the
1241environments with special init file names:
1242
6fc08d32 1243@itemize @bullet
119b882a
EZ
1244@cindex @file{gdb.ini}
1245@item
1246The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1247the limitations of file names imposed by DOS filesystems. The Windows
1248ports of @value{GDBN} use the standard name, but if they find a
1249@file{gdb.ini} file, they warn you about that and suggest to rename
1250the file to the standard name.
1251
1252@cindex @file{.vxgdbinit}
6fc08d32
EZ
1253@item
1254VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1255
1256@cindex @file{.os68gdbinit}
1257@item
1258OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1259
1260@cindex @file{.esgdbinit}
1261@item
1262ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1263
1264@item
1265CISCO 68k: @file{.cisco-gdbinit}
1266@end itemize
1267
1268
6d2ebf8b 1269@node Quitting GDB
c906108c
SS
1270@section Quitting @value{GDBN}
1271@cindex exiting @value{GDBN}
1272@cindex leaving @value{GDBN}
1273
1274@table @code
1275@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1276@kindex q @r{(@code{quit})}
96a2c332
SS
1277@item quit @r{[}@var{expression}@r{]}
1278@itemx q
1279To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1280@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1281do not supply @var{expression}, @value{GDBN} will terminate normally;
1282otherwise it will terminate using the result of @var{expression} as the
1283error code.
c906108c
SS
1284@end table
1285
1286@cindex interrupt
c8aa23ab 1287An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1288terminates the action of any @value{GDBN} command that is in progress and
1289returns to @value{GDBN} command level. It is safe to type the interrupt
1290character at any time because @value{GDBN} does not allow it to take effect
1291until a time when it is safe.
1292
c906108c
SS
1293If you have been using @value{GDBN} to control an attached process or
1294device, you can release it with the @code{detach} command
1295(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1296
6d2ebf8b 1297@node Shell Commands
c906108c
SS
1298@section Shell commands
1299
1300If you need to execute occasional shell commands during your
1301debugging session, there is no need to leave or suspend @value{GDBN}; you can
1302just use the @code{shell} command.
1303
1304@table @code
1305@kindex shell
1306@cindex shell escape
1307@item shell @var{command string}
1308Invoke a standard shell to execute @var{command string}.
c906108c 1309If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1310shell to run. Otherwise @value{GDBN} uses the default shell
1311(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1312@end table
1313
1314The utility @code{make} is often needed in development environments.
1315You do not have to use the @code{shell} command for this purpose in
1316@value{GDBN}:
1317
1318@table @code
1319@kindex make
1320@cindex calling make
1321@item make @var{make-args}
1322Execute the @code{make} program with the specified
1323arguments. This is equivalent to @samp{shell make @var{make-args}}.
1324@end table
1325
0fac0b41
DJ
1326@node Logging output
1327@section Logging output
1328@cindex logging @value{GDBN} output
9c16f35a 1329@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1330
1331You may want to save the output of @value{GDBN} commands to a file.
1332There are several commands to control @value{GDBN}'s logging.
1333
1334@table @code
1335@kindex set logging
1336@item set logging on
1337Enable logging.
1338@item set logging off
1339Disable logging.
9c16f35a 1340@cindex logging file name
0fac0b41
DJ
1341@item set logging file @var{file}
1342Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1343@item set logging overwrite [on|off]
1344By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1345you want @code{set logging on} to overwrite the logfile instead.
1346@item set logging redirect [on|off]
1347By default, @value{GDBN} output will go to both the terminal and the logfile.
1348Set @code{redirect} if you want output to go only to the log file.
1349@kindex show logging
1350@item show logging
1351Show the current values of the logging settings.
1352@end table
1353
6d2ebf8b 1354@node Commands
c906108c
SS
1355@chapter @value{GDBN} Commands
1356
1357You can abbreviate a @value{GDBN} command to the first few letters of the command
1358name, if that abbreviation is unambiguous; and you can repeat certain
1359@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1360key to get @value{GDBN} to fill out the rest of a word in a command (or to
1361show you the alternatives available, if there is more than one possibility).
1362
1363@menu
1364* Command Syntax:: How to give commands to @value{GDBN}
1365* Completion:: Command completion
1366* Help:: How to ask @value{GDBN} for help
1367@end menu
1368
6d2ebf8b 1369@node Command Syntax
c906108c
SS
1370@section Command syntax
1371
1372A @value{GDBN} command is a single line of input. There is no limit on
1373how long it can be. It starts with a command name, which is followed by
1374arguments whose meaning depends on the command name. For example, the
1375command @code{step} accepts an argument which is the number of times to
1376step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1377with no arguments. Some commands do not allow any arguments.
c906108c
SS
1378
1379@cindex abbreviation
1380@value{GDBN} command names may always be truncated if that abbreviation is
1381unambiguous. Other possible command abbreviations are listed in the
1382documentation for individual commands. In some cases, even ambiguous
1383abbreviations are allowed; for example, @code{s} is specially defined as
1384equivalent to @code{step} even though there are other commands whose
1385names start with @code{s}. You can test abbreviations by using them as
1386arguments to the @code{help} command.
1387
1388@cindex repeating commands
41afff9a 1389@kindex RET @r{(repeat last command)}
c906108c 1390A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1391repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1392will not repeat this way; these are commands whose unintentional
1393repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1394repeat. User-defined commands can disable this feature; see
1395@ref{Define, dont-repeat}.
c906108c
SS
1396
1397The @code{list} and @code{x} commands, when you repeat them with
1398@key{RET}, construct new arguments rather than repeating
1399exactly as typed. This permits easy scanning of source or memory.
1400
1401@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1402output, in a way similar to the common utility @code{more}
1403(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1404@key{RET} too many in this situation, @value{GDBN} disables command
1405repetition after any command that generates this sort of display.
1406
41afff9a 1407@kindex # @r{(a comment)}
c906108c
SS
1408@cindex comment
1409Any text from a @kbd{#} to the end of the line is a comment; it does
1410nothing. This is useful mainly in command files (@pxref{Command
1411Files,,Command files}).
1412
88118b3a 1413@cindex repeating command sequences
c8aa23ab
EZ
1414@kindex Ctrl-o @r{(operate-and-get-next)}
1415The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1416commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1417then fetches the next line relative to the current line from the history
1418for editing.
1419
6d2ebf8b 1420@node Completion
c906108c
SS
1421@section Command completion
1422
1423@cindex completion
1424@cindex word completion
1425@value{GDBN} can fill in the rest of a word in a command for you, if there is
1426only one possibility; it can also show you what the valid possibilities
1427are for the next word in a command, at any time. This works for @value{GDBN}
1428commands, @value{GDBN} subcommands, and the names of symbols in your program.
1429
1430Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1431of a word. If there is only one possibility, @value{GDBN} fills in the
1432word, and waits for you to finish the command (or press @key{RET} to
1433enter it). For example, if you type
1434
1435@c FIXME "@key" does not distinguish its argument sufficiently to permit
1436@c complete accuracy in these examples; space introduced for clarity.
1437@c If texinfo enhancements make it unnecessary, it would be nice to
1438@c replace " @key" by "@key" in the following...
474c8240 1439@smallexample
c906108c 1440(@value{GDBP}) info bre @key{TAB}
474c8240 1441@end smallexample
c906108c
SS
1442
1443@noindent
1444@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1445the only @code{info} subcommand beginning with @samp{bre}:
1446
474c8240 1447@smallexample
c906108c 1448(@value{GDBP}) info breakpoints
474c8240 1449@end smallexample
c906108c
SS
1450
1451@noindent
1452You can either press @key{RET} at this point, to run the @code{info
1453breakpoints} command, or backspace and enter something else, if
1454@samp{breakpoints} does not look like the command you expected. (If you
1455were sure you wanted @code{info breakpoints} in the first place, you
1456might as well just type @key{RET} immediately after @samp{info bre},
1457to exploit command abbreviations rather than command completion).
1458
1459If there is more than one possibility for the next word when you press
1460@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1461characters and try again, or just press @key{TAB} a second time;
1462@value{GDBN} displays all the possible completions for that word. For
1463example, you might want to set a breakpoint on a subroutine whose name
1464begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1465just sounds the bell. Typing @key{TAB} again displays all the
1466function names in your program that begin with those characters, for
1467example:
1468
474c8240 1469@smallexample
c906108c
SS
1470(@value{GDBP}) b make_ @key{TAB}
1471@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1472make_a_section_from_file make_environ
1473make_abs_section make_function_type
1474make_blockvector make_pointer_type
1475make_cleanup make_reference_type
c906108c
SS
1476make_command make_symbol_completion_list
1477(@value{GDBP}) b make_
474c8240 1478@end smallexample
c906108c
SS
1479
1480@noindent
1481After displaying the available possibilities, @value{GDBN} copies your
1482partial input (@samp{b make_} in the example) so you can finish the
1483command.
1484
1485If you just want to see the list of alternatives in the first place, you
b37052ae 1486can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1487means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1488key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1489one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1490
1491@cindex quotes in commands
1492@cindex completion of quoted strings
1493Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1494parentheses or other characters that @value{GDBN} normally excludes from
1495its notion of a word. To permit word completion to work in this
1496situation, you may enclose words in @code{'} (single quote marks) in
1497@value{GDBN} commands.
c906108c 1498
c906108c 1499The most likely situation where you might need this is in typing the
b37052ae
EZ
1500name of a C@t{++} function. This is because C@t{++} allows function
1501overloading (multiple definitions of the same function, distinguished
1502by argument type). For example, when you want to set a breakpoint you
1503may need to distinguish whether you mean the version of @code{name}
1504that takes an @code{int} parameter, @code{name(int)}, or the version
1505that takes a @code{float} parameter, @code{name(float)}. To use the
1506word-completion facilities in this situation, type a single quote
1507@code{'} at the beginning of the function name. This alerts
1508@value{GDBN} that it may need to consider more information than usual
1509when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1510
474c8240 1511@smallexample
96a2c332 1512(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1513bubble(double,double) bubble(int,int)
1514(@value{GDBP}) b 'bubble(
474c8240 1515@end smallexample
c906108c
SS
1516
1517In some cases, @value{GDBN} can tell that completing a name requires using
1518quotes. When this happens, @value{GDBN} inserts the quote for you (while
1519completing as much as it can) if you do not type the quote in the first
1520place:
1521
474c8240 1522@smallexample
c906108c
SS
1523(@value{GDBP}) b bub @key{TAB}
1524@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1525(@value{GDBP}) b 'bubble(
474c8240 1526@end smallexample
c906108c
SS
1527
1528@noindent
1529In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1530you have not yet started typing the argument list when you ask for
1531completion on an overloaded symbol.
1532
d4f3574e 1533For more information about overloaded functions, see @ref{C plus plus
b37052ae 1534expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1535overload-resolution off} to disable overload resolution;
b37052ae 1536see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1537
1538
6d2ebf8b 1539@node Help
c906108c
SS
1540@section Getting help
1541@cindex online documentation
1542@kindex help
1543
5d161b24 1544You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1545using the command @code{help}.
1546
1547@table @code
41afff9a 1548@kindex h @r{(@code{help})}
c906108c
SS
1549@item help
1550@itemx h
1551You can use @code{help} (abbreviated @code{h}) with no arguments to
1552display a short list of named classes of commands:
1553
1554@smallexample
1555(@value{GDBP}) help
1556List of classes of commands:
1557
2df3850c 1558aliases -- Aliases of other commands
c906108c 1559breakpoints -- Making program stop at certain points
2df3850c 1560data -- Examining data
c906108c 1561files -- Specifying and examining files
2df3850c
JM
1562internals -- Maintenance commands
1563obscure -- Obscure features
1564running -- Running the program
1565stack -- Examining the stack
c906108c
SS
1566status -- Status inquiries
1567support -- Support facilities
96a2c332
SS
1568tracepoints -- Tracing of program execution without@*
1569 stopping the program
c906108c 1570user-defined -- User-defined commands
c906108c 1571
5d161b24 1572Type "help" followed by a class name for a list of
c906108c 1573commands in that class.
5d161b24 1574Type "help" followed by command name for full
c906108c
SS
1575documentation.
1576Command name abbreviations are allowed if unambiguous.
1577(@value{GDBP})
1578@end smallexample
96a2c332 1579@c the above line break eliminates huge line overfull...
c906108c
SS
1580
1581@item help @var{class}
1582Using one of the general help classes as an argument, you can get a
1583list of the individual commands in that class. For example, here is the
1584help display for the class @code{status}:
1585
1586@smallexample
1587(@value{GDBP}) help status
1588Status inquiries.
1589
1590List of commands:
1591
1592@c Line break in "show" line falsifies real output, but needed
1593@c to fit in smallbook page size.
2df3850c
JM
1594info -- Generic command for showing things
1595 about the program being debugged
1596show -- Generic command for showing things
1597 about the debugger
c906108c 1598
5d161b24 1599Type "help" followed by command name for full
c906108c
SS
1600documentation.
1601Command name abbreviations are allowed if unambiguous.
1602(@value{GDBP})
1603@end smallexample
1604
1605@item help @var{command}
1606With a command name as @code{help} argument, @value{GDBN} displays a
1607short paragraph on how to use that command.
1608
6837a0a2
DB
1609@kindex apropos
1610@item apropos @var{args}
09d4efe1 1611The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1612commands, and their documentation, for the regular expression specified in
1613@var{args}. It prints out all matches found. For example:
1614
1615@smallexample
1616apropos reload
1617@end smallexample
1618
b37052ae
EZ
1619@noindent
1620results in:
6837a0a2
DB
1621
1622@smallexample
6d2ebf8b
SS
1623@c @group
1624set symbol-reloading -- Set dynamic symbol table reloading
1625 multiple times in one run
1626show symbol-reloading -- Show dynamic symbol table reloading
1627 multiple times in one run
1628@c @end group
6837a0a2
DB
1629@end smallexample
1630
c906108c
SS
1631@kindex complete
1632@item complete @var{args}
1633The @code{complete @var{args}} command lists all the possible completions
1634for the beginning of a command. Use @var{args} to specify the beginning of the
1635command you want completed. For example:
1636
1637@smallexample
1638complete i
1639@end smallexample
1640
1641@noindent results in:
1642
1643@smallexample
1644@group
2df3850c
JM
1645if
1646ignore
c906108c
SS
1647info
1648inspect
c906108c
SS
1649@end group
1650@end smallexample
1651
1652@noindent This is intended for use by @sc{gnu} Emacs.
1653@end table
1654
1655In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1656and @code{show} to inquire about the state of your program, or the state
1657of @value{GDBN} itself. Each command supports many topics of inquiry; this
1658manual introduces each of them in the appropriate context. The listings
1659under @code{info} and under @code{show} in the Index point to
1660all the sub-commands. @xref{Index}.
1661
1662@c @group
1663@table @code
1664@kindex info
41afff9a 1665@kindex i @r{(@code{info})}
c906108c
SS
1666@item info
1667This command (abbreviated @code{i}) is for describing the state of your
1668program. For example, you can list the arguments given to your program
1669with @code{info args}, list the registers currently in use with @code{info
1670registers}, or list the breakpoints you have set with @code{info breakpoints}.
1671You can get a complete list of the @code{info} sub-commands with
1672@w{@code{help info}}.
1673
1674@kindex set
1675@item set
5d161b24 1676You can assign the result of an expression to an environment variable with
c906108c
SS
1677@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1678@code{set prompt $}.
1679
1680@kindex show
1681@item show
5d161b24 1682In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1683@value{GDBN} itself.
1684You can change most of the things you can @code{show}, by using the
1685related command @code{set}; for example, you can control what number
1686system is used for displays with @code{set radix}, or simply inquire
1687which is currently in use with @code{show radix}.
1688
1689@kindex info set
1690To display all the settable parameters and their current
1691values, you can use @code{show} with no arguments; you may also use
1692@code{info set}. Both commands produce the same display.
1693@c FIXME: "info set" violates the rule that "info" is for state of
1694@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1695@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1696@end table
1697@c @end group
1698
1699Here are three miscellaneous @code{show} subcommands, all of which are
1700exceptional in lacking corresponding @code{set} commands:
1701
1702@table @code
1703@kindex show version
9c16f35a 1704@cindex @value{GDBN} version number
c906108c
SS
1705@item show version
1706Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1707information in @value{GDBN} bug-reports. If multiple versions of
1708@value{GDBN} are in use at your site, you may need to determine which
1709version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1710commands are introduced, and old ones may wither away. Also, many
1711system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1712variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1713The version number is the same as the one announced when you start
1714@value{GDBN}.
c906108c
SS
1715
1716@kindex show copying
09d4efe1 1717@kindex info copying
9c16f35a 1718@cindex display @value{GDBN} copyright
c906108c 1719@item show copying
09d4efe1 1720@itemx info copying
c906108c
SS
1721Display information about permission for copying @value{GDBN}.
1722
1723@kindex show warranty
09d4efe1 1724@kindex info warranty
c906108c 1725@item show warranty
09d4efe1 1726@itemx info warranty
2df3850c 1727Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1728if your version of @value{GDBN} comes with one.
2df3850c 1729
c906108c
SS
1730@end table
1731
6d2ebf8b 1732@node Running
c906108c
SS
1733@chapter Running Programs Under @value{GDBN}
1734
1735When you run a program under @value{GDBN}, you must first generate
1736debugging information when you compile it.
7a292a7a
SS
1737
1738You may start @value{GDBN} with its arguments, if any, in an environment
1739of your choice. If you are doing native debugging, you may redirect
1740your program's input and output, debug an already running process, or
1741kill a child process.
c906108c
SS
1742
1743@menu
1744* Compilation:: Compiling for debugging
1745* Starting:: Starting your program
c906108c
SS
1746* Arguments:: Your program's arguments
1747* Environment:: Your program's environment
c906108c
SS
1748
1749* Working Directory:: Your program's working directory
1750* Input/Output:: Your program's input and output
1751* Attach:: Debugging an already-running process
1752* Kill Process:: Killing the child process
c906108c
SS
1753
1754* Threads:: Debugging programs with multiple threads
1755* Processes:: Debugging programs with multiple processes
5c95884b 1756* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1757@end menu
1758
6d2ebf8b 1759@node Compilation
c906108c
SS
1760@section Compiling for debugging
1761
1762In order to debug a program effectively, you need to generate
1763debugging information when you compile it. This debugging information
1764is stored in the object file; it describes the data type of each
1765variable or function and the correspondence between source line numbers
1766and addresses in the executable code.
1767
1768To request debugging information, specify the @samp{-g} option when you run
1769the compiler.
1770
514c4d71
EZ
1771Programs that are to be shipped to your customers are compiled with
1772optimizations, using the @samp{-O} compiler option. However, many
1773compilers are unable to handle the @samp{-g} and @samp{-O} options
1774together. Using those compilers, you cannot generate optimized
c906108c
SS
1775executables containing debugging information.
1776
514c4d71 1777@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1778without @samp{-O}, making it possible to debug optimized code. We
1779recommend that you @emph{always} use @samp{-g} whenever you compile a
1780program. You may think your program is correct, but there is no sense
1781in pushing your luck.
c906108c
SS
1782
1783@cindex optimized code, debugging
1784@cindex debugging optimized code
1785When you debug a program compiled with @samp{-g -O}, remember that the
1786optimizer is rearranging your code; the debugger shows you what is
1787really there. Do not be too surprised when the execution path does not
1788exactly match your source file! An extreme example: if you define a
1789variable, but never use it, @value{GDBN} never sees that
1790variable---because the compiler optimizes it out of existence.
1791
1792Some things do not work as well with @samp{-g -O} as with just
1793@samp{-g}, particularly on machines with instruction scheduling. If in
1794doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1795please report it to us as a bug (including a test case!).
15387254 1796@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1797
1798Older versions of the @sc{gnu} C compiler permitted a variant option
1799@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1800format; if your @sc{gnu} C compiler has this option, do not use it.
1801
514c4d71
EZ
1802@value{GDBN} knows about preprocessor macros and can show you their
1803expansion (@pxref{Macros}). Most compilers do not include information
1804about preprocessor macros in the debugging information if you specify
1805the @option{-g} flag alone, because this information is rather large.
1806Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1807provides macro information if you specify the options
1808@option{-gdwarf-2} and @option{-g3}; the former option requests
1809debugging information in the Dwarf 2 format, and the latter requests
1810``extra information''. In the future, we hope to find more compact
1811ways to represent macro information, so that it can be included with
1812@option{-g} alone.
1813
c906108c 1814@need 2000
6d2ebf8b 1815@node Starting
c906108c
SS
1816@section Starting your program
1817@cindex starting
1818@cindex running
1819
1820@table @code
1821@kindex run
41afff9a 1822@kindex r @r{(@code{run})}
c906108c
SS
1823@item run
1824@itemx r
7a292a7a
SS
1825Use the @code{run} command to start your program under @value{GDBN}.
1826You must first specify the program name (except on VxWorks) with an
1827argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1828@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1829(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1830
1831@end table
1832
c906108c
SS
1833If you are running your program in an execution environment that
1834supports processes, @code{run} creates an inferior process and makes
1835that process run your program. (In environments without processes,
1836@code{run} jumps to the start of your program.)
1837
1838The execution of a program is affected by certain information it
1839receives from its superior. @value{GDBN} provides ways to specify this
1840information, which you must do @emph{before} starting your program. (You
1841can change it after starting your program, but such changes only affect
1842your program the next time you start it.) This information may be
1843divided into four categories:
1844
1845@table @asis
1846@item The @emph{arguments.}
1847Specify the arguments to give your program as the arguments of the
1848@code{run} command. If a shell is available on your target, the shell
1849is used to pass the arguments, so that you may use normal conventions
1850(such as wildcard expansion or variable substitution) in describing
1851the arguments.
1852In Unix systems, you can control which shell is used with the
1853@code{SHELL} environment variable.
1854@xref{Arguments, ,Your program's arguments}.
1855
1856@item The @emph{environment.}
1857Your program normally inherits its environment from @value{GDBN}, but you can
1858use the @value{GDBN} commands @code{set environment} and @code{unset
1859environment} to change parts of the environment that affect
1860your program. @xref{Environment, ,Your program's environment}.
1861
1862@item The @emph{working directory.}
1863Your program inherits its working directory from @value{GDBN}. You can set
1864the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1865@xref{Working Directory, ,Your program's working directory}.
1866
1867@item The @emph{standard input and output.}
1868Your program normally uses the same device for standard input and
1869standard output as @value{GDBN} is using. You can redirect input and output
1870in the @code{run} command line, or you can use the @code{tty} command to
1871set a different device for your program.
1872@xref{Input/Output, ,Your program's input and output}.
1873
1874@cindex pipes
1875@emph{Warning:} While input and output redirection work, you cannot use
1876pipes to pass the output of the program you are debugging to another
1877program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1878wrong program.
1879@end table
c906108c
SS
1880
1881When you issue the @code{run} command, your program begins to execute
1882immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1883of how to arrange for your program to stop. Once your program has
1884stopped, you may call functions in your program, using the @code{print}
1885or @code{call} commands. @xref{Data, ,Examining Data}.
1886
1887If the modification time of your symbol file has changed since the last
1888time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1889table, and reads it again. When it does this, @value{GDBN} tries to retain
1890your current breakpoints.
1891
4e8b0763
JB
1892@table @code
1893@kindex start
1894@item start
1895@cindex run to main procedure
1896The name of the main procedure can vary from language to language.
1897With C or C@t{++}, the main procedure name is always @code{main}, but
1898other languages such as Ada do not require a specific name for their
1899main procedure. The debugger provides a convenient way to start the
1900execution of the program and to stop at the beginning of the main
1901procedure, depending on the language used.
1902
1903The @samp{start} command does the equivalent of setting a temporary
1904breakpoint at the beginning of the main procedure and then invoking
1905the @samp{run} command.
1906
f018e82f
EZ
1907@cindex elaboration phase
1908Some programs contain an @dfn{elaboration} phase where some startup code is
1909executed before the main procedure is called. This depends on the
1910languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1911constructors for static and global objects are executed before
1912@code{main} is called. It is therefore possible that the debugger stops
1913before reaching the main procedure. However, the temporary breakpoint
1914will remain to halt execution.
1915
1916Specify the arguments to give to your program as arguments to the
1917@samp{start} command. These arguments will be given verbatim to the
1918underlying @samp{run} command. Note that the same arguments will be
1919reused if no argument is provided during subsequent calls to
1920@samp{start} or @samp{run}.
1921
1922It is sometimes necessary to debug the program during elaboration. In
1923these cases, using the @code{start} command would stop the execution of
1924your program too late, as the program would have already completed the
1925elaboration phase. Under these circumstances, insert breakpoints in your
1926elaboration code before running your program.
1927@end table
1928
6d2ebf8b 1929@node Arguments
c906108c
SS
1930@section Your program's arguments
1931
1932@cindex arguments (to your program)
1933The arguments to your program can be specified by the arguments of the
5d161b24 1934@code{run} command.
c906108c
SS
1935They are passed to a shell, which expands wildcard characters and
1936performs redirection of I/O, and thence to your program. Your
1937@code{SHELL} environment variable (if it exists) specifies what shell
1938@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1939the default shell (@file{/bin/sh} on Unix).
1940
1941On non-Unix systems, the program is usually invoked directly by
1942@value{GDBN}, which emulates I/O redirection via the appropriate system
1943calls, and the wildcard characters are expanded by the startup code of
1944the program, not by the shell.
c906108c
SS
1945
1946@code{run} with no arguments uses the same arguments used by the previous
1947@code{run}, or those set by the @code{set args} command.
1948
c906108c 1949@table @code
41afff9a 1950@kindex set args
c906108c
SS
1951@item set args
1952Specify the arguments to be used the next time your program is run. If
1953@code{set args} has no arguments, @code{run} executes your program
1954with no arguments. Once you have run your program with arguments,
1955using @code{set args} before the next @code{run} is the only way to run
1956it again without arguments.
1957
1958@kindex show args
1959@item show args
1960Show the arguments to give your program when it is started.
1961@end table
1962
6d2ebf8b 1963@node Environment
c906108c
SS
1964@section Your program's environment
1965
1966@cindex environment (of your program)
1967The @dfn{environment} consists of a set of environment variables and
1968their values. Environment variables conventionally record such things as
1969your user name, your home directory, your terminal type, and your search
1970path for programs to run. Usually you set up environment variables with
1971the shell and they are inherited by all the other programs you run. When
1972debugging, it can be useful to try running your program with a modified
1973environment without having to start @value{GDBN} over again.
1974
1975@table @code
1976@kindex path
1977@item path @var{directory}
1978Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1979(the search path for executables) that will be passed to your program.
1980The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1981You may specify several directory names, separated by whitespace or by a
1982system-dependent separator character (@samp{:} on Unix, @samp{;} on
1983MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1984is moved to the front, so it is searched sooner.
c906108c
SS
1985
1986You can use the string @samp{$cwd} to refer to whatever is the current
1987working directory at the time @value{GDBN} searches the path. If you
1988use @samp{.} instead, it refers to the directory where you executed the
1989@code{path} command. @value{GDBN} replaces @samp{.} in the
1990@var{directory} argument (with the current path) before adding
1991@var{directory} to the search path.
1992@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1993@c document that, since repeating it would be a no-op.
1994
1995@kindex show paths
1996@item show paths
1997Display the list of search paths for executables (the @code{PATH}
1998environment variable).
1999
2000@kindex show environment
2001@item show environment @r{[}@var{varname}@r{]}
2002Print the value of environment variable @var{varname} to be given to
2003your program when it starts. If you do not supply @var{varname},
2004print the names and values of all environment variables to be given to
2005your program. You can abbreviate @code{environment} as @code{env}.
2006
2007@kindex set environment
53a5351d 2008@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
2009Set environment variable @var{varname} to @var{value}. The value
2010changes for your program only, not for @value{GDBN} itself. @var{value} may
2011be any string; the values of environment variables are just strings, and
2012any interpretation is supplied by your program itself. The @var{value}
2013parameter is optional; if it is eliminated, the variable is set to a
2014null value.
2015@c "any string" here does not include leading, trailing
2016@c blanks. Gnu asks: does anyone care?
2017
2018For example, this command:
2019
474c8240 2020@smallexample
c906108c 2021set env USER = foo
474c8240 2022@end smallexample
c906108c
SS
2023
2024@noindent
d4f3574e 2025tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2026@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2027are not actually required.)
2028
2029@kindex unset environment
2030@item unset environment @var{varname}
2031Remove variable @var{varname} from the environment to be passed to your
2032program. This is different from @samp{set env @var{varname} =};
2033@code{unset environment} removes the variable from the environment,
2034rather than assigning it an empty value.
2035@end table
2036
d4f3574e
SS
2037@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2038the shell indicated
c906108c
SS
2039by your @code{SHELL} environment variable if it exists (or
2040@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2041that runs an initialization file---such as @file{.cshrc} for C-shell, or
2042@file{.bashrc} for BASH---any variables you set in that file affect
2043your program. You may wish to move setting of environment variables to
2044files that are only run when you sign on, such as @file{.login} or
2045@file{.profile}.
2046
6d2ebf8b 2047@node Working Directory
c906108c
SS
2048@section Your program's working directory
2049
2050@cindex working directory (of your program)
2051Each time you start your program with @code{run}, it inherits its
2052working directory from the current working directory of @value{GDBN}.
2053The @value{GDBN} working directory is initially whatever it inherited
2054from its parent process (typically the shell), but you can specify a new
2055working directory in @value{GDBN} with the @code{cd} command.
2056
2057The @value{GDBN} working directory also serves as a default for the commands
2058that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2059specify files}.
2060
2061@table @code
2062@kindex cd
721c2651 2063@cindex change working directory
c906108c
SS
2064@item cd @var{directory}
2065Set the @value{GDBN} working directory to @var{directory}.
2066
2067@kindex pwd
2068@item pwd
2069Print the @value{GDBN} working directory.
2070@end table
2071
60bf7e09
EZ
2072It is generally impossible to find the current working directory of
2073the process being debugged (since a program can change its directory
2074during its run). If you work on a system where @value{GDBN} is
2075configured with the @file{/proc} support, you can use the @code{info
2076proc} command (@pxref{SVR4 Process Information}) to find out the
2077current working directory of the debuggee.
2078
6d2ebf8b 2079@node Input/Output
c906108c
SS
2080@section Your program's input and output
2081
2082@cindex redirection
2083@cindex i/o
2084@cindex terminal
2085By default, the program you run under @value{GDBN} does input and output to
5d161b24 2086the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2087to its own terminal modes to interact with you, but it records the terminal
2088modes your program was using and switches back to them when you continue
2089running your program.
2090
2091@table @code
2092@kindex info terminal
2093@item info terminal
2094Displays information recorded by @value{GDBN} about the terminal modes your
2095program is using.
2096@end table
2097
2098You can redirect your program's input and/or output using shell
2099redirection with the @code{run} command. For example,
2100
474c8240 2101@smallexample
c906108c 2102run > outfile
474c8240 2103@end smallexample
c906108c
SS
2104
2105@noindent
2106starts your program, diverting its output to the file @file{outfile}.
2107
2108@kindex tty
2109@cindex controlling terminal
2110Another way to specify where your program should do input and output is
2111with the @code{tty} command. This command accepts a file name as
2112argument, and causes this file to be the default for future @code{run}
2113commands. It also resets the controlling terminal for the child
2114process, for future @code{run} commands. For example,
2115
474c8240 2116@smallexample
c906108c 2117tty /dev/ttyb
474c8240 2118@end smallexample
c906108c
SS
2119
2120@noindent
2121directs that processes started with subsequent @code{run} commands
2122default to do input and output on the terminal @file{/dev/ttyb} and have
2123that as their controlling terminal.
2124
2125An explicit redirection in @code{run} overrides the @code{tty} command's
2126effect on the input/output device, but not its effect on the controlling
2127terminal.
2128
2129When you use the @code{tty} command or redirect input in the @code{run}
2130command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2131for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2132for @code{set inferior-tty}.
2133
2134@cindex inferior tty
2135@cindex set inferior controlling terminal
2136You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2137display the name of the terminal that will be used for future runs of your
2138program.
2139
2140@table @code
2141@item set inferior-tty /dev/ttyb
2142@kindex set inferior-tty
2143Set the tty for the program being debugged to /dev/ttyb.
2144
2145@item show inferior-tty
2146@kindex show inferior-tty
2147Show the current tty for the program being debugged.
2148@end table
c906108c 2149
6d2ebf8b 2150@node Attach
c906108c
SS
2151@section Debugging an already-running process
2152@kindex attach
2153@cindex attach
2154
2155@table @code
2156@item attach @var{process-id}
2157This command attaches to a running process---one that was started
2158outside @value{GDBN}. (@code{info files} shows your active
2159targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2160find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2161or with the @samp{jobs -l} shell command.
2162
2163@code{attach} does not repeat if you press @key{RET} a second time after
2164executing the command.
2165@end table
2166
2167To use @code{attach}, your program must be running in an environment
2168which supports processes; for example, @code{attach} does not work for
2169programs on bare-board targets that lack an operating system. You must
2170also have permission to send the process a signal.
2171
2172When you use @code{attach}, the debugger finds the program running in
2173the process first by looking in the current working directory, then (if
2174the program is not found) by using the source file search path
2175(@pxref{Source Path, ,Specifying source directories}). You can also use
2176the @code{file} command to load the program. @xref{Files, ,Commands to
2177Specify Files}.
2178
2179The first thing @value{GDBN} does after arranging to debug the specified
2180process is to stop it. You can examine and modify an attached process
53a5351d
JM
2181with all the @value{GDBN} commands that are ordinarily available when
2182you start processes with @code{run}. You can insert breakpoints; you
2183can step and continue; you can modify storage. If you would rather the
2184process continue running, you may use the @code{continue} command after
c906108c
SS
2185attaching @value{GDBN} to the process.
2186
2187@table @code
2188@kindex detach
2189@item detach
2190When you have finished debugging the attached process, you can use the
2191@code{detach} command to release it from @value{GDBN} control. Detaching
2192the process continues its execution. After the @code{detach} command,
2193that process and @value{GDBN} become completely independent once more, and you
2194are ready to @code{attach} another process or start one with @code{run}.
2195@code{detach} does not repeat if you press @key{RET} again after
2196executing the command.
2197@end table
2198
2199If you exit @value{GDBN} or use the @code{run} command while you have an
2200attached process, you kill that process. By default, @value{GDBN} asks
2201for confirmation if you try to do either of these things; you can
2202control whether or not you need to confirm by using the @code{set
2203confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2204messages}).
2205
6d2ebf8b 2206@node Kill Process
c906108c 2207@section Killing the child process
c906108c
SS
2208
2209@table @code
2210@kindex kill
2211@item kill
2212Kill the child process in which your program is running under @value{GDBN}.
2213@end table
2214
2215This command is useful if you wish to debug a core dump instead of a
2216running process. @value{GDBN} ignores any core dump file while your program
2217is running.
2218
2219On some operating systems, a program cannot be executed outside @value{GDBN}
2220while you have breakpoints set on it inside @value{GDBN}. You can use the
2221@code{kill} command in this situation to permit running your program
2222outside the debugger.
2223
2224The @code{kill} command is also useful if you wish to recompile and
2225relink your program, since on many systems it is impossible to modify an
2226executable file while it is running in a process. In this case, when you
2227next type @code{run}, @value{GDBN} notices that the file has changed, and
2228reads the symbol table again (while trying to preserve your current
2229breakpoint settings).
2230
6d2ebf8b 2231@node Threads
c906108c 2232@section Debugging programs with multiple threads
c906108c
SS
2233
2234@cindex threads of execution
2235@cindex multiple threads
2236@cindex switching threads
2237In some operating systems, such as HP-UX and Solaris, a single program
2238may have more than one @dfn{thread} of execution. The precise semantics
2239of threads differ from one operating system to another, but in general
2240the threads of a single program are akin to multiple processes---except
2241that they share one address space (that is, they can all examine and
2242modify the same variables). On the other hand, each thread has its own
2243registers and execution stack, and perhaps private memory.
2244
2245@value{GDBN} provides these facilities for debugging multi-thread
2246programs:
2247
2248@itemize @bullet
2249@item automatic notification of new threads
2250@item @samp{thread @var{threadno}}, a command to switch among threads
2251@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2252@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2253a command to apply a command to a list of threads
2254@item thread-specific breakpoints
2255@end itemize
2256
c906108c
SS
2257@quotation
2258@emph{Warning:} These facilities are not yet available on every
2259@value{GDBN} configuration where the operating system supports threads.
2260If your @value{GDBN} does not support threads, these commands have no
2261effect. For example, a system without thread support shows no output
2262from @samp{info threads}, and always rejects the @code{thread} command,
2263like this:
2264
2265@smallexample
2266(@value{GDBP}) info threads
2267(@value{GDBP}) thread 1
2268Thread ID 1 not known. Use the "info threads" command to
2269see the IDs of currently known threads.
2270@end smallexample
2271@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2272@c doesn't support threads"?
2273@end quotation
c906108c
SS
2274
2275@cindex focus of debugging
2276@cindex current thread
2277The @value{GDBN} thread debugging facility allows you to observe all
2278threads while your program runs---but whenever @value{GDBN} takes
2279control, one thread in particular is always the focus of debugging.
2280This thread is called the @dfn{current thread}. Debugging commands show
2281program information from the perspective of the current thread.
2282
41afff9a 2283@cindex @code{New} @var{systag} message
c906108c
SS
2284@cindex thread identifier (system)
2285@c FIXME-implementors!! It would be more helpful if the [New...] message
2286@c included GDB's numeric thread handle, so you could just go to that
2287@c thread without first checking `info threads'.
2288Whenever @value{GDBN} detects a new thread in your program, it displays
2289the target system's identification for the thread with a message in the
2290form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2291whose form varies depending on the particular system. For example, on
2292LynxOS, you might see
2293
474c8240 2294@smallexample
c906108c 2295[New process 35 thread 27]
474c8240 2296@end smallexample
c906108c
SS
2297
2298@noindent
2299when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2300the @var{systag} is simply something like @samp{process 368}, with no
2301further qualifier.
2302
2303@c FIXME!! (1) Does the [New...] message appear even for the very first
2304@c thread of a program, or does it only appear for the
6ca652b0 2305@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2306@c program?
2307@c (2) *Is* there necessarily a first thread always? Or do some
2308@c multithread systems permit starting a program with multiple
5d161b24 2309@c threads ab initio?
c906108c
SS
2310
2311@cindex thread number
2312@cindex thread identifier (GDB)
2313For debugging purposes, @value{GDBN} associates its own thread
2314number---always a single integer---with each thread in your program.
2315
2316@table @code
2317@kindex info threads
2318@item info threads
2319Display a summary of all threads currently in your
2320program. @value{GDBN} displays for each thread (in this order):
2321
2322@enumerate
09d4efe1
EZ
2323@item
2324the thread number assigned by @value{GDBN}
c906108c 2325
09d4efe1
EZ
2326@item
2327the target system's thread identifier (@var{systag})
c906108c 2328
09d4efe1
EZ
2329@item
2330the current stack frame summary for that thread
c906108c
SS
2331@end enumerate
2332
2333@noindent
2334An asterisk @samp{*} to the left of the @value{GDBN} thread number
2335indicates the current thread.
2336
5d161b24 2337For example,
c906108c
SS
2338@end table
2339@c end table here to get a little more width for example
2340
2341@smallexample
2342(@value{GDBP}) info threads
2343 3 process 35 thread 27 0x34e5 in sigpause ()
2344 2 process 35 thread 23 0x34e5 in sigpause ()
2345* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2346 at threadtest.c:68
2347@end smallexample
53a5351d
JM
2348
2349On HP-UX systems:
c906108c 2350
4644b6e3
EZ
2351@cindex debugging multithreaded programs (on HP-UX)
2352@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2353For debugging purposes, @value{GDBN} associates its own thread
2354number---a small integer assigned in thread-creation order---with each
2355thread in your program.
2356
41afff9a
EZ
2357@cindex @code{New} @var{systag} message, on HP-UX
2358@cindex thread identifier (system), on HP-UX
c906108c
SS
2359@c FIXME-implementors!! It would be more helpful if the [New...] message
2360@c included GDB's numeric thread handle, so you could just go to that
2361@c thread without first checking `info threads'.
2362Whenever @value{GDBN} detects a new thread in your program, it displays
2363both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2364form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2365whose form varies depending on the particular system. For example, on
2366HP-UX, you see
2367
474c8240 2368@smallexample
c906108c 2369[New thread 2 (system thread 26594)]
474c8240 2370@end smallexample
c906108c
SS
2371
2372@noindent
5d161b24 2373when @value{GDBN} notices a new thread.
c906108c
SS
2374
2375@table @code
4644b6e3 2376@kindex info threads (HP-UX)
c906108c
SS
2377@item info threads
2378Display a summary of all threads currently in your
2379program. @value{GDBN} displays for each thread (in this order):
2380
2381@enumerate
2382@item the thread number assigned by @value{GDBN}
2383
2384@item the target system's thread identifier (@var{systag})
2385
2386@item the current stack frame summary for that thread
2387@end enumerate
2388
2389@noindent
2390An asterisk @samp{*} to the left of the @value{GDBN} thread number
2391indicates the current thread.
2392
5d161b24 2393For example,
c906108c
SS
2394@end table
2395@c end table here to get a little more width for example
2396
474c8240 2397@smallexample
c906108c 2398(@value{GDBP}) info threads
6d2ebf8b
SS
2399 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2400 at quicksort.c:137
2401 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2402 from /usr/lib/libc.2
2403 1 system thread 27905 0x7b003498 in _brk () \@*
2404 from /usr/lib/libc.2
474c8240 2405@end smallexample
c906108c 2406
c45da7e6
EZ
2407On Solaris, you can display more information about user threads with a
2408Solaris-specific command:
2409
2410@table @code
2411@item maint info sol-threads
2412@kindex maint info sol-threads
2413@cindex thread info (Solaris)
2414Display info on Solaris user threads.
2415@end table
2416
c906108c
SS
2417@table @code
2418@kindex thread @var{threadno}
2419@item thread @var{threadno}
2420Make thread number @var{threadno} the current thread. The command
2421argument @var{threadno} is the internal @value{GDBN} thread number, as
2422shown in the first field of the @samp{info threads} display.
2423@value{GDBN} responds by displaying the system identifier of the thread
2424you selected, and its current stack frame summary:
2425
2426@smallexample
2427@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2428(@value{GDBP}) thread 2
c906108c 2429[Switching to process 35 thread 23]
c906108c
SS
24300x34e5 in sigpause ()
2431@end smallexample
2432
2433@noindent
2434As with the @samp{[New @dots{}]} message, the form of the text after
2435@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2436threads.
c906108c 2437
9c16f35a 2438@kindex thread apply
638ac427 2439@cindex apply command to several threads
839c27b7
EZ
2440@item thread apply [@var{threadno}] [@var{all}] @var{command}
2441The @code{thread apply} command allows you to apply the named
2442@var{command} to one or more threads. Specify the numbers of the
2443threads that you want affected with the command argument
2444@var{threadno}. It can be a single thread number, one of the numbers
2445shown in the first field of the @samp{info threads} display; or it
2446could be a range of thread numbers, as in @code{2-4}. To apply a
2447command to all threads, type @kbd{thread apply all @var{command}}.
c906108c
SS
2448@end table
2449
2450@cindex automatic thread selection
2451@cindex switching threads automatically
2452@cindex threads, automatic switching
2453Whenever @value{GDBN} stops your program, due to a breakpoint or a
2454signal, it automatically selects the thread where that breakpoint or
2455signal happened. @value{GDBN} alerts you to the context switch with a
2456message of the form @samp{[Switching to @var{systag}]} to identify the
2457thread.
2458
2459@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2460more information about how @value{GDBN} behaves when you stop and start
2461programs with multiple threads.
2462
2463@xref{Set Watchpoints,,Setting watchpoints}, for information about
2464watchpoints in programs with multiple threads.
c906108c 2465
6d2ebf8b 2466@node Processes
c906108c
SS
2467@section Debugging programs with multiple processes
2468
2469@cindex fork, debugging programs which call
2470@cindex multiple processes
2471@cindex processes, multiple
53a5351d
JM
2472On most systems, @value{GDBN} has no special support for debugging
2473programs which create additional processes using the @code{fork}
2474function. When a program forks, @value{GDBN} will continue to debug the
2475parent process and the child process will run unimpeded. If you have
2476set a breakpoint in any code which the child then executes, the child
2477will get a @code{SIGTRAP} signal which (unless it catches the signal)
2478will cause it to terminate.
c906108c
SS
2479
2480However, if you want to debug the child process there is a workaround
2481which isn't too painful. Put a call to @code{sleep} in the code which
2482the child process executes after the fork. It may be useful to sleep
2483only if a certain environment variable is set, or a certain file exists,
2484so that the delay need not occur when you don't want to run @value{GDBN}
2485on the child. While the child is sleeping, use the @code{ps} program to
2486get its process ID. Then tell @value{GDBN} (a new invocation of
2487@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2488the child process (@pxref{Attach}). From that point on you can debug
c906108c 2489the child process just like any other process which you attached to.
c906108c 2490
b51970ac
DJ
2491On some systems, @value{GDBN} provides support for debugging programs that
2492create additional processes using the @code{fork} or @code{vfork} functions.
2493Currently, the only platforms with this feature are HP-UX (11.x and later
2494only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2495
2496By default, when a program forks, @value{GDBN} will continue to debug
2497the parent process and the child process will run unimpeded.
2498
2499If you want to follow the child process instead of the parent process,
2500use the command @w{@code{set follow-fork-mode}}.
2501
2502@table @code
2503@kindex set follow-fork-mode
2504@item set follow-fork-mode @var{mode}
2505Set the debugger response to a program call of @code{fork} or
2506@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2507process. The @var{mode} argument can be:
c906108c
SS
2508
2509@table @code
2510@item parent
2511The original process is debugged after a fork. The child process runs
2df3850c 2512unimpeded. This is the default.
c906108c
SS
2513
2514@item child
2515The new process is debugged after a fork. The parent process runs
2516unimpeded.
2517
c906108c
SS
2518@end table
2519
9c16f35a 2520@kindex show follow-fork-mode
c906108c 2521@item show follow-fork-mode
2df3850c 2522Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2523@end table
2524
5c95884b
MS
2525@cindex debugging multiple processes
2526On Linux, if you want to debug both the parent and child processes, use the
2527command @w{@code{set detach-on-fork}}.
2528
2529@table @code
2530@kindex set detach-on-fork
2531@item set detach-on-fork @var{mode}
2532Tells gdb whether to detach one of the processes after a fork, or
2533retain debugger control over them both.
2534
2535@table @code
2536@item on
2537The child process (or parent process, depending on the value of
2538@code{follow-fork-mode}) will be detached and allowed to run
2539independently. This is the default.
2540
2541@item off
2542Both processes will be held under the control of @value{GDBN}.
2543One process (child or parent, depending on the value of
2544@code{follow-fork-mode}) is debugged as usual, while the other
2545is held suspended.
2546
2547@end table
2548
2549@kindex show detach-on-follow
2550@item show detach-on-follow
2551Show whether detach-on-follow mode is on/off.
2552@end table
2553
2554If you choose to set @var{detach-on-follow} mode off, then
2555@value{GDBN} will retain control of all forked processes (including
2556nested forks). You can list the forked processes under the control of
2557@value{GDBN} by using the @w{@code{info forks}} command, and switch
2558from one fork to another by using the @w{@code{fork}} command.
2559
2560@table @code
2561@kindex info forks
2562@item info forks
2563Print a list of all forked processes under the control of @value{GDBN}.
2564The listing will include a fork id, a process id, and the current
2565position (program counter) of the process.
2566
2567
2568@kindex fork @var{fork-id}
2569@item fork @var{fork-id}
2570Make fork number @var{fork-id} the current process. The argument
2571@var{fork-id} is the internal fork number assigned by @value{GDBN},
2572as shown in the first field of the @samp{info forks} display.
2573
2574@end table
2575
2576To quit debugging one of the forked processes, you can either detach
2577from it by using the @w{@code{detach-fork}} command (allowing it to
2578run independently), or delete (and kill) it using the
b8db102d 2579@w{@code{delete fork}} command.
5c95884b
MS
2580
2581@table @code
2582@kindex detach-fork @var{fork-id}
2583@item detach-fork @var{fork-id}
2584Detach from the process identified by @value{GDBN} fork number
2585@var{fork-id}, and remove it from the fork list. The process will be
2586allowed to run independently.
2587
b8db102d
MS
2588@kindex delete fork @var{fork-id}
2589@item delete fork @var{fork-id}
5c95884b
MS
2590Kill the process identified by @value{GDBN} fork number @var{fork-id},
2591and remove it from the fork list.
2592
2593@end table
2594
c906108c
SS
2595If you ask to debug a child process and a @code{vfork} is followed by an
2596@code{exec}, @value{GDBN} executes the new target up to the first
2597breakpoint in the new target. If you have a breakpoint set on
2598@code{main} in your original program, the breakpoint will also be set on
2599the child process's @code{main}.
2600
2601When a child process is spawned by @code{vfork}, you cannot debug the
2602child or parent until an @code{exec} call completes.
2603
2604If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2605call executes, the new target restarts. To restart the parent process,
2606use the @code{file} command with the parent executable name as its
2607argument.
2608
2609You can use the @code{catch} command to make @value{GDBN} stop whenever
2610a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2611Catchpoints, ,Setting catchpoints}.
c906108c 2612
5c95884b
MS
2613@node Checkpoint/Restart
2614@section Setting a @emph{bookmark} to return to later
2615
2616@cindex checkpoint
2617@cindex restart
2618@cindex bookmark
2619@cindex snapshot of a process
2620@cindex rewind program state
2621
2622On certain operating systems@footnote{Currently, only
2623@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2624program's state, called a @dfn{checkpoint}, and come back to it
2625later.
2626
2627Returning to a checkpoint effectively undoes everything that has
2628happened in the program since the @code{checkpoint} was saved. This
2629includes changes in memory, registers, and even (within some limits)
2630system state. Effectively, it is like going back in time to the
2631moment when the checkpoint was saved.
2632
2633Thus, if you're stepping thru a program and you think you're
2634getting close to the point where things go wrong, you can save
2635a checkpoint. Then, if you accidentally go too far and miss
2636the critical statement, instead of having to restart your program
2637from the beginning, you can just go back to the checkpoint and
2638start again from there.
2639
2640This can be especially useful if it takes a lot of time or
2641steps to reach the point where you think the bug occurs.
2642
2643To use the @code{checkpoint}/@code{restart} method of debugging:
2644
2645@table @code
2646@kindex checkpoint
2647@item checkpoint
2648Save a snapshot of the debugged program's current execution state.
2649The @code{checkpoint} command takes no arguments, but each checkpoint
2650is assigned a small integer id, similar to a breakpoint id.
2651
2652@kindex info checkpoints
2653@item info checkpoints
2654List the checkpoints that have been saved in the current debugging
2655session. For each checkpoint, the following information will be
2656listed:
2657
2658@table @code
2659@item Checkpoint ID
2660@item Process ID
2661@item Code Address
2662@item Source line, or label
2663@end table
2664
2665@kindex restart @var{checkpoint-id}
2666@item restart @var{checkpoint-id}
2667Restore the program state that was saved as checkpoint number
2668@var{checkpoint-id}. All program variables, registers, stack frames
2669etc.@: will be returned to the values that they had when the checkpoint
2670was saved. In essence, gdb will ``wind back the clock'' to the point
2671in time when the checkpoint was saved.
2672
2673Note that breakpoints, @value{GDBN} variables, command history etc.
2674are not affected by restoring a checkpoint. In general, a checkpoint
2675only restores things that reside in the program being debugged, not in
2676the debugger.
2677
b8db102d
MS
2678@kindex delete checkpoint @var{checkpoint-id}
2679@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
2680Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2681
2682@end table
2683
2684Returning to a previously saved checkpoint will restore the user state
2685of the program being debugged, plus a significant subset of the system
2686(OS) state, including file pointers. It won't ``un-write'' data from
2687a file, but it will rewind the file pointer to the previous location,
2688so that the previously written data can be overwritten. For files
2689opened in read mode, the pointer will also be restored so that the
2690previously read data can be read again.
2691
2692Of course, characters that have been sent to a printer (or other
2693external device) cannot be ``snatched back'', and characters received
2694from eg.@: a serial device can be removed from internal program buffers,
2695but they cannot be ``pushed back'' into the serial pipeline, ready to
2696be received again. Similarly, the actual contents of files that have
2697been changed cannot be restored (at this time).
2698
2699However, within those constraints, you actually can ``rewind'' your
2700program to a previously saved point in time, and begin debugging it
2701again --- and you can change the course of events so as to debug a
2702different execution path this time.
2703
2704@cindex checkpoints and process id
2705Finally, there is one bit of internal program state that will be
2706different when you return to a checkpoint --- the program's process
2707id. Each checkpoint will have a unique process id (or @var{pid}),
2708and each will be different from the program's original @var{pid}.
2709If your program has saved a local copy of its process id, this could
2710potentially pose a problem.
2711
2712@subsection A non-obvious benefit of using checkpoints
2713
2714On some systems such as @sc{gnu}/Linux, address space randomization
2715is performed on new processes for security reasons. This makes it
2716difficult or impossible to set a breakpoint, or watchpoint, on an
2717absolute address if you have to restart the program, since the
2718absolute location of a symbol will change from one execution to the
2719next.
2720
2721A checkpoint, however, is an @emph{identical} copy of a process.
2722Therefore if you create a checkpoint at (eg.@:) the start of main,
2723and simply return to that checkpoint instead of restarting the
2724process, you can avoid the effects of address randomization and
2725your symbols will all stay in the same place.
2726
6d2ebf8b 2727@node Stopping
c906108c
SS
2728@chapter Stopping and Continuing
2729
2730The principal purposes of using a debugger are so that you can stop your
2731program before it terminates; or so that, if your program runs into
2732trouble, you can investigate and find out why.
2733
7a292a7a
SS
2734Inside @value{GDBN}, your program may stop for any of several reasons,
2735such as a signal, a breakpoint, or reaching a new line after a
2736@value{GDBN} command such as @code{step}. You may then examine and
2737change variables, set new breakpoints or remove old ones, and then
2738continue execution. Usually, the messages shown by @value{GDBN} provide
2739ample explanation of the status of your program---but you can also
2740explicitly request this information at any time.
c906108c
SS
2741
2742@table @code
2743@kindex info program
2744@item info program
2745Display information about the status of your program: whether it is
7a292a7a 2746running or not, what process it is, and why it stopped.
c906108c
SS
2747@end table
2748
2749@menu
2750* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2751* Continuing and Stepping:: Resuming execution
c906108c 2752* Signals:: Signals
c906108c 2753* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2754@end menu
2755
6d2ebf8b 2756@node Breakpoints
c906108c
SS
2757@section Breakpoints, watchpoints, and catchpoints
2758
2759@cindex breakpoints
2760A @dfn{breakpoint} makes your program stop whenever a certain point in
2761the program is reached. For each breakpoint, you can add conditions to
2762control in finer detail whether your program stops. You can set
2763breakpoints with the @code{break} command and its variants (@pxref{Set
2764Breaks, ,Setting breakpoints}), to specify the place where your program
2765should stop by line number, function name or exact address in the
2766program.
2767
09d4efe1
EZ
2768On some systems, you can set breakpoints in shared libraries before
2769the executable is run. There is a minor limitation on HP-UX systems:
2770you must wait until the executable is run in order to set breakpoints
2771in shared library routines that are not called directly by the program
2772(for example, routines that are arguments in a @code{pthread_create}
2773call).
c906108c
SS
2774
2775@cindex watchpoints
fd60e0df 2776@cindex data breakpoints
c906108c
SS
2777@cindex memory tracing
2778@cindex breakpoint on memory address
2779@cindex breakpoint on variable modification
2780A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 2781when the value of an expression changes. The expression may be a value
0ced0c34 2782of a variable, or it could involve values of one or more variables
fd60e0df
EZ
2783combined by operators, such as @samp{a + b}. This is sometimes called
2784@dfn{data breakpoints}. You must use a different command to set
2785watchpoints (@pxref{Set Watchpoints, ,Setting watchpoints}), but aside
2786from that, you can manage a watchpoint like any other breakpoint: you
2787enable, disable, and delete both breakpoints and watchpoints using the
2788same commands.
c906108c
SS
2789
2790You can arrange to have values from your program displayed automatically
2791whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2792Automatic display}.
2793
2794@cindex catchpoints
2795@cindex breakpoint on events
2796A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2797when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2798exception or the loading of a library. As with watchpoints, you use a
2799different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2800catchpoints}), but aside from that, you can manage a catchpoint like any
2801other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2802@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2803
2804@cindex breakpoint numbers
2805@cindex numbers for breakpoints
2806@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2807catchpoint when you create it; these numbers are successive integers
2808starting with one. In many of the commands for controlling various
2809features of breakpoints you use the breakpoint number to say which
2810breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2811@dfn{disabled}; if disabled, it has no effect on your program until you
2812enable it again.
2813
c5394b80
JM
2814@cindex breakpoint ranges
2815@cindex ranges of breakpoints
2816Some @value{GDBN} commands accept a range of breakpoints on which to
2817operate. A breakpoint range is either a single breakpoint number, like
2818@samp{5}, or two such numbers, in increasing order, separated by a
2819hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2820all breakpoint in that range are operated on.
2821
c906108c
SS
2822@menu
2823* Set Breaks:: Setting breakpoints
2824* Set Watchpoints:: Setting watchpoints
2825* Set Catchpoints:: Setting catchpoints
2826* Delete Breaks:: Deleting breakpoints
2827* Disabling:: Disabling breakpoints
2828* Conditions:: Break conditions
2829* Break Commands:: Breakpoint command lists
c906108c 2830* Breakpoint Menus:: Breakpoint menus
d4f3574e 2831* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2832* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2833@end menu
2834
6d2ebf8b 2835@node Set Breaks
c906108c
SS
2836@subsection Setting breakpoints
2837
5d161b24 2838@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2839@c consider in particular declaration with/without initialization.
2840@c
2841@c FIXME 2 is there stuff on this already? break at fun start, already init?
2842
2843@kindex break
41afff9a
EZ
2844@kindex b @r{(@code{break})}
2845@vindex $bpnum@r{, convenience variable}
c906108c
SS
2846@cindex latest breakpoint
2847Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2848@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2849number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2850Vars,, Convenience variables}, for a discussion of what you can do with
2851convenience variables.
2852
2853You have several ways to say where the breakpoint should go.
2854
2855@table @code
2856@item break @var{function}
5d161b24 2857Set a breakpoint at entry to function @var{function}.
c906108c 2858When using source languages that permit overloading of symbols, such as
b37052ae 2859C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2860@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2861
2862@item break +@var{offset}
2863@itemx break -@var{offset}
2864Set a breakpoint some number of lines forward or back from the position
d4f3574e 2865at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2866(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2867
2868@item break @var{linenum}
2869Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2870The current source file is the last file whose source text was printed.
2871The breakpoint will stop your program just before it executes any of the
c906108c
SS
2872code on that line.
2873
2874@item break @var{filename}:@var{linenum}
2875Set a breakpoint at line @var{linenum} in source file @var{filename}.
2876
2877@item break @var{filename}:@var{function}
2878Set a breakpoint at entry to function @var{function} found in file
2879@var{filename}. Specifying a file name as well as a function name is
2880superfluous except when multiple files contain similarly named
2881functions.
2882
2883@item break *@var{address}
2884Set a breakpoint at address @var{address}. You can use this to set
2885breakpoints in parts of your program which do not have debugging
2886information or source files.
2887
2888@item break
2889When called without any arguments, @code{break} sets a breakpoint at
2890the next instruction to be executed in the selected stack frame
2891(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2892innermost, this makes your program stop as soon as control
2893returns to that frame. This is similar to the effect of a
2894@code{finish} command in the frame inside the selected frame---except
2895that @code{finish} does not leave an active breakpoint. If you use
2896@code{break} without an argument in the innermost frame, @value{GDBN} stops
2897the next time it reaches the current location; this may be useful
2898inside loops.
2899
2900@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2901least one instruction has been executed. If it did not do this, you
2902would be unable to proceed past a breakpoint without first disabling the
2903breakpoint. This rule applies whether or not the breakpoint already
2904existed when your program stopped.
2905
2906@item break @dots{} if @var{cond}
2907Set a breakpoint with condition @var{cond}; evaluate the expression
2908@var{cond} each time the breakpoint is reached, and stop only if the
2909value is nonzero---that is, if @var{cond} evaluates as true.
2910@samp{@dots{}} stands for one of the possible arguments described
2911above (or no argument) specifying where to break. @xref{Conditions,
2912,Break conditions}, for more information on breakpoint conditions.
2913
2914@kindex tbreak
2915@item tbreak @var{args}
2916Set a breakpoint enabled only for one stop. @var{args} are the
2917same as for the @code{break} command, and the breakpoint is set in the same
2918way, but the breakpoint is automatically deleted after the first time your
2919program stops there. @xref{Disabling, ,Disabling breakpoints}.
2920
c906108c 2921@kindex hbreak
ba04e063 2922@cindex hardware breakpoints
c906108c 2923@item hbreak @var{args}
d4f3574e
SS
2924Set a hardware-assisted breakpoint. @var{args} are the same as for the
2925@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2926breakpoint requires hardware support and some target hardware may not
2927have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2928debugging, so you can set a breakpoint at an instruction without
2929changing the instruction. This can be used with the new trap-generation
09d4efe1 2930provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2931will generate traps when a program accesses some data or instruction
2932address that is assigned to the debug registers. However the hardware
2933breakpoint registers can take a limited number of breakpoints. For
2934example, on the DSU, only two data breakpoints can be set at a time, and
2935@value{GDBN} will reject this command if more than two are used. Delete
2936or disable unused hardware breakpoints before setting new ones
2937(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2938For remote targets, you can restrict the number of hardware
2939breakpoints @value{GDBN} will use, see @ref{set remote
2940hardware-breakpoint-limit}.
501eef12 2941
c906108c
SS
2942
2943@kindex thbreak
2944@item thbreak @var{args}
2945Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2946are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2947the same way. However, like the @code{tbreak} command,
c906108c
SS
2948the breakpoint is automatically deleted after the
2949first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2950command, the breakpoint requires hardware support and some target hardware
2951may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2952See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2953
2954@kindex rbreak
2955@cindex regular expression
c45da7e6
EZ
2956@cindex breakpoints in functions matching a regexp
2957@cindex set breakpoints in many functions
c906108c 2958@item rbreak @var{regex}
c906108c 2959Set breakpoints on all functions matching the regular expression
11cf8741
JM
2960@var{regex}. This command sets an unconditional breakpoint on all
2961matches, printing a list of all breakpoints it set. Once these
2962breakpoints are set, they are treated just like the breakpoints set with
2963the @code{break} command. You can delete them, disable them, or make
2964them conditional the same way as any other breakpoint.
2965
2966The syntax of the regular expression is the standard one used with tools
2967like @file{grep}. Note that this is different from the syntax used by
2968shells, so for instance @code{foo*} matches all functions that include
2969an @code{fo} followed by zero or more @code{o}s. There is an implicit
2970@code{.*} leading and trailing the regular expression you supply, so to
2971match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2972
f7dc1244 2973@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2974When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2975breakpoints on overloaded functions that are not members of any special
2976classes.
c906108c 2977
f7dc1244
EZ
2978@cindex set breakpoints on all functions
2979The @code{rbreak} command can be used to set breakpoints in
2980@strong{all} the functions in a program, like this:
2981
2982@smallexample
2983(@value{GDBP}) rbreak .
2984@end smallexample
2985
c906108c
SS
2986@kindex info breakpoints
2987@cindex @code{$_} and @code{info breakpoints}
2988@item info breakpoints @r{[}@var{n}@r{]}
2989@itemx info break @r{[}@var{n}@r{]}
2990@itemx info watchpoints @r{[}@var{n}@r{]}
2991Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734
EZ
2992not deleted. Optional argument @var{n} means print information only
2993about the specified breakpoint (or watchpoint or catchpoint). For
2994each breakpoint, following columns are printed:
c906108c
SS
2995
2996@table @emph
2997@item Breakpoint Numbers
2998@item Type
2999Breakpoint, watchpoint, or catchpoint.
3000@item Disposition
3001Whether the breakpoint is marked to be disabled or deleted when hit.
3002@item Enabled or Disabled
3003Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
3004that are not enabled.
3005@item Address
2650777c
JJ
3006Where the breakpoint is in your program, as a memory address. If the
3007breakpoint is pending (see below for details) on a future load of a shared library, the address
3008will be listed as @samp{<PENDING>}.
c906108c
SS
3009@item What
3010Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3011line number. For a pending breakpoint, the original string passed to
3012the breakpoint command will be listed as it cannot be resolved until
3013the appropriate shared library is loaded in the future.
c906108c
SS
3014@end table
3015
3016@noindent
3017If a breakpoint is conditional, @code{info break} shows the condition on
3018the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
3019are listed after that. A pending breakpoint is allowed to have a condition
3020specified for it. The condition is not parsed for validity until a shared
3021library is loaded that allows the pending breakpoint to resolve to a
3022valid location.
c906108c
SS
3023
3024@noindent
3025@code{info break} with a breakpoint
3026number @var{n} as argument lists only that breakpoint. The
3027convenience variable @code{$_} and the default examining-address for
3028the @code{x} command are set to the address of the last breakpoint
5d161b24 3029listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
3030
3031@noindent
3032@code{info break} displays a count of the number of times the breakpoint
3033has been hit. This is especially useful in conjunction with the
3034@code{ignore} command. You can ignore a large number of breakpoint
3035hits, look at the breakpoint info to see how many times the breakpoint
3036was hit, and then run again, ignoring one less than that number. This
3037will get you quickly to the last hit of that breakpoint.
3038@end table
3039
3040@value{GDBN} allows you to set any number of breakpoints at the same place in
3041your program. There is nothing silly or meaningless about this. When
3042the breakpoints are conditional, this is even useful
3043(@pxref{Conditions, ,Break conditions}).
3044
2650777c 3045@cindex pending breakpoints
dd79a6cf
JJ
3046If a specified breakpoint location cannot be found, it may be due to the fact
3047that the location is in a shared library that is yet to be loaded. In such
3048a case, you may want @value{GDBN} to create a special breakpoint (known as
3049a @dfn{pending breakpoint}) that
3050attempts to resolve itself in the future when an appropriate shared library
3051gets loaded.
3052
3053Pending breakpoints are useful to set at the start of your
2650777c
JJ
3054@value{GDBN} session for locations that you know will be dynamically loaded
3055later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
3056a check is made to see if the load resolves any pending breakpoint locations.
3057If a pending breakpoint location gets resolved,
3058a regular breakpoint is created and the original pending breakpoint is removed.
3059
3060@value{GDBN} provides some additional commands for controlling pending
3061breakpoint support:
3062
3063@kindex set breakpoint pending
3064@kindex show breakpoint pending
3065@table @code
3066@item set breakpoint pending auto
3067This is the default behavior. When @value{GDBN} cannot find the breakpoint
3068location, it queries you whether a pending breakpoint should be created.
3069
3070@item set breakpoint pending on
3071This indicates that an unrecognized breakpoint location should automatically
3072result in a pending breakpoint being created.
3073
3074@item set breakpoint pending off
3075This indicates that pending breakpoints are not to be created. Any
3076unrecognized breakpoint location results in an error. This setting does
3077not affect any pending breakpoints previously created.
3078
3079@item show breakpoint pending
3080Show the current behavior setting for creating pending breakpoints.
3081@end table
2650777c 3082
649e03f6
RM
3083@cindex operations allowed on pending breakpoints
3084Normal breakpoint operations apply to pending breakpoints as well. You may
3085specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
3086breakpoint is reached. You can also enable or disable
3087the pending breakpoint. When you specify a condition for a pending breakpoint,
3088the parsing of the condition will be deferred until the point where the
3089pending breakpoint location is resolved. Disabling a pending breakpoint
3090tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
3091shared library load. When a pending breakpoint is re-enabled,
649e03f6 3092@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
3093This is done because any number of shared library loads could have
3094occurred since the time the breakpoint was disabled and one or more
3095of these loads could resolve the location.
3096
c906108c
SS
3097@cindex negative breakpoint numbers
3098@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3099@value{GDBN} itself sometimes sets breakpoints in your program for
3100special purposes, such as proper handling of @code{longjmp} (in C
3101programs). These internal breakpoints are assigned negative numbers,
3102starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3103You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3104@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3105
3106
6d2ebf8b 3107@node Set Watchpoints
c906108c
SS
3108@subsection Setting watchpoints
3109
3110@cindex setting watchpoints
c906108c
SS
3111You can use a watchpoint to stop execution whenever the value of an
3112expression changes, without having to predict a particular place where
fd60e0df
EZ
3113this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3114The expression may be as simple as the value of a single variable, or
3115as complex as many variables combined by operators. Examples include:
3116
3117@itemize @bullet
3118@item
3119A reference to the value of a single variable.
3120
3121@item
3122An address cast to an appropriate data type. For example,
3123@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3124address (assuming an @code{int} occupies 4 bytes).
3125
3126@item
3127An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3128expression can use any operators valid in the program's native
3129language (@pxref{Languages}).
3130@end itemize
c906108c 3131
82f2d802
EZ
3132@cindex software watchpoints
3133@cindex hardware watchpoints
c906108c 3134Depending on your system, watchpoints may be implemented in software or
2df3850c 3135hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3136program and testing the variable's value each time, which is hundreds of
3137times slower than normal execution. (But this may still be worth it, to
3138catch errors where you have no clue what part of your program is the
3139culprit.)
3140
82f2d802
EZ
3141On some systems, such as HP-UX, @sc{gnu}/Linux and most other
3142x86-based targets, @value{GDBN} includes support for hardware
3143watchpoints, which do not slow down the running of your program.
c906108c
SS
3144
3145@table @code
3146@kindex watch
3147@item watch @var{expr}
fd60e0df
EZ
3148Set a watchpoint for an expression. @value{GDBN} will break when the
3149expression @var{expr} is written into by the program and its value
3150changes. The simplest (and the most popular) use of this command is
3151to watch the value of a single variable:
3152
3153@smallexample
3154(@value{GDBP}) watch foo
3155@end smallexample
c906108c
SS
3156
3157@kindex rwatch
3158@item rwatch @var{expr}
09d4efe1
EZ
3159Set a watchpoint that will break when the value of @var{expr} is read
3160by the program.
c906108c
SS
3161
3162@kindex awatch
3163@item awatch @var{expr}
09d4efe1
EZ
3164Set a watchpoint that will break when @var{expr} is either read from
3165or written into by the program.
c906108c 3166
45ac1734 3167@kindex info watchpoints @r{[}@var{n}@r{]}
c906108c
SS
3168@item info watchpoints
3169This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 3170it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
3171@end table
3172
3173@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3174watchpoints execute very quickly, and the debugger reports a change in
3175value at the exact instruction where the change occurs. If @value{GDBN}
3176cannot set a hardware watchpoint, it sets a software watchpoint, which
3177executes more slowly and reports the change in value at the next
82f2d802
EZ
3178@emph{statement}, not the instruction, after the change occurs.
3179
82f2d802
EZ
3180@cindex use only software watchpoints
3181You can force @value{GDBN} to use only software watchpoints with the
3182@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3183zero, @value{GDBN} will never try to use hardware watchpoints, even if
3184the underlying system supports them. (Note that hardware-assisted
3185watchpoints that were set @emph{before} setting
3186@code{can-use-hw-watchpoints} to zero will still use the hardware
3187mechanism of watching expressiion values.)
c906108c 3188
9c16f35a
EZ
3189@table @code
3190@item set can-use-hw-watchpoints
3191@kindex set can-use-hw-watchpoints
3192Set whether or not to use hardware watchpoints.
3193
3194@item show can-use-hw-watchpoints
3195@kindex show can-use-hw-watchpoints
3196Show the current mode of using hardware watchpoints.
3197@end table
3198
3199For remote targets, you can restrict the number of hardware
3200watchpoints @value{GDBN} will use, see @ref{set remote
3201hardware-breakpoint-limit}.
3202
c906108c
SS
3203When you issue the @code{watch} command, @value{GDBN} reports
3204
474c8240 3205@smallexample
c906108c 3206Hardware watchpoint @var{num}: @var{expr}
474c8240 3207@end smallexample
c906108c
SS
3208
3209@noindent
3210if it was able to set a hardware watchpoint.
3211
7be570e7
JM
3212Currently, the @code{awatch} and @code{rwatch} commands can only set
3213hardware watchpoints, because accesses to data that don't change the
3214value of the watched expression cannot be detected without examining
3215every instruction as it is being executed, and @value{GDBN} does not do
3216that currently. If @value{GDBN} finds that it is unable to set a
3217hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3218will print a message like this:
3219
3220@smallexample
3221Expression cannot be implemented with read/access watchpoint.
3222@end smallexample
3223
3224Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3225data type of the watched expression is wider than what a hardware
3226watchpoint on the target machine can handle. For example, some systems
3227can only watch regions that are up to 4 bytes wide; on such systems you
3228cannot set hardware watchpoints for an expression that yields a
3229double-precision floating-point number (which is typically 8 bytes
3230wide). As a work-around, it might be possible to break the large region
3231into a series of smaller ones and watch them with separate watchpoints.
3232
3233If you set too many hardware watchpoints, @value{GDBN} might be unable
3234to insert all of them when you resume the execution of your program.
3235Since the precise number of active watchpoints is unknown until such
3236time as the program is about to be resumed, @value{GDBN} might not be
3237able to warn you about this when you set the watchpoints, and the
3238warning will be printed only when the program is resumed:
3239
3240@smallexample
3241Hardware watchpoint @var{num}: Could not insert watchpoint
3242@end smallexample
3243
3244@noindent
3245If this happens, delete or disable some of the watchpoints.
3246
fd60e0df
EZ
3247Watching complex expressions that reference many variables can also
3248exhaust the resources available for hardware-assisted watchpoints.
3249That's because @value{GDBN} needs to watch every variable in the
3250expression with separately allocated resources.
3251
7be570e7
JM
3252The SPARClite DSU will generate traps when a program accesses some data
3253or instruction address that is assigned to the debug registers. For the
3254data addresses, DSU facilitates the @code{watch} command. However the
3255hardware breakpoint registers can only take two data watchpoints, and
3256both watchpoints must be the same kind. For example, you can set two
3257watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3258@strong{or} two with @code{awatch} commands, but you cannot set one
3259watchpoint with one command and the other with a different command.
c906108c
SS
3260@value{GDBN} will reject the command if you try to mix watchpoints.
3261Delete or disable unused watchpoint commands before setting new ones.
3262
3263If you call a function interactively using @code{print} or @code{call},
2df3850c 3264any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3265kind of breakpoint or the call completes.
3266
7be570e7
JM
3267@value{GDBN} automatically deletes watchpoints that watch local
3268(automatic) variables, or expressions that involve such variables, when
3269they go out of scope, that is, when the execution leaves the block in
3270which these variables were defined. In particular, when the program
3271being debugged terminates, @emph{all} local variables go out of scope,
3272and so only watchpoints that watch global variables remain set. If you
3273rerun the program, you will need to set all such watchpoints again. One
3274way of doing that would be to set a code breakpoint at the entry to the
3275@code{main} function and when it breaks, set all the watchpoints.
3276
c906108c
SS
3277@quotation
3278@cindex watchpoints and threads
3279@cindex threads and watchpoints
c906108c
SS
3280@emph{Warning:} In multi-thread programs, watchpoints have only limited
3281usefulness. With the current watchpoint implementation, @value{GDBN}
3282can only watch the value of an expression @emph{in a single thread}. If
3283you are confident that the expression can only change due to the current
3284thread's activity (and if you are also confident that no other thread
3285can become current), then you can use watchpoints as usual. However,
3286@value{GDBN} may not notice when a non-current thread's activity changes
3287the expression.
53a5351d 3288
d4f3574e 3289@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3290@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3291have only limited usefulness. If @value{GDBN} creates a software
3292watchpoint, it can only watch the value of an expression @emph{in a
3293single thread}. If you are confident that the expression can only
3294change due to the current thread's activity (and if you are also
3295confident that no other thread can become current), then you can use
3296software watchpoints as usual. However, @value{GDBN} may not notice
3297when a non-current thread's activity changes the expression. (Hardware
3298watchpoints, in contrast, watch an expression in all threads.)
c906108c 3299@end quotation
c906108c 3300
501eef12
AC
3301@xref{set remote hardware-watchpoint-limit}.
3302
6d2ebf8b 3303@node Set Catchpoints
c906108c 3304@subsection Setting catchpoints
d4f3574e 3305@cindex catchpoints, setting
c906108c
SS
3306@cindex exception handlers
3307@cindex event handling
3308
3309You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3310kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3311shared library. Use the @code{catch} command to set a catchpoint.
3312
3313@table @code
3314@kindex catch
3315@item catch @var{event}
3316Stop when @var{event} occurs. @var{event} can be any of the following:
3317@table @code
3318@item throw
4644b6e3 3319@cindex stop on C@t{++} exceptions
b37052ae 3320The throwing of a C@t{++} exception.
c906108c
SS
3321
3322@item catch
b37052ae 3323The catching of a C@t{++} exception.
c906108c
SS
3324
3325@item exec
4644b6e3 3326@cindex break on fork/exec
c906108c
SS
3327A call to @code{exec}. This is currently only available for HP-UX.
3328
3329@item fork
c906108c
SS
3330A call to @code{fork}. This is currently only available for HP-UX.
3331
3332@item vfork
c906108c
SS
3333A call to @code{vfork}. This is currently only available for HP-UX.
3334
3335@item load
3336@itemx load @var{libname}
4644b6e3 3337@cindex break on load/unload of shared library
c906108c
SS
3338The dynamic loading of any shared library, or the loading of the library
3339@var{libname}. This is currently only available for HP-UX.
3340
3341@item unload
3342@itemx unload @var{libname}
c906108c
SS
3343The unloading of any dynamically loaded shared library, or the unloading
3344of the library @var{libname}. This is currently only available for HP-UX.
3345@end table
3346
3347@item tcatch @var{event}
3348Set a catchpoint that is enabled only for one stop. The catchpoint is
3349automatically deleted after the first time the event is caught.
3350
3351@end table
3352
3353Use the @code{info break} command to list the current catchpoints.
3354
b37052ae 3355There are currently some limitations to C@t{++} exception handling
c906108c
SS
3356(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3357
3358@itemize @bullet
3359@item
3360If you call a function interactively, @value{GDBN} normally returns
3361control to you when the function has finished executing. If the call
3362raises an exception, however, the call may bypass the mechanism that
3363returns control to you and cause your program either to abort or to
3364simply continue running until it hits a breakpoint, catches a signal
3365that @value{GDBN} is listening for, or exits. This is the case even if
3366you set a catchpoint for the exception; catchpoints on exceptions are
3367disabled within interactive calls.
3368
3369@item
3370You cannot raise an exception interactively.
3371
3372@item
3373You cannot install an exception handler interactively.
3374@end itemize
3375
3376@cindex raise exceptions
3377Sometimes @code{catch} is not the best way to debug exception handling:
3378if you need to know exactly where an exception is raised, it is better to
3379stop @emph{before} the exception handler is called, since that way you
3380can see the stack before any unwinding takes place. If you set a
3381breakpoint in an exception handler instead, it may not be easy to find
3382out where the exception was raised.
3383
3384To stop just before an exception handler is called, you need some
b37052ae 3385knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3386raised by calling a library function named @code{__raise_exception}
3387which has the following ANSI C interface:
3388
474c8240 3389@smallexample
c906108c 3390 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3391 @var{id} is the exception identifier. */
3392 void __raise_exception (void **addr, void *id);
474c8240 3393@end smallexample
c906108c
SS
3394
3395@noindent
3396To make the debugger catch all exceptions before any stack
3397unwinding takes place, set a breakpoint on @code{__raise_exception}
3398(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3399
3400With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3401that depends on the value of @var{id}, you can stop your program when
3402a specific exception is raised. You can use multiple conditional
3403breakpoints to stop your program when any of a number of exceptions are
3404raised.
3405
3406
6d2ebf8b 3407@node Delete Breaks
c906108c
SS
3408@subsection Deleting breakpoints
3409
3410@cindex clearing breakpoints, watchpoints, catchpoints
3411@cindex deleting breakpoints, watchpoints, catchpoints
3412It is often necessary to eliminate a breakpoint, watchpoint, or
3413catchpoint once it has done its job and you no longer want your program
3414to stop there. This is called @dfn{deleting} the breakpoint. A
3415breakpoint that has been deleted no longer exists; it is forgotten.
3416
3417With the @code{clear} command you can delete breakpoints according to
3418where they are in your program. With the @code{delete} command you can
3419delete individual breakpoints, watchpoints, or catchpoints by specifying
3420their breakpoint numbers.
3421
3422It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3423automatically ignores breakpoints on the first instruction to be executed
3424when you continue execution without changing the execution address.
3425
3426@table @code
3427@kindex clear
3428@item clear
3429Delete any breakpoints at the next instruction to be executed in the
3430selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3431the innermost frame is selected, this is a good way to delete a
3432breakpoint where your program just stopped.
3433
3434@item clear @var{function}
3435@itemx clear @var{filename}:@var{function}
09d4efe1 3436Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3437
3438@item clear @var{linenum}
3439@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3440Delete any breakpoints set at or within the code of the specified
3441@var{linenum} of the specified @var{filename}.
c906108c
SS
3442
3443@cindex delete breakpoints
3444@kindex delete
41afff9a 3445@kindex d @r{(@code{delete})}
c5394b80
JM
3446@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3447Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3448ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3449breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3450confirm off}). You can abbreviate this command as @code{d}.
3451@end table
3452
6d2ebf8b 3453@node Disabling
c906108c
SS
3454@subsection Disabling breakpoints
3455
4644b6e3 3456@cindex enable/disable a breakpoint
c906108c
SS
3457Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3458prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3459it had been deleted, but remembers the information on the breakpoint so
3460that you can @dfn{enable} it again later.
3461
3462You disable and enable breakpoints, watchpoints, and catchpoints with
3463the @code{enable} and @code{disable} commands, optionally specifying one
3464or more breakpoint numbers as arguments. Use @code{info break} or
3465@code{info watch} to print a list of breakpoints, watchpoints, and
3466catchpoints if you do not know which numbers to use.
3467
3468A breakpoint, watchpoint, or catchpoint can have any of four different
3469states of enablement:
3470
3471@itemize @bullet
3472@item
3473Enabled. The breakpoint stops your program. A breakpoint set
3474with the @code{break} command starts out in this state.
3475@item
3476Disabled. The breakpoint has no effect on your program.
3477@item
3478Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3479disabled.
c906108c
SS
3480@item
3481Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3482immediately after it does so it is deleted permanently. A breakpoint
3483set with the @code{tbreak} command starts out in this state.
c906108c
SS
3484@end itemize
3485
3486You can use the following commands to enable or disable breakpoints,
3487watchpoints, and catchpoints:
3488
3489@table @code
c906108c 3490@kindex disable
41afff9a 3491@kindex dis @r{(@code{disable})}
c5394b80 3492@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3493Disable the specified breakpoints---or all breakpoints, if none are
3494listed. A disabled breakpoint has no effect but is not forgotten. All
3495options such as ignore-counts, conditions and commands are remembered in
3496case the breakpoint is enabled again later. You may abbreviate
3497@code{disable} as @code{dis}.
3498
c906108c 3499@kindex enable
c5394b80 3500@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3501Enable the specified breakpoints (or all defined breakpoints). They
3502become effective once again in stopping your program.
3503
c5394b80 3504@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3505Enable the specified breakpoints temporarily. @value{GDBN} disables any
3506of these breakpoints immediately after stopping your program.
3507
c5394b80 3508@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3509Enable the specified breakpoints to work once, then die. @value{GDBN}
3510deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3511Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3512@end table
3513
d4f3574e
SS
3514@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3515@c confusing: tbreak is also initially enabled.
c906108c
SS
3516Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3517,Setting breakpoints}), breakpoints that you set are initially enabled;
3518subsequently, they become disabled or enabled only when you use one of
3519the commands above. (The command @code{until} can set and delete a
3520breakpoint of its own, but it does not change the state of your other
3521breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3522stepping}.)
3523
6d2ebf8b 3524@node Conditions
c906108c
SS
3525@subsection Break conditions
3526@cindex conditional breakpoints
3527@cindex breakpoint conditions
3528
3529@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3530@c in particular for a watchpoint?
c906108c
SS
3531The simplest sort of breakpoint breaks every time your program reaches a
3532specified place. You can also specify a @dfn{condition} for a
3533breakpoint. A condition is just a Boolean expression in your
3534programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3535a condition evaluates the expression each time your program reaches it,
3536and your program stops only if the condition is @emph{true}.
3537
3538This is the converse of using assertions for program validation; in that
3539situation, you want to stop when the assertion is violated---that is,
3540when the condition is false. In C, if you want to test an assertion expressed
3541by the condition @var{assert}, you should set the condition
3542@samp{! @var{assert}} on the appropriate breakpoint.
3543
3544Conditions are also accepted for watchpoints; you may not need them,
3545since a watchpoint is inspecting the value of an expression anyhow---but
3546it might be simpler, say, to just set a watchpoint on a variable name,
3547and specify a condition that tests whether the new value is an interesting
3548one.
3549
3550Break conditions can have side effects, and may even call functions in
3551your program. This can be useful, for example, to activate functions
3552that log program progress, or to use your own print functions to
3553format special data structures. The effects are completely predictable
3554unless there is another enabled breakpoint at the same address. (In
3555that case, @value{GDBN} might see the other breakpoint first and stop your
3556program without checking the condition of this one.) Note that
d4f3574e
SS
3557breakpoint commands are usually more convenient and flexible than break
3558conditions for the
c906108c
SS
3559purpose of performing side effects when a breakpoint is reached
3560(@pxref{Break Commands, ,Breakpoint command lists}).
3561
3562Break conditions can be specified when a breakpoint is set, by using
3563@samp{if} in the arguments to the @code{break} command. @xref{Set
3564Breaks, ,Setting breakpoints}. They can also be changed at any time
3565with the @code{condition} command.
53a5351d 3566
c906108c
SS
3567You can also use the @code{if} keyword with the @code{watch} command.
3568The @code{catch} command does not recognize the @code{if} keyword;
3569@code{condition} is the only way to impose a further condition on a
3570catchpoint.
c906108c
SS
3571
3572@table @code
3573@kindex condition
3574@item condition @var{bnum} @var{expression}
3575Specify @var{expression} as the break condition for breakpoint,
3576watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3577breakpoint @var{bnum} stops your program only if the value of
3578@var{expression} is true (nonzero, in C). When you use
3579@code{condition}, @value{GDBN} checks @var{expression} immediately for
3580syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3581referents in the context of your breakpoint. If @var{expression} uses
3582symbols not referenced in the context of the breakpoint, @value{GDBN}
3583prints an error message:
3584
474c8240 3585@smallexample
d4f3574e 3586No symbol "foo" in current context.
474c8240 3587@end smallexample
d4f3574e
SS
3588
3589@noindent
c906108c
SS
3590@value{GDBN} does
3591not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3592command (or a command that sets a breakpoint with a condition, like
3593@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3594
3595@item condition @var{bnum}
3596Remove the condition from breakpoint number @var{bnum}. It becomes
3597an ordinary unconditional breakpoint.
3598@end table
3599
3600@cindex ignore count (of breakpoint)
3601A special case of a breakpoint condition is to stop only when the
3602breakpoint has been reached a certain number of times. This is so
3603useful that there is a special way to do it, using the @dfn{ignore
3604count} of the breakpoint. Every breakpoint has an ignore count, which
3605is an integer. Most of the time, the ignore count is zero, and
3606therefore has no effect. But if your program reaches a breakpoint whose
3607ignore count is positive, then instead of stopping, it just decrements
3608the ignore count by one and continues. As a result, if the ignore count
3609value is @var{n}, the breakpoint does not stop the next @var{n} times
3610your program reaches it.
3611
3612@table @code
3613@kindex ignore
3614@item ignore @var{bnum} @var{count}
3615Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3616The next @var{count} times the breakpoint is reached, your program's
3617execution does not stop; other than to decrement the ignore count, @value{GDBN}
3618takes no action.
3619
3620To make the breakpoint stop the next time it is reached, specify
3621a count of zero.
3622
3623When you use @code{continue} to resume execution of your program from a
3624breakpoint, you can specify an ignore count directly as an argument to
3625@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3626Stepping,,Continuing and stepping}.
3627
3628If a breakpoint has a positive ignore count and a condition, the
3629condition is not checked. Once the ignore count reaches zero,
3630@value{GDBN} resumes checking the condition.
3631
3632You could achieve the effect of the ignore count with a condition such
3633as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3634is decremented each time. @xref{Convenience Vars, ,Convenience
3635variables}.
3636@end table
3637
3638Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3639
3640
6d2ebf8b 3641@node Break Commands
c906108c
SS
3642@subsection Breakpoint command lists
3643
3644@cindex breakpoint commands
3645You can give any breakpoint (or watchpoint or catchpoint) a series of
3646commands to execute when your program stops due to that breakpoint. For
3647example, you might want to print the values of certain expressions, or
3648enable other breakpoints.
3649
3650@table @code
3651@kindex commands
ca91424e 3652@kindex end@r{ (breakpoint commands)}
c906108c
SS
3653@item commands @r{[}@var{bnum}@r{]}
3654@itemx @dots{} @var{command-list} @dots{}
3655@itemx end
3656Specify a list of commands for breakpoint number @var{bnum}. The commands
3657themselves appear on the following lines. Type a line containing just
3658@code{end} to terminate the commands.
3659
3660To remove all commands from a breakpoint, type @code{commands} and
3661follow it immediately with @code{end}; that is, give no commands.
3662
3663With no @var{bnum} argument, @code{commands} refers to the last
3664breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3665recently encountered).
3666@end table
3667
3668Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3669disabled within a @var{command-list}.
3670
3671You can use breakpoint commands to start your program up again. Simply
3672use the @code{continue} command, or @code{step}, or any other command
3673that resumes execution.
3674
3675Any other commands in the command list, after a command that resumes
3676execution, are ignored. This is because any time you resume execution
3677(even with a simple @code{next} or @code{step}), you may encounter
3678another breakpoint---which could have its own command list, leading to
3679ambiguities about which list to execute.
3680
3681@kindex silent
3682If the first command you specify in a command list is @code{silent}, the
3683usual message about stopping at a breakpoint is not printed. This may
3684be desirable for breakpoints that are to print a specific message and
3685then continue. If none of the remaining commands print anything, you
3686see no sign that the breakpoint was reached. @code{silent} is
3687meaningful only at the beginning of a breakpoint command list.
3688
3689The commands @code{echo}, @code{output}, and @code{printf} allow you to
3690print precisely controlled output, and are often useful in silent
3691breakpoints. @xref{Output, ,Commands for controlled output}.
3692
3693For example, here is how you could use breakpoint commands to print the
3694value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3695
474c8240 3696@smallexample
c906108c
SS
3697break foo if x>0
3698commands
3699silent
3700printf "x is %d\n",x
3701cont
3702end
474c8240 3703@end smallexample
c906108c
SS
3704
3705One application for breakpoint commands is to compensate for one bug so
3706you can test for another. Put a breakpoint just after the erroneous line
3707of code, give it a condition to detect the case in which something
3708erroneous has been done, and give it commands to assign correct values
3709to any variables that need them. End with the @code{continue} command
3710so that your program does not stop, and start with the @code{silent}
3711command so that no output is produced. Here is an example:
3712
474c8240 3713@smallexample
c906108c
SS
3714break 403
3715commands
3716silent
3717set x = y + 4
3718cont
3719end
474c8240 3720@end smallexample
c906108c 3721
6d2ebf8b 3722@node Breakpoint Menus
c906108c
SS
3723@subsection Breakpoint menus
3724@cindex overloading
3725@cindex symbol overloading
3726
b383017d 3727Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3728single function name
c906108c
SS
3729to be defined several times, for application in different contexts.
3730This is called @dfn{overloading}. When a function name is overloaded,
3731@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3732a breakpoint. If you realize this is a problem, you can use
3733something like @samp{break @var{function}(@var{types})} to specify which
3734particular version of the function you want. Otherwise, @value{GDBN} offers
3735you a menu of numbered choices for different possible breakpoints, and
3736waits for your selection with the prompt @samp{>}. The first two
3737options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3738sets a breakpoint at each definition of @var{function}, and typing
3739@kbd{0} aborts the @code{break} command without setting any new
3740breakpoints.
3741
3742For example, the following session excerpt shows an attempt to set a
3743breakpoint at the overloaded symbol @code{String::after}.
3744We choose three particular definitions of that function name:
3745
3746@c FIXME! This is likely to change to show arg type lists, at least
3747@smallexample
3748@group
3749(@value{GDBP}) b String::after
3750[0] cancel
3751[1] all
3752[2] file:String.cc; line number:867
3753[3] file:String.cc; line number:860
3754[4] file:String.cc; line number:875
3755[5] file:String.cc; line number:853
3756[6] file:String.cc; line number:846
3757[7] file:String.cc; line number:735
3758> 2 4 6
3759Breakpoint 1 at 0xb26c: file String.cc, line 867.
3760Breakpoint 2 at 0xb344: file String.cc, line 875.
3761Breakpoint 3 at 0xafcc: file String.cc, line 846.
3762Multiple breakpoints were set.
3763Use the "delete" command to delete unwanted
3764 breakpoints.
3765(@value{GDBP})
3766@end group
3767@end smallexample
c906108c
SS
3768
3769@c @ifclear BARETARGET
6d2ebf8b 3770@node Error in Breakpoints
d4f3574e 3771@subsection ``Cannot insert breakpoints''
c906108c
SS
3772@c
3773@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3774@c
d4f3574e
SS
3775Under some operating systems, breakpoints cannot be used in a program if
3776any other process is running that program. In this situation,
5d161b24 3777attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3778@value{GDBN} to print an error message:
3779
474c8240 3780@smallexample
d4f3574e
SS
3781Cannot insert breakpoints.
3782The same program may be running in another process.
474c8240 3783@end smallexample
d4f3574e
SS
3784
3785When this happens, you have three ways to proceed:
3786
3787@enumerate
3788@item
3789Remove or disable the breakpoints, then continue.
3790
3791@item
5d161b24 3792Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3793name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3794that @value{GDBN} should run your program under that name.
d4f3574e
SS
3795Then start your program again.
3796
3797@item
3798Relink your program so that the text segment is nonsharable, using the
3799linker option @samp{-N}. The operating system limitation may not apply
3800to nonsharable executables.
3801@end enumerate
c906108c
SS
3802@c @end ifclear
3803
d4f3574e
SS
3804A similar message can be printed if you request too many active
3805hardware-assisted breakpoints and watchpoints:
3806
3807@c FIXME: the precise wording of this message may change; the relevant
3808@c source change is not committed yet (Sep 3, 1999).
3809@smallexample
3810Stopped; cannot insert breakpoints.
3811You may have requested too many hardware breakpoints and watchpoints.
3812@end smallexample
3813
3814@noindent
3815This message is printed when you attempt to resume the program, since
3816only then @value{GDBN} knows exactly how many hardware breakpoints and
3817watchpoints it needs to insert.
3818
3819When this message is printed, you need to disable or remove some of the
3820hardware-assisted breakpoints and watchpoints, and then continue.
3821
1485d690
KB
3822@node Breakpoint related warnings
3823@subsection ``Breakpoint address adjusted...''
3824@cindex breakpoint address adjusted
3825
3826Some processor architectures place constraints on the addresses at
3827which breakpoints may be placed. For architectures thus constrained,
3828@value{GDBN} will attempt to adjust the breakpoint's address to comply
3829with the constraints dictated by the architecture.
3830
3831One example of such an architecture is the Fujitsu FR-V. The FR-V is
3832a VLIW architecture in which a number of RISC-like instructions may be
3833bundled together for parallel execution. The FR-V architecture
3834constrains the location of a breakpoint instruction within such a
3835bundle to the instruction with the lowest address. @value{GDBN}
3836honors this constraint by adjusting a breakpoint's address to the
3837first in the bundle.
3838
3839It is not uncommon for optimized code to have bundles which contain
3840instructions from different source statements, thus it may happen that
3841a breakpoint's address will be adjusted from one source statement to
3842another. Since this adjustment may significantly alter @value{GDBN}'s
3843breakpoint related behavior from what the user expects, a warning is
3844printed when the breakpoint is first set and also when the breakpoint
3845is hit.
3846
3847A warning like the one below is printed when setting a breakpoint
3848that's been subject to address adjustment:
3849
3850@smallexample
3851warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3852@end smallexample
3853
3854Such warnings are printed both for user settable and @value{GDBN}'s
3855internal breakpoints. If you see one of these warnings, you should
3856verify that a breakpoint set at the adjusted address will have the
3857desired affect. If not, the breakpoint in question may be removed and
b383017d 3858other breakpoints may be set which will have the desired behavior.
1485d690
KB
3859E.g., it may be sufficient to place the breakpoint at a later
3860instruction. A conditional breakpoint may also be useful in some
3861cases to prevent the breakpoint from triggering too often.
3862
3863@value{GDBN} will also issue a warning when stopping at one of these
3864adjusted breakpoints:
3865
3866@smallexample
3867warning: Breakpoint 1 address previously adjusted from 0x00010414
3868to 0x00010410.
3869@end smallexample
3870
3871When this warning is encountered, it may be too late to take remedial
3872action except in cases where the breakpoint is hit earlier or more
3873frequently than expected.
d4f3574e 3874
6d2ebf8b 3875@node Continuing and Stepping
c906108c
SS
3876@section Continuing and stepping
3877
3878@cindex stepping
3879@cindex continuing
3880@cindex resuming execution
3881@dfn{Continuing} means resuming program execution until your program
3882completes normally. In contrast, @dfn{stepping} means executing just
3883one more ``step'' of your program, where ``step'' may mean either one
3884line of source code, or one machine instruction (depending on what
7a292a7a
SS
3885particular command you use). Either when continuing or when stepping,
3886your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3887it stops due to a signal, you may want to use @code{handle}, or use
3888@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3889
3890@table @code
3891@kindex continue
41afff9a
EZ
3892@kindex c @r{(@code{continue})}
3893@kindex fg @r{(resume foreground execution)}
c906108c
SS
3894@item continue @r{[}@var{ignore-count}@r{]}
3895@itemx c @r{[}@var{ignore-count}@r{]}
3896@itemx fg @r{[}@var{ignore-count}@r{]}
3897Resume program execution, at the address where your program last stopped;
3898any breakpoints set at that address are bypassed. The optional argument
3899@var{ignore-count} allows you to specify a further number of times to
3900ignore a breakpoint at this location; its effect is like that of
3901@code{ignore} (@pxref{Conditions, ,Break conditions}).
3902
3903The argument @var{ignore-count} is meaningful only when your program
3904stopped due to a breakpoint. At other times, the argument to
3905@code{continue} is ignored.
3906
d4f3574e
SS
3907The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3908debugged program is deemed to be the foreground program) are provided
3909purely for convenience, and have exactly the same behavior as
3910@code{continue}.
c906108c
SS
3911@end table
3912
3913To resume execution at a different place, you can use @code{return}
3914(@pxref{Returning, ,Returning from a function}) to go back to the
3915calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3916different address}) to go to an arbitrary location in your program.
3917
3918A typical technique for using stepping is to set a breakpoint
3919(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3920beginning of the function or the section of your program where a problem
3921is believed to lie, run your program until it stops at that breakpoint,
3922and then step through the suspect area, examining the variables that are
3923interesting, until you see the problem happen.
3924
3925@table @code
3926@kindex step
41afff9a 3927@kindex s @r{(@code{step})}
c906108c
SS
3928@item step
3929Continue running your program until control reaches a different source
3930line, then stop it and return control to @value{GDBN}. This command is
3931abbreviated @code{s}.
3932
3933@quotation
3934@c "without debugging information" is imprecise; actually "without line
3935@c numbers in the debugging information". (gcc -g1 has debugging info but
3936@c not line numbers). But it seems complex to try to make that
3937@c distinction here.
3938@emph{Warning:} If you use the @code{step} command while control is
3939within a function that was compiled without debugging information,
3940execution proceeds until control reaches a function that does have
3941debugging information. Likewise, it will not step into a function which
3942is compiled without debugging information. To step through functions
3943without debugging information, use the @code{stepi} command, described
3944below.
3945@end quotation
3946
4a92d011
EZ
3947The @code{step} command only stops at the first instruction of a source
3948line. This prevents the multiple stops that could otherwise occur in
3949@code{switch} statements, @code{for} loops, etc. @code{step} continues
3950to stop if a function that has debugging information is called within
3951the line. In other words, @code{step} @emph{steps inside} any functions
3952called within the line.
c906108c 3953
d4f3574e
SS
3954Also, the @code{step} command only enters a function if there is line
3955number information for the function. Otherwise it acts like the
5d161b24 3956@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3957on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3958was any debugging information about the routine.
c906108c
SS
3959
3960@item step @var{count}
3961Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3962breakpoint is reached, or a signal not related to stepping occurs before
3963@var{count} steps, stepping stops right away.
c906108c
SS
3964
3965@kindex next
41afff9a 3966@kindex n @r{(@code{next})}
c906108c
SS
3967@item next @r{[}@var{count}@r{]}
3968Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3969This is similar to @code{step}, but function calls that appear within
3970the line of code are executed without stopping. Execution stops when
3971control reaches a different line of code at the original stack level
3972that was executing when you gave the @code{next} command. This command
3973is abbreviated @code{n}.
c906108c
SS
3974
3975An argument @var{count} is a repeat count, as for @code{step}.
3976
3977
3978@c FIX ME!! Do we delete this, or is there a way it fits in with
3979@c the following paragraph? --- Vctoria
3980@c
3981@c @code{next} within a function that lacks debugging information acts like
3982@c @code{step}, but any function calls appearing within the code of the
3983@c function are executed without stopping.
3984
d4f3574e
SS
3985The @code{next} command only stops at the first instruction of a
3986source line. This prevents multiple stops that could otherwise occur in
4a92d011 3987@code{switch} statements, @code{for} loops, etc.
c906108c 3988
b90a5f51
CF
3989@kindex set step-mode
3990@item set step-mode
3991@cindex functions without line info, and stepping
3992@cindex stepping into functions with no line info
3993@itemx set step-mode on
4a92d011 3994The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3995stop at the first instruction of a function which contains no debug line
3996information rather than stepping over it.
3997
4a92d011
EZ
3998This is useful in cases where you may be interested in inspecting the
3999machine instructions of a function which has no symbolic info and do not
4000want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
4001
4002@item set step-mode off
4a92d011 4003Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
4004debug information. This is the default.
4005
9c16f35a
EZ
4006@item show step-mode
4007Show whether @value{GDBN} will stop in or step over functions without
4008source line debug information.
4009
c906108c
SS
4010@kindex finish
4011@item finish
4012Continue running until just after function in the selected stack frame
4013returns. Print the returned value (if any).
4014
4015Contrast this with the @code{return} command (@pxref{Returning,
4016,Returning from a function}).
4017
4018@kindex until
41afff9a 4019@kindex u @r{(@code{until})}
09d4efe1 4020@cindex run until specified location
c906108c
SS
4021@item until
4022@itemx u
4023Continue running until a source line past the current line, in the
4024current stack frame, is reached. This command is used to avoid single
4025stepping through a loop more than once. It is like the @code{next}
4026command, except that when @code{until} encounters a jump, it
4027automatically continues execution until the program counter is greater
4028than the address of the jump.
4029
4030This means that when you reach the end of a loop after single stepping
4031though it, @code{until} makes your program continue execution until it
4032exits the loop. In contrast, a @code{next} command at the end of a loop
4033simply steps back to the beginning of the loop, which forces you to step
4034through the next iteration.
4035
4036@code{until} always stops your program if it attempts to exit the current
4037stack frame.
4038
4039@code{until} may produce somewhat counterintuitive results if the order
4040of machine code does not match the order of the source lines. For
4041example, in the following excerpt from a debugging session, the @code{f}
4042(@code{frame}) command shows that execution is stopped at line
4043@code{206}; yet when we use @code{until}, we get to line @code{195}:
4044
474c8240 4045@smallexample
c906108c
SS
4046(@value{GDBP}) f
4047#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4048206 expand_input();
4049(@value{GDBP}) until
4050195 for ( ; argc > 0; NEXTARG) @{
474c8240 4051@end smallexample
c906108c
SS
4052
4053This happened because, for execution efficiency, the compiler had
4054generated code for the loop closure test at the end, rather than the
4055start, of the loop---even though the test in a C @code{for}-loop is
4056written before the body of the loop. The @code{until} command appeared
4057to step back to the beginning of the loop when it advanced to this
4058expression; however, it has not really gone to an earlier
4059statement---not in terms of the actual machine code.
4060
4061@code{until} with no argument works by means of single
4062instruction stepping, and hence is slower than @code{until} with an
4063argument.
4064
4065@item until @var{location}
4066@itemx u @var{location}
4067Continue running your program until either the specified location is
4068reached, or the current stack frame returns. @var{location} is any of
4069the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
4070,Setting breakpoints}). This form of the command uses breakpoints, and
4071hence is quicker than @code{until} without an argument. The specified
4072location is actually reached only if it is in the current frame. This
4073implies that @code{until} can be used to skip over recursive function
4074invocations. For instance in the code below, if the current location is
4075line @code{96}, issuing @code{until 99} will execute the program up to
4076line @code{99} in the same invocation of factorial, i.e. after the inner
4077invocations have returned.
4078
4079@smallexample
408094 int factorial (int value)
408195 @{
408296 if (value > 1) @{
408397 value *= factorial (value - 1);
408498 @}
408599 return (value);
4086100 @}
4087@end smallexample
4088
4089
4090@kindex advance @var{location}
4091@itemx advance @var{location}
09d4efe1
EZ
4092Continue running the program up to the given @var{location}. An argument is
4093required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
4094command. Execution will also stop upon exit from the current stack
4095frame. This command is similar to @code{until}, but @code{advance} will
4096not skip over recursive function calls, and the target location doesn't
4097have to be in the same frame as the current one.
4098
c906108c
SS
4099
4100@kindex stepi
41afff9a 4101@kindex si @r{(@code{stepi})}
c906108c 4102@item stepi
96a2c332 4103@itemx stepi @var{arg}
c906108c
SS
4104@itemx si
4105Execute one machine instruction, then stop and return to the debugger.
4106
4107It is often useful to do @samp{display/i $pc} when stepping by machine
4108instructions. This makes @value{GDBN} automatically display the next
4109instruction to be executed, each time your program stops. @xref{Auto
4110Display,, Automatic display}.
4111
4112An argument is a repeat count, as in @code{step}.
4113
4114@need 750
4115@kindex nexti
41afff9a 4116@kindex ni @r{(@code{nexti})}
c906108c 4117@item nexti
96a2c332 4118@itemx nexti @var{arg}
c906108c
SS
4119@itemx ni
4120Execute one machine instruction, but if it is a function call,
4121proceed until the function returns.
4122
4123An argument is a repeat count, as in @code{next}.
4124@end table
4125
6d2ebf8b 4126@node Signals
c906108c
SS
4127@section Signals
4128@cindex signals
4129
4130A signal is an asynchronous event that can happen in a program. The
4131operating system defines the possible kinds of signals, and gives each
4132kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 4133signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
4134@code{SIGSEGV} is the signal a program gets from referencing a place in
4135memory far away from all the areas in use; @code{SIGALRM} occurs when
4136the alarm clock timer goes off (which happens only if your program has
4137requested an alarm).
4138
4139@cindex fatal signals
4140Some signals, including @code{SIGALRM}, are a normal part of the
4141functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 4142errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
4143program has not specified in advance some other way to handle the signal.
4144@code{SIGINT} does not indicate an error in your program, but it is normally
4145fatal so it can carry out the purpose of the interrupt: to kill the program.
4146
4147@value{GDBN} has the ability to detect any occurrence of a signal in your
4148program. You can tell @value{GDBN} in advance what to do for each kind of
4149signal.
4150
4151@cindex handling signals
24f93129
EZ
4152Normally, @value{GDBN} is set up to let the non-erroneous signals like
4153@code{SIGALRM} be silently passed to your program
4154(so as not to interfere with their role in the program's functioning)
c906108c
SS
4155but to stop your program immediately whenever an error signal happens.
4156You can change these settings with the @code{handle} command.
4157
4158@table @code
4159@kindex info signals
09d4efe1 4160@kindex info handle
c906108c 4161@item info signals
96a2c332 4162@itemx info handle
c906108c
SS
4163Print a table of all the kinds of signals and how @value{GDBN} has been told to
4164handle each one. You can use this to see the signal numbers of all
4165the defined types of signals.
4166
45ac1734
EZ
4167@item info signals @var{sig}
4168Similar, but print information only about the specified signal number.
4169
d4f3574e 4170@code{info handle} is an alias for @code{info signals}.
c906108c
SS
4171
4172@kindex handle
45ac1734 4173@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
4174Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4175can be the number of a signal or its name (with or without the
24f93129 4176@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 4177@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
4178known signals. Optional arguments @var{keywords}, described below,
4179say what change to make.
c906108c
SS
4180@end table
4181
4182@c @group
4183The keywords allowed by the @code{handle} command can be abbreviated.
4184Their full names are:
4185
4186@table @code
4187@item nostop
4188@value{GDBN} should not stop your program when this signal happens. It may
4189still print a message telling you that the signal has come in.
4190
4191@item stop
4192@value{GDBN} should stop your program when this signal happens. This implies
4193the @code{print} keyword as well.
4194
4195@item print
4196@value{GDBN} should print a message when this signal happens.
4197
4198@item noprint
4199@value{GDBN} should not mention the occurrence of the signal at all. This
4200implies the @code{nostop} keyword as well.
4201
4202@item pass
5ece1a18 4203@itemx noignore
c906108c
SS
4204@value{GDBN} should allow your program to see this signal; your program
4205can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 4206and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
4207
4208@item nopass
5ece1a18 4209@itemx ignore
c906108c 4210@value{GDBN} should not allow your program to see this signal.
5ece1a18 4211@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
4212@end table
4213@c @end group
4214
d4f3574e
SS
4215When a signal stops your program, the signal is not visible to the
4216program until you
c906108c
SS
4217continue. Your program sees the signal then, if @code{pass} is in
4218effect for the signal in question @emph{at that time}. In other words,
4219after @value{GDBN} reports a signal, you can use the @code{handle}
4220command with @code{pass} or @code{nopass} to control whether your
4221program sees that signal when you continue.
4222
24f93129
EZ
4223The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4224non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4225@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4226erroneous signals.
4227
c906108c
SS
4228You can also use the @code{signal} command to prevent your program from
4229seeing a signal, or cause it to see a signal it normally would not see,
4230or to give it any signal at any time. For example, if your program stopped
4231due to some sort of memory reference error, you might store correct
4232values into the erroneous variables and continue, hoping to see more
4233execution; but your program would probably terminate immediately as
4234a result of the fatal signal once it saw the signal. To prevent this,
4235you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 4236program a signal}.
c906108c 4237
6d2ebf8b 4238@node Thread Stops
c906108c
SS
4239@section Stopping and starting multi-thread programs
4240
4241When your program has multiple threads (@pxref{Threads,, Debugging
4242programs with multiple threads}), you can choose whether to set
4243breakpoints on all threads, or on a particular thread.
4244
4245@table @code
4246@cindex breakpoints and threads
4247@cindex thread breakpoints
4248@kindex break @dots{} thread @var{threadno}
4249@item break @var{linespec} thread @var{threadno}
4250@itemx break @var{linespec} thread @var{threadno} if @dots{}
4251@var{linespec} specifies source lines; there are several ways of
4252writing them, but the effect is always to specify some source line.
4253
4254Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4255to specify that you only want @value{GDBN} to stop the program when a
4256particular thread reaches this breakpoint. @var{threadno} is one of the
4257numeric thread identifiers assigned by @value{GDBN}, shown in the first
4258column of the @samp{info threads} display.
4259
4260If you do not specify @samp{thread @var{threadno}} when you set a
4261breakpoint, the breakpoint applies to @emph{all} threads of your
4262program.
4263
4264You can use the @code{thread} qualifier on conditional breakpoints as
4265well; in this case, place @samp{thread @var{threadno}} before the
4266breakpoint condition, like this:
4267
4268@smallexample
2df3850c 4269(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4270@end smallexample
4271
4272@end table
4273
4274@cindex stopped threads
4275@cindex threads, stopped
4276Whenever your program stops under @value{GDBN} for any reason,
4277@emph{all} threads of execution stop, not just the current thread. This
4278allows you to examine the overall state of the program, including
4279switching between threads, without worrying that things may change
4280underfoot.
4281
36d86913
MC
4282@cindex thread breakpoints and system calls
4283@cindex system calls and thread breakpoints
4284@cindex premature return from system calls
4285There is an unfortunate side effect. If one thread stops for a
4286breakpoint, or for some other reason, and another thread is blocked in a
4287system call, then the system call may return prematurely. This is a
4288consequence of the interaction between multiple threads and the signals
4289that @value{GDBN} uses to implement breakpoints and other events that
4290stop execution.
4291
4292To handle this problem, your program should check the return value of
4293each system call and react appropriately. This is good programming
4294style anyways.
4295
4296For example, do not write code like this:
4297
4298@smallexample
4299 sleep (10);
4300@end smallexample
4301
4302The call to @code{sleep} will return early if a different thread stops
4303at a breakpoint or for some other reason.
4304
4305Instead, write this:
4306
4307@smallexample
4308 int unslept = 10;
4309 while (unslept > 0)
4310 unslept = sleep (unslept);
4311@end smallexample
4312
4313A system call is allowed to return early, so the system is still
4314conforming to its specification. But @value{GDBN} does cause your
4315multi-threaded program to behave differently than it would without
4316@value{GDBN}.
4317
4318Also, @value{GDBN} uses internal breakpoints in the thread library to
4319monitor certain events such as thread creation and thread destruction.
4320When such an event happens, a system call in another thread may return
4321prematurely, even though your program does not appear to stop.
4322
c906108c
SS
4323@cindex continuing threads
4324@cindex threads, continuing
4325Conversely, whenever you restart the program, @emph{all} threads start
4326executing. @emph{This is true even when single-stepping} with commands
5d161b24 4327like @code{step} or @code{next}.
c906108c
SS
4328
4329In particular, @value{GDBN} cannot single-step all threads in lockstep.
4330Since thread scheduling is up to your debugging target's operating
4331system (not controlled by @value{GDBN}), other threads may
4332execute more than one statement while the current thread completes a
4333single step. Moreover, in general other threads stop in the middle of a
4334statement, rather than at a clean statement boundary, when the program
4335stops.
4336
4337You might even find your program stopped in another thread after
4338continuing or even single-stepping. This happens whenever some other
4339thread runs into a breakpoint, a signal, or an exception before the
4340first thread completes whatever you requested.
4341
4342On some OSes, you can lock the OS scheduler and thus allow only a single
4343thread to run.
4344
4345@table @code
4346@item set scheduler-locking @var{mode}
9c16f35a
EZ
4347@cindex scheduler locking mode
4348@cindex lock scheduler
c906108c
SS
4349Set the scheduler locking mode. If it is @code{off}, then there is no
4350locking and any thread may run at any time. If @code{on}, then only the
4351current thread may run when the inferior is resumed. The @code{step}
4352mode optimizes for single-stepping. It stops other threads from
4353``seizing the prompt'' by preempting the current thread while you are
4354stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4355when you step. They are more likely to run when you @samp{next} over a
c906108c 4356function call, and they are completely free to run when you use commands
d4f3574e 4357like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4358thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4359@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4360
4361@item show scheduler-locking
4362Display the current scheduler locking mode.
4363@end table
4364
c906108c 4365
6d2ebf8b 4366@node Stack
c906108c
SS
4367@chapter Examining the Stack
4368
4369When your program has stopped, the first thing you need to know is where it
4370stopped and how it got there.
4371
4372@cindex call stack
5d161b24
DB
4373Each time your program performs a function call, information about the call
4374is generated.
4375That information includes the location of the call in your program,
4376the arguments of the call,
c906108c 4377and the local variables of the function being called.
5d161b24 4378The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4379The stack frames are allocated in a region of memory called the @dfn{call
4380stack}.
4381
4382When your program stops, the @value{GDBN} commands for examining the
4383stack allow you to see all of this information.
4384
4385@cindex selected frame
4386One of the stack frames is @dfn{selected} by @value{GDBN} and many
4387@value{GDBN} commands refer implicitly to the selected frame. In
4388particular, whenever you ask @value{GDBN} for the value of a variable in
4389your program, the value is found in the selected frame. There are
4390special @value{GDBN} commands to select whichever frame you are
4391interested in. @xref{Selection, ,Selecting a frame}.
4392
4393When your program stops, @value{GDBN} automatically selects the
5d161b24 4394currently executing frame and describes it briefly, similar to the
c906108c
SS
4395@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4396
4397@menu
4398* Frames:: Stack frames
4399* Backtrace:: Backtraces
4400* Selection:: Selecting a frame
4401* Frame Info:: Information on a frame
c906108c
SS
4402
4403@end menu
4404
6d2ebf8b 4405@node Frames
c906108c
SS
4406@section Stack frames
4407
d4f3574e 4408@cindex frame, definition
c906108c
SS
4409@cindex stack frame
4410The call stack is divided up into contiguous pieces called @dfn{stack
4411frames}, or @dfn{frames} for short; each frame is the data associated
4412with one call to one function. The frame contains the arguments given
4413to the function, the function's local variables, and the address at
4414which the function is executing.
4415
4416@cindex initial frame
4417@cindex outermost frame
4418@cindex innermost frame
4419When your program is started, the stack has only one frame, that of the
4420function @code{main}. This is called the @dfn{initial} frame or the
4421@dfn{outermost} frame. Each time a function is called, a new frame is
4422made. Each time a function returns, the frame for that function invocation
4423is eliminated. If a function is recursive, there can be many frames for
4424the same function. The frame for the function in which execution is
4425actually occurring is called the @dfn{innermost} frame. This is the most
4426recently created of all the stack frames that still exist.
4427
4428@cindex frame pointer
4429Inside your program, stack frames are identified by their addresses. A
4430stack frame consists of many bytes, each of which has its own address; each
4431kind of computer has a convention for choosing one byte whose
4432address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4433in a register called the @dfn{frame pointer register}
4434(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4435
4436@cindex frame number
4437@value{GDBN} assigns numbers to all existing stack frames, starting with
4438zero for the innermost frame, one for the frame that called it,
4439and so on upward. These numbers do not really exist in your program;
4440they are assigned by @value{GDBN} to give you a way of designating stack
4441frames in @value{GDBN} commands.
4442
6d2ebf8b
SS
4443@c The -fomit-frame-pointer below perennially causes hbox overflow
4444@c underflow problems.
c906108c
SS
4445@cindex frameless execution
4446Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4447without stack frames. (For example, the @value{GCC} option
474c8240 4448@smallexample
6d2ebf8b 4449@samp{-fomit-frame-pointer}
474c8240 4450@end smallexample
6d2ebf8b 4451generates functions without a frame.)
c906108c
SS
4452This is occasionally done with heavily used library functions to save
4453the frame setup time. @value{GDBN} has limited facilities for dealing
4454with these function invocations. If the innermost function invocation
4455has no stack frame, @value{GDBN} nevertheless regards it as though
4456it had a separate frame, which is numbered zero as usual, allowing
4457correct tracing of the function call chain. However, @value{GDBN} has
4458no provision for frameless functions elsewhere in the stack.
4459
4460@table @code
d4f3574e 4461@kindex frame@r{, command}
41afff9a 4462@cindex current stack frame
c906108c 4463@item frame @var{args}
5d161b24 4464The @code{frame} command allows you to move from one stack frame to another,
c906108c 4465and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4466address of the frame or the stack frame number. Without an argument,
4467@code{frame} prints the current stack frame.
c906108c
SS
4468
4469@kindex select-frame
41afff9a 4470@cindex selecting frame silently
c906108c
SS
4471@item select-frame
4472The @code{select-frame} command allows you to move from one stack frame
4473to another without printing the frame. This is the silent version of
4474@code{frame}.
4475@end table
4476
6d2ebf8b 4477@node Backtrace
c906108c
SS
4478@section Backtraces
4479
09d4efe1
EZ
4480@cindex traceback
4481@cindex call stack traces
c906108c
SS
4482A backtrace is a summary of how your program got where it is. It shows one
4483line per frame, for many frames, starting with the currently executing
4484frame (frame zero), followed by its caller (frame one), and on up the
4485stack.
4486
4487@table @code
4488@kindex backtrace
41afff9a 4489@kindex bt @r{(@code{backtrace})}
c906108c
SS
4490@item backtrace
4491@itemx bt
4492Print a backtrace of the entire stack: one line per frame for all
4493frames in the stack.
4494
4495You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 4496character, normally @kbd{Ctrl-c}.
c906108c
SS
4497
4498@item backtrace @var{n}
4499@itemx bt @var{n}
4500Similar, but print only the innermost @var{n} frames.
4501
4502@item backtrace -@var{n}
4503@itemx bt -@var{n}
4504Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4505
4506@item backtrace full
0f061b69 4507@itemx bt full
dd74f6ae
NR
4508@itemx bt full @var{n}
4509@itemx bt full -@var{n}
e7109c7e 4510Print the values of the local variables also. @var{n} specifies the
286ba84d 4511number of frames to print, as described above.
c906108c
SS
4512@end table
4513
4514@kindex where
4515@kindex info stack
c906108c
SS
4516The names @code{where} and @code{info stack} (abbreviated @code{info s})
4517are additional aliases for @code{backtrace}.
4518
839c27b7
EZ
4519@cindex multiple threads, backtrace
4520In a multi-threaded program, @value{GDBN} by default shows the
4521backtrace only for the current thread. To display the backtrace for
4522several or all of the threads, use the command @code{thread apply}
4523(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
4524apply all backtrace}, @value{GDBN} will display the backtrace for all
4525the threads; this is handy when you debug a core dump of a
4526multi-threaded program.
4527
c906108c
SS
4528Each line in the backtrace shows the frame number and the function name.
4529The program counter value is also shown---unless you use @code{set
4530print address off}. The backtrace also shows the source file name and
4531line number, as well as the arguments to the function. The program
4532counter value is omitted if it is at the beginning of the code for that
4533line number.
4534
4535Here is an example of a backtrace. It was made with the command
4536@samp{bt 3}, so it shows the innermost three frames.
4537
4538@smallexample
4539@group
5d161b24 4540#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4541 at builtin.c:993
4542#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4543#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4544 at macro.c:71
4545(More stack frames follow...)
4546@end group
4547@end smallexample
4548
4549@noindent
4550The display for frame zero does not begin with a program counter
4551value, indicating that your program has stopped at the beginning of the
4552code for line @code{993} of @code{builtin.c}.
4553
18999be5
EZ
4554@cindex value optimized out, in backtrace
4555@cindex function call arguments, optimized out
4556If your program was compiled with optimizations, some compilers will
4557optimize away arguments passed to functions if those arguments are
4558never used after the call. Such optimizations generate code that
4559passes arguments through registers, but doesn't store those arguments
4560in the stack frame. @value{GDBN} has no way of displaying such
4561arguments in stack frames other than the innermost one. Here's what
4562such a backtrace might look like:
4563
4564@smallexample
4565@group
4566#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4567 at builtin.c:993
4568#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4569#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4570 at macro.c:71
4571(More stack frames follow...)
4572@end group
4573@end smallexample
4574
4575@noindent
4576The values of arguments that were not saved in their stack frames are
4577shown as @samp{<value optimized out>}.
4578
4579If you need to display the values of such optimized-out arguments,
4580either deduce that from other variables whose values depend on the one
4581you are interested in, or recompile without optimizations.
4582
a8f24a35
EZ
4583@cindex backtrace beyond @code{main} function
4584@cindex program entry point
4585@cindex startup code, and backtrace
25d29d70
AC
4586Most programs have a standard user entry point---a place where system
4587libraries and startup code transition into user code. For C this is
d416eeec
EZ
4588@code{main}@footnote{
4589Note that embedded programs (the so-called ``free-standing''
4590environment) are not required to have a @code{main} function as the
4591entry point. They could even have multiple entry points.}.
4592When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4593it will terminate the backtrace, to avoid tracing into highly
4594system-specific (and generally uninteresting) code.
4595
4596If you need to examine the startup code, or limit the number of levels
4597in a backtrace, you can change this behavior:
95f90d25
DJ
4598
4599@table @code
25d29d70
AC
4600@item set backtrace past-main
4601@itemx set backtrace past-main on
4644b6e3 4602@kindex set backtrace
25d29d70
AC
4603Backtraces will continue past the user entry point.
4604
4605@item set backtrace past-main off
95f90d25
DJ
4606Backtraces will stop when they encounter the user entry point. This is the
4607default.
4608
25d29d70 4609@item show backtrace past-main
4644b6e3 4610@kindex show backtrace
25d29d70
AC
4611Display the current user entry point backtrace policy.
4612
2315ffec
RC
4613@item set backtrace past-entry
4614@itemx set backtrace past-entry on
a8f24a35 4615Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4616This entry point is encoded by the linker when the application is built,
4617and is likely before the user entry point @code{main} (or equivalent) is called.
4618
4619@item set backtrace past-entry off
4620Backtraces will stop when they encouter the internal entry point of an
4621application. This is the default.
4622
4623@item show backtrace past-entry
4624Display the current internal entry point backtrace policy.
4625
25d29d70
AC
4626@item set backtrace limit @var{n}
4627@itemx set backtrace limit 0
4628@cindex backtrace limit
4629Limit the backtrace to @var{n} levels. A value of zero means
4630unlimited.
95f90d25 4631
25d29d70
AC
4632@item show backtrace limit
4633Display the current limit on backtrace levels.
95f90d25
DJ
4634@end table
4635
6d2ebf8b 4636@node Selection
c906108c
SS
4637@section Selecting a frame
4638
4639Most commands for examining the stack and other data in your program work on
4640whichever stack frame is selected at the moment. Here are the commands for
4641selecting a stack frame; all of them finish by printing a brief description
4642of the stack frame just selected.
4643
4644@table @code
d4f3574e 4645@kindex frame@r{, selecting}
41afff9a 4646@kindex f @r{(@code{frame})}
c906108c
SS
4647@item frame @var{n}
4648@itemx f @var{n}
4649Select frame number @var{n}. Recall that frame zero is the innermost
4650(currently executing) frame, frame one is the frame that called the
4651innermost one, and so on. The highest-numbered frame is the one for
4652@code{main}.
4653
4654@item frame @var{addr}
4655@itemx f @var{addr}
4656Select the frame at address @var{addr}. This is useful mainly if the
4657chaining of stack frames has been damaged by a bug, making it
4658impossible for @value{GDBN} to assign numbers properly to all frames. In
4659addition, this can be useful when your program has multiple stacks and
4660switches between them.
4661
c906108c
SS
4662On the SPARC architecture, @code{frame} needs two addresses to
4663select an arbitrary frame: a frame pointer and a stack pointer.
4664
4665On the MIPS and Alpha architecture, it needs two addresses: a stack
4666pointer and a program counter.
4667
4668On the 29k architecture, it needs three addresses: a register stack
4669pointer, a program counter, and a memory stack pointer.
c906108c
SS
4670
4671@kindex up
4672@item up @var{n}
4673Move @var{n} frames up the stack. For positive numbers @var{n}, this
4674advances toward the outermost frame, to higher frame numbers, to frames
4675that have existed longer. @var{n} defaults to one.
4676
4677@kindex down
41afff9a 4678@kindex do @r{(@code{down})}
c906108c
SS
4679@item down @var{n}
4680Move @var{n} frames down the stack. For positive numbers @var{n}, this
4681advances toward the innermost frame, to lower frame numbers, to frames
4682that were created more recently. @var{n} defaults to one. You may
4683abbreviate @code{down} as @code{do}.
4684@end table
4685
4686All of these commands end by printing two lines of output describing the
4687frame. The first line shows the frame number, the function name, the
4688arguments, and the source file and line number of execution in that
5d161b24 4689frame. The second line shows the text of that source line.
c906108c
SS
4690
4691@need 1000
4692For example:
4693
4694@smallexample
4695@group
4696(@value{GDBP}) up
4697#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4698 at env.c:10
469910 read_input_file (argv[i]);
4700@end group
4701@end smallexample
4702
4703After such a printout, the @code{list} command with no arguments
4704prints ten lines centered on the point of execution in the frame.
87885426
FN
4705You can also edit the program at the point of execution with your favorite
4706editing program by typing @code{edit}.
4707@xref{List, ,Printing source lines},
4708for details.
c906108c
SS
4709
4710@table @code
4711@kindex down-silently
4712@kindex up-silently
4713@item up-silently @var{n}
4714@itemx down-silently @var{n}
4715These two commands are variants of @code{up} and @code{down},
4716respectively; they differ in that they do their work silently, without
4717causing display of the new frame. They are intended primarily for use
4718in @value{GDBN} command scripts, where the output might be unnecessary and
4719distracting.
4720@end table
4721
6d2ebf8b 4722@node Frame Info
c906108c
SS
4723@section Information about a frame
4724
4725There are several other commands to print information about the selected
4726stack frame.
4727
4728@table @code
4729@item frame
4730@itemx f
4731When used without any argument, this command does not change which
4732frame is selected, but prints a brief description of the currently
4733selected stack frame. It can be abbreviated @code{f}. With an
4734argument, this command is used to select a stack frame.
4735@xref{Selection, ,Selecting a frame}.
4736
4737@kindex info frame
41afff9a 4738@kindex info f @r{(@code{info frame})}
c906108c
SS
4739@item info frame
4740@itemx info f
4741This command prints a verbose description of the selected stack frame,
4742including:
4743
4744@itemize @bullet
5d161b24
DB
4745@item
4746the address of the frame
c906108c
SS
4747@item
4748the address of the next frame down (called by this frame)
4749@item
4750the address of the next frame up (caller of this frame)
4751@item
4752the language in which the source code corresponding to this frame is written
4753@item
4754the address of the frame's arguments
4755@item
d4f3574e
SS
4756the address of the frame's local variables
4757@item
c906108c
SS
4758the program counter saved in it (the address of execution in the caller frame)
4759@item
4760which registers were saved in the frame
4761@end itemize
4762
4763@noindent The verbose description is useful when
4764something has gone wrong that has made the stack format fail to fit
4765the usual conventions.
4766
4767@item info frame @var{addr}
4768@itemx info f @var{addr}
4769Print a verbose description of the frame at address @var{addr}, without
4770selecting that frame. The selected frame remains unchanged by this
4771command. This requires the same kind of address (more than one for some
4772architectures) that you specify in the @code{frame} command.
4773@xref{Selection, ,Selecting a frame}.
4774
4775@kindex info args
4776@item info args
4777Print the arguments of the selected frame, each on a separate line.
4778
4779@item info locals
4780@kindex info locals
4781Print the local variables of the selected frame, each on a separate
4782line. These are all variables (declared either static or automatic)
4783accessible at the point of execution of the selected frame.
4784
c906108c 4785@kindex info catch
d4f3574e
SS
4786@cindex catch exceptions, list active handlers
4787@cindex exception handlers, how to list
c906108c
SS
4788@item info catch
4789Print a list of all the exception handlers that are active in the
4790current stack frame at the current point of execution. To see other
4791exception handlers, visit the associated frame (using the @code{up},
4792@code{down}, or @code{frame} commands); then type @code{info catch}.
4793@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4794
c906108c
SS
4795@end table
4796
c906108c 4797
6d2ebf8b 4798@node Source
c906108c
SS
4799@chapter Examining Source Files
4800
4801@value{GDBN} can print parts of your program's source, since the debugging
4802information recorded in the program tells @value{GDBN} what source files were
4803used to build it. When your program stops, @value{GDBN} spontaneously prints
4804the line where it stopped. Likewise, when you select a stack frame
4805(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4806execution in that frame has stopped. You can print other portions of
4807source files by explicit command.
4808
7a292a7a 4809If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4810prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4811@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4812
4813@menu
4814* List:: Printing source lines
87885426 4815* Edit:: Editing source files
c906108c 4816* Search:: Searching source files
c906108c
SS
4817* Source Path:: Specifying source directories
4818* Machine Code:: Source and machine code
4819@end menu
4820
6d2ebf8b 4821@node List
c906108c
SS
4822@section Printing source lines
4823
4824@kindex list
41afff9a 4825@kindex l @r{(@code{list})}
c906108c 4826To print lines from a source file, use the @code{list} command
5d161b24 4827(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4828There are several ways to specify what part of the file you want to print.
4829
4830Here are the forms of the @code{list} command most commonly used:
4831
4832@table @code
4833@item list @var{linenum}
4834Print lines centered around line number @var{linenum} in the
4835current source file.
4836
4837@item list @var{function}
4838Print lines centered around the beginning of function
4839@var{function}.
4840
4841@item list
4842Print more lines. If the last lines printed were printed with a
4843@code{list} command, this prints lines following the last lines
4844printed; however, if the last line printed was a solitary line printed
4845as part of displaying a stack frame (@pxref{Stack, ,Examining the
4846Stack}), this prints lines centered around that line.
4847
4848@item list -
4849Print lines just before the lines last printed.
4850@end table
4851
9c16f35a 4852@cindex @code{list}, how many lines to display
c906108c
SS
4853By default, @value{GDBN} prints ten source lines with any of these forms of
4854the @code{list} command. You can change this using @code{set listsize}:
4855
4856@table @code
4857@kindex set listsize
4858@item set listsize @var{count}
4859Make the @code{list} command display @var{count} source lines (unless
4860the @code{list} argument explicitly specifies some other number).
4861
4862@kindex show listsize
4863@item show listsize
4864Display the number of lines that @code{list} prints.
4865@end table
4866
4867Repeating a @code{list} command with @key{RET} discards the argument,
4868so it is equivalent to typing just @code{list}. This is more useful
4869than listing the same lines again. An exception is made for an
4870argument of @samp{-}; that argument is preserved in repetition so that
4871each repetition moves up in the source file.
4872
4873@cindex linespec
4874In general, the @code{list} command expects you to supply zero, one or two
4875@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4876of writing them, but the effect is always to specify some source line.
c906108c
SS
4877Here is a complete description of the possible arguments for @code{list}:
4878
4879@table @code
4880@item list @var{linespec}
4881Print lines centered around the line specified by @var{linespec}.
4882
4883@item list @var{first},@var{last}
4884Print lines from @var{first} to @var{last}. Both arguments are
4885linespecs.
4886
4887@item list ,@var{last}
4888Print lines ending with @var{last}.
4889
4890@item list @var{first},
4891Print lines starting with @var{first}.
4892
4893@item list +
4894Print lines just after the lines last printed.
4895
4896@item list -
4897Print lines just before the lines last printed.
4898
4899@item list
4900As described in the preceding table.
4901@end table
4902
4903Here are the ways of specifying a single source line---all the
4904kinds of linespec.
4905
4906@table @code
4907@item @var{number}
4908Specifies line @var{number} of the current source file.
4909When a @code{list} command has two linespecs, this refers to
4910the same source file as the first linespec.
4911
4912@item +@var{offset}
4913Specifies the line @var{offset} lines after the last line printed.
4914When used as the second linespec in a @code{list} command that has
4915two, this specifies the line @var{offset} lines down from the
4916first linespec.
4917
4918@item -@var{offset}
4919Specifies the line @var{offset} lines before the last line printed.
4920
4921@item @var{filename}:@var{number}
4922Specifies line @var{number} in the source file @var{filename}.
4923
4924@item @var{function}
4925Specifies the line that begins the body of the function @var{function}.
4926For example: in C, this is the line with the open brace.
4927
4928@item @var{filename}:@var{function}
4929Specifies the line of the open-brace that begins the body of the
4930function @var{function} in the file @var{filename}. You only need the
4931file name with a function name to avoid ambiguity when there are
4932identically named functions in different source files.
4933
4934@item *@var{address}
4935Specifies the line containing the program address @var{address}.
4936@var{address} may be any expression.
4937@end table
4938
87885426
FN
4939@node Edit
4940@section Editing source files
4941@cindex editing source files
4942
4943@kindex edit
4944@kindex e @r{(@code{edit})}
4945To edit the lines in a source file, use the @code{edit} command.
4946The editing program of your choice
4947is invoked with the current line set to
4948the active line in the program.
4949Alternatively, there are several ways to specify what part of the file you
4950want to print if you want to see other parts of the program.
4951
4952Here are the forms of the @code{edit} command most commonly used:
4953
4954@table @code
4955@item edit
4956Edit the current source file at the active line number in the program.
4957
4958@item edit @var{number}
4959Edit the current source file with @var{number} as the active line number.
4960
4961@item edit @var{function}
4962Edit the file containing @var{function} at the beginning of its definition.
4963
4964@item edit @var{filename}:@var{number}
4965Specifies line @var{number} in the source file @var{filename}.
4966
4967@item edit @var{filename}:@var{function}
4968Specifies the line that begins the body of the
4969function @var{function} in the file @var{filename}. You only need the
4970file name with a function name to avoid ambiguity when there are
4971identically named functions in different source files.
4972
4973@item edit *@var{address}
4974Specifies the line containing the program address @var{address}.
4975@var{address} may be any expression.
4976@end table
4977
4978@subsection Choosing your editor
4979You can customize @value{GDBN} to use any editor you want
4980@footnote{
4981The only restriction is that your editor (say @code{ex}), recognizes the
4982following command-line syntax:
10998722 4983@smallexample
87885426 4984ex +@var{number} file
10998722 4985@end smallexample
15387254
EZ
4986The optional numeric value +@var{number} specifies the number of the line in
4987the file where to start editing.}.
4988By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4989by setting the environment variable @code{EDITOR} before using
4990@value{GDBN}. For example, to configure @value{GDBN} to use the
4991@code{vi} editor, you could use these commands with the @code{sh} shell:
4992@smallexample
87885426
FN
4993EDITOR=/usr/bin/vi
4994export EDITOR
15387254 4995gdb @dots{}
10998722 4996@end smallexample
87885426 4997or in the @code{csh} shell,
10998722 4998@smallexample
87885426 4999setenv EDITOR /usr/bin/vi
15387254 5000gdb @dots{}
10998722 5001@end smallexample
87885426 5002
6d2ebf8b 5003@node Search
c906108c 5004@section Searching source files
15387254 5005@cindex searching source files
c906108c
SS
5006
5007There are two commands for searching through the current source file for a
5008regular expression.
5009
5010@table @code
5011@kindex search
5012@kindex forward-search
5013@item forward-search @var{regexp}
5014@itemx search @var{regexp}
5015The command @samp{forward-search @var{regexp}} checks each line,
5016starting with the one following the last line listed, for a match for
5d161b24 5017@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
5018synonym @samp{search @var{regexp}} or abbreviate the command name as
5019@code{fo}.
5020
09d4efe1 5021@kindex reverse-search
c906108c
SS
5022@item reverse-search @var{regexp}
5023The command @samp{reverse-search @var{regexp}} checks each line, starting
5024with the one before the last line listed and going backward, for a match
5025for @var{regexp}. It lists the line that is found. You can abbreviate
5026this command as @code{rev}.
5027@end table
c906108c 5028
6d2ebf8b 5029@node Source Path
c906108c
SS
5030@section Specifying source directories
5031
5032@cindex source path
5033@cindex directories for source files
5034Executable programs sometimes do not record the directories of the source
5035files from which they were compiled, just the names. Even when they do,
5036the directories could be moved between the compilation and your debugging
5037session. @value{GDBN} has a list of directories to search for source files;
5038this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
5039it tries all the directories in the list, in the order they are present
0b66e38c
EZ
5040in the list, until it finds a file with the desired name.
5041
5042For example, suppose an executable references the file
5043@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
5044@file{/mnt/cross}. The file is first looked up literally; if this
5045fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
5046fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
5047message is printed. @value{GDBN} does not look up the parts of the
5048source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
5049Likewise, the subdirectories of the source path are not searched: if
5050the source path is @file{/mnt/cross}, and the binary refers to
5051@file{foo.c}, @value{GDBN} would not find it under
5052@file{/mnt/cross/usr/src/foo-1.0/lib}.
5053
5054Plain file names, relative file names with leading directories, file
5055names containing dots, etc.@: are all treated as described above; for
5056instance, if the source path is @file{/mnt/cross}, and the source file
5057is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
5058@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
5059that---@file{/mnt/cross/foo.c}.
5060
5061Note that the executable search path is @emph{not} used to locate the
cd852561 5062source files.
c906108c
SS
5063
5064Whenever you reset or rearrange the source path, @value{GDBN} clears out
5065any information it has cached about where source files are found and where
5066each line is in the file.
5067
5068@kindex directory
5069@kindex dir
d4f3574e
SS
5070When you start @value{GDBN}, its source path includes only @samp{cdir}
5071and @samp{cwd}, in that order.
c906108c
SS
5072To add other directories, use the @code{directory} command.
5073
4b505b12
AS
5074The search path is used to find both program source files and @value{GDBN}
5075script files (read using the @samp{-command} option and @samp{source} command).
5076
30daae6c
JB
5077In addition to the source path, @value{GDBN} provides a set of commands
5078that manage a list of source path substitution rules. A @dfn{substitution
5079rule} specifies how to rewrite source directories stored in the program's
5080debug information in case the sources were moved to a different
5081directory between compilation and debugging. A rule is made of
5082two strings, the first specifying what needs to be rewritten in
5083the path, and the second specifying how it should be rewritten.
5084In @ref{set substitute-path}, we name these two parts @var{from} and
5085@var{to} respectively. @value{GDBN} does a simple string replacement
5086of @var{from} with @var{to} at the start of the directory part of the
5087source file name, and uses that result instead of the original file
5088name to look up the sources.
5089
5090Using the previous example, suppose the @file{foo-1.0} tree has been
5091moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
5092GDB to replace @file{/usr/src} in all source path names with
5093@file{/mnt/cross}. The first lookup will then be
5094@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
5095of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
5096substitution rule, use the @code{set substitute-path} command
5097(@pxref{set substitute-path}).
5098
5099To avoid unexpected substitution results, a rule is applied only if the
5100@var{from} part of the directory name ends at a directory separator.
5101For instance, a rule substituting @file{/usr/source} into
5102@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
5103not to @file{/usr/sourceware/foo-2.0}. And because the substitution
5104is applied only at the begining of the directory name, this rule will
5105not be applied to @file{/root/usr/source/baz.c} either.
5106
5107In many cases, you can achieve the same result using the @code{directory}
5108command. However, @code{set substitute-path} can be more efficient in
5109the case where the sources are organized in a complex tree with multiple
5110subdirectories. With the @code{directory} command, you need to add each
5111subdirectory of your project. If you moved the entire tree while
5112preserving its internal organization, then @code{set substitute-path}
5113allows you to direct the debugger to all the sources with one single
5114command.
5115
5116@code{set substitute-path} is also more than just a shortcut command.
5117The source path is only used if the file at the original location no
5118longer exists. On the other hand, @code{set substitute-path} modifies
5119the debugger behavior to look at the rewritten location instead. So, if
5120for any reason a source file that is not relevant to your executable is
5121located at the original location, a substitution rule is the only
5122method available to point GDB at the new location.
5123
c906108c
SS
5124@table @code
5125@item directory @var{dirname} @dots{}
5126@item dir @var{dirname} @dots{}
5127Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
5128directory names may be given to this command, separated by @samp{:}
5129(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5130part of absolute file names) or
c906108c
SS
5131whitespace. You may specify a directory that is already in the source
5132path; this moves it forward, so @value{GDBN} searches it sooner.
5133
5134@kindex cdir
5135@kindex cwd
41afff9a
EZ
5136@vindex $cdir@r{, convenience variable}
5137@vindex $cwdr@r{, convenience variable}
c906108c
SS
5138@cindex compilation directory
5139@cindex current directory
5140@cindex working directory
5141@cindex directory, current
5142@cindex directory, compilation
5143You can use the string @samp{$cdir} to refer to the compilation
5144directory (if one is recorded), and @samp{$cwd} to refer to the current
5145working directory. @samp{$cwd} is not the same as @samp{.}---the former
5146tracks the current working directory as it changes during your @value{GDBN}
5147session, while the latter is immediately expanded to the current
5148directory at the time you add an entry to the source path.
5149
5150@item directory
cd852561 5151Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
5152
5153@c RET-repeat for @code{directory} is explicitly disabled, but since
5154@c repeating it would be a no-op we do not say that. (thanks to RMS)
5155
5156@item show directories
5157@kindex show directories
5158Print the source path: show which directories it contains.
30daae6c
JB
5159
5160@anchor{set substitute-path}
5161@item set substitute-path @var{from} @var{to}
5162@kindex set substitute-path
5163Define a source path substitution rule, and add it at the end of the
5164current list of existing substitution rules. If a rule with the same
5165@var{from} was already defined, then the old rule is also deleted.
5166
5167For example, if the file @file{/foo/bar/baz.c} was moved to
5168@file{/mnt/cross/baz.c}, then the command
5169
5170@smallexample
5171(@value{GDBP}) set substitute-path /usr/src /mnt/cross
5172@end smallexample
5173
5174@noindent
5175will tell @value{GDBN} to replace @samp{/usr/src} with
5176@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
5177@file{baz.c} even though it was moved.
5178
5179In the case when more than one substitution rule have been defined,
5180the rules are evaluated one by one in the order where they have been
5181defined. The first one matching, if any, is selected to perform
5182the substitution.
5183
5184For instance, if we had entered the following commands:
5185
5186@smallexample
5187(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
5188(@value{GDBP}) set substitute-path /usr/src /mnt/src
5189@end smallexample
5190
5191@noindent
5192@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
5193@file{/mnt/include/defs.h} by using the first rule. However, it would
5194use the second rule to rewrite @file{/usr/src/lib/foo.c} into
5195@file{/mnt/src/lib/foo.c}.
5196
5197
5198@item unset substitute-path [path]
5199@kindex unset substitute-path
5200If a path is specified, search the current list of substitution rules
5201for a rule that would rewrite that path. Delete that rule if found.
5202A warning is emitted by the debugger if no rule could be found.
5203
5204If no path is specified, then all substitution rules are deleted.
5205
5206@item show substitute-path [path]
5207@kindex show substitute-path
5208If a path is specified, then print the source path substitution rule
5209which would rewrite that path, if any.
5210
5211If no path is specified, then print all existing source path substitution
5212rules.
5213
c906108c
SS
5214@end table
5215
5216If your source path is cluttered with directories that are no longer of
5217interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5218versions of source. You can correct the situation as follows:
5219
5220@enumerate
5221@item
cd852561 5222Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
5223
5224@item
5225Use @code{directory} with suitable arguments to reinstall the
5226directories you want in the source path. You can add all the
5227directories in one command.
5228@end enumerate
5229
6d2ebf8b 5230@node Machine Code
c906108c 5231@section Source and machine code
15387254 5232@cindex source line and its code address
c906108c
SS
5233
5234You can use the command @code{info line} to map source lines to program
5235addresses (and vice versa), and the command @code{disassemble} to display
5236a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 5237mode, the @code{info line} command causes the arrow to point to the
5d161b24 5238line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
5239well as hex.
5240
5241@table @code
5242@kindex info line
5243@item info line @var{linespec}
5244Print the starting and ending addresses of the compiled code for
5245source line @var{linespec}. You can specify source lines in any of
5246the ways understood by the @code{list} command (@pxref{List, ,Printing
5247source lines}).
5248@end table
5249
5250For example, we can use @code{info line} to discover the location of
5251the object code for the first line of function
5252@code{m4_changequote}:
5253
d4f3574e
SS
5254@c FIXME: I think this example should also show the addresses in
5255@c symbolic form, as they usually would be displayed.
c906108c 5256@smallexample
96a2c332 5257(@value{GDBP}) info line m4_changequote
c906108c
SS
5258Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5259@end smallexample
5260
5261@noindent
15387254 5262@cindex code address and its source line
c906108c
SS
5263We can also inquire (using @code{*@var{addr}} as the form for
5264@var{linespec}) what source line covers a particular address:
5265@smallexample
5266(@value{GDBP}) info line *0x63ff
5267Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5268@end smallexample
5269
5270@cindex @code{$_} and @code{info line}
15387254 5271@cindex @code{x} command, default address
41afff9a 5272@kindex x@r{(examine), and} info line
c906108c
SS
5273After @code{info line}, the default address for the @code{x} command
5274is changed to the starting address of the line, so that @samp{x/i} is
5275sufficient to begin examining the machine code (@pxref{Memory,
5276,Examining memory}). Also, this address is saved as the value of the
5277convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
5278variables}).
5279
5280@table @code
5281@kindex disassemble
5282@cindex assembly instructions
5283@cindex instructions, assembly
5284@cindex machine instructions
5285@cindex listing machine instructions
5286@item disassemble
5287This specialized command dumps a range of memory as machine
5288instructions. The default memory range is the function surrounding the
5289program counter of the selected frame. A single argument to this
5290command is a program counter value; @value{GDBN} dumps the function
5291surrounding this value. Two arguments specify a range of addresses
5292(first inclusive, second exclusive) to dump.
5293@end table
5294
c906108c
SS
5295The following example shows the disassembly of a range of addresses of
5296HP PA-RISC 2.0 code:
5297
5298@smallexample
5299(@value{GDBP}) disas 0x32c4 0x32e4
5300Dump of assembler code from 0x32c4 to 0x32e4:
53010x32c4 <main+204>: addil 0,dp
53020x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
53030x32cc <main+212>: ldil 0x3000,r31
53040x32d0 <main+216>: ble 0x3f8(sr4,r31)
53050x32d4 <main+220>: ldo 0(r31),rp
53060x32d8 <main+224>: addil -0x800,dp
53070x32dc <main+228>: ldo 0x588(r1),r26
53080x32e0 <main+232>: ldil 0x3000,r31
5309End of assembler dump.
5310@end smallexample
c906108c
SS
5311
5312Some architectures have more than one commonly-used set of instruction
5313mnemonics or other syntax.
5314
76d17f34
EZ
5315For programs that were dynamically linked and use shared libraries,
5316instructions that call functions or branch to locations in the shared
5317libraries might show a seemingly bogus location---it's actually a
5318location of the relocation table. On some architectures, @value{GDBN}
5319might be able to resolve these to actual function names.
5320
c906108c 5321@table @code
d4f3574e 5322@kindex set disassembly-flavor
d4f3574e
SS
5323@cindex Intel disassembly flavor
5324@cindex AT&T disassembly flavor
5325@item set disassembly-flavor @var{instruction-set}
c906108c
SS
5326Select the instruction set to use when disassembling the
5327program via the @code{disassemble} or @code{x/i} commands.
5328
5329Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
5330can set @var{instruction-set} to either @code{intel} or @code{att}.
5331The default is @code{att}, the AT&T flavor used by default by Unix
5332assemblers for x86-based targets.
9c16f35a
EZ
5333
5334@kindex show disassembly-flavor
5335@item show disassembly-flavor
5336Show the current setting of the disassembly flavor.
c906108c
SS
5337@end table
5338
5339
6d2ebf8b 5340@node Data
c906108c
SS
5341@chapter Examining Data
5342
5343@cindex printing data
5344@cindex examining data
5345@kindex print
5346@kindex inspect
5347@c "inspect" is not quite a synonym if you are using Epoch, which we do not
5348@c document because it is nonstandard... Under Epoch it displays in a
5349@c different window or something like that.
5350The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
5351command (abbreviated @code{p}), or its synonym @code{inspect}. It
5352evaluates and prints the value of an expression of the language your
5353program is written in (@pxref{Languages, ,Using @value{GDBN} with
5354Different Languages}).
c906108c
SS
5355
5356@table @code
d4f3574e
SS
5357@item print @var{expr}
5358@itemx print /@var{f} @var{expr}
5359@var{expr} is an expression (in the source language). By default the
5360value of @var{expr} is printed in a format appropriate to its data type;
c906108c 5361you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 5362@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
5363formats}.
5364
5365@item print
5366@itemx print /@var{f}
15387254 5367@cindex reprint the last value
d4f3574e 5368If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
5369@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
5370conveniently inspect the same value in an alternative format.
5371@end table
5372
5373A more low-level way of examining data is with the @code{x} command.
5374It examines data in memory at a specified address and prints it in a
5375specified format. @xref{Memory, ,Examining memory}.
5376
7a292a7a 5377If you are interested in information about types, or about how the
d4f3574e
SS
5378fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5379command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 5380Table}.
c906108c
SS
5381
5382@menu
5383* Expressions:: Expressions
5384* Variables:: Program variables
5385* Arrays:: Artificial arrays
5386* Output Formats:: Output formats
5387* Memory:: Examining memory
5388* Auto Display:: Automatic display
5389* Print Settings:: Print settings
5390* Value History:: Value history
5391* Convenience Vars:: Convenience variables
5392* Registers:: Registers
c906108c 5393* Floating Point Hardware:: Floating point hardware
53c69bd7 5394* Vector Unit:: Vector Unit
721c2651 5395* OS Information:: Auxiliary data provided by operating system
29e57380 5396* Memory Region Attributes:: Memory region attributes
16d9dec6 5397* Dump/Restore Files:: Copy between memory and a file
384ee23f 5398* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5399* Character Sets:: Debugging programs that use a different
5400 character set than GDB does
09d4efe1 5401* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5402@end menu
5403
6d2ebf8b 5404@node Expressions
c906108c
SS
5405@section Expressions
5406
5407@cindex expressions
5408@code{print} and many other @value{GDBN} commands accept an expression and
5409compute its value. Any kind of constant, variable or operator defined
5410by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5411@value{GDBN}. This includes conditional expressions, function calls,
5412casts, and string constants. It also includes preprocessor macros, if
5413you compiled your program to include this information; see
5414@ref{Compilation}.
c906108c 5415
15387254 5416@cindex arrays in expressions
d4f3574e
SS
5417@value{GDBN} supports array constants in expressions input by
5418the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5419you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5420memory that is @code{malloc}ed in the target program.
c906108c 5421
c906108c
SS
5422Because C is so widespread, most of the expressions shown in examples in
5423this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5424Languages}, for information on how to use expressions in other
5425languages.
5426
5427In this section, we discuss operators that you can use in @value{GDBN}
5428expressions regardless of your programming language.
5429
15387254 5430@cindex casts, in expressions
c906108c
SS
5431Casts are supported in all languages, not just in C, because it is so
5432useful to cast a number into a pointer in order to examine a structure
5433at that address in memory.
5434@c FIXME: casts supported---Mod2 true?
c906108c
SS
5435
5436@value{GDBN} supports these operators, in addition to those common
5437to programming languages:
5438
5439@table @code
5440@item @@
5441@samp{@@} is a binary operator for treating parts of memory as arrays.
5442@xref{Arrays, ,Artificial arrays}, for more information.
5443
5444@item ::
5445@samp{::} allows you to specify a variable in terms of the file or
5446function where it is defined. @xref{Variables, ,Program variables}.
5447
5448@cindex @{@var{type}@}
5449@cindex type casting memory
5450@cindex memory, viewing as typed object
5451@cindex casts, to view memory
5452@item @{@var{type}@} @var{addr}
5453Refers to an object of type @var{type} stored at address @var{addr} in
5454memory. @var{addr} may be any expression whose value is an integer or
5455pointer (but parentheses are required around binary operators, just as in
5456a cast). This construct is allowed regardless of what kind of data is
5457normally supposed to reside at @var{addr}.
5458@end table
5459
6d2ebf8b 5460@node Variables
c906108c
SS
5461@section Program variables
5462
5463The most common kind of expression to use is the name of a variable
5464in your program.
5465
5466Variables in expressions are understood in the selected stack frame
5467(@pxref{Selection, ,Selecting a frame}); they must be either:
5468
5469@itemize @bullet
5470@item
5471global (or file-static)
5472@end itemize
5473
5d161b24 5474@noindent or
c906108c
SS
5475
5476@itemize @bullet
5477@item
5478visible according to the scope rules of the
5479programming language from the point of execution in that frame
5d161b24 5480@end itemize
c906108c
SS
5481
5482@noindent This means that in the function
5483
474c8240 5484@smallexample
c906108c
SS
5485foo (a)
5486 int a;
5487@{
5488 bar (a);
5489 @{
5490 int b = test ();
5491 bar (b);
5492 @}
5493@}
474c8240 5494@end smallexample
c906108c
SS
5495
5496@noindent
5497you can examine and use the variable @code{a} whenever your program is
5498executing within the function @code{foo}, but you can only use or
5499examine the variable @code{b} while your program is executing inside
5500the block where @code{b} is declared.
5501
5502@cindex variable name conflict
5503There is an exception: you can refer to a variable or function whose
5504scope is a single source file even if the current execution point is not
5505in this file. But it is possible to have more than one such variable or
5506function with the same name (in different source files). If that
5507happens, referring to that name has unpredictable effects. If you wish,
5508you can specify a static variable in a particular function or file,
15387254 5509using the colon-colon (@code{::}) notation:
c906108c 5510
d4f3574e 5511@cindex colon-colon, context for variables/functions
c906108c
SS
5512@iftex
5513@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5514@cindex @code{::}, context for variables/functions
c906108c 5515@end iftex
474c8240 5516@smallexample
c906108c
SS
5517@var{file}::@var{variable}
5518@var{function}::@var{variable}
474c8240 5519@end smallexample
c906108c
SS
5520
5521@noindent
5522Here @var{file} or @var{function} is the name of the context for the
5523static @var{variable}. In the case of file names, you can use quotes to
5524make sure @value{GDBN} parses the file name as a single word---for example,
5525to print a global value of @code{x} defined in @file{f2.c}:
5526
474c8240 5527@smallexample
c906108c 5528(@value{GDBP}) p 'f2.c'::x
474c8240 5529@end smallexample
c906108c 5530
b37052ae 5531@cindex C@t{++} scope resolution
c906108c 5532This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5533use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5534scope resolution operator in @value{GDBN} expressions.
5535@c FIXME: Um, so what happens in one of those rare cases where it's in
5536@c conflict?? --mew
c906108c
SS
5537
5538@cindex wrong values
5539@cindex variable values, wrong
15387254
EZ
5540@cindex function entry/exit, wrong values of variables
5541@cindex optimized code, wrong values of variables
c906108c
SS
5542@quotation
5543@emph{Warning:} Occasionally, a local variable may appear to have the
5544wrong value at certain points in a function---just after entry to a new
5545scope, and just before exit.
5546@end quotation
5547You may see this problem when you are stepping by machine instructions.
5548This is because, on most machines, it takes more than one instruction to
5549set up a stack frame (including local variable definitions); if you are
5550stepping by machine instructions, variables may appear to have the wrong
5551values until the stack frame is completely built. On exit, it usually
5552also takes more than one machine instruction to destroy a stack frame;
5553after you begin stepping through that group of instructions, local
5554variable definitions may be gone.
5555
5556This may also happen when the compiler does significant optimizations.
5557To be sure of always seeing accurate values, turn off all optimization
5558when compiling.
5559
d4f3574e
SS
5560@cindex ``No symbol "foo" in current context''
5561Another possible effect of compiler optimizations is to optimize
5562unused variables out of existence, or assign variables to registers (as
5563opposed to memory addresses). Depending on the support for such cases
5564offered by the debug info format used by the compiler, @value{GDBN}
5565might not be able to display values for such local variables. If that
5566happens, @value{GDBN} will print a message like this:
5567
474c8240 5568@smallexample
d4f3574e 5569No symbol "foo" in current context.
474c8240 5570@end smallexample
d4f3574e
SS
5571
5572To solve such problems, either recompile without optimizations, or use a
5573different debug info format, if the compiler supports several such
15387254 5574formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5575usually supports the @option{-gstabs+} option. @option{-gstabs+}
5576produces debug info in a format that is superior to formats such as
5577COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5578an effective form for debug info. @xref{Debugging Options,,Options
5579for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5580@xref{C, , Debugging C++}, for more info about debug info formats
5581that are best suited to C@t{++} programs.
d4f3574e 5582
ab1adacd
EZ
5583If you ask to print an object whose contents are unknown to
5584@value{GDBN}, e.g., because its data type is not completely specified
5585by the debug information, @value{GDBN} will say @samp{<incomplete
5586type>}. @xref{Symbols, incomplete type}, for more about this.
5587
6d2ebf8b 5588@node Arrays
c906108c
SS
5589@section Artificial arrays
5590
5591@cindex artificial array
15387254 5592@cindex arrays
41afff9a 5593@kindex @@@r{, referencing memory as an array}
c906108c
SS
5594It is often useful to print out several successive objects of the
5595same type in memory; a section of an array, or an array of
5596dynamically determined size for which only a pointer exists in the
5597program.
5598
5599You can do this by referring to a contiguous span of memory as an
5600@dfn{artificial array}, using the binary operator @samp{@@}. The left
5601operand of @samp{@@} should be the first element of the desired array
5602and be an individual object. The right operand should be the desired length
5603of the array. The result is an array value whose elements are all of
5604the type of the left argument. The first element is actually the left
5605argument; the second element comes from bytes of memory immediately
5606following those that hold the first element, and so on. Here is an
5607example. If a program says
5608
474c8240 5609@smallexample
c906108c 5610int *array = (int *) malloc (len * sizeof (int));
474c8240 5611@end smallexample
c906108c
SS
5612
5613@noindent
5614you can print the contents of @code{array} with
5615
474c8240 5616@smallexample
c906108c 5617p *array@@len
474c8240 5618@end smallexample
c906108c
SS
5619
5620The left operand of @samp{@@} must reside in memory. Array values made
5621with @samp{@@} in this way behave just like other arrays in terms of
5622subscripting, and are coerced to pointers when used in expressions.
5623Artificial arrays most often appear in expressions via the value history
5624(@pxref{Value History, ,Value history}), after printing one out.
5625
5626Another way to create an artificial array is to use a cast.
5627This re-interprets a value as if it were an array.
5628The value need not be in memory:
474c8240 5629@smallexample
c906108c
SS
5630(@value{GDBP}) p/x (short[2])0x12345678
5631$1 = @{0x1234, 0x5678@}
474c8240 5632@end smallexample
c906108c
SS
5633
5634As a convenience, if you leave the array length out (as in
c3f6f71d 5635@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5636the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5637@smallexample
c906108c
SS
5638(@value{GDBP}) p/x (short[])0x12345678
5639$2 = @{0x1234, 0x5678@}
474c8240 5640@end smallexample
c906108c
SS
5641
5642Sometimes the artificial array mechanism is not quite enough; in
5643moderately complex data structures, the elements of interest may not
5644actually be adjacent---for example, if you are interested in the values
5645of pointers in an array. One useful work-around in this situation is
5646to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5647variables}) as a counter in an expression that prints the first
5648interesting value, and then repeat that expression via @key{RET}. For
5649instance, suppose you have an array @code{dtab} of pointers to
5650structures, and you are interested in the values of a field @code{fv}
5651in each structure. Here is an example of what you might type:
5652
474c8240 5653@smallexample
c906108c
SS
5654set $i = 0
5655p dtab[$i++]->fv
5656@key{RET}
5657@key{RET}
5658@dots{}
474c8240 5659@end smallexample
c906108c 5660
6d2ebf8b 5661@node Output Formats
c906108c
SS
5662@section Output formats
5663
5664@cindex formatted output
5665@cindex output formats
5666By default, @value{GDBN} prints a value according to its data type. Sometimes
5667this is not what you want. For example, you might want to print a number
5668in hex, or a pointer in decimal. Or you might want to view data in memory
5669at a certain address as a character string or as an instruction. To do
5670these things, specify an @dfn{output format} when you print a value.
5671
5672The simplest use of output formats is to say how to print a value
5673already computed. This is done by starting the arguments of the
5674@code{print} command with a slash and a format letter. The format
5675letters supported are:
5676
5677@table @code
5678@item x
5679Regard the bits of the value as an integer, and print the integer in
5680hexadecimal.
5681
5682@item d
5683Print as integer in signed decimal.
5684
5685@item u
5686Print as integer in unsigned decimal.
5687
5688@item o
5689Print as integer in octal.
5690
5691@item t
5692Print as integer in binary. The letter @samp{t} stands for ``two''.
5693@footnote{@samp{b} cannot be used because these format letters are also
5694used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5695see @ref{Memory,,Examining memory}.}
c906108c
SS
5696
5697@item a
5698@cindex unknown address, locating
3d67e040 5699@cindex locate address
c906108c
SS
5700Print as an address, both absolute in hexadecimal and as an offset from
5701the nearest preceding symbol. You can use this format used to discover
5702where (in what function) an unknown address is located:
5703
474c8240 5704@smallexample
c906108c
SS
5705(@value{GDBP}) p/a 0x54320
5706$3 = 0x54320 <_initialize_vx+396>
474c8240 5707@end smallexample
c906108c 5708
3d67e040
EZ
5709@noindent
5710The command @code{info symbol 0x54320} yields similar results.
5711@xref{Symbols, info symbol}.
5712
c906108c 5713@item c
51274035
EZ
5714Regard as an integer and print it as a character constant. This
5715prints both the numerical value and its character representation. The
5716character representation is replaced with the octal escape @samp{\nnn}
5717for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5718
5719@item f
5720Regard the bits of the value as a floating point number and print
5721using typical floating point syntax.
5722@end table
5723
5724For example, to print the program counter in hex (@pxref{Registers}), type
5725
474c8240 5726@smallexample
c906108c 5727p/x $pc
474c8240 5728@end smallexample
c906108c
SS
5729
5730@noindent
5731Note that no space is required before the slash; this is because command
5732names in @value{GDBN} cannot contain a slash.
5733
5734To reprint the last value in the value history with a different format,
5735you can use the @code{print} command with just a format and no
5736expression. For example, @samp{p/x} reprints the last value in hex.
5737
6d2ebf8b 5738@node Memory
c906108c
SS
5739@section Examining memory
5740
5741You can use the command @code{x} (for ``examine'') to examine memory in
5742any of several formats, independently of your program's data types.
5743
5744@cindex examining memory
5745@table @code
41afff9a 5746@kindex x @r{(examine memory)}
c906108c
SS
5747@item x/@var{nfu} @var{addr}
5748@itemx x @var{addr}
5749@itemx x
5750Use the @code{x} command to examine memory.
5751@end table
5752
5753@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5754much memory to display and how to format it; @var{addr} is an
5755expression giving the address where you want to start displaying memory.
5756If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5757Several commands set convenient defaults for @var{addr}.
5758
5759@table @r
5760@item @var{n}, the repeat count
5761The repeat count is a decimal integer; the default is 1. It specifies
5762how much memory (counting by units @var{u}) to display.
5763@c This really is **decimal**; unaffected by 'set radix' as of GDB
5764@c 4.1.2.
5765
5766@item @var{f}, the display format
51274035
EZ
5767The display format is one of the formats used by @code{print}
5768(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5769@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5770@samp{i} (for machine instructions). The default is @samp{x}
5771(hexadecimal) initially. The default changes each time you use either
5772@code{x} or @code{print}.
c906108c
SS
5773
5774@item @var{u}, the unit size
5775The unit size is any of
5776
5777@table @code
5778@item b
5779Bytes.
5780@item h
5781Halfwords (two bytes).
5782@item w
5783Words (four bytes). This is the initial default.
5784@item g
5785Giant words (eight bytes).
5786@end table
5787
5788Each time you specify a unit size with @code{x}, that size becomes the
5789default unit the next time you use @code{x}. (For the @samp{s} and
5790@samp{i} formats, the unit size is ignored and is normally not written.)
5791
5792@item @var{addr}, starting display address
5793@var{addr} is the address where you want @value{GDBN} to begin displaying
5794memory. The expression need not have a pointer value (though it may);
5795it is always interpreted as an integer address of a byte of memory.
5796@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5797@var{addr} is usually just after the last address examined---but several
5798other commands also set the default address: @code{info breakpoints} (to
5799the address of the last breakpoint listed), @code{info line} (to the
5800starting address of a line), and @code{print} (if you use it to display
5801a value from memory).
5802@end table
5803
5804For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5805(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5806starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5807words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5808@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5809
5810Since the letters indicating unit sizes are all distinct from the
5811letters specifying output formats, you do not have to remember whether
5812unit size or format comes first; either order works. The output
5813specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5814(However, the count @var{n} must come first; @samp{wx4} does not work.)
5815
5816Even though the unit size @var{u} is ignored for the formats @samp{s}
5817and @samp{i}, you might still want to use a count @var{n}; for example,
5818@samp{3i} specifies that you want to see three machine instructions,
5819including any operands. The command @code{disassemble} gives an
d4f3574e 5820alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5821Code,,Source and machine code}.
5822
5823All the defaults for the arguments to @code{x} are designed to make it
5824easy to continue scanning memory with minimal specifications each time
5825you use @code{x}. For example, after you have inspected three machine
5826instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5827with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5828the repeat count @var{n} is used again; the other arguments default as
5829for successive uses of @code{x}.
5830
5831@cindex @code{$_}, @code{$__}, and value history
5832The addresses and contents printed by the @code{x} command are not saved
5833in the value history because there is often too much of them and they
5834would get in the way. Instead, @value{GDBN} makes these values available for
5835subsequent use in expressions as values of the convenience variables
5836@code{$_} and @code{$__}. After an @code{x} command, the last address
5837examined is available for use in expressions in the convenience variable
5838@code{$_}. The contents of that address, as examined, are available in
5839the convenience variable @code{$__}.
5840
5841If the @code{x} command has a repeat count, the address and contents saved
5842are from the last memory unit printed; this is not the same as the last
5843address printed if several units were printed on the last line of output.
5844
09d4efe1
EZ
5845@cindex remote memory comparison
5846@cindex verify remote memory image
5847When you are debugging a program running on a remote target machine
5848(@pxref{Remote}), you may wish to verify the program's image in the
5849remote machine's memory against the executable file you downloaded to
5850the target. The @code{compare-sections} command is provided for such
5851situations.
5852
5853@table @code
5854@kindex compare-sections
5855@item compare-sections @r{[}@var{section-name}@r{]}
5856Compare the data of a loadable section @var{section-name} in the
5857executable file of the program being debugged with the same section in
5858the remote machine's memory, and report any mismatches. With no
5859arguments, compares all loadable sections. This command's
5860availability depends on the target's support for the @code{"qCRC"}
5861remote request.
5862@end table
5863
6d2ebf8b 5864@node Auto Display
c906108c
SS
5865@section Automatic display
5866@cindex automatic display
5867@cindex display of expressions
5868
5869If you find that you want to print the value of an expression frequently
5870(to see how it changes), you might want to add it to the @dfn{automatic
5871display list} so that @value{GDBN} prints its value each time your program stops.
5872Each expression added to the list is given a number to identify it;
5873to remove an expression from the list, you specify that number.
5874The automatic display looks like this:
5875
474c8240 5876@smallexample
c906108c
SS
58772: foo = 38
58783: bar[5] = (struct hack *) 0x3804
474c8240 5879@end smallexample
c906108c
SS
5880
5881@noindent
5882This display shows item numbers, expressions and their current values. As with
5883displays you request manually using @code{x} or @code{print}, you can
5884specify the output format you prefer; in fact, @code{display} decides
5885whether to use @code{print} or @code{x} depending on how elaborate your
5886format specification is---it uses @code{x} if you specify a unit size,
5887or one of the two formats (@samp{i} and @samp{s}) that are only
5888supported by @code{x}; otherwise it uses @code{print}.
5889
5890@table @code
5891@kindex display
d4f3574e
SS
5892@item display @var{expr}
5893Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5894each time your program stops. @xref{Expressions, ,Expressions}.
5895
5896@code{display} does not repeat if you press @key{RET} again after using it.
5897
d4f3574e 5898@item display/@var{fmt} @var{expr}
c906108c 5899For @var{fmt} specifying only a display format and not a size or
d4f3574e 5900count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5901arrange to display it each time in the specified format @var{fmt}.
5902@xref{Output Formats,,Output formats}.
5903
5904@item display/@var{fmt} @var{addr}
5905For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5906number of units, add the expression @var{addr} as a memory address to
5907be examined each time your program stops. Examining means in effect
5908doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5909@end table
5910
5911For example, @samp{display/i $pc} can be helpful, to see the machine
5912instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5913is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5914
5915@table @code
5916@kindex delete display
5917@kindex undisplay
5918@item undisplay @var{dnums}@dots{}
5919@itemx delete display @var{dnums}@dots{}
5920Remove item numbers @var{dnums} from the list of expressions to display.
5921
5922@code{undisplay} does not repeat if you press @key{RET} after using it.
5923(Otherwise you would just get the error @samp{No display number @dots{}}.)
5924
5925@kindex disable display
5926@item disable display @var{dnums}@dots{}
5927Disable the display of item numbers @var{dnums}. A disabled display
5928item is not printed automatically, but is not forgotten. It may be
5929enabled again later.
5930
5931@kindex enable display
5932@item enable display @var{dnums}@dots{}
5933Enable display of item numbers @var{dnums}. It becomes effective once
5934again in auto display of its expression, until you specify otherwise.
5935
5936@item display
5937Display the current values of the expressions on the list, just as is
5938done when your program stops.
5939
5940@kindex info display
5941@item info display
5942Print the list of expressions previously set up to display
5943automatically, each one with its item number, but without showing the
5944values. This includes disabled expressions, which are marked as such.
5945It also includes expressions which would not be displayed right now
5946because they refer to automatic variables not currently available.
5947@end table
5948
15387254 5949@cindex display disabled out of scope
c906108c
SS
5950If a display expression refers to local variables, then it does not make
5951sense outside the lexical context for which it was set up. Such an
5952expression is disabled when execution enters a context where one of its
5953variables is not defined. For example, if you give the command
5954@code{display last_char} while inside a function with an argument
5955@code{last_char}, @value{GDBN} displays this argument while your program
5956continues to stop inside that function. When it stops elsewhere---where
5957there is no variable @code{last_char}---the display is disabled
5958automatically. The next time your program stops where @code{last_char}
5959is meaningful, you can enable the display expression once again.
5960
6d2ebf8b 5961@node Print Settings
c906108c
SS
5962@section Print settings
5963
5964@cindex format options
5965@cindex print settings
5966@value{GDBN} provides the following ways to control how arrays, structures,
5967and symbols are printed.
5968
5969@noindent
5970These settings are useful for debugging programs in any language:
5971
5972@table @code
4644b6e3 5973@kindex set print
c906108c
SS
5974@item set print address
5975@itemx set print address on
4644b6e3 5976@cindex print/don't print memory addresses
c906108c
SS
5977@value{GDBN} prints memory addresses showing the location of stack
5978traces, structure values, pointer values, breakpoints, and so forth,
5979even when it also displays the contents of those addresses. The default
5980is @code{on}. For example, this is what a stack frame display looks like with
5981@code{set print address on}:
5982
5983@smallexample
5984@group
5985(@value{GDBP}) f
5986#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5987 at input.c:530
5988530 if (lquote != def_lquote)
5989@end group
5990@end smallexample
5991
5992@item set print address off
5993Do not print addresses when displaying their contents. For example,
5994this is the same stack frame displayed with @code{set print address off}:
5995
5996@smallexample
5997@group
5998(@value{GDBP}) set print addr off
5999(@value{GDBP}) f
6000#0 set_quotes (lq="<<", rq=">>") at input.c:530
6001530 if (lquote != def_lquote)
6002@end group
6003@end smallexample
6004
6005You can use @samp{set print address off} to eliminate all machine
6006dependent displays from the @value{GDBN} interface. For example, with
6007@code{print address off}, you should get the same text for backtraces on
6008all machines---whether or not they involve pointer arguments.
6009
4644b6e3 6010@kindex show print
c906108c
SS
6011@item show print address
6012Show whether or not addresses are to be printed.
6013@end table
6014
6015When @value{GDBN} prints a symbolic address, it normally prints the
6016closest earlier symbol plus an offset. If that symbol does not uniquely
6017identify the address (for example, it is a name whose scope is a single
6018source file), you may need to clarify. One way to do this is with
6019@code{info line}, for example @samp{info line *0x4537}. Alternately,
6020you can set @value{GDBN} to print the source file and line number when
6021it prints a symbolic address:
6022
6023@table @code
c906108c 6024@item set print symbol-filename on
9c16f35a
EZ
6025@cindex source file and line of a symbol
6026@cindex symbol, source file and line
c906108c
SS
6027Tell @value{GDBN} to print the source file name and line number of a
6028symbol in the symbolic form of an address.
6029
6030@item set print symbol-filename off
6031Do not print source file name and line number of a symbol. This is the
6032default.
6033
c906108c
SS
6034@item show print symbol-filename
6035Show whether or not @value{GDBN} will print the source file name and
6036line number of a symbol in the symbolic form of an address.
6037@end table
6038
6039Another situation where it is helpful to show symbol filenames and line
6040numbers is when disassembling code; @value{GDBN} shows you the line
6041number and source file that corresponds to each instruction.
6042
6043Also, you may wish to see the symbolic form only if the address being
6044printed is reasonably close to the closest earlier symbol:
6045
6046@table @code
c906108c 6047@item set print max-symbolic-offset @var{max-offset}
4644b6e3 6048@cindex maximum value for offset of closest symbol
c906108c
SS
6049Tell @value{GDBN} to only display the symbolic form of an address if the
6050offset between the closest earlier symbol and the address is less than
5d161b24 6051@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
6052to always print the symbolic form of an address if any symbol precedes it.
6053
c906108c
SS
6054@item show print max-symbolic-offset
6055Ask how large the maximum offset is that @value{GDBN} prints in a
6056symbolic address.
6057@end table
6058
6059@cindex wild pointer, interpreting
6060@cindex pointer, finding referent
6061If you have a pointer and you are not sure where it points, try
6062@samp{set print symbol-filename on}. Then you can determine the name
6063and source file location of the variable where it points, using
6064@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
6065For example, here @value{GDBN} shows that a variable @code{ptt} points
6066at another variable @code{t}, defined in @file{hi2.c}:
6067
474c8240 6068@smallexample
c906108c
SS
6069(@value{GDBP}) set print symbol-filename on
6070(@value{GDBP}) p/a ptt
6071$4 = 0xe008 <t in hi2.c>
474c8240 6072@end smallexample
c906108c
SS
6073
6074@quotation
6075@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
6076does not show the symbol name and filename of the referent, even with
6077the appropriate @code{set print} options turned on.
6078@end quotation
6079
6080Other settings control how different kinds of objects are printed:
6081
6082@table @code
c906108c
SS
6083@item set print array
6084@itemx set print array on
4644b6e3 6085@cindex pretty print arrays
c906108c
SS
6086Pretty print arrays. This format is more convenient to read,
6087but uses more space. The default is off.
6088
6089@item set print array off
6090Return to compressed format for arrays.
6091
c906108c
SS
6092@item show print array
6093Show whether compressed or pretty format is selected for displaying
6094arrays.
6095
3c9c013a
JB
6096@cindex print array indexes
6097@item set print array-indexes
6098@itemx set print array-indexes on
6099Print the index of each element when displaying arrays. May be more
6100convenient to locate a given element in the array or quickly find the
6101index of a given element in that printed array. The default is off.
6102
6103@item set print array-indexes off
6104Stop printing element indexes when displaying arrays.
6105
6106@item show print array-indexes
6107Show whether the index of each element is printed when displaying
6108arrays.
6109
c906108c 6110@item set print elements @var{number-of-elements}
4644b6e3 6111@cindex number of array elements to print
9c16f35a 6112@cindex limit on number of printed array elements
c906108c
SS
6113Set a limit on how many elements of an array @value{GDBN} will print.
6114If @value{GDBN} is printing a large array, it stops printing after it has
6115printed the number of elements set by the @code{set print elements} command.
6116This limit also applies to the display of strings.
d4f3574e 6117When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
6118Setting @var{number-of-elements} to zero means that the printing is unlimited.
6119
c906108c
SS
6120@item show print elements
6121Display the number of elements of a large array that @value{GDBN} will print.
6122If the number is 0, then the printing is unlimited.
6123
9c16f35a
EZ
6124@item set print repeats
6125@cindex repeated array elements
6126Set the threshold for suppressing display of repeated array
6127elelments. When the number of consecutive identical elements of an
6128array exceeds the threshold, @value{GDBN} prints the string
6129@code{"<repeats @var{n} times>"}, where @var{n} is the number of
6130identical repetitions, instead of displaying the identical elements
6131themselves. Setting the threshold to zero will cause all elements to
6132be individually printed. The default threshold is 10.
6133
6134@item show print repeats
6135Display the current threshold for printing repeated identical
6136elements.
6137
c906108c 6138@item set print null-stop
4644b6e3 6139@cindex @sc{null} elements in arrays
c906108c 6140Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 6141@sc{null} is encountered. This is useful when large arrays actually
c906108c 6142contain only short strings.
d4f3574e 6143The default is off.
c906108c 6144
9c16f35a
EZ
6145@item show print null-stop
6146Show whether @value{GDBN} stops printing an array on the first
6147@sc{null} character.
6148
c906108c 6149@item set print pretty on
9c16f35a
EZ
6150@cindex print structures in indented form
6151@cindex indentation in structure display
5d161b24 6152Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
6153per line, like this:
6154
6155@smallexample
6156@group
6157$1 = @{
6158 next = 0x0,
6159 flags = @{
6160 sweet = 1,
6161 sour = 1
6162 @},
6163 meat = 0x54 "Pork"
6164@}
6165@end group
6166@end smallexample
6167
6168@item set print pretty off
6169Cause @value{GDBN} to print structures in a compact format, like this:
6170
6171@smallexample
6172@group
6173$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
6174meat = 0x54 "Pork"@}
6175@end group
6176@end smallexample
6177
6178@noindent
6179This is the default format.
6180
c906108c
SS
6181@item show print pretty
6182Show which format @value{GDBN} is using to print structures.
6183
c906108c 6184@item set print sevenbit-strings on
4644b6e3
EZ
6185@cindex eight-bit characters in strings
6186@cindex octal escapes in strings
c906108c
SS
6187Print using only seven-bit characters; if this option is set,
6188@value{GDBN} displays any eight-bit characters (in strings or
6189character values) using the notation @code{\}@var{nnn}. This setting is
6190best if you are working in English (@sc{ascii}) and you use the
6191high-order bit of characters as a marker or ``meta'' bit.
6192
6193@item set print sevenbit-strings off
6194Print full eight-bit characters. This allows the use of more
6195international character sets, and is the default.
6196
c906108c
SS
6197@item show print sevenbit-strings
6198Show whether or not @value{GDBN} is printing only seven-bit characters.
6199
c906108c 6200@item set print union on
4644b6e3 6201@cindex unions in structures, printing
9c16f35a
EZ
6202Tell @value{GDBN} to print unions which are contained in structures
6203and other unions. This is the default setting.
c906108c
SS
6204
6205@item set print union off
9c16f35a
EZ
6206Tell @value{GDBN} not to print unions which are contained in
6207structures and other unions. @value{GDBN} will print @code{"@{...@}"}
6208instead.
c906108c 6209
c906108c
SS
6210@item show print union
6211Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 6212structures and other unions.
c906108c
SS
6213
6214For example, given the declarations
6215
6216@smallexample
6217typedef enum @{Tree, Bug@} Species;
6218typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 6219typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
6220 Bug_forms;
6221
6222struct thing @{
6223 Species it;
6224 union @{
6225 Tree_forms tree;
6226 Bug_forms bug;
6227 @} form;
6228@};
6229
6230struct thing foo = @{Tree, @{Acorn@}@};
6231@end smallexample
6232
6233@noindent
6234with @code{set print union on} in effect @samp{p foo} would print
6235
6236@smallexample
6237$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
6238@end smallexample
6239
6240@noindent
6241and with @code{set print union off} in effect it would print
6242
6243@smallexample
6244$1 = @{it = Tree, form = @{...@}@}
6245@end smallexample
9c16f35a
EZ
6246
6247@noindent
6248@code{set print union} affects programs written in C-like languages
6249and in Pascal.
c906108c
SS
6250@end table
6251
c906108c
SS
6252@need 1000
6253@noindent
b37052ae 6254These settings are of interest when debugging C@t{++} programs:
c906108c
SS
6255
6256@table @code
4644b6e3 6257@cindex demangling C@t{++} names
c906108c
SS
6258@item set print demangle
6259@itemx set print demangle on
b37052ae 6260Print C@t{++} names in their source form rather than in the encoded
c906108c 6261(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 6262linkage. The default is on.
c906108c 6263
c906108c 6264@item show print demangle
b37052ae 6265Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 6266
c906108c
SS
6267@item set print asm-demangle
6268@itemx set print asm-demangle on
b37052ae 6269Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
6270in assembler code printouts such as instruction disassemblies.
6271The default is off.
6272
c906108c 6273@item show print asm-demangle
b37052ae 6274Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
6275or demangled form.
6276
b37052ae
EZ
6277@cindex C@t{++} symbol decoding style
6278@cindex symbol decoding style, C@t{++}
a8f24a35 6279@kindex set demangle-style
c906108c
SS
6280@item set demangle-style @var{style}
6281Choose among several encoding schemes used by different compilers to
b37052ae 6282represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
6283
6284@table @code
6285@item auto
6286Allow @value{GDBN} to choose a decoding style by inspecting your program.
6287
6288@item gnu
b37052ae 6289Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 6290This is the default.
c906108c
SS
6291
6292@item hp
b37052ae 6293Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
6294
6295@item lucid
b37052ae 6296Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
6297
6298@item arm
b37052ae 6299Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
6300@strong{Warning:} this setting alone is not sufficient to allow
6301debugging @code{cfront}-generated executables. @value{GDBN} would
6302require further enhancement to permit that.
6303
6304@end table
6305If you omit @var{style}, you will see a list of possible formats.
6306
c906108c 6307@item show demangle-style
b37052ae 6308Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 6309
c906108c
SS
6310@item set print object
6311@itemx set print object on
4644b6e3 6312@cindex derived type of an object, printing
9c16f35a 6313@cindex display derived types
c906108c
SS
6314When displaying a pointer to an object, identify the @emph{actual}
6315(derived) type of the object rather than the @emph{declared} type, using
6316the virtual function table.
6317
6318@item set print object off
6319Display only the declared type of objects, without reference to the
6320virtual function table. This is the default setting.
6321
c906108c
SS
6322@item show print object
6323Show whether actual, or declared, object types are displayed.
6324
c906108c
SS
6325@item set print static-members
6326@itemx set print static-members on
4644b6e3 6327@cindex static members of C@t{++} objects
b37052ae 6328Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
6329
6330@item set print static-members off
b37052ae 6331Do not print static members when displaying a C@t{++} object.
c906108c 6332
c906108c 6333@item show print static-members
9c16f35a
EZ
6334Show whether C@t{++} static members are printed or not.
6335
6336@item set print pascal_static-members
6337@itemx set print pascal_static-members on
6338@cindex static members of Pacal objects
6339@cindex Pacal objects, static members display
6340Print static members when displaying a Pascal object. The default is on.
6341
6342@item set print pascal_static-members off
6343Do not print static members when displaying a Pascal object.
6344
6345@item show print pascal_static-members
6346Show whether Pascal static members are printed or not.
c906108c
SS
6347
6348@c These don't work with HP ANSI C++ yet.
c906108c
SS
6349@item set print vtbl
6350@itemx set print vtbl on
4644b6e3 6351@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
6352@cindex virtual functions (C@t{++}) display
6353@cindex VTBL display
b37052ae 6354Pretty print C@t{++} virtual function tables. The default is off.
c906108c 6355(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 6356ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
6357
6358@item set print vtbl off
b37052ae 6359Do not pretty print C@t{++} virtual function tables.
c906108c 6360
c906108c 6361@item show print vtbl
b37052ae 6362Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 6363@end table
c906108c 6364
6d2ebf8b 6365@node Value History
c906108c
SS
6366@section Value history
6367
6368@cindex value history
9c16f35a 6369@cindex history of values printed by @value{GDBN}
5d161b24
DB
6370Values printed by the @code{print} command are saved in the @value{GDBN}
6371@dfn{value history}. This allows you to refer to them in other expressions.
6372Values are kept until the symbol table is re-read or discarded
6373(for example with the @code{file} or @code{symbol-file} commands).
6374When the symbol table changes, the value history is discarded,
6375since the values may contain pointers back to the types defined in the
c906108c
SS
6376symbol table.
6377
6378@cindex @code{$}
6379@cindex @code{$$}
6380@cindex history number
6381The values printed are given @dfn{history numbers} by which you can
6382refer to them. These are successive integers starting with one.
6383@code{print} shows you the history number assigned to a value by
6384printing @samp{$@var{num} = } before the value; here @var{num} is the
6385history number.
6386
6387To refer to any previous value, use @samp{$} followed by the value's
6388history number. The way @code{print} labels its output is designed to
6389remind you of this. Just @code{$} refers to the most recent value in
6390the history, and @code{$$} refers to the value before that.
6391@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6392is the value just prior to @code{$$}, @code{$$1} is equivalent to
6393@code{$$}, and @code{$$0} is equivalent to @code{$}.
6394
6395For example, suppose you have just printed a pointer to a structure and
6396want to see the contents of the structure. It suffices to type
6397
474c8240 6398@smallexample
c906108c 6399p *$
474c8240 6400@end smallexample
c906108c
SS
6401
6402If you have a chain of structures where the component @code{next} points
6403to the next one, you can print the contents of the next one with this:
6404
474c8240 6405@smallexample
c906108c 6406p *$.next
474c8240 6407@end smallexample
c906108c
SS
6408
6409@noindent
6410You can print successive links in the chain by repeating this
6411command---which you can do by just typing @key{RET}.
6412
6413Note that the history records values, not expressions. If the value of
6414@code{x} is 4 and you type these commands:
6415
474c8240 6416@smallexample
c906108c
SS
6417print x
6418set x=5
474c8240 6419@end smallexample
c906108c
SS
6420
6421@noindent
6422then the value recorded in the value history by the @code{print} command
6423remains 4 even though the value of @code{x} has changed.
6424
6425@table @code
6426@kindex show values
6427@item show values
6428Print the last ten values in the value history, with their item numbers.
6429This is like @samp{p@ $$9} repeated ten times, except that @code{show
6430values} does not change the history.
6431
6432@item show values @var{n}
6433Print ten history values centered on history item number @var{n}.
6434
6435@item show values +
6436Print ten history values just after the values last printed. If no more
6437values are available, @code{show values +} produces no display.
6438@end table
6439
6440Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6441same effect as @samp{show values +}.
6442
6d2ebf8b 6443@node Convenience Vars
c906108c
SS
6444@section Convenience variables
6445
6446@cindex convenience variables
9c16f35a 6447@cindex user-defined variables
c906108c
SS
6448@value{GDBN} provides @dfn{convenience variables} that you can use within
6449@value{GDBN} to hold on to a value and refer to it later. These variables
6450exist entirely within @value{GDBN}; they are not part of your program, and
6451setting a convenience variable has no direct effect on further execution
6452of your program. That is why you can use them freely.
6453
6454Convenience variables are prefixed with @samp{$}. Any name preceded by
6455@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6456the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6457(Value history references, in contrast, are @emph{numbers} preceded
6458by @samp{$}. @xref{Value History, ,Value history}.)
6459
6460You can save a value in a convenience variable with an assignment
6461expression, just as you would set a variable in your program.
6462For example:
6463
474c8240 6464@smallexample
c906108c 6465set $foo = *object_ptr
474c8240 6466@end smallexample
c906108c
SS
6467
6468@noindent
6469would save in @code{$foo} the value contained in the object pointed to by
6470@code{object_ptr}.
6471
6472Using a convenience variable for the first time creates it, but its
6473value is @code{void} until you assign a new value. You can alter the
6474value with another assignment at any time.
6475
6476Convenience variables have no fixed types. You can assign a convenience
6477variable any type of value, including structures and arrays, even if
6478that variable already has a value of a different type. The convenience
6479variable, when used as an expression, has the type of its current value.
6480
6481@table @code
6482@kindex show convenience
9c16f35a 6483@cindex show all user variables
c906108c
SS
6484@item show convenience
6485Print a list of convenience variables used so far, and their values.
d4f3574e 6486Abbreviated @code{show conv}.
53e5f3cf
AS
6487
6488@kindex init-if-undefined
6489@cindex convenience variables, initializing
6490@item init-if-undefined $@var{variable} = @var{expression}
6491Set a convenience variable if it has not already been set. This is useful
6492for user-defined commands that keep some state. It is similar, in concept,
6493to using local static variables with initializers in C (except that
6494convenience variables are global). It can also be used to allow users to
6495override default values used in a command script.
6496
6497If the variable is already defined then the expression is not evaluated so
6498any side-effects do not occur.
c906108c
SS
6499@end table
6500
6501One of the ways to use a convenience variable is as a counter to be
6502incremented or a pointer to be advanced. For example, to print
6503a field from successive elements of an array of structures:
6504
474c8240 6505@smallexample
c906108c
SS
6506set $i = 0
6507print bar[$i++]->contents
474c8240 6508@end smallexample
c906108c 6509
d4f3574e
SS
6510@noindent
6511Repeat that command by typing @key{RET}.
c906108c
SS
6512
6513Some convenience variables are created automatically by @value{GDBN} and given
6514values likely to be useful.
6515
6516@table @code
41afff9a 6517@vindex $_@r{, convenience variable}
c906108c
SS
6518@item $_
6519The variable @code{$_} is automatically set by the @code{x} command to
6520the last address examined (@pxref{Memory, ,Examining memory}). Other
6521commands which provide a default address for @code{x} to examine also
6522set @code{$_} to that address; these commands include @code{info line}
6523and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6524except when set by the @code{x} command, in which case it is a pointer
6525to the type of @code{$__}.
6526
41afff9a 6527@vindex $__@r{, convenience variable}
c906108c
SS
6528@item $__
6529The variable @code{$__} is automatically set by the @code{x} command
6530to the value found in the last address examined. Its type is chosen
6531to match the format in which the data was printed.
6532
6533@item $_exitcode
41afff9a 6534@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6535The variable @code{$_exitcode} is automatically set to the exit code when
6536the program being debugged terminates.
6537@end table
6538
53a5351d
JM
6539On HP-UX systems, if you refer to a function or variable name that
6540begins with a dollar sign, @value{GDBN} searches for a user or system
6541name first, before it searches for a convenience variable.
c906108c 6542
6d2ebf8b 6543@node Registers
c906108c
SS
6544@section Registers
6545
6546@cindex registers
6547You can refer to machine register contents, in expressions, as variables
6548with names starting with @samp{$}. The names of registers are different
6549for each machine; use @code{info registers} to see the names used on
6550your machine.
6551
6552@table @code
6553@kindex info registers
6554@item info registers
6555Print the names and values of all registers except floating-point
c85508ee 6556and vector registers (in the selected stack frame).
c906108c
SS
6557
6558@kindex info all-registers
6559@cindex floating point registers
6560@item info all-registers
6561Print the names and values of all registers, including floating-point
c85508ee 6562and vector registers (in the selected stack frame).
c906108c
SS
6563
6564@item info registers @var{regname} @dots{}
6565Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6566As discussed in detail below, register values are normally relative to
6567the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6568the machine you are using, with or without the initial @samp{$}.
6569@end table
6570
e09f16f9
EZ
6571@cindex stack pointer register
6572@cindex program counter register
6573@cindex process status register
6574@cindex frame pointer register
6575@cindex standard registers
c906108c
SS
6576@value{GDBN} has four ``standard'' register names that are available (in
6577expressions) on most machines---whenever they do not conflict with an
6578architecture's canonical mnemonics for registers. The register names
6579@code{$pc} and @code{$sp} are used for the program counter register and
6580the stack pointer. @code{$fp} is used for a register that contains a
6581pointer to the current stack frame, and @code{$ps} is used for a
6582register that contains the processor status. For example,
6583you could print the program counter in hex with
6584
474c8240 6585@smallexample
c906108c 6586p/x $pc
474c8240 6587@end smallexample
c906108c
SS
6588
6589@noindent
6590or print the instruction to be executed next with
6591
474c8240 6592@smallexample
c906108c 6593x/i $pc
474c8240 6594@end smallexample
c906108c
SS
6595
6596@noindent
6597or add four to the stack pointer@footnote{This is a way of removing
6598one word from the stack, on machines where stacks grow downward in
6599memory (most machines, nowadays). This assumes that the innermost
6600stack frame is selected; setting @code{$sp} is not allowed when other
6601stack frames are selected. To pop entire frames off the stack,
6602regardless of machine architecture, use @code{return};
d4f3574e 6603see @ref{Returning, ,Returning from a function}.} with
c906108c 6604
474c8240 6605@smallexample
c906108c 6606set $sp += 4
474c8240 6607@end smallexample
c906108c
SS
6608
6609Whenever possible, these four standard register names are available on
6610your machine even though the machine has different canonical mnemonics,
6611so long as there is no conflict. The @code{info registers} command
6612shows the canonical names. For example, on the SPARC, @code{info
6613registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6614can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6615is an alias for the @sc{eflags} register.
c906108c
SS
6616
6617@value{GDBN} always considers the contents of an ordinary register as an
6618integer when the register is examined in this way. Some machines have
6619special registers which can hold nothing but floating point; these
6620registers are considered to have floating point values. There is no way
6621to refer to the contents of an ordinary register as floating point value
6622(although you can @emph{print} it as a floating point value with
6623@samp{print/f $@var{regname}}).
6624
6625Some registers have distinct ``raw'' and ``virtual'' data formats. This
6626means that the data format in which the register contents are saved by
6627the operating system is not the same one that your program normally
6628sees. For example, the registers of the 68881 floating point
6629coprocessor are always saved in ``extended'' (raw) format, but all C
6630programs expect to work with ``double'' (virtual) format. In such
5d161b24 6631cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6632that makes sense for your program), but the @code{info registers} command
6633prints the data in both formats.
6634
36b80e65
EZ
6635@cindex SSE registers (x86)
6636@cindex MMX registers (x86)
6637Some machines have special registers whose contents can be interpreted
6638in several different ways. For example, modern x86-based machines
6639have SSE and MMX registers that can hold several values packed
6640together in several different formats. @value{GDBN} refers to such
6641registers in @code{struct} notation:
6642
6643@smallexample
6644(@value{GDBP}) print $xmm1
6645$1 = @{
6646 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
6647 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
6648 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6649 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
6650 v4_int32 = @{0, 20657912, 11, 13@},
6651 v2_int64 = @{88725056443645952, 55834574859@},
6652 uint128 = 0x0000000d0000000b013b36f800000000
6653@}
6654@end smallexample
6655
6656@noindent
6657To set values of such registers, you need to tell @value{GDBN} which
6658view of the register you wish to change, as if you were assigning
6659value to a @code{struct} member:
6660
6661@smallexample
6662 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6663@end smallexample
6664
c906108c
SS
6665Normally, register values are relative to the selected stack frame
6666(@pxref{Selection, ,Selecting a frame}). This means that you get the
6667value that the register would contain if all stack frames farther in
6668were exited and their saved registers restored. In order to see the
6669true contents of hardware registers, you must select the innermost
6670frame (with @samp{frame 0}).
6671
6672However, @value{GDBN} must deduce where registers are saved, from the machine
6673code generated by your compiler. If some registers are not saved, or if
6674@value{GDBN} is unable to locate the saved registers, the selected stack
6675frame makes no difference.
6676
6d2ebf8b 6677@node Floating Point Hardware
c906108c
SS
6678@section Floating point hardware
6679@cindex floating point
6680
6681Depending on the configuration, @value{GDBN} may be able to give
6682you more information about the status of the floating point hardware.
6683
6684@table @code
6685@kindex info float
6686@item info float
6687Display hardware-dependent information about the floating
6688point unit. The exact contents and layout vary depending on the
6689floating point chip. Currently, @samp{info float} is supported on
6690the ARM and x86 machines.
6691@end table
c906108c 6692
e76f1f2e
AC
6693@node Vector Unit
6694@section Vector Unit
6695@cindex vector unit
6696
6697Depending on the configuration, @value{GDBN} may be able to give you
6698more information about the status of the vector unit.
6699
6700@table @code
6701@kindex info vector
6702@item info vector
6703Display information about the vector unit. The exact contents and
6704layout vary depending on the hardware.
6705@end table
6706
721c2651
EZ
6707@node OS Information
6708@section Operating system auxiliary information
6709@cindex OS information
6710
6711@value{GDBN} provides interfaces to useful OS facilities that can help
6712you debug your program.
6713
6714@cindex @code{ptrace} system call
6715@cindex @code{struct user} contents
6716When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6717machines), it interfaces with the inferior via the @code{ptrace}
6718system call. The operating system creates a special sata structure,
6719called @code{struct user}, for this interface. You can use the
6720command @code{info udot} to display the contents of this data
6721structure.
6722
6723@table @code
6724@item info udot
6725@kindex info udot
6726Display the contents of the @code{struct user} maintained by the OS
6727kernel for the program being debugged. @value{GDBN} displays the
6728contents of @code{struct user} as a list of hex numbers, similar to
6729the @code{examine} command.
6730@end table
6731
b383017d
RM
6732@cindex auxiliary vector
6733@cindex vector, auxiliary
b383017d
RM
6734Some operating systems supply an @dfn{auxiliary vector} to programs at
6735startup. This is akin to the arguments and environment that you
6736specify for a program, but contains a system-dependent variety of
6737binary values that tell system libraries important details about the
6738hardware, operating system, and process. Each value's purpose is
6739identified by an integer tag; the meanings are well-known but system-specific.
6740Depending on the configuration and operating system facilities,
9c16f35a
EZ
6741@value{GDBN} may be able to show you this information. For remote
6742targets, this functionality may further depend on the remote stub's
0876f84a 6743support of the @samp{qXfer:auxv:read} packet, see @ref{Remote
9c16f35a 6744configuration, auxiliary vector}.
b383017d
RM
6745
6746@table @code
6747@kindex info auxv
6748@item info auxv
6749Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6750live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6751numerically, and also shows names and text descriptions for recognized
6752tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6753pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6754most appropriate form for a recognized tag, and in hexadecimal for
6755an unrecognized tag.
6756@end table
6757
721c2651 6758
29e57380 6759@node Memory Region Attributes
b383017d 6760@section Memory region attributes
29e57380
C
6761@cindex memory region attributes
6762
b383017d 6763@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
6764required by regions of your target's memory. @value{GDBN} uses
6765attributes to determine whether to allow certain types of memory
6766accesses; whether to use specific width accesses; and whether to cache
6767target memory. By default the description of memory regions is
6768fetched from the target (if the current target supports this), but the
6769user can override the fetched regions.
29e57380
C
6770
6771Defined memory regions can be individually enabled and disabled. When a
6772memory region is disabled, @value{GDBN} uses the default attributes when
6773accessing memory in that region. Similarly, if no memory regions have
6774been defined, @value{GDBN} uses the default attributes when accessing
6775all memory.
6776
b383017d 6777When a memory region is defined, it is given a number to identify it;
29e57380
C
6778to enable, disable, or remove a memory region, you specify that number.
6779
6780@table @code
6781@kindex mem
bfac230e 6782@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6783Define a memory region bounded by @var{lower} and @var{upper} with
6784attributes @var{attributes}@dots{}, and add it to the list of regions
6785monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6786case: it is treated as the the target's maximum memory address.
bfac230e 6787(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 6788
fd79ecee
DJ
6789@item mem auto
6790Discard any user changes to the memory regions and use target-supplied
6791regions, if available, or no regions if the target does not support.
6792
29e57380
C
6793@kindex delete mem
6794@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6795Remove memory regions @var{nums}@dots{} from the list of regions
6796monitored by @value{GDBN}.
29e57380
C
6797
6798@kindex disable mem
6799@item disable mem @var{nums}@dots{}
09d4efe1 6800Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6801A disabled memory region is not forgotten.
29e57380
C
6802It may be enabled again later.
6803
6804@kindex enable mem
6805@item enable mem @var{nums}@dots{}
09d4efe1 6806Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6807
6808@kindex info mem
6809@item info mem
6810Print a table of all defined memory regions, with the following columns
09d4efe1 6811for each region:
29e57380
C
6812
6813@table @emph
6814@item Memory Region Number
6815@item Enabled or Disabled.
b383017d 6816Enabled memory regions are marked with @samp{y}.
29e57380
C
6817Disabled memory regions are marked with @samp{n}.
6818
6819@item Lo Address
6820The address defining the inclusive lower bound of the memory region.
6821
6822@item Hi Address
6823The address defining the exclusive upper bound of the memory region.
6824
6825@item Attributes
6826The list of attributes set for this memory region.
6827@end table
6828@end table
6829
6830
6831@subsection Attributes
6832
b383017d 6833@subsubsection Memory Access Mode
29e57380
C
6834The access mode attributes set whether @value{GDBN} may make read or
6835write accesses to a memory region.
6836
6837While these attributes prevent @value{GDBN} from performing invalid
6838memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 6839etc.@: from accessing memory.
29e57380
C
6840
6841@table @code
6842@item ro
6843Memory is read only.
6844@item wo
6845Memory is write only.
6846@item rw
6ca652b0 6847Memory is read/write. This is the default.
29e57380
C
6848@end table
6849
6850@subsubsection Memory Access Size
6851The acccess size attributes tells @value{GDBN} to use specific sized
6852accesses in the memory region. Often memory mapped device registers
6853require specific sized accesses. If no access size attribute is
6854specified, @value{GDBN} may use accesses of any size.
6855
6856@table @code
6857@item 8
6858Use 8 bit memory accesses.
6859@item 16
6860Use 16 bit memory accesses.
6861@item 32
6862Use 32 bit memory accesses.
6863@item 64
6864Use 64 bit memory accesses.
6865@end table
6866
6867@c @subsubsection Hardware/Software Breakpoints
6868@c The hardware/software breakpoint attributes set whether @value{GDBN}
6869@c will use hardware or software breakpoints for the internal breakpoints
6870@c used by the step, next, finish, until, etc. commands.
6871@c
6872@c @table @code
6873@c @item hwbreak
b383017d 6874@c Always use hardware breakpoints
29e57380
C
6875@c @item swbreak (default)
6876@c @end table
6877
6878@subsubsection Data Cache
6879The data cache attributes set whether @value{GDBN} will cache target
6880memory. While this generally improves performance by reducing debug
6881protocol overhead, it can lead to incorrect results because @value{GDBN}
6882does not know about volatile variables or memory mapped device
6883registers.
6884
6885@table @code
6886@item cache
b383017d 6887Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6888@item nocache
6889Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6890@end table
6891
6892@c @subsubsection Memory Write Verification
b383017d 6893@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6894@c will re-reads data after each write to verify the write was successful.
6895@c
6896@c @table @code
6897@c @item verify
6898@c @item noverify (default)
6899@c @end table
6900
16d9dec6
MS
6901@node Dump/Restore Files
6902@section Copy between memory and a file
6903@cindex dump/restore files
6904@cindex append data to a file
6905@cindex dump data to a file
6906@cindex restore data from a file
16d9dec6 6907
df5215a6
JB
6908You can use the commands @code{dump}, @code{append}, and
6909@code{restore} to copy data between target memory and a file. The
6910@code{dump} and @code{append} commands write data to a file, and the
6911@code{restore} command reads data from a file back into the inferior's
6912memory. Files may be in binary, Motorola S-record, Intel hex, or
6913Tektronix Hex format; however, @value{GDBN} can only append to binary
6914files.
6915
6916@table @code
6917
6918@kindex dump
6919@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6920@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6921Dump the contents of memory from @var{start_addr} to @var{end_addr},
6922or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6923
df5215a6 6924The @var{format} parameter may be any one of:
16d9dec6 6925@table @code
df5215a6
JB
6926@item binary
6927Raw binary form.
6928@item ihex
6929Intel hex format.
6930@item srec
6931Motorola S-record format.
6932@item tekhex
6933Tektronix Hex format.
6934@end table
6935
6936@value{GDBN} uses the same definitions of these formats as the
6937@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6938@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6939form.
6940
6941@kindex append
6942@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6943@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6944Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6945or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6946(@value{GDBN} can only append data to files in raw binary form.)
6947
6948@kindex restore
6949@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6950Restore the contents of file @var{filename} into memory. The
6951@code{restore} command can automatically recognize any known @sc{bfd}
6952file format, except for raw binary. To restore a raw binary file you
6953must specify the optional keyword @code{binary} after the filename.
16d9dec6 6954
b383017d 6955If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6956contained in the file. Binary files always start at address zero, so
6957they will be restored at address @var{bias}. Other bfd files have
6958a built-in location; they will be restored at offset @var{bias}
6959from that location.
6960
6961If @var{start} and/or @var{end} are non-zero, then only data between
6962file offset @var{start} and file offset @var{end} will be restored.
b383017d 6963These offsets are relative to the addresses in the file, before
16d9dec6
MS
6964the @var{bias} argument is applied.
6965
6966@end table
6967
384ee23f
EZ
6968@node Core File Generation
6969@section How to Produce a Core File from Your Program
6970@cindex dump core from inferior
6971
6972A @dfn{core file} or @dfn{core dump} is a file that records the memory
6973image of a running process and its process status (register values
6974etc.). Its primary use is post-mortem debugging of a program that
6975crashed while it ran outside a debugger. A program that crashes
6976automatically produces a core file, unless this feature is disabled by
6977the user. @xref{Files}, for information on invoking @value{GDBN} in
6978the post-mortem debugging mode.
6979
6980Occasionally, you may wish to produce a core file of the program you
6981are debugging in order to preserve a snapshot of its state.
6982@value{GDBN} has a special command for that.
6983
6984@table @code
6985@kindex gcore
6986@kindex generate-core-file
6987@item generate-core-file [@var{file}]
6988@itemx gcore [@var{file}]
6989Produce a core dump of the inferior process. The optional argument
6990@var{file} specifies the file name where to put the core dump. If not
6991specified, the file name defaults to @file{core.@var{pid}}, where
6992@var{pid} is the inferior process ID.
6993
6994Note that this command is implemented only for some systems (as of
6995this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6996@end table
6997
a0eb71c5
KB
6998@node Character Sets
6999@section Character Sets
7000@cindex character sets
7001@cindex charset
7002@cindex translating between character sets
7003@cindex host character set
7004@cindex target character set
7005
7006If the program you are debugging uses a different character set to
7007represent characters and strings than the one @value{GDBN} uses itself,
7008@value{GDBN} can automatically translate between the character sets for
7009you. The character set @value{GDBN} uses we call the @dfn{host
7010character set}; the one the inferior program uses we call the
7011@dfn{target character set}.
7012
7013For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
7014uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
7015remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
7016running on an IBM mainframe, which uses the @sc{ebcdic} character set,
7017then the host character set is Latin-1, and the target character set is
7018@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 7019target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
7020@sc{ebcdic} and Latin 1 as you print character or string values, or use
7021character and string literals in expressions.
7022
7023@value{GDBN} has no way to automatically recognize which character set
7024the inferior program uses; you must tell it, using the @code{set
7025target-charset} command, described below.
7026
7027Here are the commands for controlling @value{GDBN}'s character set
7028support:
7029
7030@table @code
7031@item set target-charset @var{charset}
7032@kindex set target-charset
7033Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
7034character set names @value{GDBN} recognizes below, but if you type
7035@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7036list the target character sets it supports.
a0eb71c5
KB
7037@end table
7038
7039@table @code
7040@item set host-charset @var{charset}
7041@kindex set host-charset
7042Set the current host character set to @var{charset}.
7043
7044By default, @value{GDBN} uses a host character set appropriate to the
7045system it is running on; you can override that default using the
7046@code{set host-charset} command.
7047
7048@value{GDBN} can only use certain character sets as its host character
7049set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
7050indicate which can be host character sets, but if you type
7051@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7052list the host character sets it supports.
a0eb71c5
KB
7053
7054@item set charset @var{charset}
7055@kindex set charset
e33d66ec
EZ
7056Set the current host and target character sets to @var{charset}. As
7057above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
7058@value{GDBN} will list the name of the character sets that can be used
7059for both host and target.
7060
a0eb71c5
KB
7061
7062@item show charset
a0eb71c5 7063@kindex show charset
b383017d 7064Show the names of the current host and target charsets.
e33d66ec
EZ
7065
7066@itemx show host-charset
a0eb71c5 7067@kindex show host-charset
b383017d 7068Show the name of the current host charset.
e33d66ec
EZ
7069
7070@itemx show target-charset
a0eb71c5 7071@kindex show target-charset
b383017d 7072Show the name of the current target charset.
a0eb71c5
KB
7073
7074@end table
7075
7076@value{GDBN} currently includes support for the following character
7077sets:
7078
7079@table @code
7080
7081@item ASCII
7082@cindex ASCII character set
7083Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
7084character set.
7085
7086@item ISO-8859-1
7087@cindex ISO 8859-1 character set
7088@cindex ISO Latin 1 character set
e33d66ec 7089The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
7090characters needed for French, German, and Spanish. @value{GDBN} can use
7091this as its host character set.
7092
7093@item EBCDIC-US
7094@itemx IBM1047
7095@cindex EBCDIC character set
7096@cindex IBM1047 character set
7097Variants of the @sc{ebcdic} character set, used on some of IBM's
7098mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
7099@value{GDBN} cannot use these as its host character set.
7100
7101@end table
7102
7103Note that these are all single-byte character sets. More work inside
7104GDB is needed to support multi-byte or variable-width character
7105encodings, like the UTF-8 and UCS-2 encodings of Unicode.
7106
7107Here is an example of @value{GDBN}'s character set support in action.
7108Assume that the following source code has been placed in the file
7109@file{charset-test.c}:
7110
7111@smallexample
7112#include <stdio.h>
7113
7114char ascii_hello[]
7115 = @{72, 101, 108, 108, 111, 44, 32, 119,
7116 111, 114, 108, 100, 33, 10, 0@};
7117char ibm1047_hello[]
7118 = @{200, 133, 147, 147, 150, 107, 64, 166,
7119 150, 153, 147, 132, 90, 37, 0@};
7120
7121main ()
7122@{
7123 printf ("Hello, world!\n");
7124@}
10998722 7125@end smallexample
a0eb71c5
KB
7126
7127In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
7128containing the string @samp{Hello, world!} followed by a newline,
7129encoded in the @sc{ascii} and @sc{ibm1047} character sets.
7130
7131We compile the program, and invoke the debugger on it:
7132
7133@smallexample
7134$ gcc -g charset-test.c -o charset-test
7135$ gdb -nw charset-test
7136GNU gdb 2001-12-19-cvs
7137Copyright 2001 Free Software Foundation, Inc.
7138@dots{}
f7dc1244 7139(@value{GDBP})
10998722 7140@end smallexample
a0eb71c5
KB
7141
7142We can use the @code{show charset} command to see what character sets
7143@value{GDBN} is currently using to interpret and display characters and
7144strings:
7145
7146@smallexample
f7dc1244 7147(@value{GDBP}) show charset
e33d66ec 7148The current host and target character set is `ISO-8859-1'.
f7dc1244 7149(@value{GDBP})
10998722 7150@end smallexample
a0eb71c5
KB
7151
7152For the sake of printing this manual, let's use @sc{ascii} as our
7153initial character set:
7154@smallexample
f7dc1244
EZ
7155(@value{GDBP}) set charset ASCII
7156(@value{GDBP}) show charset
e33d66ec 7157The current host and target character set is `ASCII'.
f7dc1244 7158(@value{GDBP})
10998722 7159@end smallexample
a0eb71c5
KB
7160
7161Let's assume that @sc{ascii} is indeed the correct character set for our
7162host system --- in other words, let's assume that if @value{GDBN} prints
7163characters using the @sc{ascii} character set, our terminal will display
7164them properly. Since our current target character set is also
7165@sc{ascii}, the contents of @code{ascii_hello} print legibly:
7166
7167@smallexample
f7dc1244 7168(@value{GDBP}) print ascii_hello
a0eb71c5 7169$1 = 0x401698 "Hello, world!\n"
f7dc1244 7170(@value{GDBP}) print ascii_hello[0]
a0eb71c5 7171$2 = 72 'H'
f7dc1244 7172(@value{GDBP})
10998722 7173@end smallexample
a0eb71c5
KB
7174
7175@value{GDBN} uses the target character set for character and string
7176literals you use in expressions:
7177
7178@smallexample
f7dc1244 7179(@value{GDBP}) print '+'
a0eb71c5 7180$3 = 43 '+'
f7dc1244 7181(@value{GDBP})
10998722 7182@end smallexample
a0eb71c5
KB
7183
7184The @sc{ascii} character set uses the number 43 to encode the @samp{+}
7185character.
7186
7187@value{GDBN} relies on the user to tell it which character set the
7188target program uses. If we print @code{ibm1047_hello} while our target
7189character set is still @sc{ascii}, we get jibberish:
7190
7191@smallexample
f7dc1244 7192(@value{GDBP}) print ibm1047_hello
a0eb71c5 7193$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 7194(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7195$5 = 200 '\310'
f7dc1244 7196(@value{GDBP})
10998722 7197@end smallexample
a0eb71c5 7198
e33d66ec 7199If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
7200@value{GDBN} tells us the character sets it supports:
7201
7202@smallexample
f7dc1244 7203(@value{GDBP}) set target-charset
b383017d 7204ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 7205(@value{GDBP}) set target-charset
10998722 7206@end smallexample
a0eb71c5
KB
7207
7208We can select @sc{ibm1047} as our target character set, and examine the
7209program's strings again. Now the @sc{ascii} string is wrong, but
7210@value{GDBN} translates the contents of @code{ibm1047_hello} from the
7211target character set, @sc{ibm1047}, to the host character set,
7212@sc{ascii}, and they display correctly:
7213
7214@smallexample
f7dc1244
EZ
7215(@value{GDBP}) set target-charset IBM1047
7216(@value{GDBP}) show charset
e33d66ec
EZ
7217The current host character set is `ASCII'.
7218The current target character set is `IBM1047'.
f7dc1244 7219(@value{GDBP}) print ascii_hello
a0eb71c5 7220$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 7221(@value{GDBP}) print ascii_hello[0]
a0eb71c5 7222$7 = 72 '\110'
f7dc1244 7223(@value{GDBP}) print ibm1047_hello
a0eb71c5 7224$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 7225(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7226$9 = 200 'H'
f7dc1244 7227(@value{GDBP})
10998722 7228@end smallexample
a0eb71c5
KB
7229
7230As above, @value{GDBN} uses the target character set for character and
7231string literals you use in expressions:
7232
7233@smallexample
f7dc1244 7234(@value{GDBP}) print '+'
a0eb71c5 7235$10 = 78 '+'
f7dc1244 7236(@value{GDBP})
10998722 7237@end smallexample
a0eb71c5 7238
e33d66ec 7239The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
7240character.
7241
09d4efe1
EZ
7242@node Caching Remote Data
7243@section Caching Data of Remote Targets
7244@cindex caching data of remote targets
7245
7246@value{GDBN} can cache data exchanged between the debugger and a
7247remote target (@pxref{Remote}). Such caching generally improves
7248performance, because it reduces the overhead of the remote protocol by
7249bundling memory reads and writes into large chunks. Unfortunately,
7250@value{GDBN} does not currently know anything about volatile
7251registers, and thus data caching will produce incorrect results when
7252volatile registers are in use.
7253
7254@table @code
7255@kindex set remotecache
7256@item set remotecache on
7257@itemx set remotecache off
7258Set caching state for remote targets. When @code{ON}, use data
7259caching. By default, this option is @code{OFF}.
7260
7261@kindex show remotecache
7262@item show remotecache
7263Show the current state of data caching for remote targets.
7264
7265@kindex info dcache
7266@item info dcache
7267Print the information about the data cache performance. The
7268information displayed includes: the dcache width and depth; and for
7269each cache line, how many times it was referenced, and its data and
7270state (dirty, bad, ok, etc.). This command is useful for debugging
7271the data cache operation.
7272@end table
7273
a0eb71c5 7274
e2e0bcd1
JB
7275@node Macros
7276@chapter C Preprocessor Macros
7277
49efadf5 7278Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
7279``preprocessor macros'' which expand into strings of tokens.
7280@value{GDBN} can evaluate expressions containing macro invocations, show
7281the result of macro expansion, and show a macro's definition, including
7282where it was defined.
7283
7284You may need to compile your program specially to provide @value{GDBN}
7285with information about preprocessor macros. Most compilers do not
7286include macros in their debugging information, even when you compile
7287with the @option{-g} flag. @xref{Compilation}.
7288
7289A program may define a macro at one point, remove that definition later,
7290and then provide a different definition after that. Thus, at different
7291points in the program, a macro may have different definitions, or have
7292no definition at all. If there is a current stack frame, @value{GDBN}
7293uses the macros in scope at that frame's source code line. Otherwise,
7294@value{GDBN} uses the macros in scope at the current listing location;
7295see @ref{List}.
7296
7297At the moment, @value{GDBN} does not support the @code{##}
7298token-splicing operator, the @code{#} stringification operator, or
7299variable-arity macros.
7300
7301Whenever @value{GDBN} evaluates an expression, it always expands any
7302macro invocations present in the expression. @value{GDBN} also provides
7303the following commands for working with macros explicitly.
7304
7305@table @code
7306
7307@kindex macro expand
7308@cindex macro expansion, showing the results of preprocessor
7309@cindex preprocessor macro expansion, showing the results of
7310@cindex expanding preprocessor macros
7311@item macro expand @var{expression}
7312@itemx macro exp @var{expression}
7313Show the results of expanding all preprocessor macro invocations in
7314@var{expression}. Since @value{GDBN} simply expands macros, but does
7315not parse the result, @var{expression} need not be a valid expression;
7316it can be any string of tokens.
7317
09d4efe1 7318@kindex macro exp1
e2e0bcd1
JB
7319@item macro expand-once @var{expression}
7320@itemx macro exp1 @var{expression}
4644b6e3 7321@cindex expand macro once
e2e0bcd1
JB
7322@i{(This command is not yet implemented.)} Show the results of
7323expanding those preprocessor macro invocations that appear explicitly in
7324@var{expression}. Macro invocations appearing in that expansion are
7325left unchanged. This command allows you to see the effect of a
7326particular macro more clearly, without being confused by further
7327expansions. Since @value{GDBN} simply expands macros, but does not
7328parse the result, @var{expression} need not be a valid expression; it
7329can be any string of tokens.
7330
475b0867 7331@kindex info macro
e2e0bcd1
JB
7332@cindex macro definition, showing
7333@cindex definition, showing a macro's
475b0867 7334@item info macro @var{macro}
e2e0bcd1
JB
7335Show the definition of the macro named @var{macro}, and describe the
7336source location where that definition was established.
7337
7338@kindex macro define
7339@cindex user-defined macros
7340@cindex defining macros interactively
7341@cindex macros, user-defined
7342@item macro define @var{macro} @var{replacement-list}
7343@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
7344@i{(This command is not yet implemented.)} Introduce a definition for a
7345preprocessor macro named @var{macro}, invocations of which are replaced
7346by the tokens given in @var{replacement-list}. The first form of this
7347command defines an ``object-like'' macro, which takes no arguments; the
7348second form defines a ``function-like'' macro, which takes the arguments
7349given in @var{arglist}.
7350
7351A definition introduced by this command is in scope in every expression
7352evaluated in @value{GDBN}, until it is removed with the @command{macro
7353undef} command, described below. The definition overrides all
7354definitions for @var{macro} present in the program being debugged, as
7355well as any previous user-supplied definition.
7356
7357@kindex macro undef
7358@item macro undef @var{macro}
7359@i{(This command is not yet implemented.)} Remove any user-supplied
7360definition for the macro named @var{macro}. This command only affects
7361definitions provided with the @command{macro define} command, described
7362above; it cannot remove definitions present in the program being
7363debugged.
7364
09d4efe1
EZ
7365@kindex macro list
7366@item macro list
7367@i{(This command is not yet implemented.)} List all the macros
7368defined using the @code{macro define} command.
e2e0bcd1
JB
7369@end table
7370
7371@cindex macros, example of debugging with
7372Here is a transcript showing the above commands in action. First, we
7373show our source files:
7374
7375@smallexample
7376$ cat sample.c
7377#include <stdio.h>
7378#include "sample.h"
7379
7380#define M 42
7381#define ADD(x) (M + x)
7382
7383main ()
7384@{
7385#define N 28
7386 printf ("Hello, world!\n");
7387#undef N
7388 printf ("We're so creative.\n");
7389#define N 1729
7390 printf ("Goodbye, world!\n");
7391@}
7392$ cat sample.h
7393#define Q <
7394$
7395@end smallexample
7396
7397Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
7398We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
7399compiler includes information about preprocessor macros in the debugging
7400information.
7401
7402@smallexample
7403$ gcc -gdwarf-2 -g3 sample.c -o sample
7404$
7405@end smallexample
7406
7407Now, we start @value{GDBN} on our sample program:
7408
7409@smallexample
7410$ gdb -nw sample
7411GNU gdb 2002-05-06-cvs
7412Copyright 2002 Free Software Foundation, Inc.
7413GDB is free software, @dots{}
f7dc1244 7414(@value{GDBP})
e2e0bcd1
JB
7415@end smallexample
7416
7417We can expand macros and examine their definitions, even when the
7418program is not running. @value{GDBN} uses the current listing position
7419to decide which macro definitions are in scope:
7420
7421@smallexample
f7dc1244 7422(@value{GDBP}) list main
e2e0bcd1
JB
74233
74244 #define M 42
74255 #define ADD(x) (M + x)
74266
74277 main ()
74288 @{
74299 #define N 28
743010 printf ("Hello, world!\n");
743111 #undef N
743212 printf ("We're so creative.\n");
f7dc1244 7433(@value{GDBP}) info macro ADD
e2e0bcd1
JB
7434Defined at /home/jimb/gdb/macros/play/sample.c:5
7435#define ADD(x) (M + x)
f7dc1244 7436(@value{GDBP}) info macro Q
e2e0bcd1
JB
7437Defined at /home/jimb/gdb/macros/play/sample.h:1
7438 included at /home/jimb/gdb/macros/play/sample.c:2
7439#define Q <
f7dc1244 7440(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7441expands to: (42 + 1)
f7dc1244 7442(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7443expands to: once (M + 1)
f7dc1244 7444(@value{GDBP})
e2e0bcd1
JB
7445@end smallexample
7446
7447In the example above, note that @command{macro expand-once} expands only
7448the macro invocation explicit in the original text --- the invocation of
7449@code{ADD} --- but does not expand the invocation of the macro @code{M},
7450which was introduced by @code{ADD}.
7451
7452Once the program is running, GDB uses the macro definitions in force at
7453the source line of the current stack frame:
7454
7455@smallexample
f7dc1244 7456(@value{GDBP}) break main
e2e0bcd1 7457Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7458(@value{GDBP}) run
b383017d 7459Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7460
7461Breakpoint 1, main () at sample.c:10
746210 printf ("Hello, world!\n");
f7dc1244 7463(@value{GDBP})
e2e0bcd1
JB
7464@end smallexample
7465
7466At line 10, the definition of the macro @code{N} at line 9 is in force:
7467
7468@smallexample
f7dc1244 7469(@value{GDBP}) info macro N
e2e0bcd1
JB
7470Defined at /home/jimb/gdb/macros/play/sample.c:9
7471#define N 28
f7dc1244 7472(@value{GDBP}) macro expand N Q M
e2e0bcd1 7473expands to: 28 < 42
f7dc1244 7474(@value{GDBP}) print N Q M
e2e0bcd1 7475$1 = 1
f7dc1244 7476(@value{GDBP})
e2e0bcd1
JB
7477@end smallexample
7478
7479As we step over directives that remove @code{N}'s definition, and then
7480give it a new definition, @value{GDBN} finds the definition (or lack
7481thereof) in force at each point:
7482
7483@smallexample
f7dc1244 7484(@value{GDBP}) next
e2e0bcd1
JB
7485Hello, world!
748612 printf ("We're so creative.\n");
f7dc1244 7487(@value{GDBP}) info macro N
e2e0bcd1
JB
7488The symbol `N' has no definition as a C/C++ preprocessor macro
7489at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7490(@value{GDBP}) next
e2e0bcd1
JB
7491We're so creative.
749214 printf ("Goodbye, world!\n");
f7dc1244 7493(@value{GDBP}) info macro N
e2e0bcd1
JB
7494Defined at /home/jimb/gdb/macros/play/sample.c:13
7495#define N 1729
f7dc1244 7496(@value{GDBP}) macro expand N Q M
e2e0bcd1 7497expands to: 1729 < 42
f7dc1244 7498(@value{GDBP}) print N Q M
e2e0bcd1 7499$2 = 0
f7dc1244 7500(@value{GDBP})
e2e0bcd1
JB
7501@end smallexample
7502
7503
b37052ae
EZ
7504@node Tracepoints
7505@chapter Tracepoints
7506@c This chapter is based on the documentation written by Michael
7507@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7508
7509@cindex tracepoints
7510In some applications, it is not feasible for the debugger to interrupt
7511the program's execution long enough for the developer to learn
7512anything helpful about its behavior. If the program's correctness
7513depends on its real-time behavior, delays introduced by a debugger
7514might cause the program to change its behavior drastically, or perhaps
7515fail, even when the code itself is correct. It is useful to be able
7516to observe the program's behavior without interrupting it.
7517
7518Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7519specify locations in the program, called @dfn{tracepoints}, and
7520arbitrary expressions to evaluate when those tracepoints are reached.
7521Later, using the @code{tfind} command, you can examine the values
7522those expressions had when the program hit the tracepoints. The
7523expressions may also denote objects in memory---structures or arrays,
7524for example---whose values @value{GDBN} should record; while visiting
7525a particular tracepoint, you may inspect those objects as if they were
7526in memory at that moment. However, because @value{GDBN} records these
7527values without interacting with you, it can do so quickly and
7528unobtrusively, hopefully not disturbing the program's behavior.
7529
7530The tracepoint facility is currently available only for remote
9d29849a
JB
7531targets. @xref{Targets}. In addition, your remote target must know
7532how to collect trace data. This functionality is implemented in the
7533remote stub; however, none of the stubs distributed with @value{GDBN}
7534support tracepoints as of this writing. The format of the remote
7535packets used to implement tracepoints are described in @ref{Tracepoint
7536Packets}.
b37052ae
EZ
7537
7538This chapter describes the tracepoint commands and features.
7539
7540@menu
b383017d
RM
7541* Set Tracepoints::
7542* Analyze Collected Data::
7543* Tracepoint Variables::
b37052ae
EZ
7544@end menu
7545
7546@node Set Tracepoints
7547@section Commands to Set Tracepoints
7548
7549Before running such a @dfn{trace experiment}, an arbitrary number of
7550tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7551tracepoint has a number assigned to it by @value{GDBN}. Like with
7552breakpoints, tracepoint numbers are successive integers starting from
7553one. Many of the commands associated with tracepoints take the
7554tracepoint number as their argument, to identify which tracepoint to
7555work on.
7556
7557For each tracepoint, you can specify, in advance, some arbitrary set
7558of data that you want the target to collect in the trace buffer when
7559it hits that tracepoint. The collected data can include registers,
7560local variables, or global data. Later, you can use @value{GDBN}
7561commands to examine the values these data had at the time the
7562tracepoint was hit.
7563
7564This section describes commands to set tracepoints and associated
7565conditions and actions.
7566
7567@menu
b383017d
RM
7568* Create and Delete Tracepoints::
7569* Enable and Disable Tracepoints::
7570* Tracepoint Passcounts::
7571* Tracepoint Actions::
7572* Listing Tracepoints::
7573* Starting and Stopping Trace Experiment::
b37052ae
EZ
7574@end menu
7575
7576@node Create and Delete Tracepoints
7577@subsection Create and Delete Tracepoints
7578
7579@table @code
7580@cindex set tracepoint
7581@kindex trace
7582@item trace
7583The @code{trace} command is very similar to the @code{break} command.
7584Its argument can be a source line, a function name, or an address in
7585the target program. @xref{Set Breaks}. The @code{trace} command
7586defines a tracepoint, which is a point in the target program where the
7587debugger will briefly stop, collect some data, and then allow the
7588program to continue. Setting a tracepoint or changing its commands
7589doesn't take effect until the next @code{tstart} command; thus, you
7590cannot change the tracepoint attributes once a trace experiment is
7591running.
7592
7593Here are some examples of using the @code{trace} command:
7594
7595@smallexample
7596(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7597
7598(@value{GDBP}) @b{trace +2} // 2 lines forward
7599
7600(@value{GDBP}) @b{trace my_function} // first source line of function
7601
7602(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7603
7604(@value{GDBP}) @b{trace *0x2117c4} // an address
7605@end smallexample
7606
7607@noindent
7608You can abbreviate @code{trace} as @code{tr}.
7609
7610@vindex $tpnum
7611@cindex last tracepoint number
7612@cindex recent tracepoint number
7613@cindex tracepoint number
7614The convenience variable @code{$tpnum} records the tracepoint number
7615of the most recently set tracepoint.
7616
7617@kindex delete tracepoint
7618@cindex tracepoint deletion
7619@item delete tracepoint @r{[}@var{num}@r{]}
7620Permanently delete one or more tracepoints. With no argument, the
7621default is to delete all tracepoints.
7622
7623Examples:
7624
7625@smallexample
7626(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7627
7628(@value{GDBP}) @b{delete trace} // remove all tracepoints
7629@end smallexample
7630
7631@noindent
7632You can abbreviate this command as @code{del tr}.
7633@end table
7634
7635@node Enable and Disable Tracepoints
7636@subsection Enable and Disable Tracepoints
7637
7638@table @code
7639@kindex disable tracepoint
7640@item disable tracepoint @r{[}@var{num}@r{]}
7641Disable tracepoint @var{num}, or all tracepoints if no argument
7642@var{num} is given. A disabled tracepoint will have no effect during
7643the next trace experiment, but it is not forgotten. You can re-enable
7644a disabled tracepoint using the @code{enable tracepoint} command.
7645
7646@kindex enable tracepoint
7647@item enable tracepoint @r{[}@var{num}@r{]}
7648Enable tracepoint @var{num}, or all tracepoints. The enabled
7649tracepoints will become effective the next time a trace experiment is
7650run.
7651@end table
7652
7653@node Tracepoint Passcounts
7654@subsection Tracepoint Passcounts
7655
7656@table @code
7657@kindex passcount
7658@cindex tracepoint pass count
7659@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7660Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7661automatically stop a trace experiment. If a tracepoint's passcount is
7662@var{n}, then the trace experiment will be automatically stopped on
7663the @var{n}'th time that tracepoint is hit. If the tracepoint number
7664@var{num} is not specified, the @code{passcount} command sets the
7665passcount of the most recently defined tracepoint. If no passcount is
7666given, the trace experiment will run until stopped explicitly by the
7667user.
7668
7669Examples:
7670
7671@smallexample
b383017d 7672(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7673@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7674
7675(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7676@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7677(@value{GDBP}) @b{trace foo}
7678(@value{GDBP}) @b{pass 3}
7679(@value{GDBP}) @b{trace bar}
7680(@value{GDBP}) @b{pass 2}
7681(@value{GDBP}) @b{trace baz}
7682(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7683@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7684@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7685@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7686@end smallexample
7687@end table
7688
7689@node Tracepoint Actions
7690@subsection Tracepoint Action Lists
7691
7692@table @code
7693@kindex actions
7694@cindex tracepoint actions
7695@item actions @r{[}@var{num}@r{]}
7696This command will prompt for a list of actions to be taken when the
7697tracepoint is hit. If the tracepoint number @var{num} is not
7698specified, this command sets the actions for the one that was most
7699recently defined (so that you can define a tracepoint and then say
7700@code{actions} without bothering about its number). You specify the
7701actions themselves on the following lines, one action at a time, and
7702terminate the actions list with a line containing just @code{end}. So
7703far, the only defined actions are @code{collect} and
7704@code{while-stepping}.
7705
7706@cindex remove actions from a tracepoint
7707To remove all actions from a tracepoint, type @samp{actions @var{num}}
7708and follow it immediately with @samp{end}.
7709
7710@smallexample
7711(@value{GDBP}) @b{collect @var{data}} // collect some data
7712
6826cf00 7713(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7714
6826cf00 7715(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7716@end smallexample
7717
7718In the following example, the action list begins with @code{collect}
7719commands indicating the things to be collected when the tracepoint is
7720hit. Then, in order to single-step and collect additional data
7721following the tracepoint, a @code{while-stepping} command is used,
7722followed by the list of things to be collected while stepping. The
7723@code{while-stepping} command is terminated by its own separate
7724@code{end} command. Lastly, the action list is terminated by an
7725@code{end} command.
7726
7727@smallexample
7728(@value{GDBP}) @b{trace foo}
7729(@value{GDBP}) @b{actions}
7730Enter actions for tracepoint 1, one per line:
7731> collect bar,baz
7732> collect $regs
7733> while-stepping 12
7734 > collect $fp, $sp
7735 > end
7736end
7737@end smallexample
7738
7739@kindex collect @r{(tracepoints)}
7740@item collect @var{expr1}, @var{expr2}, @dots{}
7741Collect values of the given expressions when the tracepoint is hit.
7742This command accepts a comma-separated list of any valid expressions.
7743In addition to global, static, or local variables, the following
7744special arguments are supported:
7745
7746@table @code
7747@item $regs
7748collect all registers
7749
7750@item $args
7751collect all function arguments
7752
7753@item $locals
7754collect all local variables.
7755@end table
7756
7757You can give several consecutive @code{collect} commands, each one
7758with a single argument, or one @code{collect} command with several
7759arguments separated by commas: the effect is the same.
7760
f5c37c66
EZ
7761The command @code{info scope} (@pxref{Symbols, info scope}) is
7762particularly useful for figuring out what data to collect.
7763
b37052ae
EZ
7764@kindex while-stepping @r{(tracepoints)}
7765@item while-stepping @var{n}
7766Perform @var{n} single-step traces after the tracepoint, collecting
7767new data at each step. The @code{while-stepping} command is
7768followed by the list of what to collect while stepping (followed by
7769its own @code{end} command):
7770
7771@smallexample
7772> while-stepping 12
7773 > collect $regs, myglobal
7774 > end
7775>
7776@end smallexample
7777
7778@noindent
7779You may abbreviate @code{while-stepping} as @code{ws} or
7780@code{stepping}.
7781@end table
7782
7783@node Listing Tracepoints
7784@subsection Listing Tracepoints
7785
7786@table @code
7787@kindex info tracepoints
09d4efe1 7788@kindex info tp
b37052ae
EZ
7789@cindex information about tracepoints
7790@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7791Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7792a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7793defined so far. For each tracepoint, the following information is
7794shown:
7795
7796@itemize @bullet
7797@item
7798its number
7799@item
7800whether it is enabled or disabled
7801@item
7802its address
7803@item
7804its passcount as given by the @code{passcount @var{n}} command
7805@item
7806its step count as given by the @code{while-stepping @var{n}} command
7807@item
7808where in the source files is the tracepoint set
7809@item
7810its action list as given by the @code{actions} command
7811@end itemize
7812
7813@smallexample
7814(@value{GDBP}) @b{info trace}
7815Num Enb Address PassC StepC What
78161 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
78172 y 0x0020dc64 0 0 in g_test at g_test.c:1375
78183 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7819(@value{GDBP})
7820@end smallexample
7821
7822@noindent
7823This command can be abbreviated @code{info tp}.
7824@end table
7825
7826@node Starting and Stopping Trace Experiment
7827@subsection Starting and Stopping Trace Experiment
7828
7829@table @code
7830@kindex tstart
7831@cindex start a new trace experiment
7832@cindex collected data discarded
7833@item tstart
7834This command takes no arguments. It starts the trace experiment, and
7835begins collecting data. This has the side effect of discarding all
7836the data collected in the trace buffer during the previous trace
7837experiment.
7838
7839@kindex tstop
7840@cindex stop a running trace experiment
7841@item tstop
7842This command takes no arguments. It ends the trace experiment, and
7843stops collecting data.
7844
68c71a2e 7845@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7846automatically if any tracepoint's passcount is reached
7847(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7848
7849@kindex tstatus
7850@cindex status of trace data collection
7851@cindex trace experiment, status of
7852@item tstatus
7853This command displays the status of the current trace data
7854collection.
7855@end table
7856
7857Here is an example of the commands we described so far:
7858
7859@smallexample
7860(@value{GDBP}) @b{trace gdb_c_test}
7861(@value{GDBP}) @b{actions}
7862Enter actions for tracepoint #1, one per line.
7863> collect $regs,$locals,$args
7864> while-stepping 11
7865 > collect $regs
7866 > end
7867> end
7868(@value{GDBP}) @b{tstart}
7869 [time passes @dots{}]
7870(@value{GDBP}) @b{tstop}
7871@end smallexample
7872
7873
7874@node Analyze Collected Data
7875@section Using the collected data
7876
7877After the tracepoint experiment ends, you use @value{GDBN} commands
7878for examining the trace data. The basic idea is that each tracepoint
7879collects a trace @dfn{snapshot} every time it is hit and another
7880snapshot every time it single-steps. All these snapshots are
7881consecutively numbered from zero and go into a buffer, and you can
7882examine them later. The way you examine them is to @dfn{focus} on a
7883specific trace snapshot. When the remote stub is focused on a trace
7884snapshot, it will respond to all @value{GDBN} requests for memory and
7885registers by reading from the buffer which belongs to that snapshot,
7886rather than from @emph{real} memory or registers of the program being
7887debugged. This means that @strong{all} @value{GDBN} commands
7888(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7889behave as if we were currently debugging the program state as it was
7890when the tracepoint occurred. Any requests for data that are not in
7891the buffer will fail.
7892
7893@menu
7894* tfind:: How to select a trace snapshot
7895* tdump:: How to display all data for a snapshot
7896* save-tracepoints:: How to save tracepoints for a future run
7897@end menu
7898
7899@node tfind
7900@subsection @code{tfind @var{n}}
7901
7902@kindex tfind
7903@cindex select trace snapshot
7904@cindex find trace snapshot
7905The basic command for selecting a trace snapshot from the buffer is
7906@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7907counting from zero. If no argument @var{n} is given, the next
7908snapshot is selected.
7909
7910Here are the various forms of using the @code{tfind} command.
7911
7912@table @code
7913@item tfind start
7914Find the first snapshot in the buffer. This is a synonym for
7915@code{tfind 0} (since 0 is the number of the first snapshot).
7916
7917@item tfind none
7918Stop debugging trace snapshots, resume @emph{live} debugging.
7919
7920@item tfind end
7921Same as @samp{tfind none}.
7922
7923@item tfind
7924No argument means find the next trace snapshot.
7925
7926@item tfind -
7927Find the previous trace snapshot before the current one. This permits
7928retracing earlier steps.
7929
7930@item tfind tracepoint @var{num}
7931Find the next snapshot associated with tracepoint @var{num}. Search
7932proceeds forward from the last examined trace snapshot. If no
7933argument @var{num} is given, it means find the next snapshot collected
7934for the same tracepoint as the current snapshot.
7935
7936@item tfind pc @var{addr}
7937Find the next snapshot associated with the value @var{addr} of the
7938program counter. Search proceeds forward from the last examined trace
7939snapshot. If no argument @var{addr} is given, it means find the next
7940snapshot with the same value of PC as the current snapshot.
7941
7942@item tfind outside @var{addr1}, @var{addr2}
7943Find the next snapshot whose PC is outside the given range of
7944addresses.
7945
7946@item tfind range @var{addr1}, @var{addr2}
7947Find the next snapshot whose PC is between @var{addr1} and
7948@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7949
7950@item tfind line @r{[}@var{file}:@r{]}@var{n}
7951Find the next snapshot associated with the source line @var{n}. If
7952the optional argument @var{file} is given, refer to line @var{n} in
7953that source file. Search proceeds forward from the last examined
7954trace snapshot. If no argument @var{n} is given, it means find the
7955next line other than the one currently being examined; thus saying
7956@code{tfind line} repeatedly can appear to have the same effect as
7957stepping from line to line in a @emph{live} debugging session.
7958@end table
7959
7960The default arguments for the @code{tfind} commands are specifically
7961designed to make it easy to scan through the trace buffer. For
7962instance, @code{tfind} with no argument selects the next trace
7963snapshot, and @code{tfind -} with no argument selects the previous
7964trace snapshot. So, by giving one @code{tfind} command, and then
7965simply hitting @key{RET} repeatedly you can examine all the trace
7966snapshots in order. Or, by saying @code{tfind -} and then hitting
7967@key{RET} repeatedly you can examine the snapshots in reverse order.
7968The @code{tfind line} command with no argument selects the snapshot
7969for the next source line executed. The @code{tfind pc} command with
7970no argument selects the next snapshot with the same program counter
7971(PC) as the current frame. The @code{tfind tracepoint} command with
7972no argument selects the next trace snapshot collected by the same
7973tracepoint as the current one.
7974
7975In addition to letting you scan through the trace buffer manually,
7976these commands make it easy to construct @value{GDBN} scripts that
7977scan through the trace buffer and print out whatever collected data
7978you are interested in. Thus, if we want to examine the PC, FP, and SP
7979registers from each trace frame in the buffer, we can say this:
7980
7981@smallexample
7982(@value{GDBP}) @b{tfind start}
7983(@value{GDBP}) @b{while ($trace_frame != -1)}
7984> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7985 $trace_frame, $pc, $sp, $fp
7986> tfind
7987> end
7988
7989Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7990Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7991Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7992Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7993Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7994Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7995Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7996Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7997Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7998Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7999Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
8000@end smallexample
8001
8002Or, if we want to examine the variable @code{X} at each source line in
8003the buffer:
8004
8005@smallexample
8006(@value{GDBP}) @b{tfind start}
8007(@value{GDBP}) @b{while ($trace_frame != -1)}
8008> printf "Frame %d, X == %d\n", $trace_frame, X
8009> tfind line
8010> end
8011
8012Frame 0, X = 1
8013Frame 7, X = 2
8014Frame 13, X = 255
8015@end smallexample
8016
8017@node tdump
8018@subsection @code{tdump}
8019@kindex tdump
8020@cindex dump all data collected at tracepoint
8021@cindex tracepoint data, display
8022
8023This command takes no arguments. It prints all the data collected at
8024the current trace snapshot.
8025
8026@smallexample
8027(@value{GDBP}) @b{trace 444}
8028(@value{GDBP}) @b{actions}
8029Enter actions for tracepoint #2, one per line:
8030> collect $regs, $locals, $args, gdb_long_test
8031> end
8032
8033(@value{GDBP}) @b{tstart}
8034
8035(@value{GDBP}) @b{tfind line 444}
8036#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
8037at gdb_test.c:444
8038444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
8039
8040(@value{GDBP}) @b{tdump}
8041Data collected at tracepoint 2, trace frame 1:
8042d0 0xc4aa0085 -995491707
8043d1 0x18 24
8044d2 0x80 128
8045d3 0x33 51
8046d4 0x71aea3d 119204413
8047d5 0x22 34
8048d6 0xe0 224
8049d7 0x380035 3670069
8050a0 0x19e24a 1696330
8051a1 0x3000668 50333288
8052a2 0x100 256
8053a3 0x322000 3284992
8054a4 0x3000698 50333336
8055a5 0x1ad3cc 1758156
8056fp 0x30bf3c 0x30bf3c
8057sp 0x30bf34 0x30bf34
8058ps 0x0 0
8059pc 0x20b2c8 0x20b2c8
8060fpcontrol 0x0 0
8061fpstatus 0x0 0
8062fpiaddr 0x0 0
8063p = 0x20e5b4 "gdb-test"
8064p1 = (void *) 0x11
8065p2 = (void *) 0x22
8066p3 = (void *) 0x33
8067p4 = (void *) 0x44
8068p5 = (void *) 0x55
8069p6 = (void *) 0x66
8070gdb_long_test = 17 '\021'
8071
8072(@value{GDBP})
8073@end smallexample
8074
8075@node save-tracepoints
8076@subsection @code{save-tracepoints @var{filename}}
8077@kindex save-tracepoints
8078@cindex save tracepoints for future sessions
8079
8080This command saves all current tracepoint definitions together with
8081their actions and passcounts, into a file @file{@var{filename}}
8082suitable for use in a later debugging session. To read the saved
8083tracepoint definitions, use the @code{source} command (@pxref{Command
8084Files}).
8085
8086@node Tracepoint Variables
8087@section Convenience Variables for Tracepoints
8088@cindex tracepoint variables
8089@cindex convenience variables for tracepoints
8090
8091@table @code
8092@vindex $trace_frame
8093@item (int) $trace_frame
8094The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
8095snapshot is selected.
8096
8097@vindex $tracepoint
8098@item (int) $tracepoint
8099The tracepoint for the current trace snapshot.
8100
8101@vindex $trace_line
8102@item (int) $trace_line
8103The line number for the current trace snapshot.
8104
8105@vindex $trace_file
8106@item (char []) $trace_file
8107The source file for the current trace snapshot.
8108
8109@vindex $trace_func
8110@item (char []) $trace_func
8111The name of the function containing @code{$tracepoint}.
8112@end table
8113
8114Note: @code{$trace_file} is not suitable for use in @code{printf},
8115use @code{output} instead.
8116
8117Here's a simple example of using these convenience variables for
8118stepping through all the trace snapshots and printing some of their
8119data.
8120
8121@smallexample
8122(@value{GDBP}) @b{tfind start}
8123
8124(@value{GDBP}) @b{while $trace_frame != -1}
8125> output $trace_file
8126> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
8127> tfind
8128> end
8129@end smallexample
8130
df0cd8c5
JB
8131@node Overlays
8132@chapter Debugging Programs That Use Overlays
8133@cindex overlays
8134
8135If your program is too large to fit completely in your target system's
8136memory, you can sometimes use @dfn{overlays} to work around this
8137problem. @value{GDBN} provides some support for debugging programs that
8138use overlays.
8139
8140@menu
8141* How Overlays Work:: A general explanation of overlays.
8142* Overlay Commands:: Managing overlays in @value{GDBN}.
8143* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
8144 mapped by asking the inferior.
8145* Overlay Sample Program:: A sample program using overlays.
8146@end menu
8147
8148@node How Overlays Work
8149@section How Overlays Work
8150@cindex mapped overlays
8151@cindex unmapped overlays
8152@cindex load address, overlay's
8153@cindex mapped address
8154@cindex overlay area
8155
8156Suppose you have a computer whose instruction address space is only 64
8157kilobytes long, but which has much more memory which can be accessed by
8158other means: special instructions, segment registers, or memory
8159management hardware, for example. Suppose further that you want to
8160adapt a program which is larger than 64 kilobytes to run on this system.
8161
8162One solution is to identify modules of your program which are relatively
8163independent, and need not call each other directly; call these modules
8164@dfn{overlays}. Separate the overlays from the main program, and place
8165their machine code in the larger memory. Place your main program in
8166instruction memory, but leave at least enough space there to hold the
8167largest overlay as well.
8168
8169Now, to call a function located in an overlay, you must first copy that
8170overlay's machine code from the large memory into the space set aside
8171for it in the instruction memory, and then jump to its entry point
8172there.
8173
c928edc0
AC
8174@c NB: In the below the mapped area's size is greater or equal to the
8175@c size of all overlays. This is intentional to remind the developer
8176@c that overlays don't necessarily need to be the same size.
8177
474c8240 8178@smallexample
df0cd8c5 8179@group
c928edc0
AC
8180 Data Instruction Larger
8181Address Space Address Space Address Space
8182+-----------+ +-----------+ +-----------+
8183| | | | | |
8184+-----------+ +-----------+ +-----------+<-- overlay 1
8185| program | | main | .----| overlay 1 | load address
8186| variables | | program | | +-----------+
8187| and heap | | | | | |
8188+-----------+ | | | +-----------+<-- overlay 2
8189| | +-----------+ | | | load address
8190+-----------+ | | | .-| overlay 2 |
8191 | | | | | |
8192 mapped --->+-----------+ | | +-----------+
8193 address | | | | | |
8194 | overlay | <-' | | |
8195 | area | <---' +-----------+<-- overlay 3
8196 | | <---. | | load address
8197 +-----------+ `--| overlay 3 |
8198 | | | |
8199 +-----------+ | |
8200 +-----------+
8201 | |
8202 +-----------+
8203
8204 @anchor{A code overlay}A code overlay
df0cd8c5 8205@end group
474c8240 8206@end smallexample
df0cd8c5 8207
c928edc0
AC
8208The diagram (@pxref{A code overlay}) shows a system with separate data
8209and instruction address spaces. To map an overlay, the program copies
8210its code from the larger address space to the instruction address space.
8211Since the overlays shown here all use the same mapped address, only one
8212may be mapped at a time. For a system with a single address space for
8213data and instructions, the diagram would be similar, except that the
8214program variables and heap would share an address space with the main
8215program and the overlay area.
df0cd8c5
JB
8216
8217An overlay loaded into instruction memory and ready for use is called a
8218@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
8219instruction memory. An overlay not present (or only partially present)
8220in instruction memory is called @dfn{unmapped}; its @dfn{load address}
8221is its address in the larger memory. The mapped address is also called
8222the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
8223called the @dfn{load memory address}, or @dfn{LMA}.
8224
8225Unfortunately, overlays are not a completely transparent way to adapt a
8226program to limited instruction memory. They introduce a new set of
8227global constraints you must keep in mind as you design your program:
8228
8229@itemize @bullet
8230
8231@item
8232Before calling or returning to a function in an overlay, your program
8233must make sure that overlay is actually mapped. Otherwise, the call or
8234return will transfer control to the right address, but in the wrong
8235overlay, and your program will probably crash.
8236
8237@item
8238If the process of mapping an overlay is expensive on your system, you
8239will need to choose your overlays carefully to minimize their effect on
8240your program's performance.
8241
8242@item
8243The executable file you load onto your system must contain each
8244overlay's instructions, appearing at the overlay's load address, not its
8245mapped address. However, each overlay's instructions must be relocated
8246and its symbols defined as if the overlay were at its mapped address.
8247You can use GNU linker scripts to specify different load and relocation
8248addresses for pieces of your program; see @ref{Overlay Description,,,
8249ld.info, Using ld: the GNU linker}.
8250
8251@item
8252The procedure for loading executable files onto your system must be able
8253to load their contents into the larger address space as well as the
8254instruction and data spaces.
8255
8256@end itemize
8257
8258The overlay system described above is rather simple, and could be
8259improved in many ways:
8260
8261@itemize @bullet
8262
8263@item
8264If your system has suitable bank switch registers or memory management
8265hardware, you could use those facilities to make an overlay's load area
8266contents simply appear at their mapped address in instruction space.
8267This would probably be faster than copying the overlay to its mapped
8268area in the usual way.
8269
8270@item
8271If your overlays are small enough, you could set aside more than one
8272overlay area, and have more than one overlay mapped at a time.
8273
8274@item
8275You can use overlays to manage data, as well as instructions. In
8276general, data overlays are even less transparent to your design than
8277code overlays: whereas code overlays only require care when you call or
8278return to functions, data overlays require care every time you access
8279the data. Also, if you change the contents of a data overlay, you
8280must copy its contents back out to its load address before you can copy a
8281different data overlay into the same mapped area.
8282
8283@end itemize
8284
8285
8286@node Overlay Commands
8287@section Overlay Commands
8288
8289To use @value{GDBN}'s overlay support, each overlay in your program must
8290correspond to a separate section of the executable file. The section's
8291virtual memory address and load memory address must be the overlay's
8292mapped and load addresses. Identifying overlays with sections allows
8293@value{GDBN} to determine the appropriate address of a function or
8294variable, depending on whether the overlay is mapped or not.
8295
8296@value{GDBN}'s overlay commands all start with the word @code{overlay};
8297you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
8298
8299@table @code
8300@item overlay off
4644b6e3 8301@kindex overlay
df0cd8c5
JB
8302Disable @value{GDBN}'s overlay support. When overlay support is
8303disabled, @value{GDBN} assumes that all functions and variables are
8304always present at their mapped addresses. By default, @value{GDBN}'s
8305overlay support is disabled.
8306
8307@item overlay manual
df0cd8c5
JB
8308@cindex manual overlay debugging
8309Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
8310relies on you to tell it which overlays are mapped, and which are not,
8311using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
8312commands described below.
8313
8314@item overlay map-overlay @var{overlay}
8315@itemx overlay map @var{overlay}
df0cd8c5
JB
8316@cindex map an overlay
8317Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
8318be the name of the object file section containing the overlay. When an
8319overlay is mapped, @value{GDBN} assumes it can find the overlay's
8320functions and variables at their mapped addresses. @value{GDBN} assumes
8321that any other overlays whose mapped ranges overlap that of
8322@var{overlay} are now unmapped.
8323
8324@item overlay unmap-overlay @var{overlay}
8325@itemx overlay unmap @var{overlay}
df0cd8c5
JB
8326@cindex unmap an overlay
8327Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
8328must be the name of the object file section containing the overlay.
8329When an overlay is unmapped, @value{GDBN} assumes it can find the
8330overlay's functions and variables at their load addresses.
8331
8332@item overlay auto
df0cd8c5
JB
8333Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
8334consults a data structure the overlay manager maintains in the inferior
8335to see which overlays are mapped. For details, see @ref{Automatic
8336Overlay Debugging}.
8337
8338@item overlay load-target
8339@itemx overlay load
df0cd8c5
JB
8340@cindex reloading the overlay table
8341Re-read the overlay table from the inferior. Normally, @value{GDBN}
8342re-reads the table @value{GDBN} automatically each time the inferior
8343stops, so this command should only be necessary if you have changed the
8344overlay mapping yourself using @value{GDBN}. This command is only
8345useful when using automatic overlay debugging.
8346
8347@item overlay list-overlays
8348@itemx overlay list
8349@cindex listing mapped overlays
8350Display a list of the overlays currently mapped, along with their mapped
8351addresses, load addresses, and sizes.
8352
8353@end table
8354
8355Normally, when @value{GDBN} prints a code address, it includes the name
8356of the function the address falls in:
8357
474c8240 8358@smallexample
f7dc1244 8359(@value{GDBP}) print main
df0cd8c5 8360$3 = @{int ()@} 0x11a0 <main>
474c8240 8361@end smallexample
df0cd8c5
JB
8362@noindent
8363When overlay debugging is enabled, @value{GDBN} recognizes code in
8364unmapped overlays, and prints the names of unmapped functions with
8365asterisks around them. For example, if @code{foo} is a function in an
8366unmapped overlay, @value{GDBN} prints it this way:
8367
474c8240 8368@smallexample
f7dc1244 8369(@value{GDBP}) overlay list
df0cd8c5 8370No sections are mapped.
f7dc1244 8371(@value{GDBP}) print foo
df0cd8c5 8372$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 8373@end smallexample
df0cd8c5
JB
8374@noindent
8375When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
8376name normally:
8377
474c8240 8378@smallexample
f7dc1244 8379(@value{GDBP}) overlay list
b383017d 8380Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 8381 mapped at 0x1016 - 0x104a
f7dc1244 8382(@value{GDBP}) print foo
df0cd8c5 8383$6 = @{int (int)@} 0x1016 <foo>
474c8240 8384@end smallexample
df0cd8c5
JB
8385
8386When overlay debugging is enabled, @value{GDBN} can find the correct
8387address for functions and variables in an overlay, whether or not the
8388overlay is mapped. This allows most @value{GDBN} commands, like
8389@code{break} and @code{disassemble}, to work normally, even on unmapped
8390code. However, @value{GDBN}'s breakpoint support has some limitations:
8391
8392@itemize @bullet
8393@item
8394@cindex breakpoints in overlays
8395@cindex overlays, setting breakpoints in
8396You can set breakpoints in functions in unmapped overlays, as long as
8397@value{GDBN} can write to the overlay at its load address.
8398@item
8399@value{GDBN} can not set hardware or simulator-based breakpoints in
8400unmapped overlays. However, if you set a breakpoint at the end of your
8401overlay manager (and tell @value{GDBN} which overlays are now mapped, if
8402you are using manual overlay management), @value{GDBN} will re-set its
8403breakpoints properly.
8404@end itemize
8405
8406
8407@node Automatic Overlay Debugging
8408@section Automatic Overlay Debugging
8409@cindex automatic overlay debugging
8410
8411@value{GDBN} can automatically track which overlays are mapped and which
8412are not, given some simple co-operation from the overlay manager in the
8413inferior. If you enable automatic overlay debugging with the
8414@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
8415looks in the inferior's memory for certain variables describing the
8416current state of the overlays.
8417
8418Here are the variables your overlay manager must define to support
8419@value{GDBN}'s automatic overlay debugging:
8420
8421@table @asis
8422
8423@item @code{_ovly_table}:
8424This variable must be an array of the following structures:
8425
474c8240 8426@smallexample
df0cd8c5
JB
8427struct
8428@{
8429 /* The overlay's mapped address. */
8430 unsigned long vma;
8431
8432 /* The size of the overlay, in bytes. */
8433 unsigned long size;
8434
8435 /* The overlay's load address. */
8436 unsigned long lma;
8437
8438 /* Non-zero if the overlay is currently mapped;
8439 zero otherwise. */
8440 unsigned long mapped;
8441@}
474c8240 8442@end smallexample
df0cd8c5
JB
8443
8444@item @code{_novlys}:
8445This variable must be a four-byte signed integer, holding the total
8446number of elements in @code{_ovly_table}.
8447
8448@end table
8449
8450To decide whether a particular overlay is mapped or not, @value{GDBN}
8451looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8452@code{lma} members equal the VMA and LMA of the overlay's section in the
8453executable file. When @value{GDBN} finds a matching entry, it consults
8454the entry's @code{mapped} member to determine whether the overlay is
8455currently mapped.
8456
81d46470 8457In addition, your overlay manager may define a function called
def71bfa 8458@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8459will silently set a breakpoint there. If the overlay manager then
8460calls this function whenever it has changed the overlay table, this
8461will enable @value{GDBN} to accurately keep track of which overlays
8462are in program memory, and update any breakpoints that may be set
b383017d 8463in overlays. This will allow breakpoints to work even if the
81d46470
MS
8464overlays are kept in ROM or other non-writable memory while they
8465are not being executed.
df0cd8c5
JB
8466
8467@node Overlay Sample Program
8468@section Overlay Sample Program
8469@cindex overlay example program
8470
8471When linking a program which uses overlays, you must place the overlays
8472at their load addresses, while relocating them to run at their mapped
8473addresses. To do this, you must write a linker script (@pxref{Overlay
8474Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8475since linker scripts are specific to a particular host system, target
8476architecture, and target memory layout, this manual cannot provide
8477portable sample code demonstrating @value{GDBN}'s overlay support.
8478
8479However, the @value{GDBN} source distribution does contain an overlaid
8480program, with linker scripts for a few systems, as part of its test
8481suite. The program consists of the following files from
8482@file{gdb/testsuite/gdb.base}:
8483
8484@table @file
8485@item overlays.c
8486The main program file.
8487@item ovlymgr.c
8488A simple overlay manager, used by @file{overlays.c}.
8489@item foo.c
8490@itemx bar.c
8491@itemx baz.c
8492@itemx grbx.c
8493Overlay modules, loaded and used by @file{overlays.c}.
8494@item d10v.ld
8495@itemx m32r.ld
8496Linker scripts for linking the test program on the @code{d10v-elf}
8497and @code{m32r-elf} targets.
8498@end table
8499
8500You can build the test program using the @code{d10v-elf} GCC
8501cross-compiler like this:
8502
474c8240 8503@smallexample
df0cd8c5
JB
8504$ d10v-elf-gcc -g -c overlays.c
8505$ d10v-elf-gcc -g -c ovlymgr.c
8506$ d10v-elf-gcc -g -c foo.c
8507$ d10v-elf-gcc -g -c bar.c
8508$ d10v-elf-gcc -g -c baz.c
8509$ d10v-elf-gcc -g -c grbx.c
8510$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8511 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8512@end smallexample
df0cd8c5
JB
8513
8514The build process is identical for any other architecture, except that
8515you must substitute the appropriate compiler and linker script for the
8516target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8517
8518
6d2ebf8b 8519@node Languages
c906108c
SS
8520@chapter Using @value{GDBN} with Different Languages
8521@cindex languages
8522
c906108c
SS
8523Although programming languages generally have common aspects, they are
8524rarely expressed in the same manner. For instance, in ANSI C,
8525dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8526Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8527represented (and displayed) differently. Hex numbers in C appear as
c906108c 8528@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8529
8530@cindex working language
8531Language-specific information is built into @value{GDBN} for some languages,
8532allowing you to express operations like the above in your program's
8533native language, and allowing @value{GDBN} to output values in a manner
8534consistent with the syntax of your program's native language. The
8535language you use to build expressions is called the @dfn{working
8536language}.
8537
8538@menu
8539* Setting:: Switching between source languages
8540* Show:: Displaying the language
c906108c 8541* Checks:: Type and range checks
9c16f35a 8542* Supported languages:: Supported languages
4e562065 8543* Unsupported languages:: Unsupported languages
c906108c
SS
8544@end menu
8545
6d2ebf8b 8546@node Setting
c906108c
SS
8547@section Switching between source languages
8548
8549There are two ways to control the working language---either have @value{GDBN}
8550set it automatically, or select it manually yourself. You can use the
8551@code{set language} command for either purpose. On startup, @value{GDBN}
8552defaults to setting the language automatically. The working language is
8553used to determine how expressions you type are interpreted, how values
8554are printed, etc.
8555
8556In addition to the working language, every source file that
8557@value{GDBN} knows about has its own working language. For some object
8558file formats, the compiler might indicate which language a particular
8559source file is in. However, most of the time @value{GDBN} infers the
8560language from the name of the file. The language of a source file
b37052ae 8561controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8562show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8563set the language of a source file from within @value{GDBN}, but you can
8564set the language associated with a filename extension. @xref{Show, ,
8565Displaying the language}.
c906108c
SS
8566
8567This is most commonly a problem when you use a program, such
5d161b24 8568as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8569another language. In that case, make the
8570program use @code{#line} directives in its C output; that way
8571@value{GDBN} will know the correct language of the source code of the original
8572program, and will display that source code, not the generated C code.
8573
8574@menu
8575* Filenames:: Filename extensions and languages.
8576* Manually:: Setting the working language manually
8577* Automatically:: Having @value{GDBN} infer the source language
8578@end menu
8579
6d2ebf8b 8580@node Filenames
c906108c
SS
8581@subsection List of filename extensions and languages
8582
8583If a source file name ends in one of the following extensions, then
8584@value{GDBN} infers that its language is the one indicated.
8585
8586@table @file
e07c999f
PH
8587@item .ada
8588@itemx .ads
8589@itemx .adb
8590@itemx .a
8591Ada source file.
c906108c
SS
8592
8593@item .c
8594C source file
8595
8596@item .C
8597@itemx .cc
8598@itemx .cp
8599@itemx .cpp
8600@itemx .cxx
8601@itemx .c++
b37052ae 8602C@t{++} source file
c906108c 8603
b37303ee
AF
8604@item .m
8605Objective-C source file
8606
c906108c
SS
8607@item .f
8608@itemx .F
8609Fortran source file
8610
c906108c
SS
8611@item .mod
8612Modula-2 source file
c906108c
SS
8613
8614@item .s
8615@itemx .S
8616Assembler source file. This actually behaves almost like C, but
8617@value{GDBN} does not skip over function prologues when stepping.
8618@end table
8619
8620In addition, you may set the language associated with a filename
8621extension. @xref{Show, , Displaying the language}.
8622
6d2ebf8b 8623@node Manually
c906108c
SS
8624@subsection Setting the working language
8625
8626If you allow @value{GDBN} to set the language automatically,
8627expressions are interpreted the same way in your debugging session and
8628your program.
8629
8630@kindex set language
8631If you wish, you may set the language manually. To do this, issue the
8632command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8633a language, such as
c906108c 8634@code{c} or @code{modula-2}.
c906108c
SS
8635For a list of the supported languages, type @samp{set language}.
8636
c906108c
SS
8637Setting the language manually prevents @value{GDBN} from updating the working
8638language automatically. This can lead to confusion if you try
8639to debug a program when the working language is not the same as the
8640source language, when an expression is acceptable to both
8641languages---but means different things. For instance, if the current
8642source file were written in C, and @value{GDBN} was parsing Modula-2, a
8643command such as:
8644
474c8240 8645@smallexample
c906108c 8646print a = b + c
474c8240 8647@end smallexample
c906108c
SS
8648
8649@noindent
8650might not have the effect you intended. In C, this means to add
8651@code{b} and @code{c} and place the result in @code{a}. The result
8652printed would be the value of @code{a}. In Modula-2, this means to compare
8653@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8654
6d2ebf8b 8655@node Automatically
c906108c
SS
8656@subsection Having @value{GDBN} infer the source language
8657
8658To have @value{GDBN} set the working language automatically, use
8659@samp{set language local} or @samp{set language auto}. @value{GDBN}
8660then infers the working language. That is, when your program stops in a
8661frame (usually by encountering a breakpoint), @value{GDBN} sets the
8662working language to the language recorded for the function in that
8663frame. If the language for a frame is unknown (that is, if the function
8664or block corresponding to the frame was defined in a source file that
8665does not have a recognized extension), the current working language is
8666not changed, and @value{GDBN} issues a warning.
8667
8668This may not seem necessary for most programs, which are written
8669entirely in one source language. However, program modules and libraries
8670written in one source language can be used by a main program written in
8671a different source language. Using @samp{set language auto} in this
8672case frees you from having to set the working language manually.
8673
6d2ebf8b 8674@node Show
c906108c 8675@section Displaying the language
c906108c
SS
8676
8677The following commands help you find out which language is the
8678working language, and also what language source files were written in.
8679
c906108c
SS
8680@table @code
8681@item show language
9c16f35a 8682@kindex show language
c906108c
SS
8683Display the current working language. This is the
8684language you can use with commands such as @code{print} to
8685build and compute expressions that may involve variables in your program.
8686
8687@item info frame
4644b6e3 8688@kindex info frame@r{, show the source language}
5d161b24 8689Display the source language for this frame. This language becomes the
c906108c 8690working language if you use an identifier from this frame.
5d161b24 8691@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8692information listed here.
8693
8694@item info source
4644b6e3 8695@kindex info source@r{, show the source language}
c906108c 8696Display the source language of this source file.
5d161b24 8697@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8698information listed here.
8699@end table
8700
8701In unusual circumstances, you may have source files with extensions
8702not in the standard list. You can then set the extension associated
8703with a language explicitly:
8704
c906108c 8705@table @code
09d4efe1 8706@item set extension-language @var{ext} @var{language}
9c16f35a 8707@kindex set extension-language
09d4efe1
EZ
8708Tell @value{GDBN} that source files with extension @var{ext} are to be
8709assumed as written in the source language @var{language}.
c906108c
SS
8710
8711@item info extensions
9c16f35a 8712@kindex info extensions
c906108c
SS
8713List all the filename extensions and the associated languages.
8714@end table
8715
6d2ebf8b 8716@node Checks
c906108c
SS
8717@section Type and range checking
8718
8719@quotation
8720@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8721checking are included, but they do not yet have any effect. This
8722section documents the intended facilities.
8723@end quotation
8724@c FIXME remove warning when type/range code added
8725
8726Some languages are designed to guard you against making seemingly common
8727errors through a series of compile- and run-time checks. These include
8728checking the type of arguments to functions and operators, and making
8729sure mathematical overflows are caught at run time. Checks such as
8730these help to ensure a program's correctness once it has been compiled
8731by eliminating type mismatches, and providing active checks for range
8732errors when your program is running.
8733
8734@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8735Although @value{GDBN} does not check the statements in your program,
8736it can check expressions entered directly into @value{GDBN} for
8737evaluation via the @code{print} command, for example. As with the
8738working language, @value{GDBN} can also decide whether or not to check
8739automatically based on your program's source language.
8740@xref{Supported languages, ,Supported languages}, for the default
8741settings of supported languages.
c906108c
SS
8742
8743@menu
8744* Type Checking:: An overview of type checking
8745* Range Checking:: An overview of range checking
8746@end menu
8747
8748@cindex type checking
8749@cindex checks, type
6d2ebf8b 8750@node Type Checking
c906108c
SS
8751@subsection An overview of type checking
8752
8753Some languages, such as Modula-2, are strongly typed, meaning that the
8754arguments to operators and functions have to be of the correct type,
8755otherwise an error occurs. These checks prevent type mismatch
8756errors from ever causing any run-time problems. For example,
8757
8758@smallexample
87591 + 2 @result{} 3
8760@exdent but
8761@error{} 1 + 2.3
8762@end smallexample
8763
8764The second example fails because the @code{CARDINAL} 1 is not
8765type-compatible with the @code{REAL} 2.3.
8766
5d161b24
DB
8767For the expressions you use in @value{GDBN} commands, you can tell the
8768@value{GDBN} type checker to skip checking;
8769to treat any mismatches as errors and abandon the expression;
8770or to only issue warnings when type mismatches occur,
c906108c
SS
8771but evaluate the expression anyway. When you choose the last of
8772these, @value{GDBN} evaluates expressions like the second example above, but
8773also issues a warning.
8774
5d161b24
DB
8775Even if you turn type checking off, there may be other reasons
8776related to type that prevent @value{GDBN} from evaluating an expression.
8777For instance, @value{GDBN} does not know how to add an @code{int} and
8778a @code{struct foo}. These particular type errors have nothing to do
8779with the language in use, and usually arise from expressions, such as
c906108c
SS
8780the one described above, which make little sense to evaluate anyway.
8781
8782Each language defines to what degree it is strict about type. For
8783instance, both Modula-2 and C require the arguments to arithmetical
8784operators to be numbers. In C, enumerated types and pointers can be
8785represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8786operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8787details on specific languages.
8788
8789@value{GDBN} provides some additional commands for controlling the type checker:
8790
c906108c
SS
8791@kindex set check type
8792@kindex show check type
8793@table @code
8794@item set check type auto
8795Set type checking on or off based on the current working language.
9c16f35a 8796@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8797each language.
8798
8799@item set check type on
8800@itemx set check type off
8801Set type checking on or off, overriding the default setting for the
8802current working language. Issue a warning if the setting does not
8803match the language default. If any type mismatches occur in
d4f3574e 8804evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8805message and aborts evaluation of the expression.
8806
8807@item set check type warn
8808Cause the type checker to issue warnings, but to always attempt to
8809evaluate the expression. Evaluating the expression may still
8810be impossible for other reasons. For example, @value{GDBN} cannot add
8811numbers and structures.
8812
8813@item show type
5d161b24 8814Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8815is setting it automatically.
8816@end table
8817
8818@cindex range checking
8819@cindex checks, range
6d2ebf8b 8820@node Range Checking
c906108c
SS
8821@subsection An overview of range checking
8822
8823In some languages (such as Modula-2), it is an error to exceed the
8824bounds of a type; this is enforced with run-time checks. Such range
8825checking is meant to ensure program correctness by making sure
8826computations do not overflow, or indices on an array element access do
8827not exceed the bounds of the array.
8828
8829For expressions you use in @value{GDBN} commands, you can tell
8830@value{GDBN} to treat range errors in one of three ways: ignore them,
8831always treat them as errors and abandon the expression, or issue
8832warnings but evaluate the expression anyway.
8833
8834A range error can result from numerical overflow, from exceeding an
8835array index bound, or when you type a constant that is not a member
8836of any type. Some languages, however, do not treat overflows as an
8837error. In many implementations of C, mathematical overflow causes the
8838result to ``wrap around'' to lower values---for example, if @var{m} is
8839the largest integer value, and @var{s} is the smallest, then
8840
474c8240 8841@smallexample
c906108c 8842@var{m} + 1 @result{} @var{s}
474c8240 8843@end smallexample
c906108c
SS
8844
8845This, too, is specific to individual languages, and in some cases
9c16f35a 8846specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8847Supported languages}, for further details on specific languages.
8848
8849@value{GDBN} provides some additional commands for controlling the range checker:
8850
c906108c
SS
8851@kindex set check range
8852@kindex show check range
8853@table @code
8854@item set check range auto
8855Set range checking on or off based on the current working language.
9c16f35a 8856@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8857each language.
8858
8859@item set check range on
8860@itemx set check range off
8861Set range checking on or off, overriding the default setting for the
8862current working language. A warning is issued if the setting does not
c3f6f71d
JM
8863match the language default. If a range error occurs and range checking is on,
8864then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8865
8866@item set check range warn
8867Output messages when the @value{GDBN} range checker detects a range error,
8868but attempt to evaluate the expression anyway. Evaluating the
8869expression may still be impossible for other reasons, such as accessing
8870memory that the process does not own (a typical example from many Unix
8871systems).
8872
8873@item show range
8874Show the current setting of the range checker, and whether or not it is
8875being set automatically by @value{GDBN}.
8876@end table
c906108c 8877
9c16f35a 8878@node Supported languages
c906108c 8879@section Supported languages
c906108c 8880
9c16f35a
EZ
8881@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8882assembly, Modula-2, and Ada.
cce74817 8883@c This is false ...
c906108c
SS
8884Some @value{GDBN} features may be used in expressions regardless of the
8885language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8886and the @samp{@{type@}addr} construct (@pxref{Expressions,
8887,Expressions}) can be used with the constructs of any supported
8888language.
8889
8890The following sections detail to what degree each source language is
8891supported by @value{GDBN}. These sections are not meant to be language
8892tutorials or references, but serve only as a reference guide to what the
8893@value{GDBN} expression parser accepts, and what input and output
8894formats should look like for different languages. There are many good
8895books written on each of these languages; please look to these for a
8896language reference or tutorial.
8897
c906108c 8898@menu
b37303ee 8899* C:: C and C@t{++}
b383017d 8900* Objective-C:: Objective-C
09d4efe1 8901* Fortran:: Fortran
9c16f35a 8902* Pascal:: Pascal
b37303ee 8903* Modula-2:: Modula-2
e07c999f 8904* Ada:: Ada
c906108c
SS
8905@end menu
8906
6d2ebf8b 8907@node C
b37052ae 8908@subsection C and C@t{++}
7a292a7a 8909
b37052ae
EZ
8910@cindex C and C@t{++}
8911@cindex expressions in C or C@t{++}
c906108c 8912
b37052ae 8913Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8914to both languages. Whenever this is the case, we discuss those languages
8915together.
8916
41afff9a
EZ
8917@cindex C@t{++}
8918@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8919@cindex @sc{gnu} C@t{++}
8920The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8921compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8922effectively, you must compile your C@t{++} programs with a supported
8923C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8924compiler (@code{aCC}).
8925
0179ffac
DC
8926For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8927format; if it doesn't work on your system, try the stabs+ debugging
8928format. You can select those formats explicitly with the @code{g++}
8929command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8930@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8931CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8932
c906108c 8933@menu
b37052ae
EZ
8934* C Operators:: C and C@t{++} operators
8935* C Constants:: C and C@t{++} constants
8936* C plus plus expressions:: C@t{++} expressions
8937* C Defaults:: Default settings for C and C@t{++}
8938* C Checks:: C and C@t{++} type and range checks
c906108c 8939* Debugging C:: @value{GDBN} and C
b37052ae 8940* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8941@end menu
c906108c 8942
6d2ebf8b 8943@node C Operators
b37052ae 8944@subsubsection C and C@t{++} operators
7a292a7a 8945
b37052ae 8946@cindex C and C@t{++} operators
c906108c
SS
8947
8948Operators must be defined on values of specific types. For instance,
8949@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8950often defined on groups of types.
c906108c 8951
b37052ae 8952For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8953
8954@itemize @bullet
53a5351d 8955
c906108c 8956@item
c906108c 8957@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8958specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8959
8960@item
d4f3574e
SS
8961@emph{Floating-point types} include @code{float}, @code{double}, and
8962@code{long double} (if supported by the target platform).
c906108c
SS
8963
8964@item
53a5351d 8965@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8966
8967@item
8968@emph{Scalar types} include all of the above.
53a5351d 8969
c906108c
SS
8970@end itemize
8971
8972@noindent
8973The following operators are supported. They are listed here
8974in order of increasing precedence:
8975
8976@table @code
8977@item ,
8978The comma or sequencing operator. Expressions in a comma-separated list
8979are evaluated from left to right, with the result of the entire
8980expression being the last expression evaluated.
8981
8982@item =
8983Assignment. The value of an assignment expression is the value
8984assigned. Defined on scalar types.
8985
8986@item @var{op}=
8987Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8988and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8989@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8990@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8991@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8992
8993@item ?:
8994The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8995of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8996integral type.
8997
8998@item ||
8999Logical @sc{or}. Defined on integral types.
9000
9001@item &&
9002Logical @sc{and}. Defined on integral types.
9003
9004@item |
9005Bitwise @sc{or}. Defined on integral types.
9006
9007@item ^
9008Bitwise exclusive-@sc{or}. Defined on integral types.
9009
9010@item &
9011Bitwise @sc{and}. Defined on integral types.
9012
9013@item ==@r{, }!=
9014Equality and inequality. Defined on scalar types. The value of these
9015expressions is 0 for false and non-zero for true.
9016
9017@item <@r{, }>@r{, }<=@r{, }>=
9018Less than, greater than, less than or equal, greater than or equal.
9019Defined on scalar types. The value of these expressions is 0 for false
9020and non-zero for true.
9021
9022@item <<@r{, }>>
9023left shift, and right shift. Defined on integral types.
9024
9025@item @@
9026The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9027
9028@item +@r{, }-
9029Addition and subtraction. Defined on integral types, floating-point types and
9030pointer types.
9031
9032@item *@r{, }/@r{, }%
9033Multiplication, division, and modulus. Multiplication and division are
9034defined on integral and floating-point types. Modulus is defined on
9035integral types.
9036
9037@item ++@r{, }--
9038Increment and decrement. When appearing before a variable, the
9039operation is performed before the variable is used in an expression;
9040when appearing after it, the variable's value is used before the
9041operation takes place.
9042
9043@item *
9044Pointer dereferencing. Defined on pointer types. Same precedence as
9045@code{++}.
9046
9047@item &
9048Address operator. Defined on variables. Same precedence as @code{++}.
9049
b37052ae
EZ
9050For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
9051allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 9052(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 9053where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 9054stored.
c906108c
SS
9055
9056@item -
9057Negative. Defined on integral and floating-point types. Same
9058precedence as @code{++}.
9059
9060@item !
9061Logical negation. Defined on integral types. Same precedence as
9062@code{++}.
9063
9064@item ~
9065Bitwise complement operator. Defined on integral types. Same precedence as
9066@code{++}.
9067
9068
9069@item .@r{, }->
9070Structure member, and pointer-to-structure member. For convenience,
9071@value{GDBN} regards the two as equivalent, choosing whether to dereference a
9072pointer based on the stored type information.
9073Defined on @code{struct} and @code{union} data.
9074
c906108c
SS
9075@item .*@r{, }->*
9076Dereferences of pointers to members.
c906108c
SS
9077
9078@item []
9079Array indexing. @code{@var{a}[@var{i}]} is defined as
9080@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
9081
9082@item ()
9083Function parameter list. Same precedence as @code{->}.
9084
c906108c 9085@item ::
b37052ae 9086C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 9087and @code{class} types.
c906108c
SS
9088
9089@item ::
7a292a7a
SS
9090Doubled colons also represent the @value{GDBN} scope operator
9091(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
9092above.
c906108c
SS
9093@end table
9094
c906108c
SS
9095If an operator is redefined in the user code, @value{GDBN} usually
9096attempts to invoke the redefined version instead of using the operator's
9097predefined meaning.
c906108c 9098
c906108c 9099@menu
5d161b24 9100* C Constants::
c906108c
SS
9101@end menu
9102
6d2ebf8b 9103@node C Constants
b37052ae 9104@subsubsection C and C@t{++} constants
c906108c 9105
b37052ae 9106@cindex C and C@t{++} constants
c906108c 9107
b37052ae 9108@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 9109following ways:
c906108c
SS
9110
9111@itemize @bullet
9112@item
9113Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
9114specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
9115by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
9116@samp{l}, specifying that the constant should be treated as a
9117@code{long} value.
9118
9119@item
9120Floating point constants are a sequence of digits, followed by a decimal
9121point, followed by a sequence of digits, and optionally followed by an
9122exponent. An exponent is of the form:
9123@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
9124sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
9125A floating-point constant may also end with a letter @samp{f} or
9126@samp{F}, specifying that the constant should be treated as being of
9127the @code{float} (as opposed to the default @code{double}) type; or with
9128a letter @samp{l} or @samp{L}, which specifies a @code{long double}
9129constant.
c906108c
SS
9130
9131@item
9132Enumerated constants consist of enumerated identifiers, or their
9133integral equivalents.
9134
9135@item
9136Character constants are a single character surrounded by single quotes
9137(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 9138(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
9139be represented by a letter or by @dfn{escape sequences}, which are of
9140the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
9141of the character's ordinal value; or of the form @samp{\@var{x}}, where
9142@samp{@var{x}} is a predefined special character---for example,
9143@samp{\n} for newline.
9144
9145@item
96a2c332
SS
9146String constants are a sequence of character constants surrounded by
9147double quotes (@code{"}). Any valid character constant (as described
9148above) may appear. Double quotes within the string must be preceded by
9149a backslash, so for instance @samp{"a\"b'c"} is a string of five
9150characters.
c906108c
SS
9151
9152@item
9153Pointer constants are an integral value. You can also write pointers
9154to constants using the C operator @samp{&}.
9155
9156@item
9157Array constants are comma-separated lists surrounded by braces @samp{@{}
9158and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
9159integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
9160and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
9161@end itemize
9162
c906108c 9163@menu
5d161b24
DB
9164* C plus plus expressions::
9165* C Defaults::
9166* C Checks::
c906108c 9167
5d161b24 9168* Debugging C::
c906108c
SS
9169@end menu
9170
6d2ebf8b 9171@node C plus plus expressions
b37052ae
EZ
9172@subsubsection C@t{++} expressions
9173
9174@cindex expressions in C@t{++}
9175@value{GDBN} expression handling can interpret most C@t{++} expressions.
9176
0179ffac
DC
9177@cindex debugging C@t{++} programs
9178@cindex C@t{++} compilers
9179@cindex debug formats and C@t{++}
9180@cindex @value{NGCC} and C@t{++}
c906108c 9181@quotation
b37052ae 9182@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
9183proper compiler and the proper debug format. Currently, @value{GDBN}
9184works best when debugging C@t{++} code that is compiled with
9185@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
9186@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
9187stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
9188stabs+ as their default debug format, so you usually don't need to
9189specify a debug format explicitly. Other compilers and/or debug formats
9190are likely to work badly or not at all when using @value{GDBN} to debug
9191C@t{++} code.
c906108c 9192@end quotation
c906108c
SS
9193
9194@enumerate
9195
9196@cindex member functions
9197@item
9198Member function calls are allowed; you can use expressions like
9199
474c8240 9200@smallexample
c906108c 9201count = aml->GetOriginal(x, y)
474c8240 9202@end smallexample
c906108c 9203
41afff9a 9204@vindex this@r{, inside C@t{++} member functions}
b37052ae 9205@cindex namespace in C@t{++}
c906108c
SS
9206@item
9207While a member function is active (in the selected stack frame), your
9208expressions have the same namespace available as the member function;
9209that is, @value{GDBN} allows implicit references to the class instance
b37052ae 9210pointer @code{this} following the same rules as C@t{++}.
c906108c 9211
c906108c 9212@cindex call overloaded functions
d4f3574e 9213@cindex overloaded functions, calling
b37052ae 9214@cindex type conversions in C@t{++}
c906108c
SS
9215@item
9216You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 9217call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
9218perform overload resolution involving user-defined type conversions,
9219calls to constructors, or instantiations of templates that do not exist
9220in the program. It also cannot handle ellipsis argument lists or
9221default arguments.
9222
9223It does perform integral conversions and promotions, floating-point
9224promotions, arithmetic conversions, pointer conversions, conversions of
9225class objects to base classes, and standard conversions such as those of
9226functions or arrays to pointers; it requires an exact match on the
9227number of function arguments.
9228
9229Overload resolution is always performed, unless you have specified
9230@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 9231,@value{GDBN} features for C@t{++}}.
c906108c 9232
d4f3574e 9233You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
9234explicit function signature to call an overloaded function, as in
9235@smallexample
9236p 'foo(char,int)'('x', 13)
9237@end smallexample
d4f3574e 9238
c906108c 9239The @value{GDBN} command-completion facility can simplify this;
d4f3574e 9240see @ref{Completion, ,Command completion}.
c906108c 9241
c906108c
SS
9242@cindex reference declarations
9243@item
b37052ae
EZ
9244@value{GDBN} understands variables declared as C@t{++} references; you can use
9245them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
9246dereferenced.
9247
9248In the parameter list shown when @value{GDBN} displays a frame, the values of
9249reference variables are not displayed (unlike other variables); this
9250avoids clutter, since references are often used for large structures.
9251The @emph{address} of a reference variable is always shown, unless
9252you have specified @samp{set print address off}.
9253
9254@item
b37052ae 9255@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
9256expressions can use it just as expressions in your program do. Since
9257one scope may be defined in another, you can use @code{::} repeatedly if
9258necessary, for example in an expression like
9259@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 9260resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
9261debugging (@pxref{Variables, ,Program variables}).
9262@end enumerate
9263
b37052ae 9264In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
9265calling virtual functions correctly, printing out virtual bases of
9266objects, calling functions in a base subobject, casting objects, and
9267invoking user-defined operators.
c906108c 9268
6d2ebf8b 9269@node C Defaults
b37052ae 9270@subsubsection C and C@t{++} defaults
7a292a7a 9271
b37052ae 9272@cindex C and C@t{++} defaults
c906108c 9273
c906108c
SS
9274If you allow @value{GDBN} to set type and range checking automatically, they
9275both default to @code{off} whenever the working language changes to
b37052ae 9276C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 9277selects the working language.
c906108c
SS
9278
9279If you allow @value{GDBN} to set the language automatically, it
9280recognizes source files whose names end with @file{.c}, @file{.C}, or
9281@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 9282these files, it sets the working language to C or C@t{++}.
c906108c
SS
9283@xref{Automatically, ,Having @value{GDBN} infer the source language},
9284for further details.
9285
c906108c
SS
9286@c Type checking is (a) primarily motivated by Modula-2, and (b)
9287@c unimplemented. If (b) changes, it might make sense to let this node
9288@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 9289
6d2ebf8b 9290@node C Checks
b37052ae 9291@subsubsection C and C@t{++} type and range checks
7a292a7a 9292
b37052ae 9293@cindex C and C@t{++} checks
c906108c 9294
b37052ae 9295By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
9296is not used. However, if you turn type checking on, @value{GDBN}
9297considers two variables type equivalent if:
9298
9299@itemize @bullet
9300@item
9301The two variables are structured and have the same structure, union, or
9302enumerated tag.
9303
9304@item
9305The two variables have the same type name, or types that have been
9306declared equivalent through @code{typedef}.
9307
9308@ignore
9309@c leaving this out because neither J Gilmore nor R Pesch understand it.
9310@c FIXME--beers?
9311@item
9312The two @code{struct}, @code{union}, or @code{enum} variables are
9313declared in the same declaration. (Note: this may not be true for all C
9314compilers.)
9315@end ignore
9316@end itemize
9317
9318Range checking, if turned on, is done on mathematical operations. Array
9319indices are not checked, since they are often used to index a pointer
9320that is not itself an array.
c906108c 9321
6d2ebf8b 9322@node Debugging C
c906108c 9323@subsubsection @value{GDBN} and C
c906108c
SS
9324
9325The @code{set print union} and @code{show print union} commands apply to
9326the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
9327inside a @code{struct} or @code{class} is also printed. Otherwise, it
9328appears as @samp{@{...@}}.
c906108c
SS
9329
9330The @code{@@} operator aids in the debugging of dynamic arrays, formed
9331with pointers and a memory allocation function. @xref{Expressions,
9332,Expressions}.
9333
c906108c 9334@menu
5d161b24 9335* Debugging C plus plus::
c906108c
SS
9336@end menu
9337
6d2ebf8b 9338@node Debugging C plus plus
b37052ae 9339@subsubsection @value{GDBN} features for C@t{++}
c906108c 9340
b37052ae 9341@cindex commands for C@t{++}
7a292a7a 9342
b37052ae
EZ
9343Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
9344designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
9345
9346@table @code
9347@cindex break in overloaded functions
9348@item @r{breakpoint menus}
9349When you want a breakpoint in a function whose name is overloaded,
9350@value{GDBN} breakpoint menus help you specify which function definition
9351you want. @xref{Breakpoint Menus,,Breakpoint menus}.
9352
b37052ae 9353@cindex overloading in C@t{++}
c906108c
SS
9354@item rbreak @var{regex}
9355Setting breakpoints using regular expressions is helpful for setting
9356breakpoints on overloaded functions that are not members of any special
9357classes.
9358@xref{Set Breaks, ,Setting breakpoints}.
9359
b37052ae 9360@cindex C@t{++} exception handling
c906108c
SS
9361@item catch throw
9362@itemx catch catch
b37052ae 9363Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
9364Catchpoints, , Setting catchpoints}.
9365
9366@cindex inheritance
9367@item ptype @var{typename}
9368Print inheritance relationships as well as other information for type
9369@var{typename}.
9370@xref{Symbols, ,Examining the Symbol Table}.
9371
b37052ae 9372@cindex C@t{++} symbol display
c906108c
SS
9373@item set print demangle
9374@itemx show print demangle
9375@itemx set print asm-demangle
9376@itemx show print asm-demangle
b37052ae
EZ
9377Control whether C@t{++} symbols display in their source form, both when
9378displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
9379@xref{Print Settings, ,Print settings}.
9380
9381@item set print object
9382@itemx show print object
9383Choose whether to print derived (actual) or declared types of objects.
9384@xref{Print Settings, ,Print settings}.
9385
9386@item set print vtbl
9387@itemx show print vtbl
9388Control the format for printing virtual function tables.
9389@xref{Print Settings, ,Print settings}.
c906108c 9390(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 9391ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
9392
9393@kindex set overload-resolution
d4f3574e 9394@cindex overloaded functions, overload resolution
c906108c 9395@item set overload-resolution on
b37052ae 9396Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
9397is on. For overloaded functions, @value{GDBN} evaluates the arguments
9398and searches for a function whose signature matches the argument types,
b37052ae 9399using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 9400expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
9401message.
9402
9403@item set overload-resolution off
b37052ae 9404Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
9405overloaded functions that are not class member functions, @value{GDBN}
9406chooses the first function of the specified name that it finds in the
9407symbol table, whether or not its arguments are of the correct type. For
9408overloaded functions that are class member functions, @value{GDBN}
9409searches for a function whose signature @emph{exactly} matches the
9410argument types.
c906108c 9411
9c16f35a
EZ
9412@kindex show overload-resolution
9413@item show overload-resolution
9414Show the current setting of overload resolution.
9415
c906108c
SS
9416@item @r{Overloaded symbol names}
9417You can specify a particular definition of an overloaded symbol, using
b37052ae 9418the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
9419@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
9420also use the @value{GDBN} command-line word completion facilities to list the
9421available choices, or to finish the type list for you.
9422@xref{Completion,, Command completion}, for details on how to do this.
9423@end table
c906108c 9424
b37303ee
AF
9425@node Objective-C
9426@subsection Objective-C
9427
9428@cindex Objective-C
9429This section provides information about some commands and command
721c2651
EZ
9430options that are useful for debugging Objective-C code. See also
9431@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9432few more commands specific to Objective-C support.
b37303ee
AF
9433
9434@menu
b383017d
RM
9435* Method Names in Commands::
9436* The Print Command with Objective-C::
b37303ee
AF
9437@end menu
9438
9439@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
9440@subsubsection Method Names in Commands
9441
9442The following commands have been extended to accept Objective-C method
9443names as line specifications:
9444
9445@kindex clear@r{, and Objective-C}
9446@kindex break@r{, and Objective-C}
9447@kindex info line@r{, and Objective-C}
9448@kindex jump@r{, and Objective-C}
9449@kindex list@r{, and Objective-C}
9450@itemize
9451@item @code{clear}
9452@item @code{break}
9453@item @code{info line}
9454@item @code{jump}
9455@item @code{list}
9456@end itemize
9457
9458A fully qualified Objective-C method name is specified as
9459
9460@smallexample
9461-[@var{Class} @var{methodName}]
9462@end smallexample
9463
c552b3bb
JM
9464where the minus sign is used to indicate an instance method and a
9465plus sign (not shown) is used to indicate a class method. The class
9466name @var{Class} and method name @var{methodName} are enclosed in
9467brackets, similar to the way messages are specified in Objective-C
9468source code. For example, to set a breakpoint at the @code{create}
9469instance method of class @code{Fruit} in the program currently being
9470debugged, enter:
b37303ee
AF
9471
9472@smallexample
9473break -[Fruit create]
9474@end smallexample
9475
9476To list ten program lines around the @code{initialize} class method,
9477enter:
9478
9479@smallexample
9480list +[NSText initialize]
9481@end smallexample
9482
c552b3bb
JM
9483In the current version of @value{GDBN}, the plus or minus sign is
9484required. In future versions of @value{GDBN}, the plus or minus
9485sign will be optional, but you can use it to narrow the search. It
9486is also possible to specify just a method name:
b37303ee
AF
9487
9488@smallexample
9489break create
9490@end smallexample
9491
9492You must specify the complete method name, including any colons. If
9493your program's source files contain more than one @code{create} method,
9494you'll be presented with a numbered list of classes that implement that
9495method. Indicate your choice by number, or type @samp{0} to exit if
9496none apply.
9497
9498As another example, to clear a breakpoint established at the
9499@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9500
9501@smallexample
9502clear -[NSWindow makeKeyAndOrderFront:]
9503@end smallexample
9504
9505@node The Print Command with Objective-C
9506@subsubsection The Print Command With Objective-C
721c2651 9507@cindex Objective-C, print objects
c552b3bb
JM
9508@kindex print-object
9509@kindex po @r{(@code{print-object})}
b37303ee 9510
c552b3bb 9511The print command has also been extended to accept methods. For example:
b37303ee
AF
9512
9513@smallexample
c552b3bb 9514print -[@var{object} hash]
b37303ee
AF
9515@end smallexample
9516
9517@cindex print an Objective-C object description
c552b3bb
JM
9518@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9519@noindent
9520will tell @value{GDBN} to send the @code{hash} message to @var{object}
9521and print the result. Also, an additional command has been added,
9522@code{print-object} or @code{po} for short, which is meant to print
9523the description of an object. However, this command may only work
9524with certain Objective-C libraries that have a particular hook
9525function, @code{_NSPrintForDebugger}, defined.
b37303ee 9526
09d4efe1
EZ
9527@node Fortran
9528@subsection Fortran
9529@cindex Fortran-specific support in @value{GDBN}
9530
814e32d7
WZ
9531@value{GDBN} can be used to debug programs written in Fortran, but it
9532currently supports only the features of Fortran 77 language.
9533
9534@cindex trailing underscore, in Fortran symbols
9535Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
9536among them) append an underscore to the names of variables and
9537functions. When you debug programs compiled by those compilers, you
9538will need to refer to variables and functions with a trailing
9539underscore.
9540
9541@menu
9542* Fortran Operators:: Fortran operators and expressions
9543* Fortran Defaults:: Default settings for Fortran
9544* Special Fortran commands:: Special @value{GDBN} commands for Fortran
9545@end menu
9546
9547@node Fortran Operators
9548@subsubsection Fortran operators and expressions
9549
9550@cindex Fortran operators and expressions
9551
9552Operators must be defined on values of specific types. For instance,
9553@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 9554arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
9555
9556@table @code
9557@item **
9558The exponentiation operator. It raises the first operand to the power
9559of the second one.
9560
9561@item :
9562The range operator. Normally used in the form of array(low:high) to
9563represent a section of array.
9564@end table
9565
9566@node Fortran Defaults
9567@subsubsection Fortran Defaults
9568
9569@cindex Fortran Defaults
9570
9571Fortran symbols are usually case-insensitive, so @value{GDBN} by
9572default uses case-insensitive matches for Fortran symbols. You can
9573change that with the @samp{set case-insensitive} command, see
9574@ref{Symbols}, for the details.
9575
9576@node Special Fortran commands
9577@subsubsection Special Fortran commands
9578
9579@cindex Special Fortran commands
9580
9581@value{GDBN} had some commands to support Fortran specific feature,
9582such as common block displaying.
9583
09d4efe1
EZ
9584@table @code
9585@cindex @code{COMMON} blocks, Fortran
9586@kindex info common
9587@item info common @r{[}@var{common-name}@r{]}
9588This command prints the values contained in the Fortran @code{COMMON}
9589block whose name is @var{common-name}. With no argument, the names of
9590all @code{COMMON} blocks visible at current program location are
9591printed.
9592@end table
9593
9c16f35a
EZ
9594@node Pascal
9595@subsection Pascal
9596
9597@cindex Pascal support in @value{GDBN}, limitations
9598Debugging Pascal programs which use sets, subranges, file variables, or
9599nested functions does not currently work. @value{GDBN} does not support
9600entering expressions, printing values, or similar features using Pascal
9601syntax.
9602
9603The Pascal-specific command @code{set print pascal_static-members}
9604controls whether static members of Pascal objects are displayed.
9605@xref{Print Settings, pascal_static-members}.
9606
09d4efe1 9607@node Modula-2
c906108c 9608@subsection Modula-2
7a292a7a 9609
d4f3574e 9610@cindex Modula-2, @value{GDBN} support
c906108c
SS
9611
9612The extensions made to @value{GDBN} to support Modula-2 only support
9613output from the @sc{gnu} Modula-2 compiler (which is currently being
9614developed). Other Modula-2 compilers are not currently supported, and
9615attempting to debug executables produced by them is most likely
9616to give an error as @value{GDBN} reads in the executable's symbol
9617table.
9618
9619@cindex expressions in Modula-2
9620@menu
9621* M2 Operators:: Built-in operators
9622* Built-In Func/Proc:: Built-in functions and procedures
9623* M2 Constants:: Modula-2 constants
72019c9c 9624* M2 Types:: Modula-2 types
c906108c
SS
9625* M2 Defaults:: Default settings for Modula-2
9626* Deviations:: Deviations from standard Modula-2
9627* M2 Checks:: Modula-2 type and range checks
9628* M2 Scope:: The scope operators @code{::} and @code{.}
9629* GDB/M2:: @value{GDBN} and Modula-2
9630@end menu
9631
6d2ebf8b 9632@node M2 Operators
c906108c
SS
9633@subsubsection Operators
9634@cindex Modula-2 operators
9635
9636Operators must be defined on values of specific types. For instance,
9637@code{+} is defined on numbers, but not on structures. Operators are
9638often defined on groups of types. For the purposes of Modula-2, the
9639following definitions hold:
9640
9641@itemize @bullet
9642
9643@item
9644@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9645their subranges.
9646
9647@item
9648@emph{Character types} consist of @code{CHAR} and its subranges.
9649
9650@item
9651@emph{Floating-point types} consist of @code{REAL}.
9652
9653@item
9654@emph{Pointer types} consist of anything declared as @code{POINTER TO
9655@var{type}}.
9656
9657@item
9658@emph{Scalar types} consist of all of the above.
9659
9660@item
9661@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9662
9663@item
9664@emph{Boolean types} consist of @code{BOOLEAN}.
9665@end itemize
9666
9667@noindent
9668The following operators are supported, and appear in order of
9669increasing precedence:
9670
9671@table @code
9672@item ,
9673Function argument or array index separator.
9674
9675@item :=
9676Assignment. The value of @var{var} @code{:=} @var{value} is
9677@var{value}.
9678
9679@item <@r{, }>
9680Less than, greater than on integral, floating-point, or enumerated
9681types.
9682
9683@item <=@r{, }>=
96a2c332 9684Less than or equal to, greater than or equal to
c906108c
SS
9685on integral, floating-point and enumerated types, or set inclusion on
9686set types. Same precedence as @code{<}.
9687
9688@item =@r{, }<>@r{, }#
9689Equality and two ways of expressing inequality, valid on scalar types.
9690Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9691available for inequality, since @code{#} conflicts with the script
9692comment character.
9693
9694@item IN
9695Set membership. Defined on set types and the types of their members.
9696Same precedence as @code{<}.
9697
9698@item OR
9699Boolean disjunction. Defined on boolean types.
9700
9701@item AND@r{, }&
d4f3574e 9702Boolean conjunction. Defined on boolean types.
c906108c
SS
9703
9704@item @@
9705The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9706
9707@item +@r{, }-
9708Addition and subtraction on integral and floating-point types, or union
9709and difference on set types.
9710
9711@item *
9712Multiplication on integral and floating-point types, or set intersection
9713on set types.
9714
9715@item /
9716Division on floating-point types, or symmetric set difference on set
9717types. Same precedence as @code{*}.
9718
9719@item DIV@r{, }MOD
9720Integer division and remainder. Defined on integral types. Same
9721precedence as @code{*}.
9722
9723@item -
9724Negative. Defined on @code{INTEGER} and @code{REAL} data.
9725
9726@item ^
9727Pointer dereferencing. Defined on pointer types.
9728
9729@item NOT
9730Boolean negation. Defined on boolean types. Same precedence as
9731@code{^}.
9732
9733@item .
9734@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9735precedence as @code{^}.
9736
9737@item []
9738Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9739
9740@item ()
9741Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9742as @code{^}.
9743
9744@item ::@r{, }.
9745@value{GDBN} and Modula-2 scope operators.
9746@end table
9747
9748@quotation
72019c9c 9749@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
9750treats the use of the operator @code{IN}, or the use of operators
9751@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9752@code{<=}, and @code{>=} on sets as an error.
9753@end quotation
9754
cb51c4e0 9755
6d2ebf8b 9756@node Built-In Func/Proc
c906108c 9757@subsubsection Built-in functions and procedures
cb51c4e0 9758@cindex Modula-2 built-ins
c906108c
SS
9759
9760Modula-2 also makes available several built-in procedures and functions.
9761In describing these, the following metavariables are used:
9762
9763@table @var
9764
9765@item a
9766represents an @code{ARRAY} variable.
9767
9768@item c
9769represents a @code{CHAR} constant or variable.
9770
9771@item i
9772represents a variable or constant of integral type.
9773
9774@item m
9775represents an identifier that belongs to a set. Generally used in the
9776same function with the metavariable @var{s}. The type of @var{s} should
9777be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9778
9779@item n
9780represents a variable or constant of integral or floating-point type.
9781
9782@item r
9783represents a variable or constant of floating-point type.
9784
9785@item t
9786represents a type.
9787
9788@item v
9789represents a variable.
9790
9791@item x
9792represents a variable or constant of one of many types. See the
9793explanation of the function for details.
9794@end table
9795
9796All Modula-2 built-in procedures also return a result, described below.
9797
9798@table @code
9799@item ABS(@var{n})
9800Returns the absolute value of @var{n}.
9801
9802@item CAP(@var{c})
9803If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9804equivalent, otherwise it returns its argument.
c906108c
SS
9805
9806@item CHR(@var{i})
9807Returns the character whose ordinal value is @var{i}.
9808
9809@item DEC(@var{v})
c3f6f71d 9810Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9811
9812@item DEC(@var{v},@var{i})
9813Decrements the value in the variable @var{v} by @var{i}. Returns the
9814new value.
9815
9816@item EXCL(@var{m},@var{s})
9817Removes the element @var{m} from the set @var{s}. Returns the new
9818set.
9819
9820@item FLOAT(@var{i})
9821Returns the floating point equivalent of the integer @var{i}.
9822
9823@item HIGH(@var{a})
9824Returns the index of the last member of @var{a}.
9825
9826@item INC(@var{v})
c3f6f71d 9827Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9828
9829@item INC(@var{v},@var{i})
9830Increments the value in the variable @var{v} by @var{i}. Returns the
9831new value.
9832
9833@item INCL(@var{m},@var{s})
9834Adds the element @var{m} to the set @var{s} if it is not already
9835there. Returns the new set.
9836
9837@item MAX(@var{t})
9838Returns the maximum value of the type @var{t}.
9839
9840@item MIN(@var{t})
9841Returns the minimum value of the type @var{t}.
9842
9843@item ODD(@var{i})
9844Returns boolean TRUE if @var{i} is an odd number.
9845
9846@item ORD(@var{x})
9847Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9848value of a character is its @sc{ascii} value (on machines supporting the
9849@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9850integral, character and enumerated types.
9851
9852@item SIZE(@var{x})
9853Returns the size of its argument. @var{x} can be a variable or a type.
9854
9855@item TRUNC(@var{r})
9856Returns the integral part of @var{r}.
9857
9858@item VAL(@var{t},@var{i})
9859Returns the member of the type @var{t} whose ordinal value is @var{i}.
9860@end table
9861
9862@quotation
9863@emph{Warning:} Sets and their operations are not yet supported, so
9864@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9865an error.
9866@end quotation
9867
9868@cindex Modula-2 constants
6d2ebf8b 9869@node M2 Constants
c906108c
SS
9870@subsubsection Constants
9871
9872@value{GDBN} allows you to express the constants of Modula-2 in the following
9873ways:
9874
9875@itemize @bullet
9876
9877@item
9878Integer constants are simply a sequence of digits. When used in an
9879expression, a constant is interpreted to be type-compatible with the
9880rest of the expression. Hexadecimal integers are specified by a
9881trailing @samp{H}, and octal integers by a trailing @samp{B}.
9882
9883@item
9884Floating point constants appear as a sequence of digits, followed by a
9885decimal point and another sequence of digits. An optional exponent can
9886then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9887@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9888digits of the floating point constant must be valid decimal (base 10)
9889digits.
9890
9891@item
9892Character constants consist of a single character enclosed by a pair of
9893like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9894also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9895followed by a @samp{C}.
9896
9897@item
9898String constants consist of a sequence of characters enclosed by a
9899pair of like quotes, either single (@code{'}) or double (@code{"}).
9900Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9901Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9902sequences.
9903
9904@item
9905Enumerated constants consist of an enumerated identifier.
9906
9907@item
9908Boolean constants consist of the identifiers @code{TRUE} and
9909@code{FALSE}.
9910
9911@item
9912Pointer constants consist of integral values only.
9913
9914@item
9915Set constants are not yet supported.
9916@end itemize
9917
72019c9c
GM
9918@node M2 Types
9919@subsubsection Modula-2 Types
9920@cindex Modula-2 types
9921
9922Currently @value{GDBN} can print the following data types in Modula-2
9923syntax: array types, record types, set types, pointer types, procedure
9924types, enumerated types, subrange types and base types. You can also
9925print the contents of variables declared using these type.
9926This section gives a number of simple source code examples together with
9927sample @value{GDBN} sessions.
9928
9929The first example contains the following section of code:
9930
9931@smallexample
9932VAR
9933 s: SET OF CHAR ;
9934 r: [20..40] ;
9935@end smallexample
9936
9937@noindent
9938and you can request @value{GDBN} to interrogate the type and value of
9939@code{r} and @code{s}.
9940
9941@smallexample
9942(@value{GDBP}) print s
9943@{'A'..'C', 'Z'@}
9944(@value{GDBP}) ptype s
9945SET OF CHAR
9946(@value{GDBP}) print r
994721
9948(@value{GDBP}) ptype r
9949[20..40]
9950@end smallexample
9951
9952@noindent
9953Likewise if your source code declares @code{s} as:
9954
9955@smallexample
9956VAR
9957 s: SET ['A'..'Z'] ;
9958@end smallexample
9959
9960@noindent
9961then you may query the type of @code{s} by:
9962
9963@smallexample
9964(@value{GDBP}) ptype s
9965type = SET ['A'..'Z']
9966@end smallexample
9967
9968@noindent
9969Note that at present you cannot interactively manipulate set
9970expressions using the debugger.
9971
9972The following example shows how you might declare an array in Modula-2
9973and how you can interact with @value{GDBN} to print its type and contents:
9974
9975@smallexample
9976VAR
9977 s: ARRAY [-10..10] OF CHAR ;
9978@end smallexample
9979
9980@smallexample
9981(@value{GDBP}) ptype s
9982ARRAY [-10..10] OF CHAR
9983@end smallexample
9984
9985Note that the array handling is not yet complete and although the type
9986is printed correctly, expression handling still assumes that all
9987arrays have a lower bound of zero and not @code{-10} as in the example
9988above. Unbounded arrays are also not yet recognized in @value{GDBN}.
9989
9990Here are some more type related Modula-2 examples:
9991
9992@smallexample
9993TYPE
9994 colour = (blue, red, yellow, green) ;
9995 t = [blue..yellow] ;
9996VAR
9997 s: t ;
9998BEGIN
9999 s := blue ;
10000@end smallexample
10001
10002@noindent
10003The @value{GDBN} interaction shows how you can query the data type
10004and value of a variable.
10005
10006@smallexample
10007(@value{GDBP}) print s
10008$1 = blue
10009(@value{GDBP}) ptype t
10010type = [blue..yellow]
10011@end smallexample
10012
10013@noindent
10014In this example a Modula-2 array is declared and its contents
10015displayed. Observe that the contents are written in the same way as
10016their @code{C} counterparts.
10017
10018@smallexample
10019VAR
10020 s: ARRAY [1..5] OF CARDINAL ;
10021BEGIN
10022 s[1] := 1 ;
10023@end smallexample
10024
10025@smallexample
10026(@value{GDBP}) print s
10027$1 = @{1, 0, 0, 0, 0@}
10028(@value{GDBP}) ptype s
10029type = ARRAY [1..5] OF CARDINAL
10030@end smallexample
10031
10032The Modula-2 language interface to @value{GDBN} also understands
10033pointer types as shown in this example:
10034
10035@smallexample
10036VAR
10037 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
10038BEGIN
10039 NEW(s) ;
10040 s^[1] := 1 ;
10041@end smallexample
10042
10043@noindent
10044and you can request that @value{GDBN} describes the type of @code{s}.
10045
10046@smallexample
10047(@value{GDBP}) ptype s
10048type = POINTER TO ARRAY [1..5] OF CARDINAL
10049@end smallexample
10050
10051@value{GDBN} handles compound types as we can see in this example.
10052Here we combine array types, record types, pointer types and subrange
10053types:
10054
10055@smallexample
10056TYPE
10057 foo = RECORD
10058 f1: CARDINAL ;
10059 f2: CHAR ;
10060 f3: myarray ;
10061 END ;
10062
10063 myarray = ARRAY myrange OF CARDINAL ;
10064 myrange = [-2..2] ;
10065VAR
10066 s: POINTER TO ARRAY myrange OF foo ;
10067@end smallexample
10068
10069@noindent
10070and you can ask @value{GDBN} to describe the type of @code{s} as shown
10071below.
10072
10073@smallexample
10074(@value{GDBP}) ptype s
10075type = POINTER TO ARRAY [-2..2] OF foo = RECORD
10076 f1 : CARDINAL;
10077 f2 : CHAR;
10078 f3 : ARRAY [-2..2] OF CARDINAL;
10079END
10080@end smallexample
10081
6d2ebf8b 10082@node M2 Defaults
c906108c
SS
10083@subsubsection Modula-2 defaults
10084@cindex Modula-2 defaults
10085
10086If type and range checking are set automatically by @value{GDBN}, they
10087both default to @code{on} whenever the working language changes to
d4f3574e 10088Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
10089selected the working language.
10090
10091If you allow @value{GDBN} to set the language automatically, then entering
10092code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 10093working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
10094the language automatically}, for further details.
10095
6d2ebf8b 10096@node Deviations
c906108c
SS
10097@subsubsection Deviations from standard Modula-2
10098@cindex Modula-2, deviations from
10099
10100A few changes have been made to make Modula-2 programs easier to debug.
10101This is done primarily via loosening its type strictness:
10102
10103@itemize @bullet
10104@item
10105Unlike in standard Modula-2, pointer constants can be formed by
10106integers. This allows you to modify pointer variables during
10107debugging. (In standard Modula-2, the actual address contained in a
10108pointer variable is hidden from you; it can only be modified
10109through direct assignment to another pointer variable or expression that
10110returned a pointer.)
10111
10112@item
10113C escape sequences can be used in strings and characters to represent
10114non-printable characters. @value{GDBN} prints out strings with these
10115escape sequences embedded. Single non-printable characters are
10116printed using the @samp{CHR(@var{nnn})} format.
10117
10118@item
10119The assignment operator (@code{:=}) returns the value of its right-hand
10120argument.
10121
10122@item
10123All built-in procedures both modify @emph{and} return their argument.
10124@end itemize
10125
6d2ebf8b 10126@node M2 Checks
c906108c
SS
10127@subsubsection Modula-2 type and range checks
10128@cindex Modula-2 checks
10129
10130@quotation
10131@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
10132range checking.
10133@end quotation
10134@c FIXME remove warning when type/range checks added
10135
10136@value{GDBN} considers two Modula-2 variables type equivalent if:
10137
10138@itemize @bullet
10139@item
10140They are of types that have been declared equivalent via a @code{TYPE
10141@var{t1} = @var{t2}} statement
10142
10143@item
10144They have been declared on the same line. (Note: This is true of the
10145@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
10146@end itemize
10147
10148As long as type checking is enabled, any attempt to combine variables
10149whose types are not equivalent is an error.
10150
10151Range checking is done on all mathematical operations, assignment, array
10152index bounds, and all built-in functions and procedures.
10153
6d2ebf8b 10154@node M2 Scope
c906108c
SS
10155@subsubsection The scope operators @code{::} and @code{.}
10156@cindex scope
41afff9a 10157@cindex @code{.}, Modula-2 scope operator
c906108c
SS
10158@cindex colon, doubled as scope operator
10159@ifinfo
41afff9a 10160@vindex colon-colon@r{, in Modula-2}
c906108c
SS
10161@c Info cannot handle :: but TeX can.
10162@end ifinfo
10163@iftex
41afff9a 10164@vindex ::@r{, in Modula-2}
c906108c
SS
10165@end iftex
10166
10167There are a few subtle differences between the Modula-2 scope operator
10168(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
10169similar syntax:
10170
474c8240 10171@smallexample
c906108c
SS
10172
10173@var{module} . @var{id}
10174@var{scope} :: @var{id}
474c8240 10175@end smallexample
c906108c
SS
10176
10177@noindent
10178where @var{scope} is the name of a module or a procedure,
10179@var{module} the name of a module, and @var{id} is any declared
10180identifier within your program, except another module.
10181
10182Using the @code{::} operator makes @value{GDBN} search the scope
10183specified by @var{scope} for the identifier @var{id}. If it is not
10184found in the specified scope, then @value{GDBN} searches all scopes
10185enclosing the one specified by @var{scope}.
10186
10187Using the @code{.} operator makes @value{GDBN} search the current scope for
10188the identifier specified by @var{id} that was imported from the
10189definition module specified by @var{module}. With this operator, it is
10190an error if the identifier @var{id} was not imported from definition
10191module @var{module}, or if @var{id} is not an identifier in
10192@var{module}.
10193
6d2ebf8b 10194@node GDB/M2
c906108c
SS
10195@subsubsection @value{GDBN} and Modula-2
10196
10197Some @value{GDBN} commands have little use when debugging Modula-2 programs.
10198Five subcommands of @code{set print} and @code{show print} apply
b37052ae 10199specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 10200@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 10201apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
10202analogue in Modula-2.
10203
10204The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 10205with any language, is not useful with Modula-2. Its
c906108c 10206intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 10207created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 10208address can be specified by an integral constant, the construct
d4f3574e 10209@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
10210
10211@cindex @code{#} in Modula-2
10212In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
10213interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 10214
e07c999f
PH
10215@node Ada
10216@subsection Ada
10217@cindex Ada
10218
10219The extensions made to @value{GDBN} for Ada only support
10220output from the @sc{gnu} Ada (GNAT) compiler.
10221Other Ada compilers are not currently supported, and
10222attempting to debug executables produced by them is most likely
10223to be difficult.
10224
10225
10226@cindex expressions in Ada
10227@menu
10228* Ada Mode Intro:: General remarks on the Ada syntax
10229 and semantics supported by Ada mode
10230 in @value{GDBN}.
10231* Omissions from Ada:: Restrictions on the Ada expression syntax.
10232* Additions to Ada:: Extensions of the Ada expression syntax.
10233* Stopping Before Main Program:: Debugging the program during elaboration.
10234* Ada Glitches:: Known peculiarities of Ada mode.
10235@end menu
10236
10237@node Ada Mode Intro
10238@subsubsection Introduction
10239@cindex Ada mode, general
10240
10241The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
10242syntax, with some extensions.
10243The philosophy behind the design of this subset is
10244
10245@itemize @bullet
10246@item
10247That @value{GDBN} should provide basic literals and access to operations for
10248arithmetic, dereferencing, field selection, indexing, and subprogram calls,
10249leaving more sophisticated computations to subprograms written into the
10250program (which therefore may be called from @value{GDBN}).
10251
10252@item
10253That type safety and strict adherence to Ada language restrictions
10254are not particularly important to the @value{GDBN} user.
10255
10256@item
10257That brevity is important to the @value{GDBN} user.
10258@end itemize
10259
10260Thus, for brevity, the debugger acts as if there were
10261implicit @code{with} and @code{use} clauses in effect for all user-written
10262packages, making it unnecessary to fully qualify most names with
10263their packages, regardless of context. Where this causes ambiguity,
10264@value{GDBN} asks the user's intent.
10265
10266The debugger will start in Ada mode if it detects an Ada main program.
10267As for other languages, it will enter Ada mode when stopped in a program that
10268was translated from an Ada source file.
10269
10270While in Ada mode, you may use `@t{--}' for comments. This is useful
10271mostly for documenting command files. The standard @value{GDBN} comment
10272(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
10273middle (to allow based literals).
10274
10275The debugger supports limited overloading. Given a subprogram call in which
10276the function symbol has multiple definitions, it will use the number of
10277actual parameters and some information about their types to attempt to narrow
10278the set of definitions. It also makes very limited use of context, preferring
10279procedures to functions in the context of the @code{call} command, and
10280functions to procedures elsewhere.
10281
10282@node Omissions from Ada
10283@subsubsection Omissions from Ada
10284@cindex Ada, omissions from
10285
10286Here are the notable omissions from the subset:
10287
10288@itemize @bullet
10289@item
10290Only a subset of the attributes are supported:
10291
10292@itemize @minus
10293@item
10294@t{'First}, @t{'Last}, and @t{'Length}
10295 on array objects (not on types and subtypes).
10296
10297@item
10298@t{'Min} and @t{'Max}.
10299
10300@item
10301@t{'Pos} and @t{'Val}.
10302
10303@item
10304@t{'Tag}.
10305
10306@item
10307@t{'Range} on array objects (not subtypes), but only as the right
10308operand of the membership (@code{in}) operator.
10309
10310@item
10311@t{'Access}, @t{'Unchecked_Access}, and
10312@t{'Unrestricted_Access} (a GNAT extension).
10313
10314@item
10315@t{'Address}.
10316@end itemize
10317
10318@item
10319The names in
10320@code{Characters.Latin_1} are not available and
10321concatenation is not implemented. Thus, escape characters in strings are
10322not currently available.
10323
10324@item
10325Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
10326equality of representations. They will generally work correctly
10327for strings and arrays whose elements have integer or enumeration types.
10328They may not work correctly for arrays whose element
10329types have user-defined equality, for arrays of real values
10330(in particular, IEEE-conformant floating point, because of negative
10331zeroes and NaNs), and for arrays whose elements contain unused bits with
10332indeterminate values.
10333
10334@item
10335The other component-by-component array operations (@code{and}, @code{or},
10336@code{xor}, @code{not}, and relational tests other than equality)
10337are not implemented.
10338
10339@item
860701dc
PH
10340@cindex array aggregates (Ada)
10341@cindex record aggregates (Ada)
10342@cindex aggregates (Ada)
10343There is limited support for array and record aggregates. They are
10344permitted only on the right sides of assignments, as in these examples:
10345
10346@smallexample
10347set An_Array := (1, 2, 3, 4, 5, 6)
10348set An_Array := (1, others => 0)
10349set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
10350set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
10351set A_Record := (1, "Peter", True);
10352set A_Record := (Name => "Peter", Id => 1, Alive => True)
10353@end smallexample
10354
10355Changing a
10356discriminant's value by assigning an aggregate has an
10357undefined effect if that discriminant is used within the record.
10358However, you can first modify discriminants by directly assigning to
10359them (which normally would not be allowed in Ada), and then performing an
10360aggregate assignment. For example, given a variable @code{A_Rec}
10361declared to have a type such as:
10362
10363@smallexample
10364type Rec (Len : Small_Integer := 0) is record
10365 Id : Integer;
10366 Vals : IntArray (1 .. Len);
10367end record;
10368@end smallexample
10369
10370you can assign a value with a different size of @code{Vals} with two
10371assignments:
10372
10373@smallexample
10374set A_Rec.Len := 4
10375set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
10376@end smallexample
10377
10378As this example also illustrates, @value{GDBN} is very loose about the usual
10379rules concerning aggregates. You may leave out some of the
10380components of an array or record aggregate (such as the @code{Len}
10381component in the assignment to @code{A_Rec} above); they will retain their
10382original values upon assignment. You may freely use dynamic values as
10383indices in component associations. You may even use overlapping or
10384redundant component associations, although which component values are
10385assigned in such cases is not defined.
e07c999f
PH
10386
10387@item
10388Calls to dispatching subprograms are not implemented.
10389
10390@item
10391The overloading algorithm is much more limited (i.e., less selective)
10392than that of real Ada. It makes only limited use of the context in which a subexpression
10393appears to resolve its meaning, and it is much looser in its rules for allowing
10394type matches. As a result, some function calls will be ambiguous, and the user
10395will be asked to choose the proper resolution.
10396
10397@item
10398The @code{new} operator is not implemented.
10399
10400@item
10401Entry calls are not implemented.
10402
10403@item
10404Aside from printing, arithmetic operations on the native VAX floating-point
10405formats are not supported.
10406
10407@item
10408It is not possible to slice a packed array.
10409@end itemize
10410
10411@node Additions to Ada
10412@subsubsection Additions to Ada
10413@cindex Ada, deviations from
10414
10415As it does for other languages, @value{GDBN} makes certain generic
10416extensions to Ada (@pxref{Expressions}):
10417
10418@itemize @bullet
10419@item
10420If the expression @var{E} is a variable residing in memory
10421(typically a local variable or array element) and @var{N} is
10422a positive integer, then @code{@var{E}@@@var{N}} displays the values of
10423@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
10424In Ada, this operator is generally not necessary, since its prime use
10425is in displaying parts of an array, and slicing will usually do this in Ada.
10426However, there are occasional uses when debugging programs
10427in which certain debugging information has been optimized away.
10428
10429@item
10430@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
10431in function or file @var{B}.'' When @var{B} is a file name, you must typically
10432surround it in single quotes.
10433
10434@item
10435The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
10436@var{type} that appears at address @var{addr}.''
10437
10438@item
10439A name starting with @samp{$} is a convenience variable
10440(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
10441@end itemize
10442
10443In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
10444to Ada:
10445
10446@itemize @bullet
10447@item
10448The assignment statement is allowed as an expression, returning
10449its right-hand operand as its value. Thus, you may enter
10450
10451@smallexample
10452set x := y + 3
10453print A(tmp := y + 1)
10454@end smallexample
10455
10456@item
10457The semicolon is allowed as an ``operator,'' returning as its value
10458the value of its right-hand operand.
10459This allows, for example,
10460complex conditional breaks:
10461
10462@smallexample
10463break f
10464condition 1 (report(i); k += 1; A(k) > 100)
10465@end smallexample
10466
10467@item
10468Rather than use catenation and symbolic character names to introduce special
10469characters into strings, one may instead use a special bracket notation,
10470which is also used to print strings. A sequence of characters of the form
10471@samp{["@var{XX}"]} within a string or character literal denotes the
10472(single) character whose numeric encoding is @var{XX} in hexadecimal. The
10473sequence of characters @samp{["""]} also denotes a single quotation mark
10474in strings. For example,
10475@smallexample
10476 "One line.["0a"]Next line.["0a"]"
10477@end smallexample
10478@noindent
10479contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
10480period.
10481
10482@item
10483The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
10484@t{'Max} is optional (and is ignored in any case). For example, it is valid
10485to write
10486
10487@smallexample
10488print 'max(x, y)
10489@end smallexample
10490
10491@item
10492When printing arrays, @value{GDBN} uses positional notation when the
10493array has a lower bound of 1, and uses a modified named notation otherwise.
10494For example, a one-dimensional array of three integers with a lower bound of 3 might print as
10495
10496@smallexample
10497(3 => 10, 17, 1)
10498@end smallexample
10499
10500@noindent
10501That is, in contrast to valid Ada, only the first component has a @code{=>}
10502clause.
10503
10504@item
10505You may abbreviate attributes in expressions with any unique,
10506multi-character subsequence of
10507their names (an exact match gets preference).
10508For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
10509in place of @t{a'length}.
10510
10511@item
10512@cindex quoting Ada internal identifiers
10513Since Ada is case-insensitive, the debugger normally maps identifiers you type
10514to lower case. The GNAT compiler uses upper-case characters for
10515some of its internal identifiers, which are normally of no interest to users.
10516For the rare occasions when you actually have to look at them,
10517enclose them in angle brackets to avoid the lower-case mapping.
10518For example,
10519@smallexample
10520@value{GDBP} print <JMPBUF_SAVE>[0]
10521@end smallexample
10522
10523@item
10524Printing an object of class-wide type or dereferencing an
10525access-to-class-wide value will display all the components of the object's
10526specific type (as indicated by its run-time tag). Likewise, component
10527selection on such a value will operate on the specific type of the
10528object.
10529
10530@end itemize
10531
10532@node Stopping Before Main Program
10533@subsubsection Stopping at the Very Beginning
10534
10535@cindex breakpointing Ada elaboration code
10536It is sometimes necessary to debug the program during elaboration, and
10537before reaching the main procedure.
10538As defined in the Ada Reference
10539Manual, the elaboration code is invoked from a procedure called
10540@code{adainit}. To run your program up to the beginning of
10541elaboration, simply use the following two commands:
10542@code{tbreak adainit} and @code{run}.
10543
10544@node Ada Glitches
10545@subsubsection Known Peculiarities of Ada Mode
10546@cindex Ada, problems
10547
10548Besides the omissions listed previously (@pxref{Omissions from Ada}),
10549we know of several problems with and limitations of Ada mode in
10550@value{GDBN},
10551some of which will be fixed with planned future releases of the debugger
10552and the GNU Ada compiler.
10553
10554@itemize @bullet
10555@item
10556Currently, the debugger
10557has insufficient information to determine whether certain pointers represent
10558pointers to objects or the objects themselves.
10559Thus, the user may have to tack an extra @code{.all} after an expression
10560to get it printed properly.
10561
10562@item
10563Static constants that the compiler chooses not to materialize as objects in
10564storage are invisible to the debugger.
10565
10566@item
10567Named parameter associations in function argument lists are ignored (the
10568argument lists are treated as positional).
10569
10570@item
10571Many useful library packages are currently invisible to the debugger.
10572
10573@item
10574Fixed-point arithmetic, conversions, input, and output is carried out using
10575floating-point arithmetic, and may give results that only approximate those on
10576the host machine.
10577
10578@item
10579The type of the @t{'Address} attribute may not be @code{System.Address}.
10580
10581@item
10582The GNAT compiler never generates the prefix @code{Standard} for any of
10583the standard symbols defined by the Ada language. @value{GDBN} knows about
10584this: it will strip the prefix from names when you use it, and will never
10585look for a name you have so qualified among local symbols, nor match against
10586symbols in other packages or subprograms. If you have
10587defined entities anywhere in your program other than parameters and
10588local variables whose simple names match names in @code{Standard},
10589GNAT's lack of qualification here can cause confusion. When this happens,
10590you can usually resolve the confusion
10591by qualifying the problematic names with package
10592@code{Standard} explicitly.
10593@end itemize
10594
4e562065
JB
10595@node Unsupported languages
10596@section Unsupported languages
10597
10598@cindex unsupported languages
10599@cindex minimal language
10600In addition to the other fully-supported programming languages,
10601@value{GDBN} also provides a pseudo-language, called @code{minimal}.
10602It does not represent a real programming language, but provides a set
10603of capabilities close to what the C or assembly languages provide.
10604This should allow most simple operations to be performed while debugging
10605an application that uses a language currently not supported by @value{GDBN}.
10606
10607If the language is set to @code{auto}, @value{GDBN} will automatically
10608select this language if the current frame corresponds to an unsupported
10609language.
10610
6d2ebf8b 10611@node Symbols
c906108c
SS
10612@chapter Examining the Symbol Table
10613
d4f3574e 10614The commands described in this chapter allow you to inquire about the
c906108c
SS
10615symbols (names of variables, functions and types) defined in your
10616program. This information is inherent in the text of your program and
10617does not change as your program executes. @value{GDBN} finds it in your
10618program's symbol table, in the file indicated when you started @value{GDBN}
10619(@pxref{File Options, ,Choosing files}), or by one of the
10620file-management commands (@pxref{Files, ,Commands to specify files}).
10621
10622@cindex symbol names
10623@cindex names of symbols
10624@cindex quoting names
10625Occasionally, you may need to refer to symbols that contain unusual
10626characters, which @value{GDBN} ordinarily treats as word delimiters. The
10627most frequent case is in referring to static variables in other
10628source files (@pxref{Variables,,Program variables}). File names
10629are recorded in object files as debugging symbols, but @value{GDBN} would
10630ordinarily parse a typical file name, like @file{foo.c}, as the three words
10631@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
10632@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
10633
474c8240 10634@smallexample
c906108c 10635p 'foo.c'::x
474c8240 10636@end smallexample
c906108c
SS
10637
10638@noindent
10639looks up the value of @code{x} in the scope of the file @file{foo.c}.
10640
10641@table @code
a8f24a35
EZ
10642@cindex case-insensitive symbol names
10643@cindex case sensitivity in symbol names
10644@kindex set case-sensitive
10645@item set case-sensitive on
10646@itemx set case-sensitive off
10647@itemx set case-sensitive auto
10648Normally, when @value{GDBN} looks up symbols, it matches their names
10649with case sensitivity determined by the current source language.
10650Occasionally, you may wish to control that. The command @code{set
10651case-sensitive} lets you do that by specifying @code{on} for
10652case-sensitive matches or @code{off} for case-insensitive ones. If
10653you specify @code{auto}, case sensitivity is reset to the default
10654suitable for the source language. The default is case-sensitive
10655matches for all languages except for Fortran, for which the default is
10656case-insensitive matches.
10657
9c16f35a
EZ
10658@kindex show case-sensitive
10659@item show case-sensitive
a8f24a35
EZ
10660This command shows the current setting of case sensitivity for symbols
10661lookups.
10662
c906108c 10663@kindex info address
b37052ae 10664@cindex address of a symbol
c906108c
SS
10665@item info address @var{symbol}
10666Describe where the data for @var{symbol} is stored. For a register
10667variable, this says which register it is kept in. For a non-register
10668local variable, this prints the stack-frame offset at which the variable
10669is always stored.
10670
10671Note the contrast with @samp{print &@var{symbol}}, which does not work
10672at all for a register variable, and for a stack local variable prints
10673the exact address of the current instantiation of the variable.
10674
3d67e040 10675@kindex info symbol
b37052ae 10676@cindex symbol from address
9c16f35a 10677@cindex closest symbol and offset for an address
3d67e040
EZ
10678@item info symbol @var{addr}
10679Print the name of a symbol which is stored at the address @var{addr}.
10680If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10681nearest symbol and an offset from it:
10682
474c8240 10683@smallexample
3d67e040
EZ
10684(@value{GDBP}) info symbol 0x54320
10685_initialize_vx + 396 in section .text
474c8240 10686@end smallexample
3d67e040
EZ
10687
10688@noindent
10689This is the opposite of the @code{info address} command. You can use
10690it to find out the name of a variable or a function given its address.
10691
c906108c 10692@kindex whatis
62f3a2ba
FF
10693@item whatis [@var{arg}]
10694Print the data type of @var{arg}, which can be either an expression or
10695a data type. With no argument, print the data type of @code{$}, the
10696last value in the value history. If @var{arg} is an expression, it is
10697not actually evaluated, and any side-effecting operations (such as
10698assignments or function calls) inside it do not take place. If
10699@var{arg} is a type name, it may be the name of a type or typedef, or
10700for C code it may have the form @samp{class @var{class-name}},
10701@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
10702@samp{enum @var{enum-tag}}.
c906108c
SS
10703@xref{Expressions, ,Expressions}.
10704
c906108c 10705@kindex ptype
62f3a2ba
FF
10706@item ptype [@var{arg}]
10707@code{ptype} accepts the same arguments as @code{whatis}, but prints a
10708detailed description of the type, instead of just the name of the type.
10709@xref{Expressions, ,Expressions}.
c906108c
SS
10710
10711For example, for this variable declaration:
10712
474c8240 10713@smallexample
c906108c 10714struct complex @{double real; double imag;@} v;
474c8240 10715@end smallexample
c906108c
SS
10716
10717@noindent
10718the two commands give this output:
10719
474c8240 10720@smallexample
c906108c
SS
10721@group
10722(@value{GDBP}) whatis v
10723type = struct complex
10724(@value{GDBP}) ptype v
10725type = struct complex @{
10726 double real;
10727 double imag;
10728@}
10729@end group
474c8240 10730@end smallexample
c906108c
SS
10731
10732@noindent
10733As with @code{whatis}, using @code{ptype} without an argument refers to
10734the type of @code{$}, the last value in the value history.
10735
ab1adacd
EZ
10736@cindex incomplete type
10737Sometimes, programs use opaque data types or incomplete specifications
10738of complex data structure. If the debug information included in the
10739program does not allow @value{GDBN} to display a full declaration of
10740the data type, it will say @samp{<incomplete type>}. For example,
10741given these declarations:
10742
10743@smallexample
10744 struct foo;
10745 struct foo *fooptr;
10746@end smallexample
10747
10748@noindent
10749but no definition for @code{struct foo} itself, @value{GDBN} will say:
10750
10751@smallexample
ddb50cd7 10752 (@value{GDBP}) ptype foo
ab1adacd
EZ
10753 $1 = <incomplete type>
10754@end smallexample
10755
10756@noindent
10757``Incomplete type'' is C terminology for data types that are not
10758completely specified.
10759
c906108c
SS
10760@kindex info types
10761@item info types @var{regexp}
10762@itemx info types
09d4efe1
EZ
10763Print a brief description of all types whose names match the regular
10764expression @var{regexp} (or all types in your program, if you supply
10765no argument). Each complete typename is matched as though it were a
10766complete line; thus, @samp{i type value} gives information on all
10767types in your program whose names include the string @code{value}, but
10768@samp{i type ^value$} gives information only on types whose complete
10769name is @code{value}.
c906108c
SS
10770
10771This command differs from @code{ptype} in two ways: first, like
10772@code{whatis}, it does not print a detailed description; second, it
10773lists all source files where a type is defined.
10774
b37052ae
EZ
10775@kindex info scope
10776@cindex local variables
09d4efe1 10777@item info scope @var{location}
b37052ae 10778List all the variables local to a particular scope. This command
09d4efe1
EZ
10779accepts a @var{location} argument---a function name, a source line, or
10780an address preceded by a @samp{*}, and prints all the variables local
10781to the scope defined by that location. For example:
b37052ae
EZ
10782
10783@smallexample
10784(@value{GDBP}) @b{info scope command_line_handler}
10785Scope for command_line_handler:
10786Symbol rl is an argument at stack/frame offset 8, length 4.
10787Symbol linebuffer is in static storage at address 0x150a18, length 4.
10788Symbol linelength is in static storage at address 0x150a1c, length 4.
10789Symbol p is a local variable in register $esi, length 4.
10790Symbol p1 is a local variable in register $ebx, length 4.
10791Symbol nline is a local variable in register $edx, length 4.
10792Symbol repeat is a local variable at frame offset -8, length 4.
10793@end smallexample
10794
f5c37c66
EZ
10795@noindent
10796This command is especially useful for determining what data to collect
10797during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10798collect}.
10799
c906108c
SS
10800@kindex info source
10801@item info source
919d772c
JB
10802Show information about the current source file---that is, the source file for
10803the function containing the current point of execution:
10804@itemize @bullet
10805@item
10806the name of the source file, and the directory containing it,
10807@item
10808the directory it was compiled in,
10809@item
10810its length, in lines,
10811@item
10812which programming language it is written in,
10813@item
10814whether the executable includes debugging information for that file, and
10815if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10816@item
10817whether the debugging information includes information about
10818preprocessor macros.
10819@end itemize
10820
c906108c
SS
10821
10822@kindex info sources
10823@item info sources
10824Print the names of all source files in your program for which there is
10825debugging information, organized into two lists: files whose symbols
10826have already been read, and files whose symbols will be read when needed.
10827
10828@kindex info functions
10829@item info functions
10830Print the names and data types of all defined functions.
10831
10832@item info functions @var{regexp}
10833Print the names and data types of all defined functions
10834whose names contain a match for regular expression @var{regexp}.
10835Thus, @samp{info fun step} finds all functions whose names
10836include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 10837start with @code{step}. If a function name contains characters
c1468174 10838that conflict with the regular expression language (e.g.@:
1c5dfdad 10839@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10840
10841@kindex info variables
10842@item info variables
10843Print the names and data types of all variables that are declared
6ca652b0 10844outside of functions (i.e.@: excluding local variables).
c906108c
SS
10845
10846@item info variables @var{regexp}
10847Print the names and data types of all variables (except for local
10848variables) whose names contain a match for regular expression
10849@var{regexp}.
10850
b37303ee 10851@kindex info classes
721c2651 10852@cindex Objective-C, classes and selectors
b37303ee
AF
10853@item info classes
10854@itemx info classes @var{regexp}
10855Display all Objective-C classes in your program, or
10856(with the @var{regexp} argument) all those matching a particular regular
10857expression.
10858
10859@kindex info selectors
10860@item info selectors
10861@itemx info selectors @var{regexp}
10862Display all Objective-C selectors in your program, or
10863(with the @var{regexp} argument) all those matching a particular regular
10864expression.
10865
c906108c
SS
10866@ignore
10867This was never implemented.
10868@kindex info methods
10869@item info methods
10870@itemx info methods @var{regexp}
10871The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10872methods within C@t{++} program, or (with the @var{regexp} argument) a
10873specific set of methods found in the various C@t{++} classes. Many
10874C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10875from the @code{ptype} command can be overwhelming and hard to use. The
10876@code{info-methods} command filters the methods, printing only those
10877which match the regular-expression @var{regexp}.
10878@end ignore
10879
c906108c
SS
10880@cindex reloading symbols
10881Some systems allow individual object files that make up your program to
7a292a7a
SS
10882be replaced without stopping and restarting your program. For example,
10883in VxWorks you can simply recompile a defective object file and keep on
10884running. If you are running on one of these systems, you can allow
10885@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10886
10887@table @code
10888@kindex set symbol-reloading
10889@item set symbol-reloading on
10890Replace symbol definitions for the corresponding source file when an
10891object file with a particular name is seen again.
10892
10893@item set symbol-reloading off
6d2ebf8b
SS
10894Do not replace symbol definitions when encountering object files of the
10895same name more than once. This is the default state; if you are not
10896running on a system that permits automatic relinking of modules, you
10897should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10898may discard symbols when linking large programs, that may contain
10899several modules (from different directories or libraries) with the same
10900name.
c906108c
SS
10901
10902@kindex show symbol-reloading
10903@item show symbol-reloading
10904Show the current @code{on} or @code{off} setting.
10905@end table
c906108c 10906
9c16f35a 10907@cindex opaque data types
c906108c
SS
10908@kindex set opaque-type-resolution
10909@item set opaque-type-resolution on
10910Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10911declared as a pointer to a @code{struct}, @code{class}, or
10912@code{union}---for example, @code{struct MyType *}---that is used in one
10913source file although the full declaration of @code{struct MyType} is in
10914another source file. The default is on.
10915
10916A change in the setting of this subcommand will not take effect until
10917the next time symbols for a file are loaded.
10918
10919@item set opaque-type-resolution off
10920Tell @value{GDBN} not to resolve opaque types. In this case, the type
10921is printed as follows:
10922@smallexample
10923@{<no data fields>@}
10924@end smallexample
10925
10926@kindex show opaque-type-resolution
10927@item show opaque-type-resolution
10928Show whether opaque types are resolved or not.
c906108c
SS
10929
10930@kindex maint print symbols
10931@cindex symbol dump
10932@kindex maint print psymbols
10933@cindex partial symbol dump
10934@item maint print symbols @var{filename}
10935@itemx maint print psymbols @var{filename}
10936@itemx maint print msymbols @var{filename}
10937Write a dump of debugging symbol data into the file @var{filename}.
10938These commands are used to debug the @value{GDBN} symbol-reading code. Only
10939symbols with debugging data are included. If you use @samp{maint print
10940symbols}, @value{GDBN} includes all the symbols for which it has already
10941collected full details: that is, @var{filename} reflects symbols for
10942only those files whose symbols @value{GDBN} has read. You can use the
10943command @code{info sources} to find out which files these are. If you
10944use @samp{maint print psymbols} instead, the dump shows information about
10945symbols that @value{GDBN} only knows partially---that is, symbols defined in
10946files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10947@samp{maint print msymbols} dumps just the minimal symbol information
10948required for each object file from which @value{GDBN} has read some symbols.
10949@xref{Files, ,Commands to specify files}, for a discussion of how
10950@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10951
5e7b2f39
JB
10952@kindex maint info symtabs
10953@kindex maint info psymtabs
44ea7b70
JB
10954@cindex listing @value{GDBN}'s internal symbol tables
10955@cindex symbol tables, listing @value{GDBN}'s internal
10956@cindex full symbol tables, listing @value{GDBN}'s internal
10957@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10958@item maint info symtabs @r{[} @var{regexp} @r{]}
10959@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10960
10961List the @code{struct symtab} or @code{struct partial_symtab}
10962structures whose names match @var{regexp}. If @var{regexp} is not
10963given, list them all. The output includes expressions which you can
10964copy into a @value{GDBN} debugging this one to examine a particular
10965structure in more detail. For example:
10966
10967@smallexample
5e7b2f39 10968(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10969@{ objfile /home/gnu/build/gdb/gdb
10970 ((struct objfile *) 0x82e69d0)
b383017d 10971 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10972 ((struct partial_symtab *) 0x8474b10)
10973 readin no
10974 fullname (null)
10975 text addresses 0x814d3c8 -- 0x8158074
10976 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10977 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10978 dependencies (none)
10979 @}
10980@}
5e7b2f39 10981(@value{GDBP}) maint info symtabs
44ea7b70
JB
10982(@value{GDBP})
10983@end smallexample
10984@noindent
10985We see that there is one partial symbol table whose filename contains
10986the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10987and we see that @value{GDBN} has not read in any symtabs yet at all.
10988If we set a breakpoint on a function, that will cause @value{GDBN} to
10989read the symtab for the compilation unit containing that function:
10990
10991@smallexample
10992(@value{GDBP}) break dwarf2_psymtab_to_symtab
10993Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10994line 1574.
5e7b2f39 10995(@value{GDBP}) maint info symtabs
b383017d 10996@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10997 ((struct objfile *) 0x82e69d0)
b383017d 10998 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10999 ((struct symtab *) 0x86c1f38)
11000 dirname (null)
11001 fullname (null)
11002 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
11003 debugformat DWARF 2
11004 @}
11005@}
b383017d 11006(@value{GDBP})
44ea7b70 11007@end smallexample
c906108c
SS
11008@end table
11009
44ea7b70 11010
6d2ebf8b 11011@node Altering
c906108c
SS
11012@chapter Altering Execution
11013
11014Once you think you have found an error in your program, you might want to
11015find out for certain whether correcting the apparent error would lead to
11016correct results in the rest of the run. You can find the answer by
11017experiment, using the @value{GDBN} features for altering execution of the
11018program.
11019
11020For example, you can store new values into variables or memory
7a292a7a
SS
11021locations, give your program a signal, restart it at a different
11022address, or even return prematurely from a function.
c906108c
SS
11023
11024@menu
11025* Assignment:: Assignment to variables
11026* Jumping:: Continuing at a different address
c906108c 11027* Signaling:: Giving your program a signal
c906108c
SS
11028* Returning:: Returning from a function
11029* Calling:: Calling your program's functions
11030* Patching:: Patching your program
11031@end menu
11032
6d2ebf8b 11033@node Assignment
c906108c
SS
11034@section Assignment to variables
11035
11036@cindex assignment
11037@cindex setting variables
11038To alter the value of a variable, evaluate an assignment expression.
11039@xref{Expressions, ,Expressions}. For example,
11040
474c8240 11041@smallexample
c906108c 11042print x=4
474c8240 11043@end smallexample
c906108c
SS
11044
11045@noindent
11046stores the value 4 into the variable @code{x}, and then prints the
5d161b24 11047value of the assignment expression (which is 4).
c906108c
SS
11048@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
11049information on operators in supported languages.
c906108c
SS
11050
11051@kindex set variable
11052@cindex variables, setting
11053If you are not interested in seeing the value of the assignment, use the
11054@code{set} command instead of the @code{print} command. @code{set} is
11055really the same as @code{print} except that the expression's value is
11056not printed and is not put in the value history (@pxref{Value History,
11057,Value history}). The expression is evaluated only for its effects.
11058
c906108c
SS
11059If the beginning of the argument string of the @code{set} command
11060appears identical to a @code{set} subcommand, use the @code{set
11061variable} command instead of just @code{set}. This command is identical
11062to @code{set} except for its lack of subcommands. For example, if your
11063program has a variable @code{width}, you get an error if you try to set
11064a new value with just @samp{set width=13}, because @value{GDBN} has the
11065command @code{set width}:
11066
474c8240 11067@smallexample
c906108c
SS
11068(@value{GDBP}) whatis width
11069type = double
11070(@value{GDBP}) p width
11071$4 = 13
11072(@value{GDBP}) set width=47
11073Invalid syntax in expression.
474c8240 11074@end smallexample
c906108c
SS
11075
11076@noindent
11077The invalid expression, of course, is @samp{=47}. In
11078order to actually set the program's variable @code{width}, use
11079
474c8240 11080@smallexample
c906108c 11081(@value{GDBP}) set var width=47
474c8240 11082@end smallexample
53a5351d 11083
c906108c
SS
11084Because the @code{set} command has many subcommands that can conflict
11085with the names of program variables, it is a good idea to use the
11086@code{set variable} command instead of just @code{set}. For example, if
11087your program has a variable @code{g}, you run into problems if you try
11088to set a new value with just @samp{set g=4}, because @value{GDBN} has
11089the command @code{set gnutarget}, abbreviated @code{set g}:
11090
474c8240 11091@smallexample
c906108c
SS
11092@group
11093(@value{GDBP}) whatis g
11094type = double
11095(@value{GDBP}) p g
11096$1 = 1
11097(@value{GDBP}) set g=4
2df3850c 11098(@value{GDBP}) p g
c906108c
SS
11099$2 = 1
11100(@value{GDBP}) r
11101The program being debugged has been started already.
11102Start it from the beginning? (y or n) y
11103Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
11104"/home/smith/cc_progs/a.out": can't open to read symbols:
11105 Invalid bfd target.
c906108c
SS
11106(@value{GDBP}) show g
11107The current BFD target is "=4".
11108@end group
474c8240 11109@end smallexample
c906108c
SS
11110
11111@noindent
11112The program variable @code{g} did not change, and you silently set the
11113@code{gnutarget} to an invalid value. In order to set the variable
11114@code{g}, use
11115
474c8240 11116@smallexample
c906108c 11117(@value{GDBP}) set var g=4
474c8240 11118@end smallexample
c906108c
SS
11119
11120@value{GDBN} allows more implicit conversions in assignments than C; you can
11121freely store an integer value into a pointer variable or vice versa,
11122and you can convert any structure to any other structure that is the
11123same length or shorter.
11124@comment FIXME: how do structs align/pad in these conversions?
11125@comment /doc@cygnus.com 18dec1990
11126
11127To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
11128construct to generate a value of specified type at a specified address
11129(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
11130to memory location @code{0x83040} as an integer (which implies a certain size
11131and representation in memory), and
11132
474c8240 11133@smallexample
c906108c 11134set @{int@}0x83040 = 4
474c8240 11135@end smallexample
c906108c
SS
11136
11137@noindent
11138stores the value 4 into that memory location.
11139
6d2ebf8b 11140@node Jumping
c906108c
SS
11141@section Continuing at a different address
11142
11143Ordinarily, when you continue your program, you do so at the place where
11144it stopped, with the @code{continue} command. You can instead continue at
11145an address of your own choosing, with the following commands:
11146
11147@table @code
11148@kindex jump
11149@item jump @var{linespec}
11150Resume execution at line @var{linespec}. Execution stops again
11151immediately if there is a breakpoint there. @xref{List, ,Printing
11152source lines}, for a description of the different forms of
11153@var{linespec}. It is common practice to use the @code{tbreak} command
11154in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
11155breakpoints}.
11156
11157The @code{jump} command does not change the current stack frame, or
11158the stack pointer, or the contents of any memory location or any
11159register other than the program counter. If line @var{linespec} is in
11160a different function from the one currently executing, the results may
11161be bizarre if the two functions expect different patterns of arguments or
11162of local variables. For this reason, the @code{jump} command requests
11163confirmation if the specified line is not in the function currently
11164executing. However, even bizarre results are predictable if you are
11165well acquainted with the machine-language code of your program.
11166
11167@item jump *@var{address}
11168Resume execution at the instruction at address @var{address}.
11169@end table
11170
c906108c 11171@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
11172On many systems, you can get much the same effect as the @code{jump}
11173command by storing a new value into the register @code{$pc}. The
11174difference is that this does not start your program running; it only
11175changes the address of where it @emph{will} run when you continue. For
11176example,
c906108c 11177
474c8240 11178@smallexample
c906108c 11179set $pc = 0x485
474c8240 11180@end smallexample
c906108c
SS
11181
11182@noindent
11183makes the next @code{continue} command or stepping command execute at
11184address @code{0x485}, rather than at the address where your program stopped.
11185@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
11186
11187The most common occasion to use the @code{jump} command is to back
11188up---perhaps with more breakpoints set---over a portion of a program
11189that has already executed, in order to examine its execution in more
11190detail.
11191
c906108c 11192@c @group
6d2ebf8b 11193@node Signaling
c906108c 11194@section Giving your program a signal
9c16f35a 11195@cindex deliver a signal to a program
c906108c
SS
11196
11197@table @code
11198@kindex signal
11199@item signal @var{signal}
11200Resume execution where your program stopped, but immediately give it the
11201signal @var{signal}. @var{signal} can be the name or the number of a
11202signal. For example, on many systems @code{signal 2} and @code{signal
11203SIGINT} are both ways of sending an interrupt signal.
11204
11205Alternatively, if @var{signal} is zero, continue execution without
11206giving a signal. This is useful when your program stopped on account of
11207a signal and would ordinary see the signal when resumed with the
11208@code{continue} command; @samp{signal 0} causes it to resume without a
11209signal.
11210
11211@code{signal} does not repeat when you press @key{RET} a second time
11212after executing the command.
11213@end table
11214@c @end group
11215
11216Invoking the @code{signal} command is not the same as invoking the
11217@code{kill} utility from the shell. Sending a signal with @code{kill}
11218causes @value{GDBN} to decide what to do with the signal depending on
11219the signal handling tables (@pxref{Signals}). The @code{signal} command
11220passes the signal directly to your program.
11221
c906108c 11222
6d2ebf8b 11223@node Returning
c906108c
SS
11224@section Returning from a function
11225
11226@table @code
11227@cindex returning from a function
11228@kindex return
11229@item return
11230@itemx return @var{expression}
11231You can cancel execution of a function call with the @code{return}
11232command. If you give an
11233@var{expression} argument, its value is used as the function's return
11234value.
11235@end table
11236
11237When you use @code{return}, @value{GDBN} discards the selected stack frame
11238(and all frames within it). You can think of this as making the
11239discarded frame return prematurely. If you wish to specify a value to
11240be returned, give that value as the argument to @code{return}.
11241
11242This pops the selected stack frame (@pxref{Selection, ,Selecting a
11243frame}), and any other frames inside of it, leaving its caller as the
11244innermost remaining frame. That frame becomes selected. The
11245specified value is stored in the registers used for returning values
11246of functions.
11247
11248The @code{return} command does not resume execution; it leaves the
11249program stopped in the state that would exist if the function had just
11250returned. In contrast, the @code{finish} command (@pxref{Continuing
11251and Stepping, ,Continuing and stepping}) resumes execution until the
11252selected stack frame returns naturally.
11253
6d2ebf8b 11254@node Calling
c906108c
SS
11255@section Calling program functions
11256
f8568604 11257@table @code
c906108c 11258@cindex calling functions
f8568604
EZ
11259@cindex inferior functions, calling
11260@item print @var{expr}
9c16f35a 11261Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
11262@var{expr} may include calls to functions in the program being
11263debugged.
11264
c906108c 11265@kindex call
c906108c
SS
11266@item call @var{expr}
11267Evaluate the expression @var{expr} without displaying @code{void}
11268returned values.
c906108c
SS
11269
11270You can use this variant of the @code{print} command if you want to
f8568604
EZ
11271execute a function from your program that does not return anything
11272(a.k.a.@: @dfn{a void function}), but without cluttering the output
11273with @code{void} returned values that @value{GDBN} will otherwise
11274print. If the result is not void, it is printed and saved in the
11275value history.
11276@end table
11277
9c16f35a
EZ
11278It is possible for the function you call via the @code{print} or
11279@code{call} command to generate a signal (e.g., if there's a bug in
11280the function, or if you passed it incorrect arguments). What happens
11281in that case is controlled by the @code{set unwindonsignal} command.
11282
11283@table @code
11284@item set unwindonsignal
11285@kindex set unwindonsignal
11286@cindex unwind stack in called functions
11287@cindex call dummy stack unwinding
11288Set unwinding of the stack if a signal is received while in a function
11289that @value{GDBN} called in the program being debugged. If set to on,
11290@value{GDBN} unwinds the stack it created for the call and restores
11291the context to what it was before the call. If set to off (the
11292default), @value{GDBN} stops in the frame where the signal was
11293received.
11294
11295@item show unwindonsignal
11296@kindex show unwindonsignal
11297Show the current setting of stack unwinding in the functions called by
11298@value{GDBN}.
11299@end table
11300
f8568604
EZ
11301@cindex weak alias functions
11302Sometimes, a function you wish to call is actually a @dfn{weak alias}
11303for another function. In such case, @value{GDBN} might not pick up
11304the type information, including the types of the function arguments,
11305which causes @value{GDBN} to call the inferior function incorrectly.
11306As a result, the called function will function erroneously and may
11307even crash. A solution to that is to use the name of the aliased
11308function instead.
c906108c 11309
6d2ebf8b 11310@node Patching
c906108c 11311@section Patching programs
7a292a7a 11312
c906108c
SS
11313@cindex patching binaries
11314@cindex writing into executables
c906108c 11315@cindex writing into corefiles
c906108c 11316
7a292a7a
SS
11317By default, @value{GDBN} opens the file containing your program's
11318executable code (or the corefile) read-only. This prevents accidental
11319alterations to machine code; but it also prevents you from intentionally
11320patching your program's binary.
c906108c
SS
11321
11322If you'd like to be able to patch the binary, you can specify that
11323explicitly with the @code{set write} command. For example, you might
11324want to turn on internal debugging flags, or even to make emergency
11325repairs.
11326
11327@table @code
11328@kindex set write
11329@item set write on
11330@itemx set write off
7a292a7a
SS
11331If you specify @samp{set write on}, @value{GDBN} opens executable and
11332core files for both reading and writing; if you specify @samp{set write
c906108c
SS
11333off} (the default), @value{GDBN} opens them read-only.
11334
11335If you have already loaded a file, you must load it again (using the
7a292a7a
SS
11336@code{exec-file} or @code{core-file} command) after changing @code{set
11337write}, for your new setting to take effect.
c906108c
SS
11338
11339@item show write
11340@kindex show write
7a292a7a
SS
11341Display whether executable files and core files are opened for writing
11342as well as reading.
c906108c
SS
11343@end table
11344
6d2ebf8b 11345@node GDB Files
c906108c
SS
11346@chapter @value{GDBN} Files
11347
7a292a7a
SS
11348@value{GDBN} needs to know the file name of the program to be debugged,
11349both in order to read its symbol table and in order to start your
11350program. To debug a core dump of a previous run, you must also tell
11351@value{GDBN} the name of the core dump file.
c906108c
SS
11352
11353@menu
11354* Files:: Commands to specify files
5b5d99cf 11355* Separate Debug Files:: Debugging information in separate files
c906108c
SS
11356* Symbol Errors:: Errors reading symbol files
11357@end menu
11358
6d2ebf8b 11359@node Files
c906108c 11360@section Commands to specify files
c906108c 11361
7a292a7a 11362@cindex symbol table
c906108c 11363@cindex core dump file
7a292a7a
SS
11364
11365You may want to specify executable and core dump file names. The usual
11366way to do this is at start-up time, using the arguments to
11367@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
11368Out of @value{GDBN}}).
c906108c
SS
11369
11370Occasionally it is necessary to change to a different file during a
397ca115
EZ
11371@value{GDBN} session. Or you may run @value{GDBN} and forget to
11372specify a file you want to use. Or you are debugging a remote target
11373via @code{gdbserver} (@pxref{Server, file}). In these situations the
11374@value{GDBN} commands to specify new files are useful.
c906108c
SS
11375
11376@table @code
11377@cindex executable file
11378@kindex file
11379@item file @var{filename}
11380Use @var{filename} as the program to be debugged. It is read for its
11381symbols and for the contents of pure memory. It is also the program
11382executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
11383directory and the file is not found in the @value{GDBN} working directory,
11384@value{GDBN} uses the environment variable @code{PATH} as a list of
11385directories to search, just as the shell does when looking for a program
11386to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
11387and your program, using the @code{path} command.
11388
fc8be69e
EZ
11389@cindex unlinked object files
11390@cindex patching object files
11391You can load unlinked object @file{.o} files into @value{GDBN} using
11392the @code{file} command. You will not be able to ``run'' an object
11393file, but you can disassemble functions and inspect variables. Also,
11394if the underlying BFD functionality supports it, you could use
11395@kbd{gdb -write} to patch object files using this technique. Note
11396that @value{GDBN} can neither interpret nor modify relocations in this
11397case, so branches and some initialized variables will appear to go to
11398the wrong place. But this feature is still handy from time to time.
11399
c906108c
SS
11400@item file
11401@code{file} with no argument makes @value{GDBN} discard any information it
11402has on both executable file and the symbol table.
11403
11404@kindex exec-file
11405@item exec-file @r{[} @var{filename} @r{]}
11406Specify that the program to be run (but not the symbol table) is found
11407in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
11408if necessary to locate your program. Omitting @var{filename} means to
11409discard information on the executable file.
11410
11411@kindex symbol-file
11412@item symbol-file @r{[} @var{filename} @r{]}
11413Read symbol table information from file @var{filename}. @code{PATH} is
11414searched when necessary. Use the @code{file} command to get both symbol
11415table and program to run from the same file.
11416
11417@code{symbol-file} with no argument clears out @value{GDBN} information on your
11418program's symbol table.
11419
ae5a43e0
DJ
11420The @code{symbol-file} command causes @value{GDBN} to forget the contents of
11421some breakpoints and auto-display expressions. This is because they may
11422contain pointers to the internal data recording symbols and data types,
11423which are part of the old symbol table data being discarded inside
11424@value{GDBN}.
c906108c
SS
11425
11426@code{symbol-file} does not repeat if you press @key{RET} again after
11427executing it once.
11428
11429When @value{GDBN} is configured for a particular environment, it
11430understands debugging information in whatever format is the standard
11431generated for that environment; you may use either a @sc{gnu} compiler, or
11432other compilers that adhere to the local conventions.
c906108c
SS
11433Best results are usually obtained from @sc{gnu} compilers; for example,
11434using @code{@value{GCC}} you can generate debugging information for
11435optimized code.
c906108c
SS
11436
11437For most kinds of object files, with the exception of old SVR3 systems
11438using COFF, the @code{symbol-file} command does not normally read the
11439symbol table in full right away. Instead, it scans the symbol table
11440quickly to find which source files and which symbols are present. The
11441details are read later, one source file at a time, as they are needed.
11442
11443The purpose of this two-stage reading strategy is to make @value{GDBN}
11444start up faster. For the most part, it is invisible except for
11445occasional pauses while the symbol table details for a particular source
11446file are being read. (The @code{set verbose} command can turn these
11447pauses into messages if desired. @xref{Messages/Warnings, ,Optional
11448warnings and messages}.)
11449
c906108c
SS
11450We have not implemented the two-stage strategy for COFF yet. When the
11451symbol table is stored in COFF format, @code{symbol-file} reads the
11452symbol table data in full right away. Note that ``stabs-in-COFF''
11453still does the two-stage strategy, since the debug info is actually
11454in stabs format.
11455
11456@kindex readnow
11457@cindex reading symbols immediately
11458@cindex symbols, reading immediately
a94ab193
EZ
11459@item symbol-file @var{filename} @r{[} -readnow @r{]}
11460@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
11461You can override the @value{GDBN} two-stage strategy for reading symbol
11462tables by using the @samp{-readnow} option with any of the commands that
11463load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 11464entire symbol table available.
c906108c 11465
c906108c
SS
11466@c FIXME: for now no mention of directories, since this seems to be in
11467@c flux. 13mar1992 status is that in theory GDB would look either in
11468@c current dir or in same dir as myprog; but issues like competing
11469@c GDB's, or clutter in system dirs, mean that in practice right now
11470@c only current dir is used. FFish says maybe a special GDB hierarchy
11471@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
11472@c files.
11473
c906108c 11474@kindex core-file
09d4efe1 11475@item core-file @r{[}@var{filename}@r{]}
4644b6e3 11476@itemx core
c906108c
SS
11477Specify the whereabouts of a core dump file to be used as the ``contents
11478of memory''. Traditionally, core files contain only some parts of the
11479address space of the process that generated them; @value{GDBN} can access the
11480executable file itself for other parts.
11481
11482@code{core-file} with no argument specifies that no core file is
11483to be used.
11484
11485Note that the core file is ignored when your program is actually running
7a292a7a
SS
11486under @value{GDBN}. So, if you have been running your program and you
11487wish to debug a core file instead, you must kill the subprocess in which
11488the program is running. To do this, use the @code{kill} command
c906108c 11489(@pxref{Kill Process, ,Killing the child process}).
c906108c 11490
c906108c
SS
11491@kindex add-symbol-file
11492@cindex dynamic linking
11493@item add-symbol-file @var{filename} @var{address}
a94ab193 11494@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 11495@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
11496The @code{add-symbol-file} command reads additional symbol table
11497information from the file @var{filename}. You would use this command
11498when @var{filename} has been dynamically loaded (by some other means)
11499into the program that is running. @var{address} should be the memory
11500address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
11501this out for itself. You can additionally specify an arbitrary number
11502of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
11503section name and base address for that section. You can specify any
11504@var{address} as an expression.
c906108c
SS
11505
11506The symbol table of the file @var{filename} is added to the symbol table
11507originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
11508@code{add-symbol-file} command any number of times; the new symbol data
11509thus read keeps adding to the old. To discard all old symbol data
11510instead, use the @code{symbol-file} command without any arguments.
c906108c 11511
17d9d558
JB
11512@cindex relocatable object files, reading symbols from
11513@cindex object files, relocatable, reading symbols from
11514@cindex reading symbols from relocatable object files
11515@cindex symbols, reading from relocatable object files
11516@cindex @file{.o} files, reading symbols from
11517Although @var{filename} is typically a shared library file, an
11518executable file, or some other object file which has been fully
11519relocated for loading into a process, you can also load symbolic
11520information from relocatable @file{.o} files, as long as:
11521
11522@itemize @bullet
11523@item
11524the file's symbolic information refers only to linker symbols defined in
11525that file, not to symbols defined by other object files,
11526@item
11527every section the file's symbolic information refers to has actually
11528been loaded into the inferior, as it appears in the file, and
11529@item
11530you can determine the address at which every section was loaded, and
11531provide these to the @code{add-symbol-file} command.
11532@end itemize
11533
11534@noindent
11535Some embedded operating systems, like Sun Chorus and VxWorks, can load
11536relocatable files into an already running program; such systems
11537typically make the requirements above easy to meet. However, it's
11538important to recognize that many native systems use complex link
49efadf5 11539procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
11540assembly, for example) that make the requirements difficult to meet. In
11541general, one cannot assume that using @code{add-symbol-file} to read a
11542relocatable object file's symbolic information will have the same effect
11543as linking the relocatable object file into the program in the normal
11544way.
11545
c906108c
SS
11546@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
11547
c45da7e6
EZ
11548@kindex add-symbol-file-from-memory
11549@cindex @code{syscall DSO}
11550@cindex load symbols from memory
11551@item add-symbol-file-from-memory @var{address}
11552Load symbols from the given @var{address} in a dynamically loaded
11553object file whose image is mapped directly into the inferior's memory.
11554For example, the Linux kernel maps a @code{syscall DSO} into each
11555process's address space; this DSO provides kernel-specific code for
11556some system calls. The argument can be any expression whose
11557evaluation yields the address of the file's shared object file header.
11558For this command to work, you must have used @code{symbol-file} or
11559@code{exec-file} commands in advance.
11560
09d4efe1
EZ
11561@kindex add-shared-symbol-files
11562@kindex assf
11563@item add-shared-symbol-files @var{library-file}
11564@itemx assf @var{library-file}
11565The @code{add-shared-symbol-files} command can currently be used only
11566in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
11567alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
11568@value{GDBN} automatically looks for shared libraries, however if
11569@value{GDBN} does not find yours, you can invoke
11570@code{add-shared-symbol-files}. It takes one argument: the shared
11571library's file name. @code{assf} is a shorthand alias for
11572@code{add-shared-symbol-files}.
c906108c 11573
c906108c 11574@kindex section
09d4efe1
EZ
11575@item section @var{section} @var{addr}
11576The @code{section} command changes the base address of the named
11577@var{section} of the exec file to @var{addr}. This can be used if the
11578exec file does not contain section addresses, (such as in the
11579@code{a.out} format), or when the addresses specified in the file
11580itself are wrong. Each section must be changed separately. The
11581@code{info files} command, described below, lists all the sections and
11582their addresses.
c906108c
SS
11583
11584@kindex info files
11585@kindex info target
11586@item info files
11587@itemx info target
7a292a7a
SS
11588@code{info files} and @code{info target} are synonymous; both print the
11589current target (@pxref{Targets, ,Specifying a Debugging Target}),
11590including the names of the executable and core dump files currently in
11591use by @value{GDBN}, and the files from which symbols were loaded. The
11592command @code{help target} lists all possible targets rather than
11593current ones.
11594
fe95c787
MS
11595@kindex maint info sections
11596@item maint info sections
11597Another command that can give you extra information about program sections
11598is @code{maint info sections}. In addition to the section information
11599displayed by @code{info files}, this command displays the flags and file
11600offset of each section in the executable and core dump files. In addition,
11601@code{maint info sections} provides the following command options (which
11602may be arbitrarily combined):
11603
11604@table @code
11605@item ALLOBJ
11606Display sections for all loaded object files, including shared libraries.
11607@item @var{sections}
6600abed 11608Display info only for named @var{sections}.
fe95c787
MS
11609@item @var{section-flags}
11610Display info only for sections for which @var{section-flags} are true.
11611The section flags that @value{GDBN} currently knows about are:
11612@table @code
11613@item ALLOC
11614Section will have space allocated in the process when loaded.
11615Set for all sections except those containing debug information.
11616@item LOAD
11617Section will be loaded from the file into the child process memory.
11618Set for pre-initialized code and data, clear for @code{.bss} sections.
11619@item RELOC
11620Section needs to be relocated before loading.
11621@item READONLY
11622Section cannot be modified by the child process.
11623@item CODE
11624Section contains executable code only.
6600abed 11625@item DATA
fe95c787
MS
11626Section contains data only (no executable code).
11627@item ROM
11628Section will reside in ROM.
11629@item CONSTRUCTOR
11630Section contains data for constructor/destructor lists.
11631@item HAS_CONTENTS
11632Section is not empty.
11633@item NEVER_LOAD
11634An instruction to the linker to not output the section.
11635@item COFF_SHARED_LIBRARY
11636A notification to the linker that the section contains
11637COFF shared library information.
11638@item IS_COMMON
11639Section contains common symbols.
11640@end table
11641@end table
6763aef9 11642@kindex set trust-readonly-sections
9c16f35a 11643@cindex read-only sections
6763aef9
MS
11644@item set trust-readonly-sections on
11645Tell @value{GDBN} that readonly sections in your object file
6ca652b0 11646really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
11647In that case, @value{GDBN} can fetch values from these sections
11648out of the object file, rather than from the target program.
11649For some targets (notably embedded ones), this can be a significant
11650enhancement to debugging performance.
11651
11652The default is off.
11653
11654@item set trust-readonly-sections off
15110bc3 11655Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
11656the contents of the section might change while the program is running,
11657and must therefore be fetched from the target when needed.
9c16f35a
EZ
11658
11659@item show trust-readonly-sections
11660Show the current setting of trusting readonly sections.
c906108c
SS
11661@end table
11662
11663All file-specifying commands allow both absolute and relative file names
11664as arguments. @value{GDBN} always converts the file name to an absolute file
11665name and remembers it that way.
11666
c906108c 11667@cindex shared libraries
9c16f35a
EZ
11668@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
11669and IBM RS/6000 AIX shared libraries.
53a5351d 11670
c906108c
SS
11671@value{GDBN} automatically loads symbol definitions from shared libraries
11672when you use the @code{run} command, or when you examine a core file.
11673(Before you issue the @code{run} command, @value{GDBN} does not understand
11674references to a function in a shared library, however---unless you are
11675debugging a core file).
53a5351d
JM
11676
11677On HP-UX, if the program loads a library explicitly, @value{GDBN}
11678automatically loads the symbols at the time of the @code{shl_load} call.
11679
c906108c
SS
11680@c FIXME: some @value{GDBN} release may permit some refs to undef
11681@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11682@c FIXME...lib; check this from time to time when updating manual
11683
b7209cb4
FF
11684There are times, however, when you may wish to not automatically load
11685symbol definitions from shared libraries, such as when they are
11686particularly large or there are many of them.
11687
11688To control the automatic loading of shared library symbols, use the
11689commands:
11690
11691@table @code
11692@kindex set auto-solib-add
11693@item set auto-solib-add @var{mode}
11694If @var{mode} is @code{on}, symbols from all shared object libraries
11695will be loaded automatically when the inferior begins execution, you
11696attach to an independently started inferior, or when the dynamic linker
11697informs @value{GDBN} that a new library has been loaded. If @var{mode}
11698is @code{off}, symbols must be loaded manually, using the
11699@code{sharedlibrary} command. The default value is @code{on}.
11700
dcaf7c2c
EZ
11701@cindex memory used for symbol tables
11702If your program uses lots of shared libraries with debug info that
11703takes large amounts of memory, you can decrease the @value{GDBN}
11704memory footprint by preventing it from automatically loading the
11705symbols from shared libraries. To that end, type @kbd{set
11706auto-solib-add off} before running the inferior, then load each
11707library whose debug symbols you do need with @kbd{sharedlibrary
11708@var{regexp}}, where @var{regexp} is a regular expresion that matches
11709the libraries whose symbols you want to be loaded.
11710
b7209cb4
FF
11711@kindex show auto-solib-add
11712@item show auto-solib-add
11713Display the current autoloading mode.
11714@end table
11715
c45da7e6 11716@cindex load shared library
b7209cb4
FF
11717To explicitly load shared library symbols, use the @code{sharedlibrary}
11718command:
11719
c906108c
SS
11720@table @code
11721@kindex info sharedlibrary
11722@kindex info share
11723@item info share
11724@itemx info sharedlibrary
11725Print the names of the shared libraries which are currently loaded.
11726
11727@kindex sharedlibrary
11728@kindex share
11729@item sharedlibrary @var{regex}
11730@itemx share @var{regex}
c906108c
SS
11731Load shared object library symbols for files matching a
11732Unix regular expression.
11733As with files loaded automatically, it only loads shared libraries
11734required by your program for a core file or after typing @code{run}. If
11735@var{regex} is omitted all shared libraries required by your program are
11736loaded.
c45da7e6
EZ
11737
11738@item nosharedlibrary
11739@kindex nosharedlibrary
11740@cindex unload symbols from shared libraries
11741Unload all shared object library symbols. This discards all symbols
11742that have been loaded from all shared libraries. Symbols from shared
11743libraries that were loaded by explicit user requests are not
11744discarded.
c906108c
SS
11745@end table
11746
721c2651
EZ
11747Sometimes you may wish that @value{GDBN} stops and gives you control
11748when any of shared library events happen. Use the @code{set
11749stop-on-solib-events} command for this:
11750
11751@table @code
11752@item set stop-on-solib-events
11753@kindex set stop-on-solib-events
11754This command controls whether @value{GDBN} should give you control
11755when the dynamic linker notifies it about some shared library event.
11756The most common event of interest is loading or unloading of a new
11757shared library.
11758
11759@item show stop-on-solib-events
11760@kindex show stop-on-solib-events
11761Show whether @value{GDBN} stops and gives you control when shared
11762library events happen.
11763@end table
11764
f5ebfba0
DJ
11765Shared libraries are also supported in many cross or remote debugging
11766configurations. A copy of the target's libraries need to be present on the
11767host system; they need to be the same as the target libraries, although the
11768copies on the target can be stripped as long as the copies on the host are
11769not.
11770
59b7b46f
EZ
11771@cindex where to look for shared libraries
11772For remote debugging, you need to tell @value{GDBN} where the target
11773libraries are, so that it can load the correct copies---otherwise, it
11774may try to load the host's libraries. @value{GDBN} has two variables
11775to specify the search directories for target libraries.
f5ebfba0
DJ
11776
11777@table @code
59b7b46f 11778@cindex prefix for shared library file names
f5ebfba0
DJ
11779@kindex set solib-absolute-prefix
11780@item set solib-absolute-prefix @var{path}
11781If this variable is set, @var{path} will be used as a prefix for any
11782absolute shared library paths; many runtime loaders store the absolute
11783paths to the shared library in the target program's memory. If you use
11784@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11785out in the same way that they are on the target, with e.g.@: a
11786@file{/usr/lib} hierarchy under @var{path}.
11787
59b7b46f
EZ
11788@cindex default value of @samp{solib-absolute-prefix}
11789@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11790You can set the default value of @samp{solib-absolute-prefix} by using the
11791configure-time @samp{--with-sysroot} option.
11792
11793@kindex show solib-absolute-prefix
11794@item show solib-absolute-prefix
11795Display the current shared library prefix.
11796
11797@kindex set solib-search-path
11798@item set solib-search-path @var{path}
11799If this variable is set, @var{path} is a colon-separated list of directories
11800to search for shared libraries. @samp{solib-search-path} is used after
11801@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11802the library is relative instead of absolute. If you want to use
11803@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11804set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11805@value{GDBN} from finding your host's libraries.
11806
11807@kindex show solib-search-path
11808@item show solib-search-path
11809Display the current shared library search path.
11810@end table
11811
5b5d99cf
JB
11812
11813@node Separate Debug Files
11814@section Debugging Information in Separate Files
11815@cindex separate debugging information files
11816@cindex debugging information in separate files
11817@cindex @file{.debug} subdirectories
11818@cindex debugging information directory, global
11819@cindex global debugging information directory
11820
11821@value{GDBN} allows you to put a program's debugging information in a
11822file separate from the executable itself, in a way that allows
11823@value{GDBN} to find and load the debugging information automatically.
11824Since debugging information can be very large --- sometimes larger
11825than the executable code itself --- some systems distribute debugging
11826information for their executables in separate files, which users can
11827install only when they need to debug a problem.
11828
11829If an executable's debugging information has been extracted to a
11830separate file, the executable should contain a @dfn{debug link} giving
11831the name of the debugging information file (with no directory
11832components), and a checksum of its contents. (The exact form of a
11833debug link is described below.) If the full name of the directory
11834containing the executable is @var{execdir}, and the executable has a
11835debug link that specifies the name @var{debugfile}, then @value{GDBN}
11836will automatically search for the debugging information file in three
11837places:
11838
11839@itemize @bullet
11840@item
11841the directory containing the executable file (that is, it will look
11842for a file named @file{@var{execdir}/@var{debugfile}},
11843@item
11844a subdirectory of that directory named @file{.debug} (that is, the
11845file @file{@var{execdir}/.debug/@var{debugfile}}, and
11846@item
11847a subdirectory of the global debug file directory that includes the
11848executable's full path, and the name from the link (that is, the file
11849@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11850@var{globaldebugdir} is the global debug file directory, and
11851@var{execdir} has been turned into a relative path).
11852@end itemize
11853@noindent
11854@value{GDBN} checks under each of these names for a debugging
11855information file whose checksum matches that given in the link, and
11856reads the debugging information from the first one it finds.
11857
11858So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11859which has a link containing the name @file{ls.debug}, and the global
11860debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11861for debug information in @file{/usr/bin/ls.debug},
11862@file{/usr/bin/.debug/ls.debug}, and
11863@file{/usr/lib/debug/usr/bin/ls.debug}.
11864
11865You can set the global debugging info directory's name, and view the
11866name @value{GDBN} is currently using.
11867
11868@table @code
11869
11870@kindex set debug-file-directory
11871@item set debug-file-directory @var{directory}
11872Set the directory which @value{GDBN} searches for separate debugging
11873information files to @var{directory}.
11874
11875@kindex show debug-file-directory
11876@item show debug-file-directory
11877Show the directory @value{GDBN} searches for separate debugging
11878information files.
11879
11880@end table
11881
11882@cindex @code{.gnu_debuglink} sections
11883@cindex debug links
11884A debug link is a special section of the executable file named
11885@code{.gnu_debuglink}. The section must contain:
11886
11887@itemize
11888@item
11889A filename, with any leading directory components removed, followed by
11890a zero byte,
11891@item
11892zero to three bytes of padding, as needed to reach the next four-byte
11893boundary within the section, and
11894@item
11895a four-byte CRC checksum, stored in the same endianness used for the
11896executable file itself. The checksum is computed on the debugging
11897information file's full contents by the function given below, passing
11898zero as the @var{crc} argument.
11899@end itemize
11900
11901Any executable file format can carry a debug link, as long as it can
11902contain a section named @code{.gnu_debuglink} with the contents
11903described above.
11904
11905The debugging information file itself should be an ordinary
11906executable, containing a full set of linker symbols, sections, and
11907debugging information. The sections of the debugging information file
11908should have the same names, addresses and sizes as the original file,
11909but they need not contain any data --- much like a @code{.bss} section
11910in an ordinary executable.
11911
11912As of December 2002, there is no standard GNU utility to produce
11913separated executable / debugging information file pairs. Ulrich
11914Drepper's @file{elfutils} package, starting with version 0.53,
11915contains a version of the @code{strip} command such that the command
11916@kbd{strip foo -f foo.debug} removes the debugging information from
11917the executable file @file{foo}, places it in the file
11918@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11919
11920Since there are many different ways to compute CRC's (different
11921polynomials, reversals, byte ordering, etc.), the simplest way to
11922describe the CRC used in @code{.gnu_debuglink} sections is to give the
11923complete code for a function that computes it:
11924
4644b6e3 11925@kindex gnu_debuglink_crc32
5b5d99cf
JB
11926@smallexample
11927unsigned long
11928gnu_debuglink_crc32 (unsigned long crc,
11929 unsigned char *buf, size_t len)
11930@{
11931 static const unsigned long crc32_table[256] =
11932 @{
11933 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11934 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11935 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11936 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11937 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11938 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11939 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11940 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11941 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11942 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11943 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11944 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11945 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11946 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11947 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11948 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11949 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11950 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11951 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11952 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11953 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11954 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11955 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11956 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11957 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11958 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11959 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11960 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11961 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11962 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11963 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11964 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11965 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11966 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11967 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11968 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11969 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11970 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11971 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11972 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11973 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11974 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11975 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11976 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11977 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11978 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11979 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11980 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11981 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11982 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11983 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11984 0x2d02ef8d
11985 @};
11986 unsigned char *end;
11987
11988 crc = ~crc & 0xffffffff;
11989 for (end = buf + len; buf < end; ++buf)
11990 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11991 return ~crc & 0xffffffff;
5b5d99cf
JB
11992@}
11993@end smallexample
11994
11995
6d2ebf8b 11996@node Symbol Errors
c906108c
SS
11997@section Errors reading symbol files
11998
11999While reading a symbol file, @value{GDBN} occasionally encounters problems,
12000such as symbol types it does not recognize, or known bugs in compiler
12001output. By default, @value{GDBN} does not notify you of such problems, since
12002they are relatively common and primarily of interest to people
12003debugging compilers. If you are interested in seeing information
12004about ill-constructed symbol tables, you can either ask @value{GDBN} to print
12005only one message about each such type of problem, no matter how many
12006times the problem occurs; or you can ask @value{GDBN} to print more messages,
12007to see how many times the problems occur, with the @code{set
12008complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
12009messages}).
12010
12011The messages currently printed, and their meanings, include:
12012
12013@table @code
12014@item inner block not inside outer block in @var{symbol}
12015
12016The symbol information shows where symbol scopes begin and end
12017(such as at the start of a function or a block of statements). This
12018error indicates that an inner scope block is not fully contained
12019in its outer scope blocks.
12020
12021@value{GDBN} circumvents the problem by treating the inner block as if it had
12022the same scope as the outer block. In the error message, @var{symbol}
12023may be shown as ``@code{(don't know)}'' if the outer block is not a
12024function.
12025
12026@item block at @var{address} out of order
12027
12028The symbol information for symbol scope blocks should occur in
12029order of increasing addresses. This error indicates that it does not
12030do so.
12031
12032@value{GDBN} does not circumvent this problem, and has trouble
12033locating symbols in the source file whose symbols it is reading. (You
12034can often determine what source file is affected by specifying
12035@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
12036messages}.)
12037
12038@item bad block start address patched
12039
12040The symbol information for a symbol scope block has a start address
12041smaller than the address of the preceding source line. This is known
12042to occur in the SunOS 4.1.1 (and earlier) C compiler.
12043
12044@value{GDBN} circumvents the problem by treating the symbol scope block as
12045starting on the previous source line.
12046
12047@item bad string table offset in symbol @var{n}
12048
12049@cindex foo
12050Symbol number @var{n} contains a pointer into the string table which is
12051larger than the size of the string table.
12052
12053@value{GDBN} circumvents the problem by considering the symbol to have the
12054name @code{foo}, which may cause other problems if many symbols end up
12055with this name.
12056
12057@item unknown symbol type @code{0x@var{nn}}
12058
7a292a7a
SS
12059The symbol information contains new data types that @value{GDBN} does
12060not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 12061uncomprehended information, in hexadecimal.
c906108c 12062
7a292a7a
SS
12063@value{GDBN} circumvents the error by ignoring this symbol information.
12064This usually allows you to debug your program, though certain symbols
c906108c 12065are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
12066debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
12067on @code{complain}, then go up to the function @code{read_dbx_symtab}
12068and examine @code{*bufp} to see the symbol.
c906108c
SS
12069
12070@item stub type has NULL name
c906108c 12071
7a292a7a 12072@value{GDBN} could not find the full definition for a struct or class.
c906108c 12073
7a292a7a 12074@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 12075The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
12076information that recent versions of the compiler should have output for
12077it.
c906108c
SS
12078
12079@item info mismatch between compiler and debugger
12080
12081@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 12082
c906108c
SS
12083@end table
12084
6d2ebf8b 12085@node Targets
c906108c 12086@chapter Specifying a Debugging Target
7a292a7a 12087
c906108c 12088@cindex debugging target
c906108c 12089A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
12090
12091Often, @value{GDBN} runs in the same host environment as your program;
12092in that case, the debugging target is specified as a side effect when
12093you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
12094flexibility---for example, running @value{GDBN} on a physically separate
12095host, or controlling a standalone system over a serial port or a
53a5351d
JM
12096realtime system over a TCP/IP connection---you can use the @code{target}
12097command to specify one of the target types configured for @value{GDBN}
12098(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 12099
a8f24a35
EZ
12100@cindex target architecture
12101It is possible to build @value{GDBN} for several different @dfn{target
12102architectures}. When @value{GDBN} is built like that, you can choose
12103one of the available architectures with the @kbd{set architecture}
12104command.
12105
12106@table @code
12107@kindex set architecture
12108@kindex show architecture
12109@item set architecture @var{arch}
12110This command sets the current target architecture to @var{arch}. The
12111value of @var{arch} can be @code{"auto"}, in addition to one of the
12112supported architectures.
12113
12114@item show architecture
12115Show the current target architecture.
9c16f35a
EZ
12116
12117@item set processor
12118@itemx processor
12119@kindex set processor
12120@kindex show processor
12121These are alias commands for, respectively, @code{set architecture}
12122and @code{show architecture}.
a8f24a35
EZ
12123@end table
12124
c906108c
SS
12125@menu
12126* Active Targets:: Active targets
12127* Target Commands:: Commands for managing targets
c906108c
SS
12128* Byte Order:: Choosing target byte order
12129* Remote:: Remote debugging
c906108c
SS
12130
12131@end menu
12132
6d2ebf8b 12133@node Active Targets
c906108c 12134@section Active targets
7a292a7a 12135
c906108c
SS
12136@cindex stacking targets
12137@cindex active targets
12138@cindex multiple targets
12139
c906108c 12140There are three classes of targets: processes, core files, and
7a292a7a
SS
12141executable files. @value{GDBN} can work concurrently on up to three
12142active targets, one in each class. This allows you to (for example)
12143start a process and inspect its activity without abandoning your work on
12144a core file.
c906108c
SS
12145
12146For example, if you execute @samp{gdb a.out}, then the executable file
12147@code{a.out} is the only active target. If you designate a core file as
12148well---presumably from a prior run that crashed and coredumped---then
12149@value{GDBN} has two active targets and uses them in tandem, looking
12150first in the corefile target, then in the executable file, to satisfy
12151requests for memory addresses. (Typically, these two classes of target
12152are complementary, since core files contain only a program's
12153read-write memory---variables and so on---plus machine status, while
12154executable files contain only the program text and initialized data.)
c906108c
SS
12155
12156When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
12157target as well. When a process target is active, all @value{GDBN}
12158commands requesting memory addresses refer to that target; addresses in
12159an active core file or executable file target are obscured while the
12160process target is active.
c906108c 12161
7a292a7a
SS
12162Use the @code{core-file} and @code{exec-file} commands to select a new
12163core file or executable target (@pxref{Files, ,Commands to specify
c906108c 12164files}). To specify as a target a process that is already running, use
7a292a7a
SS
12165the @code{attach} command (@pxref{Attach, ,Debugging an already-running
12166process}).
c906108c 12167
6d2ebf8b 12168@node Target Commands
c906108c
SS
12169@section Commands for managing targets
12170
12171@table @code
12172@item target @var{type} @var{parameters}
7a292a7a
SS
12173Connects the @value{GDBN} host environment to a target machine or
12174process. A target is typically a protocol for talking to debugging
12175facilities. You use the argument @var{type} to specify the type or
12176protocol of the target machine.
c906108c
SS
12177
12178Further @var{parameters} are interpreted by the target protocol, but
12179typically include things like device names or host names to connect
12180with, process numbers, and baud rates.
c906108c
SS
12181
12182The @code{target} command does not repeat if you press @key{RET} again
12183after executing the command.
12184
12185@kindex help target
12186@item help target
12187Displays the names of all targets available. To display targets
12188currently selected, use either @code{info target} or @code{info files}
12189(@pxref{Files, ,Commands to specify files}).
12190
12191@item help target @var{name}
12192Describe a particular target, including any parameters necessary to
12193select it.
12194
12195@kindex set gnutarget
12196@item set gnutarget @var{args}
5d161b24 12197@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 12198knows whether it is reading an @dfn{executable},
5d161b24
DB
12199a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
12200with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
12201with @code{gnutarget} the @code{target} refers to a program, not a machine.
12202
d4f3574e 12203@quotation
c906108c
SS
12204@emph{Warning:} To specify a file format with @code{set gnutarget},
12205you must know the actual BFD name.
d4f3574e 12206@end quotation
c906108c 12207
d4f3574e
SS
12208@noindent
12209@xref{Files, , Commands to specify files}.
c906108c 12210
5d161b24 12211@kindex show gnutarget
c906108c
SS
12212@item show gnutarget
12213Use the @code{show gnutarget} command to display what file format
12214@code{gnutarget} is set to read. If you have not set @code{gnutarget},
12215@value{GDBN} will determine the file format for each file automatically,
12216and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
12217@end table
12218
4644b6e3 12219@cindex common targets
c906108c
SS
12220Here are some common targets (available, or not, depending on the GDB
12221configuration):
c906108c
SS
12222
12223@table @code
4644b6e3 12224@kindex target
c906108c 12225@item target exec @var{program}
4644b6e3 12226@cindex executable file target
c906108c
SS
12227An executable file. @samp{target exec @var{program}} is the same as
12228@samp{exec-file @var{program}}.
12229
c906108c 12230@item target core @var{filename}
4644b6e3 12231@cindex core dump file target
c906108c
SS
12232A core dump file. @samp{target core @var{filename}} is the same as
12233@samp{core-file @var{filename}}.
c906108c 12234
1a10341b 12235@item target remote @var{medium}
4644b6e3 12236@cindex remote target
1a10341b
JB
12237A remote system connected to @value{GDBN} via a serial line or network
12238connection. This command tells @value{GDBN} to use its own remote
12239protocol over @var{medium} for debugging. @xref{Remote Debugging}.
12240
12241For example, if you have a board connected to @file{/dev/ttya} on the
12242machine running @value{GDBN}, you could say:
12243
12244@smallexample
12245target remote /dev/ttya
12246@end smallexample
12247
12248@code{target remote} supports the @code{load} command. This is only
12249useful if you have some other way of getting the stub to the target
12250system, and you can put it somewhere in memory where it won't get
12251clobbered by the download.
c906108c 12252
c906108c 12253@item target sim
4644b6e3 12254@cindex built-in simulator target
2df3850c 12255Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 12256In general,
474c8240 12257@smallexample
104c1213
JM
12258 target sim
12259 load
12260 run
474c8240 12261@end smallexample
d4f3574e 12262@noindent
104c1213 12263works; however, you cannot assume that a specific memory map, device
d4f3574e 12264drivers, or even basic I/O is available, although some simulators do
104c1213
JM
12265provide these. For info about any processor-specific simulator details,
12266see the appropriate section in @ref{Embedded Processors, ,Embedded
12267Processors}.
12268
c906108c
SS
12269@end table
12270
104c1213 12271Some configurations may include these targets as well:
c906108c
SS
12272
12273@table @code
12274
c906108c 12275@item target nrom @var{dev}
4644b6e3 12276@cindex NetROM ROM emulator target
c906108c
SS
12277NetROM ROM emulator. This target only supports downloading.
12278
c906108c
SS
12279@end table
12280
5d161b24 12281Different targets are available on different configurations of @value{GDBN};
c906108c 12282your configuration may have more or fewer targets.
c906108c 12283
721c2651
EZ
12284Many remote targets require you to download the executable's code once
12285you've successfully established a connection. You may wish to control
3d00d119
DJ
12286various aspects of this process.
12287
12288@table @code
721c2651
EZ
12289
12290@item set hash
12291@kindex set hash@r{, for remote monitors}
12292@cindex hash mark while downloading
12293This command controls whether a hash mark @samp{#} is displayed while
12294downloading a file to the remote monitor. If on, a hash mark is
12295displayed after each S-record is successfully downloaded to the
12296monitor.
12297
12298@item show hash
12299@kindex show hash@r{, for remote monitors}
12300Show the current status of displaying the hash mark.
12301
12302@item set debug monitor
12303@kindex set debug monitor
12304@cindex display remote monitor communications
12305Enable or disable display of communications messages between
12306@value{GDBN} and the remote monitor.
12307
12308@item show debug monitor
12309@kindex show debug monitor
12310Show the current status of displaying communications between
12311@value{GDBN} and the remote monitor.
a8f24a35 12312@end table
c906108c
SS
12313
12314@table @code
12315
12316@kindex load @var{filename}
12317@item load @var{filename}
c906108c
SS
12318Depending on what remote debugging facilities are configured into
12319@value{GDBN}, the @code{load} command may be available. Where it exists, it
12320is meant to make @var{filename} (an executable) available for debugging
12321on the remote system---by downloading, or dynamic linking, for example.
12322@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
12323the @code{add-symbol-file} command.
12324
12325If your @value{GDBN} does not have a @code{load} command, attempting to
12326execute it gets the error message ``@code{You can't do that when your
12327target is @dots{}}''
c906108c
SS
12328
12329The file is loaded at whatever address is specified in the executable.
12330For some object file formats, you can specify the load address when you
12331link the program; for other formats, like a.out, the object file format
12332specifies a fixed address.
12333@c FIXME! This would be a good place for an xref to the GNU linker doc.
12334
68437a39
DJ
12335Depending on the remote side capabilities, @value{GDBN} may be able to
12336load programs into flash memory.
12337
c906108c
SS
12338@code{load} does not repeat if you press @key{RET} again after using it.
12339@end table
12340
6d2ebf8b 12341@node Byte Order
c906108c 12342@section Choosing target byte order
7a292a7a 12343
c906108c
SS
12344@cindex choosing target byte order
12345@cindex target byte order
c906108c 12346
172c2a43 12347Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
12348offer the ability to run either big-endian or little-endian byte
12349orders. Usually the executable or symbol will include a bit to
12350designate the endian-ness, and you will not need to worry about
12351which to use. However, you may still find it useful to adjust
d4f3574e 12352@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
12353
12354@table @code
4644b6e3 12355@kindex set endian
c906108c
SS
12356@item set endian big
12357Instruct @value{GDBN} to assume the target is big-endian.
12358
c906108c
SS
12359@item set endian little
12360Instruct @value{GDBN} to assume the target is little-endian.
12361
c906108c
SS
12362@item set endian auto
12363Instruct @value{GDBN} to use the byte order associated with the
12364executable.
12365
12366@item show endian
12367Display @value{GDBN}'s current idea of the target byte order.
12368
12369@end table
12370
12371Note that these commands merely adjust interpretation of symbolic
12372data on the host, and that they have absolutely no effect on the
12373target system.
12374
6d2ebf8b 12375@node Remote
c906108c
SS
12376@section Remote debugging
12377@cindex remote debugging
12378
12379If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
12380@value{GDBN} in the usual way, it is often useful to use remote debugging.
12381For example, you might use remote debugging on an operating system kernel,
c906108c
SS
12382or on a small system which does not have a general purpose operating system
12383powerful enough to run a full-featured debugger.
12384
12385Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
12386to make this work with particular debugging targets. In addition,
5d161b24 12387@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
12388but not specific to any particular target system) which you can use if you
12389write the remote stubs---the code that runs on the remote system to
12390communicate with @value{GDBN}.
12391
12392Other remote targets may be available in your
12393configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 12394
c45da7e6
EZ
12395Once you've connected to the remote target, @value{GDBN} allows you to
12396send arbitrary commands to the remote monitor:
12397
12398@table @code
12399@item remote @var{command}
12400@kindex remote@r{, a command}
12401@cindex send command to remote monitor
12402Send an arbitrary @var{command} string to the remote monitor.
12403@end table
12404
12405
6f05cf9f
AC
12406@node Remote Debugging
12407@chapter Debugging remote programs
12408
6b2f586d 12409@menu
07f31aa6 12410* Connecting:: Connecting to a remote target
6b2f586d 12411* Server:: Using the gdbserver program
501eef12 12412* Remote configuration:: Remote configuration
6b2f586d 12413* remote stub:: Implementing a remote stub
6b2f586d
AC
12414@end menu
12415
07f31aa6
DJ
12416@node Connecting
12417@section Connecting to a remote target
12418
12419On the @value{GDBN} host machine, you will need an unstripped copy of
12420your program, since @value{GDBN} needs symobl and debugging information.
12421Start up @value{GDBN} as usual, using the name of the local copy of your
12422program as the first argument.
12423
86941c27
JB
12424@cindex @code{target remote}
12425@value{GDBN} can communicate with the target over a serial line, or
12426over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
12427each case, @value{GDBN} uses the same protocol for debugging your
12428program; only the medium carrying the debugging packets varies. The
12429@code{target remote} command establishes a connection to the target.
12430Its arguments indicate which medium to use:
12431
12432@table @code
12433
12434@item target remote @var{serial-device}
07f31aa6 12435@cindex serial line, @code{target remote}
86941c27
JB
12436Use @var{serial-device} to communicate with the target. For example,
12437to use a serial line connected to the device named @file{/dev/ttyb}:
12438
12439@smallexample
12440target remote /dev/ttyb
12441@end smallexample
12442
07f31aa6
DJ
12443If you're using a serial line, you may want to give @value{GDBN} the
12444@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
12445(@pxref{Remote configuration, set remotebaud}) before the
12446@code{target} command.
07f31aa6 12447
86941c27
JB
12448@item target remote @code{@var{host}:@var{port}}
12449@itemx target remote @code{tcp:@var{host}:@var{port}}
12450@cindex @acronym{TCP} port, @code{target remote}
12451Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
12452The @var{host} may be either a host name or a numeric @acronym{IP}
12453address; @var{port} must be a decimal number. The @var{host} could be
12454the target machine itself, if it is directly connected to the net, or
12455it might be a terminal server which in turn has a serial line to the
12456target.
07f31aa6 12457
86941c27
JB
12458For example, to connect to port 2828 on a terminal server named
12459@code{manyfarms}:
07f31aa6
DJ
12460
12461@smallexample
12462target remote manyfarms:2828
12463@end smallexample
12464
86941c27
JB
12465If your remote target is actually running on the same machine as your
12466debugger session (e.g.@: a simulator for your target running on the
12467same host), you can omit the hostname. For example, to connect to
12468port 1234 on your local machine:
07f31aa6
DJ
12469
12470@smallexample
12471target remote :1234
12472@end smallexample
12473@noindent
12474
12475Note that the colon is still required here.
12476
86941c27
JB
12477@item target remote @code{udp:@var{host}:@var{port}}
12478@cindex @acronym{UDP} port, @code{target remote}
12479Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
12480connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
12481
12482@smallexample
12483target remote udp:manyfarms:2828
12484@end smallexample
12485
86941c27
JB
12486When using a @acronym{UDP} connection for remote debugging, you should
12487keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
12488can silently drop packets on busy or unreliable networks, which will
12489cause havoc with your debugging session.
12490
66b8c7f6
JB
12491@item target remote | @var{command}
12492@cindex pipe, @code{target remote} to
12493Run @var{command} in the background and communicate with it using a
12494pipe. The @var{command} is a shell command, to be parsed and expanded
12495by the system's command shell, @code{/bin/sh}; it should expect remote
12496protocol packets on its standard input, and send replies on its
12497standard output. You could use this to run a stand-alone simulator
12498that speaks the remote debugging protocol, to make net connections
12499using programs like @code{ssh}, or for other similar tricks.
12500
12501If @var{command} closes its standard output (perhaps by exiting),
12502@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
12503program has already exited, this will have no effect.)
12504
86941c27 12505@end table
07f31aa6 12506
86941c27
JB
12507Once the connection has been established, you can use all the usual
12508commands to examine and change data and to step and continue the
12509remote program.
07f31aa6
DJ
12510
12511@cindex interrupting remote programs
12512@cindex remote programs, interrupting
12513Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 12514interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
12515program. This may or may not succeed, depending in part on the hardware
12516and the serial drivers the remote system uses. If you type the
12517interrupt character once again, @value{GDBN} displays this prompt:
12518
12519@smallexample
12520Interrupted while waiting for the program.
12521Give up (and stop debugging it)? (y or n)
12522@end smallexample
12523
12524If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
12525(If you decide you want to try again later, you can use @samp{target
12526remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
12527goes back to waiting.
12528
12529@table @code
12530@kindex detach (remote)
12531@item detach
12532When you have finished debugging the remote program, you can use the
12533@code{detach} command to release it from @value{GDBN} control.
12534Detaching from the target normally resumes its execution, but the results
12535will depend on your particular remote stub. After the @code{detach}
12536command, @value{GDBN} is free to connect to another target.
12537
12538@kindex disconnect
12539@item disconnect
12540The @code{disconnect} command behaves like @code{detach}, except that
12541the target is generally not resumed. It will wait for @value{GDBN}
12542(this instance or another one) to connect and continue debugging. After
12543the @code{disconnect} command, @value{GDBN} is again free to connect to
12544another target.
09d4efe1
EZ
12545
12546@cindex send command to remote monitor
fad38dfa
EZ
12547@cindex extend @value{GDBN} for remote targets
12548@cindex add new commands for external monitor
09d4efe1
EZ
12549@kindex monitor
12550@item monitor @var{cmd}
fad38dfa
EZ
12551This command allows you to send arbitrary commands directly to the
12552remote monitor. Since @value{GDBN} doesn't care about the commands it
12553sends like this, this command is the way to extend @value{GDBN}---you
12554can add new commands that only the external monitor will understand
12555and implement.
07f31aa6
DJ
12556@end table
12557
6f05cf9f
AC
12558@node Server
12559@section Using the @code{gdbserver} program
12560
12561@kindex gdbserver
12562@cindex remote connection without stubs
12563@code{gdbserver} is a control program for Unix-like systems, which
12564allows you to connect your program with a remote @value{GDBN} via
12565@code{target remote}---but without linking in the usual debugging stub.
12566
12567@code{gdbserver} is not a complete replacement for the debugging stubs,
12568because it requires essentially the same operating-system facilities
12569that @value{GDBN} itself does. In fact, a system that can run
12570@code{gdbserver} to connect to a remote @value{GDBN} could also run
12571@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
12572because it is a much smaller program than @value{GDBN} itself. It is
12573also easier to port than all of @value{GDBN}, so you may be able to get
12574started more quickly on a new system by using @code{gdbserver}.
12575Finally, if you develop code for real-time systems, you may find that
12576the tradeoffs involved in real-time operation make it more convenient to
12577do as much development work as possible on another system, for example
12578by cross-compiling. You can use @code{gdbserver} to make a similar
12579choice for debugging.
12580
12581@value{GDBN} and @code{gdbserver} communicate via either a serial line
12582or a TCP connection, using the standard @value{GDBN} remote serial
12583protocol.
12584
12585@table @emph
12586@item On the target machine,
12587you need to have a copy of the program you want to debug.
12588@code{gdbserver} does not need your program's symbol table, so you can
12589strip the program if necessary to save space. @value{GDBN} on the host
12590system does all the symbol handling.
12591
12592To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 12593the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
12594syntax is:
12595
12596@smallexample
12597target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
12598@end smallexample
12599
12600@var{comm} is either a device name (to use a serial line) or a TCP
12601hostname and portnumber. For example, to debug Emacs with the argument
12602@samp{foo.txt} and communicate with @value{GDBN} over the serial port
12603@file{/dev/com1}:
12604
12605@smallexample
12606target> gdbserver /dev/com1 emacs foo.txt
12607@end smallexample
12608
12609@code{gdbserver} waits passively for the host @value{GDBN} to communicate
12610with it.
12611
12612To use a TCP connection instead of a serial line:
12613
12614@smallexample
12615target> gdbserver host:2345 emacs foo.txt
12616@end smallexample
12617
12618The only difference from the previous example is the first argument,
12619specifying that you are communicating with the host @value{GDBN} via
12620TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
12621expect a TCP connection from machine @samp{host} to local TCP port 2345.
12622(Currently, the @samp{host} part is ignored.) You can choose any number
12623you want for the port number as long as it does not conflict with any
12624TCP ports already in use on the target system (for example, @code{23} is
12625reserved for @code{telnet}).@footnote{If you choose a port number that
12626conflicts with another service, @code{gdbserver} prints an error message
12627and exits.} You must use the same port number with the host @value{GDBN}
12628@code{target remote} command.
12629
56460a61
DJ
12630On some targets, @code{gdbserver} can also attach to running programs.
12631This is accomplished via the @code{--attach} argument. The syntax is:
12632
12633@smallexample
12634target> gdbserver @var{comm} --attach @var{pid}
12635@end smallexample
12636
12637@var{pid} is the process ID of a currently running process. It isn't necessary
12638to point @code{gdbserver} at a binary for the running process.
12639
b1fe9455
DJ
12640@pindex pidof
12641@cindex attach to a program by name
12642You can debug processes by name instead of process ID if your target has the
12643@code{pidof} utility:
12644
12645@smallexample
12646target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
12647@end smallexample
12648
12649In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
12650has multiple threads, most versions of @code{pidof} support the
12651@code{-s} option to only return the first process ID.
12652
07f31aa6
DJ
12653@item On the host machine,
12654connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
12655For TCP connections, you must start up @code{gdbserver} prior to using
12656the @code{target remote} command. Otherwise you may get an error whose
12657text depends on the host system, but which usually looks something like
07f31aa6 12658@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
12659command in @value{GDBN} when using @code{gdbserver}, since the program is
12660already on the target. However, if you want to load the symbols (as
12661you normally would), do that with the @code{file} command, and issue
12662it @emph{before} connecting to the server; otherwise, you will get an
12663error message saying @code{"Program is already running"}, since the
12664program is considered running after the connection.
07f31aa6 12665
6f05cf9f
AC
12666@end table
12667
501eef12
AC
12668@node Remote configuration
12669@section Remote configuration
12670
9c16f35a
EZ
12671@kindex set remote
12672@kindex show remote
12673This section documents the configuration options available when
12674debugging remote programs. For the options related to the File I/O
fc320d37 12675extensions of the remote protocol, see @ref{system,
9c16f35a 12676system-call-allowed}.
501eef12
AC
12677
12678@table @code
9c16f35a
EZ
12679@item set remoteaddresssize @var{bits}
12680@cindex adress size for remote targets
12681@cindex bits in remote address
12682Set the maximum size of address in a memory packet to the specified
12683number of bits. @value{GDBN} will mask off the address bits above
12684that number, when it passes addresses to the remote target. The
12685default value is the number of bits in the target's address.
12686
12687@item show remoteaddresssize
12688Show the current value of remote address size in bits.
12689
12690@item set remotebaud @var{n}
12691@cindex baud rate for remote targets
12692Set the baud rate for the remote serial I/O to @var{n} baud. The
12693value is used to set the speed of the serial port used for debugging
12694remote targets.
12695
12696@item show remotebaud
12697Show the current speed of the remote connection.
12698
12699@item set remotebreak
12700@cindex interrupt remote programs
12701@cindex BREAK signal instead of Ctrl-C
9a6253be 12702@anchor{set remotebreak}
9c16f35a 12703If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 12704when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 12705on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
12706character instead. The default is off, since most remote systems
12707expect to see @samp{Ctrl-C} as the interrupt signal.
12708
12709@item show remotebreak
12710Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12711interrupt the remote program.
12712
9c16f35a
EZ
12713@item set remotedevice @var{device}
12714@cindex serial port name
12715Set the name of the serial port through which to communicate to the
12716remote target to @var{device}. This is the device used by
12717@value{GDBN} to open the serial communications line to the remote
12718target. There's no default, so you must set a valid port name for the
12719remote serial communications to work. (Some varieties of the
12720@code{target} command accept the port name as part of their
12721arguments.)
12722
12723@item show remotedevice
12724Show the current name of the serial port.
12725
12726@item set remotelogbase @var{base}
12727Set the base (a.k.a.@: radix) of logging serial protocol
12728communications to @var{base}. Supported values of @var{base} are:
12729@code{ascii}, @code{octal}, and @code{hex}. The default is
12730@code{ascii}.
12731
12732@item show remotelogbase
12733Show the current setting of the radix for logging remote serial
12734protocol.
12735
12736@item set remotelogfile @var{file}
12737@cindex record serial communications on file
12738Record remote serial communications on the named @var{file}. The
12739default is not to record at all.
12740
12741@item show remotelogfile.
12742Show the current setting of the file name on which to record the
12743serial communications.
12744
12745@item set remotetimeout @var{num}
12746@cindex timeout for serial communications
12747@cindex remote timeout
12748Set the timeout limit to wait for the remote target to respond to
12749@var{num} seconds. The default is 2 seconds.
12750
12751@item show remotetimeout
12752Show the current number of seconds to wait for the remote target
12753responses.
12754
12755@cindex limit hardware breakpoints and watchpoints
12756@cindex remote target, limit break- and watchpoints
501eef12
AC
12757@anchor{set remote hardware-watchpoint-limit}
12758@anchor{set remote hardware-breakpoint-limit}
12759@item set remote hardware-watchpoint-limit @var{limit}
12760@itemx set remote hardware-breakpoint-limit @var{limit}
12761Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12762watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12763
12764@item set remote fetch-register-packet
12765@itemx set remote set-register-packet
12766@itemx set remote P-packet
12767@itemx set remote p-packet
12768@cindex P-packet
12769@cindex fetch registers from remote targets
12770@cindex set registers in remote targets
12771Determine whether @value{GDBN} can set and fetch registers from the
12772remote target using the @samp{P} packets. The default depends on the
12773remote stub's support of the @samp{P} packets (@value{GDBN} queries
12774the stub when this packet is first required).
12775
12776@item show remote fetch-register-packet
12777@itemx show remote set-register-packet
12778@itemx show remote P-packet
12779@itemx show remote p-packet
12780Show the current setting of using the @samp{P} packets for setting and
12781fetching registers from the remote target.
12782
12783@cindex binary downloads
12784@cindex X-packet
12785@item set remote binary-download-packet
12786@itemx set remote X-packet
12787Determine whether @value{GDBN} sends downloads in binary mode using
12788the @samp{X} packets. The default is on.
12789
12790@item show remote binary-download-packet
12791@itemx show remote X-packet
12792Show the current setting of using the @samp{X} packets for binary
12793downloads.
12794
12795@item set remote read-aux-vector-packet
12796@cindex auxiliary vector of remote target
12797@cindex @code{auxv}, and remote targets
0876f84a
DJ
12798Set the use of the remote protocol's @samp{qXfer:auxv:read} (target
12799auxiliary vector) request. This request is used to fetch the
721c2651
EZ
12800remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12801Auxiliary Vector}. The default setting depends on the remote stub's
12802support of this request (@value{GDBN} queries the stub when this
0876f84a 12803request is first required). @xref{General Query Packets, qXfer}, for
721c2651 12804more information about this request.
9c16f35a
EZ
12805
12806@item show remote read-aux-vector-packet
0876f84a 12807Show the current setting of use of the @samp{qXfer:auxv:read} request.
9c16f35a
EZ
12808
12809@item set remote symbol-lookup-packet
12810@cindex remote symbol lookup request
12811Set the use of the remote protocol's @samp{qSymbol} (target symbol
12812lookup) request. This request is used to communicate symbol
12813information to the remote target, e.g., whenever a new shared library
12814is loaded by the remote (@pxref{Files, shared libraries}). The
12815default setting depends on the remote stub's support of this request
12816(@value{GDBN} queries the stub when this request is first required).
12817@xref{General Query Packets, qSymbol}, for more information about this
12818request.
12819
12820@item show remote symbol-lookup-packet
12821Show the current setting of use of the @samp{qSymbol} request.
12822
12823@item set remote verbose-resume-packet
12824@cindex resume remote target
12825@cindex signal thread, and remote targets
12826@cindex single-step thread, and remote targets
12827@cindex thread-specific operations on remote targets
12828Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12829request. This request is used to resume specific threads in the
12830remote target, and to single-step or signal them. The default setting
12831depends on the remote stub's support of this request (@value{GDBN}
12832queries the stub when this request is first required). This setting
12833affects debugging of multithreaded programs: if @samp{vCont} cannot be
12834used, @value{GDBN} might be unable to single-step a specific thread,
12835especially under @code{set scheduler-locking off}; it is also
12836impossible to pause a specific thread. @xref{Packets, vCont}, for
12837more details.
12838
12839@item show remote verbose-resume-packet
12840Show the current setting of use of the @samp{vCont} request
12841
12842@item set remote software-breakpoint-packet
12843@itemx set remote hardware-breakpoint-packet
12844@itemx set remote write-watchpoint-packet
12845@itemx set remote read-watchpoint-packet
12846@itemx set remote access-watchpoint-packet
12847@itemx set remote Z-packet
12848@cindex Z-packet
12849@cindex remote hardware breakpoints and watchpoints
12850These commands enable or disable the use of @samp{Z} packets for
12851setting breakpoints and watchpoints in the remote target. The default
12852depends on the remote stub's support of the @samp{Z} packets
12853(@value{GDBN} queries the stub when each packet is first required).
12854The command @code{set remote Z-packet}, kept for back-compatibility,
12855turns on or off all the features that require the use of @samp{Z}
12856packets.
12857
12858@item show remote software-breakpoint-packet
12859@itemx show remote hardware-breakpoint-packet
12860@itemx show remote write-watchpoint-packet
12861@itemx show remote read-watchpoint-packet
12862@itemx show remote access-watchpoint-packet
12863@itemx show remote Z-packet
12864Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12865
12866@item set remote get-thread-local-storage-address
12867@kindex set remote get-thread-local-storage-address
12868@cindex thread local storage of remote targets
12869This command enables or disables the use of the @samp{qGetTLSAddr}
12870(Get Thread Local Storage Address) request packet. The default
12871depends on whether the remote stub supports this request.
12872@xref{General Query Packets, qGetTLSAddr}, for more details about this
12873packet.
12874
12875@item show remote get-thread-local-storage-address
12876@kindex show remote get-thread-local-storage-address
12877Show the current setting of @samp{qGetTLSAddr} packet usage.
be2a5f71
DJ
12878
12879@item set remote supported-packets
12880@kindex set remote supported-packets
12881@cindex query supported packets of remote targets
12882This command enables or disables the use of the @samp{qSupported}
12883request packet. @xref{General Query Packets, qSupported}, for more
12884details about this packet. The default is to use @samp{qSupported}.
12885
12886@item show remote supported-packets
12887@kindex show remote supported-packets
12888Show the current setting of @samp{qSupported} packet usage.
501eef12
AC
12889@end table
12890
6f05cf9f
AC
12891@node remote stub
12892@section Implementing a remote stub
7a292a7a 12893
8e04817f
AC
12894@cindex debugging stub, example
12895@cindex remote stub, example
12896@cindex stub example, remote debugging
12897The stub files provided with @value{GDBN} implement the target side of the
12898communication protocol, and the @value{GDBN} side is implemented in the
12899@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12900these subroutines to communicate, and ignore the details. (If you're
12901implementing your own stub file, you can still ignore the details: start
12902with one of the existing stub files. @file{sparc-stub.c} is the best
12903organized, and therefore the easiest to read.)
12904
104c1213
JM
12905@cindex remote serial debugging, overview
12906To debug a program running on another machine (the debugging
12907@dfn{target} machine), you must first arrange for all the usual
12908prerequisites for the program to run by itself. For example, for a C
12909program, you need:
c906108c 12910
104c1213
JM
12911@enumerate
12912@item
12913A startup routine to set up the C runtime environment; these usually
12914have a name like @file{crt0}. The startup routine may be supplied by
12915your hardware supplier, or you may have to write your own.
96baa820 12916
5d161b24 12917@item
d4f3574e 12918A C subroutine library to support your program's
104c1213 12919subroutine calls, notably managing input and output.
96baa820 12920
104c1213
JM
12921@item
12922A way of getting your program to the other machine---for example, a
12923download program. These are often supplied by the hardware
12924manufacturer, but you may have to write your own from hardware
12925documentation.
12926@end enumerate
96baa820 12927
104c1213
JM
12928The next step is to arrange for your program to use a serial port to
12929communicate with the machine where @value{GDBN} is running (the @dfn{host}
12930machine). In general terms, the scheme looks like this:
96baa820 12931
104c1213
JM
12932@table @emph
12933@item On the host,
12934@value{GDBN} already understands how to use this protocol; when everything
12935else is set up, you can simply use the @samp{target remote} command
12936(@pxref{Targets,,Specifying a Debugging Target}).
12937
12938@item On the target,
12939you must link with your program a few special-purpose subroutines that
12940implement the @value{GDBN} remote serial protocol. The file containing these
12941subroutines is called a @dfn{debugging stub}.
12942
12943On certain remote targets, you can use an auxiliary program
12944@code{gdbserver} instead of linking a stub into your program.
12945@xref{Server,,Using the @code{gdbserver} program}, for details.
12946@end table
96baa820 12947
104c1213
JM
12948The debugging stub is specific to the architecture of the remote
12949machine; for example, use @file{sparc-stub.c} to debug programs on
12950@sc{sparc} boards.
96baa820 12951
104c1213
JM
12952@cindex remote serial stub list
12953These working remote stubs are distributed with @value{GDBN}:
96baa820 12954
104c1213
JM
12955@table @code
12956
12957@item i386-stub.c
41afff9a 12958@cindex @file{i386-stub.c}
104c1213
JM
12959@cindex Intel
12960@cindex i386
12961For Intel 386 and compatible architectures.
12962
12963@item m68k-stub.c
41afff9a 12964@cindex @file{m68k-stub.c}
104c1213
JM
12965@cindex Motorola 680x0
12966@cindex m680x0
12967For Motorola 680x0 architectures.
12968
12969@item sh-stub.c
41afff9a 12970@cindex @file{sh-stub.c}
172c2a43 12971@cindex Renesas
104c1213 12972@cindex SH
172c2a43 12973For Renesas SH architectures.
104c1213
JM
12974
12975@item sparc-stub.c
41afff9a 12976@cindex @file{sparc-stub.c}
104c1213
JM
12977@cindex Sparc
12978For @sc{sparc} architectures.
12979
12980@item sparcl-stub.c
41afff9a 12981@cindex @file{sparcl-stub.c}
104c1213
JM
12982@cindex Fujitsu
12983@cindex SparcLite
12984For Fujitsu @sc{sparclite} architectures.
12985
12986@end table
12987
12988The @file{README} file in the @value{GDBN} distribution may list other
12989recently added stubs.
12990
12991@menu
12992* Stub Contents:: What the stub can do for you
12993* Bootstrapping:: What you must do for the stub
12994* Debug Session:: Putting it all together
104c1213
JM
12995@end menu
12996
6d2ebf8b 12997@node Stub Contents
6f05cf9f 12998@subsection What the stub can do for you
104c1213
JM
12999
13000@cindex remote serial stub
13001The debugging stub for your architecture supplies these three
13002subroutines:
13003
13004@table @code
13005@item set_debug_traps
4644b6e3 13006@findex set_debug_traps
104c1213
JM
13007@cindex remote serial stub, initialization
13008This routine arranges for @code{handle_exception} to run when your
13009program stops. You must call this subroutine explicitly near the
13010beginning of your program.
13011
13012@item handle_exception
4644b6e3 13013@findex handle_exception
104c1213
JM
13014@cindex remote serial stub, main routine
13015This is the central workhorse, but your program never calls it
13016explicitly---the setup code arranges for @code{handle_exception} to
13017run when a trap is triggered.
13018
13019@code{handle_exception} takes control when your program stops during
13020execution (for example, on a breakpoint), and mediates communications
13021with @value{GDBN} on the host machine. This is where the communications
13022protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 13023representative on the target machine. It begins by sending summary
104c1213
JM
13024information on the state of your program, then continues to execute,
13025retrieving and transmitting any information @value{GDBN} needs, until you
13026execute a @value{GDBN} command that makes your program resume; at that point,
13027@code{handle_exception} returns control to your own code on the target
5d161b24 13028machine.
104c1213
JM
13029
13030@item breakpoint
13031@cindex @code{breakpoint} subroutine, remote
13032Use this auxiliary subroutine to make your program contain a
13033breakpoint. Depending on the particular situation, this may be the only
13034way for @value{GDBN} to get control. For instance, if your target
13035machine has some sort of interrupt button, you won't need to call this;
13036pressing the interrupt button transfers control to
13037@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
13038simply receiving characters on the serial port may also trigger a trap;
13039again, in that situation, you don't need to call @code{breakpoint} from
13040your own program---simply running @samp{target remote} from the host
5d161b24 13041@value{GDBN} session gets control.
104c1213
JM
13042
13043Call @code{breakpoint} if none of these is true, or if you simply want
13044to make certain your program stops at a predetermined point for the
13045start of your debugging session.
13046@end table
13047
6d2ebf8b 13048@node Bootstrapping
6f05cf9f 13049@subsection What you must do for the stub
104c1213
JM
13050
13051@cindex remote stub, support routines
13052The debugging stubs that come with @value{GDBN} are set up for a particular
13053chip architecture, but they have no information about the rest of your
13054debugging target machine.
13055
13056First of all you need to tell the stub how to communicate with the
13057serial port.
13058
13059@table @code
13060@item int getDebugChar()
4644b6e3 13061@findex getDebugChar
104c1213
JM
13062Write this subroutine to read a single character from the serial port.
13063It may be identical to @code{getchar} for your target system; a
13064different name is used to allow you to distinguish the two if you wish.
13065
13066@item void putDebugChar(int)
4644b6e3 13067@findex putDebugChar
104c1213 13068Write this subroutine to write a single character to the serial port.
5d161b24 13069It may be identical to @code{putchar} for your target system; a
104c1213
JM
13070different name is used to allow you to distinguish the two if you wish.
13071@end table
13072
13073@cindex control C, and remote debugging
13074@cindex interrupting remote targets
13075If you want @value{GDBN} to be able to stop your program while it is
13076running, you need to use an interrupt-driven serial driver, and arrange
13077for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
13078character). That is the character which @value{GDBN} uses to tell the
13079remote system to stop.
13080
13081Getting the debugging target to return the proper status to @value{GDBN}
13082probably requires changes to the standard stub; one quick and dirty way
13083is to just execute a breakpoint instruction (the ``dirty'' part is that
13084@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
13085
13086Other routines you need to supply are:
13087
13088@table @code
13089@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 13090@findex exceptionHandler
104c1213
JM
13091Write this function to install @var{exception_address} in the exception
13092handling tables. You need to do this because the stub does not have any
13093way of knowing what the exception handling tables on your target system
13094are like (for example, the processor's table might be in @sc{rom},
13095containing entries which point to a table in @sc{ram}).
13096@var{exception_number} is the exception number which should be changed;
13097its meaning is architecture-dependent (for example, different numbers
13098might represent divide by zero, misaligned access, etc). When this
13099exception occurs, control should be transferred directly to
13100@var{exception_address}, and the processor state (stack, registers,
13101and so on) should be just as it is when a processor exception occurs. So if
13102you want to use a jump instruction to reach @var{exception_address}, it
13103should be a simple jump, not a jump to subroutine.
13104
13105For the 386, @var{exception_address} should be installed as an interrupt
13106gate so that interrupts are masked while the handler runs. The gate
13107should be at privilege level 0 (the most privileged level). The
13108@sc{sparc} and 68k stubs are able to mask interrupts themselves without
13109help from @code{exceptionHandler}.
13110
13111@item void flush_i_cache()
4644b6e3 13112@findex flush_i_cache
d4f3574e 13113On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
13114instruction cache, if any, on your target machine. If there is no
13115instruction cache, this subroutine may be a no-op.
13116
13117On target machines that have instruction caches, @value{GDBN} requires this
13118function to make certain that the state of your program is stable.
13119@end table
13120
13121@noindent
13122You must also make sure this library routine is available:
13123
13124@table @code
13125@item void *memset(void *, int, int)
4644b6e3 13126@findex memset
104c1213
JM
13127This is the standard library function @code{memset} that sets an area of
13128memory to a known value. If you have one of the free versions of
13129@code{libc.a}, @code{memset} can be found there; otherwise, you must
13130either obtain it from your hardware manufacturer, or write your own.
13131@end table
13132
13133If you do not use the GNU C compiler, you may need other standard
13134library subroutines as well; this varies from one stub to another,
13135but in general the stubs are likely to use any of the common library
d4f3574e 13136subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
13137
13138
6d2ebf8b 13139@node Debug Session
6f05cf9f 13140@subsection Putting it all together
104c1213
JM
13141
13142@cindex remote serial debugging summary
13143In summary, when your program is ready to debug, you must follow these
13144steps.
13145
13146@enumerate
13147@item
6d2ebf8b 13148Make sure you have defined the supporting low-level routines
104c1213
JM
13149(@pxref{Bootstrapping,,What you must do for the stub}):
13150@display
13151@code{getDebugChar}, @code{putDebugChar},
13152@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
13153@end display
13154
13155@item
13156Insert these lines near the top of your program:
13157
474c8240 13158@smallexample
104c1213
JM
13159set_debug_traps();
13160breakpoint();
474c8240 13161@end smallexample
104c1213
JM
13162
13163@item
13164For the 680x0 stub only, you need to provide a variable called
13165@code{exceptionHook}. Normally you just use:
13166
474c8240 13167@smallexample
104c1213 13168void (*exceptionHook)() = 0;
474c8240 13169@end smallexample
104c1213 13170
d4f3574e 13171@noindent
104c1213 13172but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 13173function in your program, that function is called when
104c1213
JM
13174@code{@value{GDBN}} continues after stopping on a trap (for example, bus
13175error). The function indicated by @code{exceptionHook} is called with
13176one parameter: an @code{int} which is the exception number.
13177
13178@item
13179Compile and link together: your program, the @value{GDBN} debugging stub for
13180your target architecture, and the supporting subroutines.
13181
13182@item
13183Make sure you have a serial connection between your target machine and
13184the @value{GDBN} host, and identify the serial port on the host.
13185
13186@item
13187@c The "remote" target now provides a `load' command, so we should
13188@c document that. FIXME.
13189Download your program to your target machine (or get it there by
13190whatever means the manufacturer provides), and start it.
13191
13192@item
07f31aa6
DJ
13193Start @value{GDBN} on the host, and connect to the target
13194(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 13195
104c1213
JM
13196@end enumerate
13197
8e04817f
AC
13198@node Configurations
13199@chapter Configuration-Specific Information
104c1213 13200
8e04817f
AC
13201While nearly all @value{GDBN} commands are available for all native and
13202cross versions of the debugger, there are some exceptions. This chapter
13203describes things that are only available in certain configurations.
104c1213 13204
8e04817f
AC
13205There are three major categories of configurations: native
13206configurations, where the host and target are the same, embedded
13207operating system configurations, which are usually the same for several
13208different processor architectures, and bare embedded processors, which
13209are quite different from each other.
104c1213 13210
8e04817f
AC
13211@menu
13212* Native::
13213* Embedded OS::
13214* Embedded Processors::
13215* Architectures::
13216@end menu
104c1213 13217
8e04817f
AC
13218@node Native
13219@section Native
104c1213 13220
8e04817f
AC
13221This section describes details specific to particular native
13222configurations.
6cf7e474 13223
8e04817f
AC
13224@menu
13225* HP-UX:: HP-UX
7561d450 13226* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
13227* SVR4 Process Information:: SVR4 process information
13228* DJGPP Native:: Features specific to the DJGPP port
78c47bea 13229* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 13230* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 13231* Neutrino:: Features specific to QNX Neutrino
8e04817f 13232@end menu
6cf7e474 13233
8e04817f
AC
13234@node HP-UX
13235@subsection HP-UX
104c1213 13236
8e04817f
AC
13237On HP-UX systems, if you refer to a function or variable name that
13238begins with a dollar sign, @value{GDBN} searches for a user or system
13239name first, before it searches for a convenience variable.
104c1213 13240
9c16f35a 13241
7561d450
MK
13242@node BSD libkvm Interface
13243@subsection BSD libkvm Interface
13244
13245@cindex libkvm
13246@cindex kernel memory image
13247@cindex kernel crash dump
13248
13249BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
13250interface that provides a uniform interface for accessing kernel virtual
13251memory images, including live systems and crash dumps. @value{GDBN}
13252uses this interface to allow you to debug live kernels and kernel crash
13253dumps on many native BSD configurations. This is implemented as a
13254special @code{kvm} debugging target. For debugging a live system, load
13255the currently running kernel into @value{GDBN} and connect to the
13256@code{kvm} target:
13257
13258@smallexample
13259(@value{GDBP}) @b{target kvm}
13260@end smallexample
13261
13262For debugging crash dumps, provide the file name of the crash dump as an
13263argument:
13264
13265@smallexample
13266(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
13267@end smallexample
13268
13269Once connected to the @code{kvm} target, the following commands are
13270available:
13271
13272@table @code
13273@kindex kvm
13274@item kvm pcb
721c2651 13275Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
13276
13277@item kvm proc
13278Set current context from proc address. This command isn't available on
13279modern FreeBSD systems.
13280@end table
13281
8e04817f
AC
13282@node SVR4 Process Information
13283@subsection SVR4 process information
60bf7e09
EZ
13284@cindex /proc
13285@cindex examine process image
13286@cindex process info via @file{/proc}
104c1213 13287
60bf7e09
EZ
13288Many versions of SVR4 and compatible systems provide a facility called
13289@samp{/proc} that can be used to examine the image of a running
13290process using file-system subroutines. If @value{GDBN} is configured
13291for an operating system with this facility, the command @code{info
13292proc} is available to report information about the process running
13293your program, or about any process running on your system. @code{info
13294proc} works only on SVR4 systems that include the @code{procfs} code.
13295This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
13296Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 13297
8e04817f
AC
13298@table @code
13299@kindex info proc
60bf7e09 13300@cindex process ID
8e04817f 13301@item info proc
60bf7e09
EZ
13302@itemx info proc @var{process-id}
13303Summarize available information about any running process. If a
13304process ID is specified by @var{process-id}, display information about
13305that process; otherwise display information about the program being
13306debugged. The summary includes the debugged process ID, the command
13307line used to invoke it, its current working directory, and its
13308executable file's absolute file name.
13309
13310On some systems, @var{process-id} can be of the form
13311@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
13312within a process. If the optional @var{pid} part is missing, it means
13313a thread from the process being debugged (the leading @samp{/} still
13314needs to be present, or else @value{GDBN} will interpret the number as
13315a process ID rather than a thread ID).
6cf7e474 13316
8e04817f 13317@item info proc mappings
60bf7e09
EZ
13318@cindex memory address space mappings
13319Report the memory address space ranges accessible in the program, with
13320information on whether the process has read, write, or execute access
13321rights to each range. On @sc{gnu}/Linux systems, each memory range
13322includes the object file which is mapped to that range, instead of the
13323memory access rights to that range.
13324
13325@item info proc stat
13326@itemx info proc status
13327@cindex process detailed status information
13328These subcommands are specific to @sc{gnu}/Linux systems. They show
13329the process-related information, including the user ID and group ID;
13330how many threads are there in the process; its virtual memory usage;
13331the signals that are pending, blocked, and ignored; its TTY; its
13332consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 13333value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
13334(type @kbd{man 5 proc} from your shell prompt).
13335
13336@item info proc all
13337Show all the information about the process described under all of the
13338above @code{info proc} subcommands.
13339
8e04817f
AC
13340@ignore
13341@comment These sub-options of 'info proc' were not included when
13342@comment procfs.c was re-written. Keep their descriptions around
13343@comment against the day when someone finds the time to put them back in.
13344@kindex info proc times
13345@item info proc times
13346Starting time, user CPU time, and system CPU time for your program and
13347its children.
6cf7e474 13348
8e04817f
AC
13349@kindex info proc id
13350@item info proc id
13351Report on the process IDs related to your program: its own process ID,
13352the ID of its parent, the process group ID, and the session ID.
8e04817f 13353@end ignore
721c2651
EZ
13354
13355@item set procfs-trace
13356@kindex set procfs-trace
13357@cindex @code{procfs} API calls
13358This command enables and disables tracing of @code{procfs} API calls.
13359
13360@item show procfs-trace
13361@kindex show procfs-trace
13362Show the current state of @code{procfs} API call tracing.
13363
13364@item set procfs-file @var{file}
13365@kindex set procfs-file
13366Tell @value{GDBN} to write @code{procfs} API trace to the named
13367@var{file}. @value{GDBN} appends the trace info to the previous
13368contents of the file. The default is to display the trace on the
13369standard output.
13370
13371@item show procfs-file
13372@kindex show procfs-file
13373Show the file to which @code{procfs} API trace is written.
13374
13375@item proc-trace-entry
13376@itemx proc-trace-exit
13377@itemx proc-untrace-entry
13378@itemx proc-untrace-exit
13379@kindex proc-trace-entry
13380@kindex proc-trace-exit
13381@kindex proc-untrace-entry
13382@kindex proc-untrace-exit
13383These commands enable and disable tracing of entries into and exits
13384from the @code{syscall} interface.
13385
13386@item info pidlist
13387@kindex info pidlist
13388@cindex process list, QNX Neutrino
13389For QNX Neutrino only, this command displays the list of all the
13390processes and all the threads within each process.
13391
13392@item info meminfo
13393@kindex info meminfo
13394@cindex mapinfo list, QNX Neutrino
13395For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 13396@end table
104c1213 13397
8e04817f
AC
13398@node DJGPP Native
13399@subsection Features for Debugging @sc{djgpp} Programs
13400@cindex @sc{djgpp} debugging
13401@cindex native @sc{djgpp} debugging
13402@cindex MS-DOS-specific commands
104c1213 13403
514c4d71
EZ
13404@cindex DPMI
13405@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
13406MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
13407that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
13408top of real-mode DOS systems and their emulations.
104c1213 13409
8e04817f
AC
13410@value{GDBN} supports native debugging of @sc{djgpp} programs, and
13411defines a few commands specific to the @sc{djgpp} port. This
13412subsection describes those commands.
104c1213 13413
8e04817f
AC
13414@table @code
13415@kindex info dos
13416@item info dos
13417This is a prefix of @sc{djgpp}-specific commands which print
13418information about the target system and important OS structures.
f1251bdd 13419
8e04817f
AC
13420@kindex sysinfo
13421@cindex MS-DOS system info
13422@cindex free memory information (MS-DOS)
13423@item info dos sysinfo
13424This command displays assorted information about the underlying
13425platform: the CPU type and features, the OS version and flavor, the
13426DPMI version, and the available conventional and DPMI memory.
104c1213 13427
8e04817f
AC
13428@cindex GDT
13429@cindex LDT
13430@cindex IDT
13431@cindex segment descriptor tables
13432@cindex descriptor tables display
13433@item info dos gdt
13434@itemx info dos ldt
13435@itemx info dos idt
13436These 3 commands display entries from, respectively, Global, Local,
13437and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
13438tables are data structures which store a descriptor for each segment
13439that is currently in use. The segment's selector is an index into a
13440descriptor table; the table entry for that index holds the
13441descriptor's base address and limit, and its attributes and access
13442rights.
104c1213 13443
8e04817f
AC
13444A typical @sc{djgpp} program uses 3 segments: a code segment, a data
13445segment (used for both data and the stack), and a DOS segment (which
13446allows access to DOS/BIOS data structures and absolute addresses in
13447conventional memory). However, the DPMI host will usually define
13448additional segments in order to support the DPMI environment.
d4f3574e 13449
8e04817f
AC
13450@cindex garbled pointers
13451These commands allow to display entries from the descriptor tables.
13452Without an argument, all entries from the specified table are
13453displayed. An argument, which should be an integer expression, means
13454display a single entry whose index is given by the argument. For
13455example, here's a convenient way to display information about the
13456debugged program's data segment:
104c1213 13457
8e04817f
AC
13458@smallexample
13459@exdent @code{(@value{GDBP}) info dos ldt $ds}
13460@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
13461@end smallexample
104c1213 13462
8e04817f
AC
13463@noindent
13464This comes in handy when you want to see whether a pointer is outside
13465the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 13466
8e04817f
AC
13467@cindex page tables display (MS-DOS)
13468@item info dos pde
13469@itemx info dos pte
13470These two commands display entries from, respectively, the Page
13471Directory and the Page Tables. Page Directories and Page Tables are
13472data structures which control how virtual memory addresses are mapped
13473into physical addresses. A Page Table includes an entry for every
13474page of memory that is mapped into the program's address space; there
13475may be several Page Tables, each one holding up to 4096 entries. A
13476Page Directory has up to 4096 entries, one each for every Page Table
13477that is currently in use.
104c1213 13478
8e04817f
AC
13479Without an argument, @kbd{info dos pde} displays the entire Page
13480Directory, and @kbd{info dos pte} displays all the entries in all of
13481the Page Tables. An argument, an integer expression, given to the
13482@kbd{info dos pde} command means display only that entry from the Page
13483Directory table. An argument given to the @kbd{info dos pte} command
13484means display entries from a single Page Table, the one pointed to by
13485the specified entry in the Page Directory.
104c1213 13486
8e04817f
AC
13487@cindex direct memory access (DMA) on MS-DOS
13488These commands are useful when your program uses @dfn{DMA} (Direct
13489Memory Access), which needs physical addresses to program the DMA
13490controller.
104c1213 13491
8e04817f 13492These commands are supported only with some DPMI servers.
104c1213 13493
8e04817f
AC
13494@cindex physical address from linear address
13495@item info dos address-pte @var{addr}
13496This command displays the Page Table entry for a specified linear
514c4d71
EZ
13497address. The argument @var{addr} is a linear address which should
13498already have the appropriate segment's base address added to it,
13499because this command accepts addresses which may belong to @emph{any}
13500segment. For example, here's how to display the Page Table entry for
13501the page where a variable @code{i} is stored:
104c1213 13502
b383017d 13503@smallexample
8e04817f
AC
13504@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
13505@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 13506@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 13507@end smallexample
104c1213 13508
8e04817f
AC
13509@noindent
13510This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 13511whose physical base address is @code{0x02698000}, and shows all the
8e04817f 13512attributes of that page.
104c1213 13513
8e04817f
AC
13514Note that you must cast the addresses of variables to a @code{char *},
13515since otherwise the value of @code{__djgpp_base_address}, the base
13516address of all variables and functions in a @sc{djgpp} program, will
13517be added using the rules of C pointer arithmetics: if @code{i} is
13518declared an @code{int}, @value{GDBN} will add 4 times the value of
13519@code{__djgpp_base_address} to the address of @code{i}.
104c1213 13520
8e04817f
AC
13521Here's another example, it displays the Page Table entry for the
13522transfer buffer:
104c1213 13523
8e04817f
AC
13524@smallexample
13525@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
13526@exdent @code{Page Table entry for address 0x29110:}
13527@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
13528@end smallexample
104c1213 13529
8e04817f
AC
13530@noindent
13531(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
135323rd member of the @code{_go32_info_block} structure.) The output
13533clearly shows that this DPMI server maps the addresses in conventional
13534memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
13535linear (@code{0x29110}) addresses are identical.
104c1213 13536
8e04817f
AC
13537This command is supported only with some DPMI servers.
13538@end table
104c1213 13539
c45da7e6 13540@cindex DOS serial data link, remote debugging
a8f24a35
EZ
13541In addition to native debugging, the DJGPP port supports remote
13542debugging via a serial data link. The following commands are specific
13543to remote serial debugging in the DJGPP port of @value{GDBN}.
13544
13545@table @code
13546@kindex set com1base
13547@kindex set com1irq
13548@kindex set com2base
13549@kindex set com2irq
13550@kindex set com3base
13551@kindex set com3irq
13552@kindex set com4base
13553@kindex set com4irq
13554@item set com1base @var{addr}
13555This command sets the base I/O port address of the @file{COM1} serial
13556port.
13557
13558@item set com1irq @var{irq}
13559This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
13560for the @file{COM1} serial port.
13561
13562There are similar commands @samp{set com2base}, @samp{set com3irq},
13563etc.@: for setting the port address and the @code{IRQ} lines for the
13564other 3 COM ports.
13565
13566@kindex show com1base
13567@kindex show com1irq
13568@kindex show com2base
13569@kindex show com2irq
13570@kindex show com3base
13571@kindex show com3irq
13572@kindex show com4base
13573@kindex show com4irq
13574The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
13575display the current settings of the base address and the @code{IRQ}
13576lines used by the COM ports.
c45da7e6
EZ
13577
13578@item info serial
13579@kindex info serial
13580@cindex DOS serial port status
13581This command prints the status of the 4 DOS serial ports. For each
13582port, it prints whether it's active or not, its I/O base address and
13583IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
13584counts of various errors encountered so far.
a8f24a35
EZ
13585@end table
13586
13587
78c47bea
PM
13588@node Cygwin Native
13589@subsection Features for Debugging MS Windows PE executables
13590@cindex MS Windows debugging
13591@cindex native Cygwin debugging
13592@cindex Cygwin-specific commands
13593
be448670
CF
13594@value{GDBN} supports native debugging of MS Windows programs, including
13595DLLs with and without symbolic debugging information. There are various
13596additional Cygwin-specific commands, described in this subsection. The
13597subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
13598that have no debugging symbols.
13599
78c47bea
PM
13600
13601@table @code
13602@kindex info w32
13603@item info w32
13604This is a prefix of MS Windows specific commands which print
13605information about the target system and important OS structures.
13606
13607@item info w32 selector
13608This command displays information returned by
13609the Win32 API @code{GetThreadSelectorEntry} function.
13610It takes an optional argument that is evaluated to
13611a long value to give the information about this given selector.
13612Without argument, this command displays information
13613about the the six segment registers.
13614
13615@kindex info dll
13616@item info dll
13617This is a Cygwin specific alias of info shared.
13618
13619@kindex dll-symbols
13620@item dll-symbols
13621This command loads symbols from a dll similarly to
13622add-sym command but without the need to specify a base address.
13623
be90c084 13624@kindex set cygwin-exceptions
e16b02ee
EZ
13625@cindex debugging the Cygwin DLL
13626@cindex Cygwin DLL, debugging
be90c084 13627@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
13628If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
13629happen inside the Cygwin DLL. If @var{mode} is @code{off},
13630@value{GDBN} will delay recognition of exceptions, and may ignore some
13631exceptions which seem to be caused by internal Cygwin DLL
13632``bookkeeping''. This option is meant primarily for debugging the
13633Cygwin DLL itself; the default value is @code{off} to avoid annoying
13634@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
13635
13636@kindex show cygwin-exceptions
13637@item show cygwin-exceptions
e16b02ee
EZ
13638Displays whether @value{GDBN} will break on exceptions that happen
13639inside the Cygwin DLL itself.
be90c084 13640
b383017d 13641@kindex set new-console
78c47bea 13642@item set new-console @var{mode}
b383017d 13643If @var{mode} is @code{on} the debuggee will
78c47bea
PM
13644be started in a new console on next start.
13645If @var{mode} is @code{off}i, the debuggee will
13646be started in the same console as the debugger.
13647
13648@kindex show new-console
13649@item show new-console
13650Displays whether a new console is used
13651when the debuggee is started.
13652
13653@kindex set new-group
13654@item set new-group @var{mode}
13655This boolean value controls whether the debuggee should
13656start a new group or stay in the same group as the debugger.
13657This affects the way the Windows OS handles
c8aa23ab 13658@samp{Ctrl-C}.
78c47bea
PM
13659
13660@kindex show new-group
13661@item show new-group
13662Displays current value of new-group boolean.
13663
13664@kindex set debugevents
13665@item set debugevents
219eec71
EZ
13666This boolean value adds debug output concerning kernel events related
13667to the debuggee seen by the debugger. This includes events that
13668signal thread and process creation and exit, DLL loading and
13669unloading, console interrupts, and debugging messages produced by the
13670Windows @code{OutputDebugString} API call.
78c47bea
PM
13671
13672@kindex set debugexec
13673@item set debugexec
b383017d 13674This boolean value adds debug output concerning execute events
219eec71 13675(such as resume thread) seen by the debugger.
78c47bea
PM
13676
13677@kindex set debugexceptions
13678@item set debugexceptions
219eec71
EZ
13679This boolean value adds debug output concerning exceptions in the
13680debuggee seen by the debugger.
78c47bea
PM
13681
13682@kindex set debugmemory
13683@item set debugmemory
219eec71
EZ
13684This boolean value adds debug output concerning debuggee memory reads
13685and writes by the debugger.
78c47bea
PM
13686
13687@kindex set shell
13688@item set shell
13689This boolean values specifies whether the debuggee is called
13690via a shell or directly (default value is on).
13691
13692@kindex show shell
13693@item show shell
13694Displays if the debuggee will be started with a shell.
13695
13696@end table
13697
be448670
CF
13698@menu
13699* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13700@end menu
13701
13702@node Non-debug DLL symbols
13703@subsubsection Support for DLLs without debugging symbols
13704@cindex DLLs with no debugging symbols
13705@cindex Minimal symbols and DLLs
13706
13707Very often on windows, some of the DLLs that your program relies on do
13708not include symbolic debugging information (for example,
13709@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13710symbols in a DLL, it relies on the minimal amount of symbolic
13711information contained in the DLL's export table. This subsubsection
13712describes working with such symbols, known internally to @value{GDBN} as
13713``minimal symbols''.
13714
13715Note that before the debugged program has started execution, no DLLs
13716will have been loaded. The easiest way around this problem is simply to
13717start the program --- either by setting a breakpoint or letting the
13718program run once to completion. It is also possible to force
13719@value{GDBN} to load a particular DLL before starting the executable ---
13720see the shared library information in @pxref{Files} or the
13721@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13722explicitly loading symbols from a DLL with no debugging information will
13723cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13724which may adversely affect symbol lookup performance.
13725
13726@subsubsection DLL name prefixes
13727
13728In keeping with the naming conventions used by the Microsoft debugging
13729tools, DLL export symbols are made available with a prefix based on the
13730DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13731also entered into the symbol table, so @code{CreateFileA} is often
13732sufficient. In some cases there will be name clashes within a program
13733(particularly if the executable itself includes full debugging symbols)
13734necessitating the use of the fully qualified name when referring to the
13735contents of the DLL. Use single-quotes around the name to avoid the
13736exclamation mark (``!'') being interpreted as a language operator.
13737
13738Note that the internal name of the DLL may be all upper-case, even
13739though the file name of the DLL is lower-case, or vice-versa. Since
13740symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13741some confusion. If in doubt, try the @code{info functions} and
13742@code{info variables} commands or even @code{maint print msymbols} (see
13743@pxref{Symbols}). Here's an example:
13744
13745@smallexample
f7dc1244 13746(@value{GDBP}) info function CreateFileA
be448670
CF
13747All functions matching regular expression "CreateFileA":
13748
13749Non-debugging symbols:
137500x77e885f4 CreateFileA
137510x77e885f4 KERNEL32!CreateFileA
13752@end smallexample
13753
13754@smallexample
f7dc1244 13755(@value{GDBP}) info function !
be448670
CF
13756All functions matching regular expression "!":
13757
13758Non-debugging symbols:
137590x6100114c cygwin1!__assert
137600x61004034 cygwin1!_dll_crt0@@0
137610x61004240 cygwin1!dll_crt0(per_process *)
13762[etc...]
13763@end smallexample
13764
13765@subsubsection Working with minimal symbols
13766
13767Symbols extracted from a DLL's export table do not contain very much
13768type information. All that @value{GDBN} can do is guess whether a symbol
13769refers to a function or variable depending on the linker section that
13770contains the symbol. Also note that the actual contents of the memory
13771contained in a DLL are not available unless the program is running. This
13772means that you cannot examine the contents of a variable or disassemble
13773a function within a DLL without a running program.
13774
13775Variables are generally treated as pointers and dereferenced
13776automatically. For this reason, it is often necessary to prefix a
13777variable name with the address-of operator (``&'') and provide explicit
13778type information in the command. Here's an example of the type of
13779problem:
13780
13781@smallexample
f7dc1244 13782(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13783$1 = 268572168
13784@end smallexample
13785
13786@smallexample
f7dc1244 13787(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
137880x10021610: "\230y\""
13789@end smallexample
13790
13791And two possible solutions:
13792
13793@smallexample
f7dc1244 13794(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13795$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13796@end smallexample
13797
13798@smallexample
f7dc1244 13799(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 138000x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13801(@value{GDBP}) x/x 0x10021608
be448670 138020x10021608: 0x0022fd98
f7dc1244 13803(@value{GDBP}) x/s 0x0022fd98
be448670
CF
138040x22fd98: "/cygdrive/c/mydirectory/myprogram"
13805@end smallexample
13806
13807Setting a break point within a DLL is possible even before the program
13808starts execution. However, under these circumstances, @value{GDBN} can't
13809examine the initial instructions of the function in order to skip the
13810function's frame set-up code. You can work around this by using ``*&''
13811to set the breakpoint at a raw memory address:
13812
13813@smallexample
f7dc1244 13814(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13815Breakpoint 1 at 0x1e04eff0
13816@end smallexample
13817
13818The author of these extensions is not entirely convinced that setting a
13819break point within a shared DLL like @file{kernel32.dll} is completely
13820safe.
13821
14d6dd68
EZ
13822@node Hurd Native
13823@subsection Commands specific to @sc{gnu} Hurd systems
13824@cindex @sc{gnu} Hurd debugging
13825
13826This subsection describes @value{GDBN} commands specific to the
13827@sc{gnu} Hurd native debugging.
13828
13829@table @code
13830@item set signals
13831@itemx set sigs
13832@kindex set signals@r{, Hurd command}
13833@kindex set sigs@r{, Hurd command}
13834This command toggles the state of inferior signal interception by
13835@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13836affected by this command. @code{sigs} is a shorthand alias for
13837@code{signals}.
13838
13839@item show signals
13840@itemx show sigs
13841@kindex show signals@r{, Hurd command}
13842@kindex show sigs@r{, Hurd command}
13843Show the current state of intercepting inferior's signals.
13844
13845@item set signal-thread
13846@itemx set sigthread
13847@kindex set signal-thread
13848@kindex set sigthread
13849This command tells @value{GDBN} which thread is the @code{libc} signal
13850thread. That thread is run when a signal is delivered to a running
13851process. @code{set sigthread} is the shorthand alias of @code{set
13852signal-thread}.
13853
13854@item show signal-thread
13855@itemx show sigthread
13856@kindex show signal-thread
13857@kindex show sigthread
13858These two commands show which thread will run when the inferior is
13859delivered a signal.
13860
13861@item set stopped
13862@kindex set stopped@r{, Hurd command}
13863This commands tells @value{GDBN} that the inferior process is stopped,
13864as with the @code{SIGSTOP} signal. The stopped process can be
13865continued by delivering a signal to it.
13866
13867@item show stopped
13868@kindex show stopped@r{, Hurd command}
13869This command shows whether @value{GDBN} thinks the debuggee is
13870stopped.
13871
13872@item set exceptions
13873@kindex set exceptions@r{, Hurd command}
13874Use this command to turn off trapping of exceptions in the inferior.
13875When exception trapping is off, neither breakpoints nor
13876single-stepping will work. To restore the default, set exception
13877trapping on.
13878
13879@item show exceptions
13880@kindex show exceptions@r{, Hurd command}
13881Show the current state of trapping exceptions in the inferior.
13882
13883@item set task pause
13884@kindex set task@r{, Hurd commands}
13885@cindex task attributes (@sc{gnu} Hurd)
13886@cindex pause current task (@sc{gnu} Hurd)
13887This command toggles task suspension when @value{GDBN} has control.
13888Setting it to on takes effect immediately, and the task is suspended
13889whenever @value{GDBN} gets control. Setting it to off will take
13890effect the next time the inferior is continued. If this option is set
13891to off, you can use @code{set thread default pause on} or @code{set
13892thread pause on} (see below) to pause individual threads.
13893
13894@item show task pause
13895@kindex show task@r{, Hurd commands}
13896Show the current state of task suspension.
13897
13898@item set task detach-suspend-count
13899@cindex task suspend count
13900@cindex detach from task, @sc{gnu} Hurd
13901This command sets the suspend count the task will be left with when
13902@value{GDBN} detaches from it.
13903
13904@item show task detach-suspend-count
13905Show the suspend count the task will be left with when detaching.
13906
13907@item set task exception-port
13908@itemx set task excp
13909@cindex task exception port, @sc{gnu} Hurd
13910This command sets the task exception port to which @value{GDBN} will
13911forward exceptions. The argument should be the value of the @dfn{send
13912rights} of the task. @code{set task excp} is a shorthand alias.
13913
13914@item set noninvasive
13915@cindex noninvasive task options
13916This command switches @value{GDBN} to a mode that is the least
13917invasive as far as interfering with the inferior is concerned. This
13918is the same as using @code{set task pause}, @code{set exceptions}, and
13919@code{set signals} to values opposite to the defaults.
13920
13921@item info send-rights
13922@itemx info receive-rights
13923@itemx info port-rights
13924@itemx info port-sets
13925@itemx info dead-names
13926@itemx info ports
13927@itemx info psets
13928@cindex send rights, @sc{gnu} Hurd
13929@cindex receive rights, @sc{gnu} Hurd
13930@cindex port rights, @sc{gnu} Hurd
13931@cindex port sets, @sc{gnu} Hurd
13932@cindex dead names, @sc{gnu} Hurd
13933These commands display information about, respectively, send rights,
13934receive rights, port rights, port sets, and dead names of a task.
13935There are also shorthand aliases: @code{info ports} for @code{info
13936port-rights} and @code{info psets} for @code{info port-sets}.
13937
13938@item set thread pause
13939@kindex set thread@r{, Hurd command}
13940@cindex thread properties, @sc{gnu} Hurd
13941@cindex pause current thread (@sc{gnu} Hurd)
13942This command toggles current thread suspension when @value{GDBN} has
13943control. Setting it to on takes effect immediately, and the current
13944thread is suspended whenever @value{GDBN} gets control. Setting it to
13945off will take effect the next time the inferior is continued.
13946Normally, this command has no effect, since when @value{GDBN} has
13947control, the whole task is suspended. However, if you used @code{set
13948task pause off} (see above), this command comes in handy to suspend
13949only the current thread.
13950
13951@item show thread pause
13952@kindex show thread@r{, Hurd command}
13953This command shows the state of current thread suspension.
13954
13955@item set thread run
13956This comamnd sets whether the current thread is allowed to run.
13957
13958@item show thread run
13959Show whether the current thread is allowed to run.
13960
13961@item set thread detach-suspend-count
13962@cindex thread suspend count, @sc{gnu} Hurd
13963@cindex detach from thread, @sc{gnu} Hurd
13964This command sets the suspend count @value{GDBN} will leave on a
13965thread when detaching. This number is relative to the suspend count
13966found by @value{GDBN} when it notices the thread; use @code{set thread
13967takeover-suspend-count} to force it to an absolute value.
13968
13969@item show thread detach-suspend-count
13970Show the suspend count @value{GDBN} will leave on the thread when
13971detaching.
13972
13973@item set thread exception-port
13974@itemx set thread excp
13975Set the thread exception port to which to forward exceptions. This
13976overrides the port set by @code{set task exception-port} (see above).
13977@code{set thread excp} is the shorthand alias.
13978
13979@item set thread takeover-suspend-count
13980Normally, @value{GDBN}'s thread suspend counts are relative to the
13981value @value{GDBN} finds when it notices each thread. This command
13982changes the suspend counts to be absolute instead.
13983
13984@item set thread default
13985@itemx show thread default
13986@cindex thread default settings, @sc{gnu} Hurd
13987Each of the above @code{set thread} commands has a @code{set thread
13988default} counterpart (e.g., @code{set thread default pause}, @code{set
13989thread default exception-port}, etc.). The @code{thread default}
13990variety of commands sets the default thread properties for all
13991threads; you can then change the properties of individual threads with
13992the non-default commands.
13993@end table
13994
13995
a64548ea
EZ
13996@node Neutrino
13997@subsection QNX Neutrino
13998@cindex QNX Neutrino
13999
14000@value{GDBN} provides the following commands specific to the QNX
14001Neutrino target:
14002
14003@table @code
14004@item set debug nto-debug
14005@kindex set debug nto-debug
14006When set to on, enables debugging messages specific to the QNX
14007Neutrino support.
14008
14009@item show debug nto-debug
14010@kindex show debug nto-debug
14011Show the current state of QNX Neutrino messages.
14012@end table
14013
14014
8e04817f
AC
14015@node Embedded OS
14016@section Embedded Operating Systems
104c1213 14017
8e04817f
AC
14018This section describes configurations involving the debugging of
14019embedded operating systems that are available for several different
14020architectures.
d4f3574e 14021
8e04817f
AC
14022@menu
14023* VxWorks:: Using @value{GDBN} with VxWorks
14024@end menu
104c1213 14025
8e04817f
AC
14026@value{GDBN} includes the ability to debug programs running on
14027various real-time operating systems.
104c1213 14028
8e04817f
AC
14029@node VxWorks
14030@subsection Using @value{GDBN} with VxWorks
104c1213 14031
8e04817f 14032@cindex VxWorks
104c1213 14033
8e04817f 14034@table @code
104c1213 14035
8e04817f
AC
14036@kindex target vxworks
14037@item target vxworks @var{machinename}
14038A VxWorks system, attached via TCP/IP. The argument @var{machinename}
14039is the target system's machine name or IP address.
104c1213 14040
8e04817f 14041@end table
104c1213 14042
8e04817f
AC
14043On VxWorks, @code{load} links @var{filename} dynamically on the
14044current target system as well as adding its symbols in @value{GDBN}.
104c1213 14045
8e04817f
AC
14046@value{GDBN} enables developers to spawn and debug tasks running on networked
14047VxWorks targets from a Unix host. Already-running tasks spawned from
14048the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
14049both the Unix host and on the VxWorks target. The program
14050@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
14051installed with the name @code{vxgdb}, to distinguish it from a
14052@value{GDBN} for debugging programs on the host itself.)
104c1213 14053
8e04817f
AC
14054@table @code
14055@item VxWorks-timeout @var{args}
14056@kindex vxworks-timeout
14057All VxWorks-based targets now support the option @code{vxworks-timeout}.
14058This option is set by the user, and @var{args} represents the number of
14059seconds @value{GDBN} waits for responses to rpc's. You might use this if
14060your VxWorks target is a slow software simulator or is on the far side
14061of a thin network line.
14062@end table
104c1213 14063
8e04817f
AC
14064The following information on connecting to VxWorks was current when
14065this manual was produced; newer releases of VxWorks may use revised
14066procedures.
104c1213 14067
4644b6e3 14068@findex INCLUDE_RDB
8e04817f
AC
14069To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
14070to include the remote debugging interface routines in the VxWorks
14071library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
14072VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
14073kernel. The resulting kernel contains @file{rdb.a}, and spawns the
14074source debugging task @code{tRdbTask} when VxWorks is booted. For more
14075information on configuring and remaking VxWorks, see the manufacturer's
14076manual.
14077@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 14078
8e04817f
AC
14079Once you have included @file{rdb.a} in your VxWorks system image and set
14080your Unix execution search path to find @value{GDBN}, you are ready to
14081run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
14082@code{vxgdb}, depending on your installation).
104c1213 14083
8e04817f 14084@value{GDBN} comes up showing the prompt:
104c1213 14085
474c8240 14086@smallexample
8e04817f 14087(vxgdb)
474c8240 14088@end smallexample
104c1213 14089
8e04817f
AC
14090@menu
14091* VxWorks Connection:: Connecting to VxWorks
14092* VxWorks Download:: VxWorks download
14093* VxWorks Attach:: Running tasks
14094@end menu
104c1213 14095
8e04817f
AC
14096@node VxWorks Connection
14097@subsubsection Connecting to VxWorks
104c1213 14098
8e04817f
AC
14099The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
14100network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 14101
474c8240 14102@smallexample
8e04817f 14103(vxgdb) target vxworks tt
474c8240 14104@end smallexample
104c1213 14105
8e04817f
AC
14106@need 750
14107@value{GDBN} displays messages like these:
104c1213 14108
8e04817f
AC
14109@smallexample
14110Attaching remote machine across net...
14111Connected to tt.
14112@end smallexample
104c1213 14113
8e04817f
AC
14114@need 1000
14115@value{GDBN} then attempts to read the symbol tables of any object modules
14116loaded into the VxWorks target since it was last booted. @value{GDBN} locates
14117these files by searching the directories listed in the command search
14118path (@pxref{Environment, ,Your program's environment}); if it fails
14119to find an object file, it displays a message such as:
5d161b24 14120
474c8240 14121@smallexample
8e04817f 14122prog.o: No such file or directory.
474c8240 14123@end smallexample
104c1213 14124
8e04817f
AC
14125When this happens, add the appropriate directory to the search path with
14126the @value{GDBN} command @code{path}, and execute the @code{target}
14127command again.
104c1213 14128
8e04817f
AC
14129@node VxWorks Download
14130@subsubsection VxWorks download
104c1213 14131
8e04817f
AC
14132@cindex download to VxWorks
14133If you have connected to the VxWorks target and you want to debug an
14134object that has not yet been loaded, you can use the @value{GDBN}
14135@code{load} command to download a file from Unix to VxWorks
14136incrementally. The object file given as an argument to the @code{load}
14137command is actually opened twice: first by the VxWorks target in order
14138to download the code, then by @value{GDBN} in order to read the symbol
14139table. This can lead to problems if the current working directories on
14140the two systems differ. If both systems have NFS mounted the same
14141filesystems, you can avoid these problems by using absolute paths.
14142Otherwise, it is simplest to set the working directory on both systems
14143to the directory in which the object file resides, and then to reference
14144the file by its name, without any path. For instance, a program
14145@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
14146and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
14147program, type this on VxWorks:
104c1213 14148
474c8240 14149@smallexample
8e04817f 14150-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 14151@end smallexample
104c1213 14152
8e04817f
AC
14153@noindent
14154Then, in @value{GDBN}, type:
104c1213 14155
474c8240 14156@smallexample
8e04817f
AC
14157(vxgdb) cd @var{hostpath}/vw/demo/rdb
14158(vxgdb) load prog.o
474c8240 14159@end smallexample
104c1213 14160
8e04817f 14161@value{GDBN} displays a response similar to this:
104c1213 14162
8e04817f
AC
14163@smallexample
14164Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
14165@end smallexample
104c1213 14166
8e04817f
AC
14167You can also use the @code{load} command to reload an object module
14168after editing and recompiling the corresponding source file. Note that
14169this makes @value{GDBN} delete all currently-defined breakpoints,
14170auto-displays, and convenience variables, and to clear the value
14171history. (This is necessary in order to preserve the integrity of
14172debugger's data structures that reference the target system's symbol
14173table.)
104c1213 14174
8e04817f
AC
14175@node VxWorks Attach
14176@subsubsection Running tasks
104c1213
JM
14177
14178@cindex running VxWorks tasks
14179You can also attach to an existing task using the @code{attach} command as
14180follows:
14181
474c8240 14182@smallexample
104c1213 14183(vxgdb) attach @var{task}
474c8240 14184@end smallexample
104c1213
JM
14185
14186@noindent
14187where @var{task} is the VxWorks hexadecimal task ID. The task can be running
14188or suspended when you attach to it. Running tasks are suspended at
14189the time of attachment.
14190
6d2ebf8b 14191@node Embedded Processors
104c1213
JM
14192@section Embedded Processors
14193
14194This section goes into details specific to particular embedded
14195configurations.
14196
c45da7e6
EZ
14197@cindex send command to simulator
14198Whenever a specific embedded processor has a simulator, @value{GDBN}
14199allows to send an arbitrary command to the simulator.
14200
14201@table @code
14202@item sim @var{command}
14203@kindex sim@r{, a command}
14204Send an arbitrary @var{command} string to the simulator. Consult the
14205documentation for the specific simulator in use for information about
14206acceptable commands.
14207@end table
14208
7d86b5d5 14209
104c1213 14210@menu
c45da7e6 14211* ARM:: ARM RDI
172c2a43
KI
14212* H8/300:: Renesas H8/300
14213* H8/500:: Renesas H8/500
14214* M32R/D:: Renesas M32R/D
104c1213 14215* M68K:: Motorola M68K
104c1213 14216* MIPS Embedded:: MIPS Embedded
a37295f9 14217* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
14218* PA:: HP PA Embedded
14219* PowerPC: PowerPC
172c2a43 14220* SH:: Renesas SH
104c1213
JM
14221* Sparclet:: Tsqware Sparclet
14222* Sparclite:: Fujitsu Sparclite
14223* ST2000:: Tandem ST2000
14224* Z8000:: Zilog Z8000
a64548ea
EZ
14225* AVR:: Atmel AVR
14226* CRIS:: CRIS
14227* Super-H:: Renesas Super-H
c45da7e6 14228* WinCE:: Windows CE child processes
104c1213
JM
14229@end menu
14230
6d2ebf8b 14231@node ARM
104c1213 14232@subsection ARM
c45da7e6 14233@cindex ARM RDI
104c1213
JM
14234
14235@table @code
8e04817f
AC
14236@kindex target rdi
14237@item target rdi @var{dev}
14238ARM Angel monitor, via RDI library interface to ADP protocol. You may
14239use this target to communicate with both boards running the Angel
14240monitor, or with the EmbeddedICE JTAG debug device.
14241
14242@kindex target rdp
14243@item target rdp @var{dev}
14244ARM Demon monitor.
14245
14246@end table
14247
e2f4edfd
EZ
14248@value{GDBN} provides the following ARM-specific commands:
14249
14250@table @code
14251@item set arm disassembler
14252@kindex set arm
14253This commands selects from a list of disassembly styles. The
14254@code{"std"} style is the standard style.
14255
14256@item show arm disassembler
14257@kindex show arm
14258Show the current disassembly style.
14259
14260@item set arm apcs32
14261@cindex ARM 32-bit mode
14262This command toggles ARM operation mode between 32-bit and 26-bit.
14263
14264@item show arm apcs32
14265Display the current usage of the ARM 32-bit mode.
14266
14267@item set arm fpu @var{fputype}
14268This command sets the ARM floating-point unit (FPU) type. The
14269argument @var{fputype} can be one of these:
14270
14271@table @code
14272@item auto
14273Determine the FPU type by querying the OS ABI.
14274@item softfpa
14275Software FPU, with mixed-endian doubles on little-endian ARM
14276processors.
14277@item fpa
14278GCC-compiled FPA co-processor.
14279@item softvfp
14280Software FPU with pure-endian doubles.
14281@item vfp
14282VFP co-processor.
14283@end table
14284
14285@item show arm fpu
14286Show the current type of the FPU.
14287
14288@item set arm abi
14289This command forces @value{GDBN} to use the specified ABI.
14290
14291@item show arm abi
14292Show the currently used ABI.
14293
14294@item set debug arm
14295Toggle whether to display ARM-specific debugging messages from the ARM
14296target support subsystem.
14297
14298@item show debug arm
14299Show whether ARM-specific debugging messages are enabled.
14300@end table
14301
c45da7e6
EZ
14302The following commands are available when an ARM target is debugged
14303using the RDI interface:
14304
14305@table @code
14306@item rdilogfile @r{[}@var{file}@r{]}
14307@kindex rdilogfile
14308@cindex ADP (Angel Debugger Protocol) logging
14309Set the filename for the ADP (Angel Debugger Protocol) packet log.
14310With an argument, sets the log file to the specified @var{file}. With
14311no argument, show the current log file name. The default log file is
14312@file{rdi.log}.
14313
14314@item rdilogenable @r{[}@var{arg}@r{]}
14315@kindex rdilogenable
14316Control logging of ADP packets. With an argument of 1 or @code{"yes"}
14317enables logging, with an argument 0 or @code{"no"} disables it. With
14318no arguments displays the current setting. When logging is enabled,
14319ADP packets exchanged between @value{GDBN} and the RDI target device
14320are logged to a file.
14321
14322@item set rdiromatzero
14323@kindex set rdiromatzero
14324@cindex ROM at zero address, RDI
14325Tell @value{GDBN} whether the target has ROM at address 0. If on,
14326vector catching is disabled, so that zero address can be used. If off
14327(the default), vector catching is enabled. For this command to take
14328effect, it needs to be invoked prior to the @code{target rdi} command.
14329
14330@item show rdiromatzero
14331@kindex show rdiromatzero
14332Show the current setting of ROM at zero address.
14333
14334@item set rdiheartbeat
14335@kindex set rdiheartbeat
14336@cindex RDI heartbeat
14337Enable or disable RDI heartbeat packets. It is not recommended to
14338turn on this option, since it confuses ARM and EPI JTAG interface, as
14339well as the Angel monitor.
14340
14341@item show rdiheartbeat
14342@kindex show rdiheartbeat
14343Show the setting of RDI heartbeat packets.
14344@end table
14345
e2f4edfd 14346
8e04817f 14347@node H8/300
172c2a43 14348@subsection Renesas H8/300
8e04817f
AC
14349
14350@table @code
14351
14352@kindex target hms@r{, with H8/300}
14353@item target hms @var{dev}
172c2a43 14354A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
14355Use special commands @code{device} and @code{speed} to control the serial
14356line and the communications speed used.
14357
14358@kindex target e7000@r{, with H8/300}
14359@item target e7000 @var{dev}
172c2a43 14360E7000 emulator for Renesas H8 and SH.
8e04817f
AC
14361
14362@kindex target sh3@r{, with H8/300}
14363@kindex target sh3e@r{, with H8/300}
14364@item target sh3 @var{dev}
14365@itemx target sh3e @var{dev}
172c2a43 14366Renesas SH-3 and SH-3E target systems.
8e04817f
AC
14367
14368@end table
14369
14370@cindex download to H8/300 or H8/500
14371@cindex H8/300 or H8/500 download
172c2a43
KI
14372@cindex download to Renesas SH
14373@cindex Renesas SH download
14374When you select remote debugging to a Renesas SH, H8/300, or H8/500
14375board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
14376board and also opens it as the current executable target for
14377@value{GDBN} on your host (like the @code{file} command).
14378
14379@value{GDBN} needs to know these things to talk to your
172c2a43 14380Renesas SH, H8/300, or H8/500:
8e04817f
AC
14381
14382@enumerate
14383@item
14384that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
14385for Renesas microprocessors, or @samp{target e7000}, the in-circuit
14386emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
14387the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
14388H8/300, or H8/500.)
14389
14390@item
172c2a43 14391what serial device connects your host to your Renesas board (the first
8e04817f
AC
14392serial device available on your host is the default).
14393
14394@item
14395what speed to use over the serial device.
14396@end enumerate
14397
14398@menu
172c2a43
KI
14399* Renesas Boards:: Connecting to Renesas boards.
14400* Renesas ICE:: Using the E7000 In-Circuit Emulator.
14401* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
14402@end menu
14403
172c2a43
KI
14404@node Renesas Boards
14405@subsubsection Connecting to Renesas boards
8e04817f
AC
14406
14407@c only for Unix hosts
14408@kindex device
172c2a43 14409@cindex serial device, Renesas micros
8e04817f
AC
14410Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
14411need to explicitly set the serial device. The default @var{port} is the
14412first available port on your host. This is only necessary on Unix
14413hosts, where it is typically something like @file{/dev/ttya}.
14414
14415@kindex speed
172c2a43 14416@cindex serial line speed, Renesas micros
8e04817f
AC
14417@code{@value{GDBN}} has another special command to set the communications
14418speed: @samp{speed @var{bps}}. This command also is only used from Unix
14419hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
14420the DOS @code{mode} command (for instance,
14421@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
14422
14423The @samp{device} and @samp{speed} commands are available only when you
172c2a43 14424use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
14425use a DOS host,
14426@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
14427called @code{asynctsr} to communicate with the development board
14428through a PC serial port. You must also use the DOS @code{mode} command
14429to set up the serial port on the DOS side.
14430
14431The following sample session illustrates the steps needed to start a
14432program under @value{GDBN} control on an H8/300. The example uses a
14433sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 14434the Renesas SH and the H8/500.
8e04817f
AC
14435
14436First hook up your development board. In this example, we use a
14437board attached to serial port @code{COM2}; if you use a different serial
14438port, substitute its name in the argument of the @code{mode} command.
14439When you call @code{asynctsr}, the auxiliary comms program used by the
14440debugger, you give it just the numeric part of the serial port's name;
14441for example, @samp{asyncstr 2} below runs @code{asyncstr} on
14442@code{COM2}.
14443
474c8240 14444@smallexample
8e04817f
AC
14445C:\H8300\TEST> asynctsr 2
14446C:\H8300\TEST> mode com2:9600,n,8,1,p
14447
14448Resident portion of MODE loaded
14449
14450COM2: 9600, n, 8, 1, p
14451
474c8240 14452@end smallexample
8e04817f
AC
14453
14454@quotation
14455@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
14456@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
14457disable it, or even boot without it, to use @code{asynctsr} to control
14458your development board.
14459@end quotation
14460
14461@kindex target hms@r{, and serial protocol}
14462Now that serial communications are set up, and the development board is
9c16f35a 14463connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
14464the name of your program as the argument. @code{@value{GDBN}} prompts
14465you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
14466commands to begin your debugging session: @samp{target hms} to specify
172c2a43 14467cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
14468download your program to the board. @code{load} displays the names of
14469the program's sections, and a @samp{*} for each 2K of data downloaded.
14470(If you want to refresh @value{GDBN} data on symbols or on the
14471executable file without downloading, use the @value{GDBN} commands
14472@code{file} or @code{symbol-file}. These commands, and @code{load}
14473itself, are described in @ref{Files,,Commands to specify files}.)
14474
14475@smallexample
14476(eg-C:\H8300\TEST) @value{GDBP} t.x
14477@value{GDBN} is free software and you are welcome to distribute copies
14478 of it under certain conditions; type "show copying" to see
14479 the conditions.
14480There is absolutely no warranty for @value{GDBN}; type "show warranty"
14481for details.
14482@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
14483(@value{GDBP}) target hms
14484Connected to remote H8/300 HMS system.
14485(@value{GDBP}) load t.x
14486.text : 0x8000 .. 0xabde ***********
14487.data : 0xabde .. 0xad30 *
14488.stack : 0xf000 .. 0xf014 *
14489@end smallexample
14490
14491At this point, you're ready to run or debug your program. From here on,
14492you can use all the usual @value{GDBN} commands. The @code{break} command
14493sets breakpoints; the @code{run} command starts your program;
14494@code{print} or @code{x} display data; the @code{continue} command
14495resumes execution after stopping at a breakpoint. You can use the
14496@code{help} command at any time to find out more about @value{GDBN} commands.
14497
14498Remember, however, that @emph{operating system} facilities aren't
14499available on your development board; for example, if your program hangs,
14500you can't send an interrupt---but you can press the @sc{reset} switch!
14501
14502Use the @sc{reset} button on the development board
14503@itemize @bullet
14504@item
c8aa23ab 14505to interrupt your program (don't use @kbd{Ctrl-c} on the DOS host---it has
8e04817f
AC
14506no way to pass an interrupt signal to the development board); and
14507
14508@item
14509to return to the @value{GDBN} command prompt after your program finishes
14510normally. The communications protocol provides no other way for @value{GDBN}
14511to detect program completion.
14512@end itemize
14513
14514In either case, @value{GDBN} sees the effect of a @sc{reset} on the
14515development board as a ``normal exit'' of your program.
14516
172c2a43 14517@node Renesas ICE
8e04817f
AC
14518@subsubsection Using the E7000 in-circuit emulator
14519
172c2a43 14520@kindex target e7000@r{, with Renesas ICE}
8e04817f 14521You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 14522Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
14523e7000} command to connect @value{GDBN} to your E7000:
14524
14525@table @code
14526@item target e7000 @var{port} @var{speed}
14527Use this form if your E7000 is connected to a serial port. The
14528@var{port} argument identifies what serial port to use (for example,
14529@samp{com2}). The third argument is the line speed in bits per second
14530(for example, @samp{9600}).
14531
14532@item target e7000 @var{hostname}
14533If your E7000 is installed as a host on a TCP/IP network, you can just
14534specify its hostname; @value{GDBN} uses @code{telnet} to connect.
14535@end table
14536
ba04e063
EZ
14537The following special commands are available when debugging with the
14538Renesas E7000 ICE:
14539
14540@table @code
14541@item e7000 @var{command}
14542@kindex e7000
14543@cindex send command to E7000 monitor
14544This sends the specified @var{command} to the E7000 monitor.
14545
14546@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
14547@kindex ftplogin@r{, E7000}
14548This command records information for subsequent interface with the
14549E7000 monitor via the FTP protocol: @value{GDBN} will log into the
14550named @var{machine} using specified @var{username} and @var{password},
14551and then chdir to the named directory @var{dir}.
14552
14553@item ftpload @var{file}
14554@kindex ftpload@r{, E7000}
14555This command uses credentials recorded by @code{ftplogin} to fetch and
14556load the named @var{file} from the E7000 monitor.
14557
14558@item drain
14559@kindex drain@r{, E7000}
14560This command drains any pending text buffers stored on the E7000.
14561
14562@item set usehardbreakpoints
14563@itemx show usehardbreakpoints
14564@kindex set usehardbreakpoints@r{, E7000}
14565@kindex show usehardbreakpoints@r{, E7000}
14566@cindex hardware breakpoints, and E7000
14567These commands set and show the use of hardware breakpoints for all
14568breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
14569more information about using hardware breakpoints selectively.
14570@end table
14571
172c2a43
KI
14572@node Renesas Special
14573@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
14574
14575Some @value{GDBN} commands are available only for the H8/300:
14576
14577@table @code
14578
14579@kindex set machine
14580@kindex show machine
14581@item set machine h8300
14582@itemx set machine h8300h
14583Condition @value{GDBN} for one of the two variants of the H8/300
14584architecture with @samp{set machine}. You can use @samp{show machine}
14585to check which variant is currently in effect.
104c1213
JM
14586
14587@end table
14588
8e04817f
AC
14589@node H8/500
14590@subsection H8/500
104c1213
JM
14591
14592@table @code
14593
8e04817f
AC
14594@kindex set memory @var{mod}
14595@cindex memory models, H8/500
14596@item set memory @var{mod}
14597@itemx show memory
14598Specify which H8/500 memory model (@var{mod}) you are using with
14599@samp{set memory}; check which memory model is in effect with @samp{show
14600memory}. The accepted values for @var{mod} are @code{small},
14601@code{big}, @code{medium}, and @code{compact}.
104c1213 14602
8e04817f 14603@end table
104c1213 14604
8e04817f 14605@node M32R/D
ba04e063 14606@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
14607
14608@table @code
8e04817f
AC
14609@kindex target m32r
14610@item target m32r @var{dev}
172c2a43 14611Renesas M32R/D ROM monitor.
8e04817f 14612
fb3e19c0
KI
14613@kindex target m32rsdi
14614@item target m32rsdi @var{dev}
14615Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
14616@end table
14617
14618The following @value{GDBN} commands are specific to the M32R monitor:
14619
14620@table @code
14621@item set download-path @var{path}
14622@kindex set download-path
14623@cindex find downloadable @sc{srec} files (M32R)
14624Set the default path for finding donwloadable @sc{srec} files.
14625
14626@item show download-path
14627@kindex show download-path
14628Show the default path for downloadable @sc{srec} files.
fb3e19c0 14629
721c2651
EZ
14630@item set board-address @var{addr}
14631@kindex set board-address
14632@cindex M32-EVA target board address
14633Set the IP address for the M32R-EVA target board.
14634
14635@item show board-address
14636@kindex show board-address
14637Show the current IP address of the target board.
14638
14639@item set server-address @var{addr}
14640@kindex set server-address
14641@cindex download server address (M32R)
14642Set the IP address for the download server, which is the @value{GDBN}'s
14643host machine.
14644
14645@item show server-address
14646@kindex show server-address
14647Display the IP address of the download server.
14648
14649@item upload @r{[}@var{file}@r{]}
14650@kindex upload@r{, M32R}
14651Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14652upload capability. If no @var{file} argument is given, the current
14653executable file is uploaded.
14654
14655@item tload @r{[}@var{file}@r{]}
14656@kindex tload@r{, M32R}
14657Test the @code{upload} command.
8e04817f
AC
14658@end table
14659
ba04e063
EZ
14660The following commands are available for M32R/SDI:
14661
14662@table @code
14663@item sdireset
14664@kindex sdireset
14665@cindex reset SDI connection, M32R
14666This command resets the SDI connection.
14667
14668@item sdistatus
14669@kindex sdistatus
14670This command shows the SDI connection status.
14671
14672@item debug_chaos
14673@kindex debug_chaos
14674@cindex M32R/Chaos debugging
14675Instructs the remote that M32R/Chaos debugging is to be used.
14676
14677@item use_debug_dma
14678@kindex use_debug_dma
14679Instructs the remote to use the DEBUG_DMA method of accessing memory.
14680
14681@item use_mon_code
14682@kindex use_mon_code
14683Instructs the remote to use the MON_CODE method of accessing memory.
14684
14685@item use_ib_break
14686@kindex use_ib_break
14687Instructs the remote to set breakpoints by IB break.
14688
14689@item use_dbt_break
14690@kindex use_dbt_break
14691Instructs the remote to set breakpoints by DBT.
14692@end table
14693
8e04817f
AC
14694@node M68K
14695@subsection M68k
14696
14697The Motorola m68k configuration includes ColdFire support, and
14698target command for the following ROM monitors.
14699
14700@table @code
14701
14702@kindex target abug
14703@item target abug @var{dev}
14704ABug ROM monitor for M68K.
14705
14706@kindex target cpu32bug
14707@item target cpu32bug @var{dev}
14708CPU32BUG monitor, running on a CPU32 (M68K) board.
14709
14710@kindex target dbug
14711@item target dbug @var{dev}
14712dBUG ROM monitor for Motorola ColdFire.
14713
14714@kindex target est
14715@item target est @var{dev}
14716EST-300 ICE monitor, running on a CPU32 (M68K) board.
14717
14718@kindex target rom68k
14719@item target rom68k @var{dev}
14720ROM 68K monitor, running on an M68K IDP board.
14721
14722@end table
14723
8e04817f
AC
14724@table @code
14725
14726@kindex target rombug
14727@item target rombug @var{dev}
14728ROMBUG ROM monitor for OS/9000.
14729
14730@end table
14731
8e04817f
AC
14732@node MIPS Embedded
14733@subsection MIPS Embedded
14734
14735@cindex MIPS boards
14736@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14737MIPS board attached to a serial line. This is available when
14738you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14739
8e04817f
AC
14740@need 1000
14741Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14742
8e04817f
AC
14743@table @code
14744@item target mips @var{port}
14745@kindex target mips @var{port}
14746To run a program on the board, start up @code{@value{GDBP}} with the
14747name of your program as the argument. To connect to the board, use the
14748command @samp{target mips @var{port}}, where @var{port} is the name of
14749the serial port connected to the board. If the program has not already
14750been downloaded to the board, you may use the @code{load} command to
14751download it. You can then use all the usual @value{GDBN} commands.
104c1213 14752
8e04817f
AC
14753For example, this sequence connects to the target board through a serial
14754port, and loads and runs a program called @var{prog} through the
14755debugger:
104c1213 14756
474c8240 14757@smallexample
8e04817f
AC
14758host$ @value{GDBP} @var{prog}
14759@value{GDBN} is free software and @dots{}
14760(@value{GDBP}) target mips /dev/ttyb
14761(@value{GDBP}) load @var{prog}
14762(@value{GDBP}) run
474c8240 14763@end smallexample
104c1213 14764
8e04817f
AC
14765@item target mips @var{hostname}:@var{portnumber}
14766On some @value{GDBN} host configurations, you can specify a TCP
14767connection (for instance, to a serial line managed by a terminal
14768concentrator) instead of a serial port, using the syntax
14769@samp{@var{hostname}:@var{portnumber}}.
104c1213 14770
8e04817f
AC
14771@item target pmon @var{port}
14772@kindex target pmon @var{port}
14773PMON ROM monitor.
104c1213 14774
8e04817f
AC
14775@item target ddb @var{port}
14776@kindex target ddb @var{port}
14777NEC's DDB variant of PMON for Vr4300.
104c1213 14778
8e04817f
AC
14779@item target lsi @var{port}
14780@kindex target lsi @var{port}
14781LSI variant of PMON.
104c1213 14782
8e04817f
AC
14783@kindex target r3900
14784@item target r3900 @var{dev}
14785Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14786
8e04817f
AC
14787@kindex target array
14788@item target array @var{dev}
14789Array Tech LSI33K RAID controller board.
104c1213 14790
8e04817f 14791@end table
104c1213 14792
104c1213 14793
8e04817f
AC
14794@noindent
14795@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14796
8e04817f 14797@table @code
8e04817f
AC
14798@item set mipsfpu double
14799@itemx set mipsfpu single
14800@itemx set mipsfpu none
a64548ea 14801@itemx set mipsfpu auto
8e04817f
AC
14802@itemx show mipsfpu
14803@kindex set mipsfpu
14804@kindex show mipsfpu
14805@cindex MIPS remote floating point
14806@cindex floating point, MIPS remote
14807If your target board does not support the MIPS floating point
14808coprocessor, you should use the command @samp{set mipsfpu none} (if you
14809need this, you may wish to put the command in your @value{GDBN} init
14810file). This tells @value{GDBN} how to find the return value of
14811functions which return floating point values. It also allows
14812@value{GDBN} to avoid saving the floating point registers when calling
14813functions on the board. If you are using a floating point coprocessor
14814with only single precision floating point support, as on the @sc{r4650}
14815processor, use the command @samp{set mipsfpu single}. The default
14816double precision floating point coprocessor may be selected using
14817@samp{set mipsfpu double}.
104c1213 14818
8e04817f
AC
14819In previous versions the only choices were double precision or no
14820floating point, so @samp{set mipsfpu on} will select double precision
14821and @samp{set mipsfpu off} will select no floating point.
104c1213 14822
8e04817f
AC
14823As usual, you can inquire about the @code{mipsfpu} variable with
14824@samp{show mipsfpu}.
104c1213 14825
8e04817f
AC
14826@item set timeout @var{seconds}
14827@itemx set retransmit-timeout @var{seconds}
14828@itemx show timeout
14829@itemx show retransmit-timeout
14830@cindex @code{timeout}, MIPS protocol
14831@cindex @code{retransmit-timeout}, MIPS protocol
14832@kindex set timeout
14833@kindex show timeout
14834@kindex set retransmit-timeout
14835@kindex show retransmit-timeout
14836You can control the timeout used while waiting for a packet, in the MIPS
14837remote protocol, with the @code{set timeout @var{seconds}} command. The
14838default is 5 seconds. Similarly, you can control the timeout used while
14839waiting for an acknowledgement of a packet with the @code{set
14840retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14841You can inspect both values with @code{show timeout} and @code{show
14842retransmit-timeout}. (These commands are @emph{only} available when
14843@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14844
8e04817f
AC
14845The timeout set by @code{set timeout} does not apply when @value{GDBN}
14846is waiting for your program to stop. In that case, @value{GDBN} waits
14847forever because it has no way of knowing how long the program is going
14848to run before stopping.
ba04e063
EZ
14849
14850@item set syn-garbage-limit @var{num}
14851@kindex set syn-garbage-limit@r{, MIPS remote}
14852@cindex synchronize with remote MIPS target
14853Limit the maximum number of characters @value{GDBN} should ignore when
14854it tries to synchronize with the remote target. The default is 10
14855characters. Setting the limit to -1 means there's no limit.
14856
14857@item show syn-garbage-limit
14858@kindex show syn-garbage-limit@r{, MIPS remote}
14859Show the current limit on the number of characters to ignore when
14860trying to synchronize with the remote system.
14861
14862@item set monitor-prompt @var{prompt}
14863@kindex set monitor-prompt@r{, MIPS remote}
14864@cindex remote monitor prompt
14865Tell @value{GDBN} to expect the specified @var{prompt} string from the
14866remote monitor. The default depends on the target:
14867@table @asis
14868@item pmon target
14869@samp{PMON}
14870@item ddb target
14871@samp{NEC010}
14872@item lsi target
14873@samp{PMON>}
14874@end table
14875
14876@item show monitor-prompt
14877@kindex show monitor-prompt@r{, MIPS remote}
14878Show the current strings @value{GDBN} expects as the prompt from the
14879remote monitor.
14880
14881@item set monitor-warnings
14882@kindex set monitor-warnings@r{, MIPS remote}
14883Enable or disable monitor warnings about hardware breakpoints. This
14884has effect only for the @code{lsi} target. When on, @value{GDBN} will
14885display warning messages whose codes are returned by the @code{lsi}
14886PMON monitor for breakpoint commands.
14887
14888@item show monitor-warnings
14889@kindex show monitor-warnings@r{, MIPS remote}
14890Show the current setting of printing monitor warnings.
14891
14892@item pmon @var{command}
14893@kindex pmon@r{, MIPS remote}
14894@cindex send PMON command
14895This command allows sending an arbitrary @var{command} string to the
14896monitor. The monitor must be in debug mode for this to work.
8e04817f 14897@end table
104c1213 14898
a37295f9
MM
14899@node OpenRISC 1000
14900@subsection OpenRISC 1000
14901@cindex OpenRISC 1000
14902
14903@cindex or1k boards
14904See OR1k Architecture document (@uref{www.opencores.org}) for more information
14905about platform and commands.
14906
14907@table @code
14908
14909@kindex target jtag
14910@item target jtag jtag://@var{host}:@var{port}
14911
14912Connects to remote JTAG server.
14913JTAG remote server can be either an or1ksim or JTAG server,
14914connected via parallel port to the board.
14915
14916Example: @code{target jtag jtag://localhost:9999}
14917
14918@kindex or1ksim
14919@item or1ksim @var{command}
14920If connected to @code{or1ksim} OpenRISC 1000 Architectural
14921Simulator, proprietary commands can be executed.
14922
14923@kindex info or1k spr
14924@item info or1k spr
14925Displays spr groups.
14926
14927@item info or1k spr @var{group}
14928@itemx info or1k spr @var{groupno}
14929Displays register names in selected group.
14930
14931@item info or1k spr @var{group} @var{register}
14932@itemx info or1k spr @var{register}
14933@itemx info or1k spr @var{groupno} @var{registerno}
14934@itemx info or1k spr @var{registerno}
14935Shows information about specified spr register.
14936
14937@kindex spr
14938@item spr @var{group} @var{register} @var{value}
14939@itemx spr @var{register @var{value}}
14940@itemx spr @var{groupno} @var{registerno @var{value}}
14941@itemx spr @var{registerno @var{value}}
14942Writes @var{value} to specified spr register.
14943@end table
14944
14945Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14946It is very similar to @value{GDBN} trace, except it does not interfere with normal
14947program execution and is thus much faster. Hardware breakpoints/watchpoint
14948triggers can be set using:
14949@table @code
14950@item $LEA/$LDATA
14951Load effective address/data
14952@item $SEA/$SDATA
14953Store effective address/data
14954@item $AEA/$ADATA
14955Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14956@item $FETCH
14957Fetch data
14958@end table
14959
14960When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14961@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14962
14963@code{htrace} commands:
14964@cindex OpenRISC 1000 htrace
14965@table @code
14966@kindex hwatch
14967@item hwatch @var{conditional}
14968Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14969or Data. For example:
14970
14971@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14972
14973@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14974
4644b6e3 14975@kindex htrace
a37295f9
MM
14976@item htrace info
14977Display information about current HW trace configuration.
14978
a37295f9
MM
14979@item htrace trigger @var{conditional}
14980Set starting criteria for HW trace.
14981
a37295f9
MM
14982@item htrace qualifier @var{conditional}
14983Set acquisition qualifier for HW trace.
14984
a37295f9
MM
14985@item htrace stop @var{conditional}
14986Set HW trace stopping criteria.
14987
f153cc92 14988@item htrace record [@var{data}]*
a37295f9
MM
14989Selects the data to be recorded, when qualifier is met and HW trace was
14990triggered.
14991
a37295f9 14992@item htrace enable
a37295f9
MM
14993@itemx htrace disable
14994Enables/disables the HW trace.
14995
f153cc92 14996@item htrace rewind [@var{filename}]
a37295f9
MM
14997Clears currently recorded trace data.
14998
14999If filename is specified, new trace file is made and any newly collected data
15000will be written there.
15001
f153cc92 15002@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
15003Prints trace buffer, using current record configuration.
15004
a37295f9
MM
15005@item htrace mode continuous
15006Set continuous trace mode.
15007
a37295f9
MM
15008@item htrace mode suspend
15009Set suspend trace mode.
15010
15011@end table
15012
8e04817f
AC
15013@node PowerPC
15014@subsection PowerPC
104c1213
JM
15015
15016@table @code
8e04817f
AC
15017@kindex target dink32
15018@item target dink32 @var{dev}
15019DINK32 ROM monitor.
104c1213 15020
8e04817f
AC
15021@kindex target ppcbug
15022@item target ppcbug @var{dev}
15023@kindex target ppcbug1
15024@item target ppcbug1 @var{dev}
15025PPCBUG ROM monitor for PowerPC.
104c1213 15026
8e04817f
AC
15027@kindex target sds
15028@item target sds @var{dev}
15029SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 15030@end table
8e04817f 15031
c45da7e6
EZ
15032@cindex SDS protocol
15033The following commands specifi to the SDS protocol are supported
15034by@value{GDBN}:
15035
15036@table @code
15037@item set sdstimeout @var{nsec}
15038@kindex set sdstimeout
15039Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
15040default is 2 seconds.
15041
15042@item show sdstimeout
15043@kindex show sdstimeout
15044Show the current value of the SDS timeout.
15045
15046@item sds @var{command}
15047@kindex sds@r{, a command}
15048Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
15049@end table
15050
c45da7e6 15051
8e04817f
AC
15052@node PA
15053@subsection HP PA Embedded
104c1213
JM
15054
15055@table @code
15056
8e04817f
AC
15057@kindex target op50n
15058@item target op50n @var{dev}
15059OP50N monitor, running on an OKI HPPA board.
15060
15061@kindex target w89k
15062@item target w89k @var{dev}
15063W89K monitor, running on a Winbond HPPA board.
104c1213
JM
15064
15065@end table
15066
8e04817f 15067@node SH
172c2a43 15068@subsection Renesas SH
104c1213
JM
15069
15070@table @code
15071
172c2a43 15072@kindex target hms@r{, with Renesas SH}
8e04817f 15073@item target hms @var{dev}
172c2a43 15074A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
15075commands @code{device} and @code{speed} to control the serial line and
15076the communications speed used.
104c1213 15077
172c2a43 15078@kindex target e7000@r{, with Renesas SH}
8e04817f 15079@item target e7000 @var{dev}
172c2a43 15080E7000 emulator for Renesas SH.
104c1213 15081
8e04817f
AC
15082@kindex target sh3@r{, with SH}
15083@kindex target sh3e@r{, with SH}
15084@item target sh3 @var{dev}
15085@item target sh3e @var{dev}
172c2a43 15086Renesas SH-3 and SH-3E target systems.
104c1213 15087
8e04817f 15088@end table
104c1213 15089
8e04817f
AC
15090@node Sparclet
15091@subsection Tsqware Sparclet
104c1213 15092
8e04817f
AC
15093@cindex Sparclet
15094
15095@value{GDBN} enables developers to debug tasks running on
15096Sparclet targets from a Unix host.
15097@value{GDBN} uses code that runs on
15098both the Unix host and on the Sparclet target. The program
15099@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 15100
8e04817f
AC
15101@table @code
15102@item remotetimeout @var{args}
15103@kindex remotetimeout
15104@value{GDBN} supports the option @code{remotetimeout}.
15105This option is set by the user, and @var{args} represents the number of
15106seconds @value{GDBN} waits for responses.
104c1213
JM
15107@end table
15108
8e04817f
AC
15109@cindex compiling, on Sparclet
15110When compiling for debugging, include the options @samp{-g} to get debug
15111information and @samp{-Ttext} to relocate the program to where you wish to
15112load it on the target. You may also want to add the options @samp{-n} or
15113@samp{-N} in order to reduce the size of the sections. Example:
104c1213 15114
474c8240 15115@smallexample
8e04817f 15116sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 15117@end smallexample
104c1213 15118
8e04817f 15119You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 15120
474c8240 15121@smallexample
8e04817f 15122sparclet-aout-objdump --headers --syms prog
474c8240 15123@end smallexample
104c1213 15124
8e04817f
AC
15125@cindex running, on Sparclet
15126Once you have set
15127your Unix execution search path to find @value{GDBN}, you are ready to
15128run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
15129(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 15130
8e04817f
AC
15131@value{GDBN} comes up showing the prompt:
15132
474c8240 15133@smallexample
8e04817f 15134(gdbslet)
474c8240 15135@end smallexample
104c1213
JM
15136
15137@menu
8e04817f
AC
15138* Sparclet File:: Setting the file to debug
15139* Sparclet Connection:: Connecting to Sparclet
15140* Sparclet Download:: Sparclet download
15141* Sparclet Execution:: Running and debugging
104c1213
JM
15142@end menu
15143
8e04817f
AC
15144@node Sparclet File
15145@subsubsection Setting file to debug
104c1213 15146
8e04817f 15147The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 15148
474c8240 15149@smallexample
8e04817f 15150(gdbslet) file prog
474c8240 15151@end smallexample
104c1213 15152
8e04817f
AC
15153@need 1000
15154@value{GDBN} then attempts to read the symbol table of @file{prog}.
15155@value{GDBN} locates
15156the file by searching the directories listed in the command search
15157path.
15158If the file was compiled with debug information (option "-g"), source
15159files will be searched as well.
15160@value{GDBN} locates
15161the source files by searching the directories listed in the directory search
15162path (@pxref{Environment, ,Your program's environment}).
15163If it fails
15164to find a file, it displays a message such as:
104c1213 15165
474c8240 15166@smallexample
8e04817f 15167prog: No such file or directory.
474c8240 15168@end smallexample
104c1213 15169
8e04817f
AC
15170When this happens, add the appropriate directories to the search paths with
15171the @value{GDBN} commands @code{path} and @code{dir}, and execute the
15172@code{target} command again.
104c1213 15173
8e04817f
AC
15174@node Sparclet Connection
15175@subsubsection Connecting to Sparclet
104c1213 15176
8e04817f
AC
15177The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
15178To connect to a target on serial port ``@code{ttya}'', type:
104c1213 15179
474c8240 15180@smallexample
8e04817f
AC
15181(gdbslet) target sparclet /dev/ttya
15182Remote target sparclet connected to /dev/ttya
15183main () at ../prog.c:3
474c8240 15184@end smallexample
104c1213 15185
8e04817f
AC
15186@need 750
15187@value{GDBN} displays messages like these:
104c1213 15188
474c8240 15189@smallexample
8e04817f 15190Connected to ttya.
474c8240 15191@end smallexample
104c1213 15192
8e04817f
AC
15193@node Sparclet Download
15194@subsubsection Sparclet download
104c1213 15195
8e04817f
AC
15196@cindex download to Sparclet
15197Once connected to the Sparclet target,
15198you can use the @value{GDBN}
15199@code{load} command to download the file from the host to the target.
15200The file name and load offset should be given as arguments to the @code{load}
15201command.
15202Since the file format is aout, the program must be loaded to the starting
15203address. You can use @code{objdump} to find out what this value is. The load
15204offset is an offset which is added to the VMA (virtual memory address)
15205of each of the file's sections.
15206For instance, if the program
15207@file{prog} was linked to text address 0x1201000, with data at 0x12010160
15208and bss at 0x12010170, in @value{GDBN}, type:
104c1213 15209
474c8240 15210@smallexample
8e04817f
AC
15211(gdbslet) load prog 0x12010000
15212Loading section .text, size 0xdb0 vma 0x12010000
474c8240 15213@end smallexample
104c1213 15214
8e04817f
AC
15215If the code is loaded at a different address then what the program was linked
15216to, you may need to use the @code{section} and @code{add-symbol-file} commands
15217to tell @value{GDBN} where to map the symbol table.
15218
15219@node Sparclet Execution
15220@subsubsection Running and debugging
15221
15222@cindex running and debugging Sparclet programs
15223You can now begin debugging the task using @value{GDBN}'s execution control
15224commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
15225manual for the list of commands.
15226
474c8240 15227@smallexample
8e04817f
AC
15228(gdbslet) b main
15229Breakpoint 1 at 0x12010000: file prog.c, line 3.
15230(gdbslet) run
15231Starting program: prog
15232Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
152333 char *symarg = 0;
15234(gdbslet) step
152354 char *execarg = "hello!";
15236(gdbslet)
474c8240 15237@end smallexample
8e04817f
AC
15238
15239@node Sparclite
15240@subsection Fujitsu Sparclite
104c1213
JM
15241
15242@table @code
15243
8e04817f
AC
15244@kindex target sparclite
15245@item target sparclite @var{dev}
15246Fujitsu sparclite boards, used only for the purpose of loading.
15247You must use an additional command to debug the program.
15248For example: target remote @var{dev} using @value{GDBN} standard
15249remote protocol.
104c1213
JM
15250
15251@end table
15252
8e04817f
AC
15253@node ST2000
15254@subsection Tandem ST2000
104c1213 15255
8e04817f
AC
15256@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
15257STDBUG protocol.
104c1213 15258
8e04817f
AC
15259To connect your ST2000 to the host system, see the manufacturer's
15260manual. Once the ST2000 is physically attached, you can run:
104c1213 15261
474c8240 15262@smallexample
8e04817f 15263target st2000 @var{dev} @var{speed}
474c8240 15264@end smallexample
104c1213 15265
8e04817f
AC
15266@noindent
15267to establish it as your debugging environment. @var{dev} is normally
15268the name of a serial device, such as @file{/dev/ttya}, connected to the
15269ST2000 via a serial line. You can instead specify @var{dev} as a TCP
15270connection (for example, to a serial line attached via a terminal
15271concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 15272
8e04817f
AC
15273The @code{load} and @code{attach} commands are @emph{not} defined for
15274this target; you must load your program into the ST2000 as you normally
15275would for standalone operation. @value{GDBN} reads debugging information
15276(such as symbols) from a separate, debugging version of the program
15277available on your host computer.
15278@c FIXME!! This is terribly vague; what little content is here is
15279@c basically hearsay.
104c1213 15280
8e04817f
AC
15281@cindex ST2000 auxiliary commands
15282These auxiliary @value{GDBN} commands are available to help you with the ST2000
15283environment:
104c1213 15284
8e04817f
AC
15285@table @code
15286@item st2000 @var{command}
15287@kindex st2000 @var{cmd}
15288@cindex STDBUG commands (ST2000)
15289@cindex commands to STDBUG (ST2000)
15290Send a @var{command} to the STDBUG monitor. See the manufacturer's
15291manual for available commands.
104c1213 15292
8e04817f
AC
15293@item connect
15294@cindex connect (to STDBUG)
15295Connect the controlling terminal to the STDBUG command monitor. When
15296you are done interacting with STDBUG, typing either of two character
15297sequences gets you back to the @value{GDBN} command prompt:
7f9087cb 15298@kbd{@key{RET} ~ .} (Return, followed by tilde and period) or
58955e58 15299@kbd{@key{RET} ~ Ctrl-d} (Return, followed by tilde and control-D).
104c1213
JM
15300@end table
15301
8e04817f
AC
15302@node Z8000
15303@subsection Zilog Z8000
104c1213 15304
8e04817f
AC
15305@cindex Z8000
15306@cindex simulator, Z8000
15307@cindex Zilog Z8000 simulator
104c1213 15308
8e04817f
AC
15309When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
15310a Z8000 simulator.
15311
15312For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
15313unsegmented variant of the Z8000 architecture) or the Z8001 (the
15314segmented variant). The simulator recognizes which architecture is
15315appropriate by inspecting the object code.
104c1213 15316
8e04817f
AC
15317@table @code
15318@item target sim @var{args}
15319@kindex sim
15320@kindex target sim@r{, with Z8000}
15321Debug programs on a simulated CPU. If the simulator supports setup
15322options, specify them via @var{args}.
104c1213
JM
15323@end table
15324
8e04817f
AC
15325@noindent
15326After specifying this target, you can debug programs for the simulated
15327CPU in the same style as programs for your host computer; use the
15328@code{file} command to load a new program image, the @code{run} command
15329to run your program, and so on.
15330
15331As well as making available all the usual machine registers
15332(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
15333additional items of information as specially named registers:
104c1213
JM
15334
15335@table @code
15336
8e04817f
AC
15337@item cycles
15338Counts clock-ticks in the simulator.
104c1213 15339
8e04817f
AC
15340@item insts
15341Counts instructions run in the simulator.
104c1213 15342
8e04817f
AC
15343@item time
15344Execution time in 60ths of a second.
104c1213 15345
8e04817f 15346@end table
104c1213 15347
8e04817f
AC
15348You can refer to these values in @value{GDBN} expressions with the usual
15349conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
15350conditional breakpoint that suspends only after at least 5000
15351simulated clock ticks.
104c1213 15352
a64548ea
EZ
15353@node AVR
15354@subsection Atmel AVR
15355@cindex AVR
15356
15357When configured for debugging the Atmel AVR, @value{GDBN} supports the
15358following AVR-specific commands:
15359
15360@table @code
15361@item info io_registers
15362@kindex info io_registers@r{, AVR}
15363@cindex I/O registers (Atmel AVR)
15364This command displays information about the AVR I/O registers. For
15365each register, @value{GDBN} prints its number and value.
15366@end table
15367
15368@node CRIS
15369@subsection CRIS
15370@cindex CRIS
15371
15372When configured for debugging CRIS, @value{GDBN} provides the
15373following CRIS-specific commands:
15374
15375@table @code
15376@item set cris-version @var{ver}
15377@cindex CRIS version
e22e55c9
OF
15378Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
15379The CRIS version affects register names and sizes. This command is useful in
15380case autodetection of the CRIS version fails.
a64548ea
EZ
15381
15382@item show cris-version
15383Show the current CRIS version.
15384
15385@item set cris-dwarf2-cfi
15386@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
15387Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
15388Change to @samp{off} when using @code{gcc-cris} whose version is below
15389@code{R59}.
a64548ea
EZ
15390
15391@item show cris-dwarf2-cfi
15392Show the current state of using DWARF-2 CFI.
e22e55c9
OF
15393
15394@item set cris-mode @var{mode}
15395@cindex CRIS mode
15396Set the current CRIS mode to @var{mode}. It should only be changed when
15397debugging in guru mode, in which case it should be set to
15398@samp{guru} (the default is @samp{normal}).
15399
15400@item show cris-mode
15401Show the current CRIS mode.
a64548ea
EZ
15402@end table
15403
15404@node Super-H
15405@subsection Renesas Super-H
15406@cindex Super-H
15407
15408For the Renesas Super-H processor, @value{GDBN} provides these
15409commands:
15410
15411@table @code
15412@item regs
15413@kindex regs@r{, Super-H}
15414Show the values of all Super-H registers.
15415@end table
15416
c45da7e6
EZ
15417@node WinCE
15418@subsection Windows CE
15419@cindex Windows CE
15420
15421The following commands are available for Windows CE:
15422
15423@table @code
15424@item set remotedirectory @var{dir}
15425@kindex set remotedirectory
15426Tell @value{GDBN} to upload files from the named directory @var{dir}.
15427The default is @file{/gdb}, i.e.@: the root directory on the current
15428drive.
15429
15430@item show remotedirectory
15431@kindex show remotedirectory
15432Show the current value of the upload directory.
15433
15434@item set remoteupload @var{method}
15435@kindex set remoteupload
15436Set the method used to upload files to remote device. Valid values
15437for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
15438The default is @samp{newer}.
15439
15440@item show remoteupload
15441@kindex show remoteupload
15442Show the current setting of the upload method.
15443
15444@item set remoteaddhost
15445@kindex set remoteaddhost
15446Tell @value{GDBN} whether to add this host to the remote stub's
15447arguments when you debug over a network.
15448
15449@item show remoteaddhost
15450@kindex show remoteaddhost
15451Show whether to add this host to remote stub's arguments when
15452debugging over a network.
15453@end table
15454
a64548ea 15455
8e04817f
AC
15456@node Architectures
15457@section Architectures
104c1213 15458
8e04817f
AC
15459This section describes characteristics of architectures that affect
15460all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 15461
8e04817f 15462@menu
9c16f35a 15463* i386::
8e04817f
AC
15464* A29K::
15465* Alpha::
15466* MIPS::
a64548ea 15467* HPPA:: HP PA architecture
8e04817f 15468@end menu
104c1213 15469
9c16f35a
EZ
15470@node i386
15471@subsection x86 Architecture-specific issues.
15472
15473@table @code
15474@item set struct-convention @var{mode}
15475@kindex set struct-convention
15476@cindex struct return convention
15477@cindex struct/union returned in registers
15478Set the convention used by the inferior to return @code{struct}s and
15479@code{union}s from functions to @var{mode}. Possible values of
15480@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
15481default). @code{"default"} or @code{"pcc"} means that @code{struct}s
15482are returned on the stack, while @code{"reg"} means that a
15483@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
15484be returned in a register.
15485
15486@item show struct-convention
15487@kindex show struct-convention
15488Show the current setting of the convention to return @code{struct}s
15489from functions.
15490@end table
15491
8e04817f
AC
15492@node A29K
15493@subsection A29K
104c1213
JM
15494
15495@table @code
104c1213 15496
8e04817f
AC
15497@kindex set rstack_high_address
15498@cindex AMD 29K register stack
15499@cindex register stack, AMD29K
15500@item set rstack_high_address @var{address}
15501On AMD 29000 family processors, registers are saved in a separate
15502@dfn{register stack}. There is no way for @value{GDBN} to determine the
15503extent of this stack. Normally, @value{GDBN} just assumes that the
15504stack is ``large enough''. This may result in @value{GDBN} referencing
15505memory locations that do not exist. If necessary, you can get around
15506this problem by specifying the ending address of the register stack with
15507the @code{set rstack_high_address} command. The argument should be an
15508address, which you probably want to precede with @samp{0x} to specify in
15509hexadecimal.
104c1213 15510
8e04817f
AC
15511@kindex show rstack_high_address
15512@item show rstack_high_address
15513Display the current limit of the register stack, on AMD 29000 family
15514processors.
104c1213 15515
8e04817f 15516@end table
104c1213 15517
8e04817f
AC
15518@node Alpha
15519@subsection Alpha
104c1213 15520
8e04817f 15521See the following section.
104c1213 15522
8e04817f
AC
15523@node MIPS
15524@subsection MIPS
104c1213 15525
8e04817f
AC
15526@cindex stack on Alpha
15527@cindex stack on MIPS
15528@cindex Alpha stack
15529@cindex MIPS stack
15530Alpha- and MIPS-based computers use an unusual stack frame, which
15531sometimes requires @value{GDBN} to search backward in the object code to
15532find the beginning of a function.
104c1213 15533
8e04817f
AC
15534@cindex response time, MIPS debugging
15535To improve response time (especially for embedded applications, where
15536@value{GDBN} may be restricted to a slow serial line for this search)
15537you may want to limit the size of this search, using one of these
15538commands:
104c1213 15539
8e04817f
AC
15540@table @code
15541@cindex @code{heuristic-fence-post} (Alpha, MIPS)
15542@item set heuristic-fence-post @var{limit}
15543Restrict @value{GDBN} to examining at most @var{limit} bytes in its
15544search for the beginning of a function. A value of @var{0} (the
15545default) means there is no limit. However, except for @var{0}, the
15546larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
15547and therefore the longer it takes to run. You should only need to use
15548this command when debugging a stripped executable.
104c1213 15549
8e04817f
AC
15550@item show heuristic-fence-post
15551Display the current limit.
15552@end table
104c1213
JM
15553
15554@noindent
8e04817f
AC
15555These commands are available @emph{only} when @value{GDBN} is configured
15556for debugging programs on Alpha or MIPS processors.
104c1213 15557
a64548ea
EZ
15558Several MIPS-specific commands are available when debugging MIPS
15559programs:
15560
15561@table @code
15562@item set mips saved-gpreg-size @var{size}
15563@kindex set mips saved-gpreg-size
15564@cindex MIPS GP register size on stack
15565Set the size of MIPS general-purpose registers saved on the stack.
15566The argument @var{size} can be one of the following:
15567
15568@table @samp
15569@item 32
1557032-bit GP registers
15571@item 64
1557264-bit GP registers
15573@item auto
15574Use the target's default setting or autodetect the saved size from the
15575information contained in the executable. This is the default
15576@end table
15577
15578@item show mips saved-gpreg-size
15579@kindex show mips saved-gpreg-size
15580Show the current size of MIPS GP registers on the stack.
15581
15582@item set mips stack-arg-size @var{size}
15583@kindex set mips stack-arg-size
15584@cindex MIPS stack space for arguments
15585Set the amount of stack space reserved for arguments to functions.
15586The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
15587(the default).
15588
15589@item set mips abi @var{arg}
15590@kindex set mips abi
15591@cindex set ABI for MIPS
15592Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
15593values of @var{arg} are:
15594
15595@table @samp
15596@item auto
15597The default ABI associated with the current binary (this is the
15598default).
15599@item o32
15600@item o64
15601@item n32
15602@item n64
15603@item eabi32
15604@item eabi64
15605@item auto
15606@end table
15607
15608@item show mips abi
15609@kindex show mips abi
15610Show the MIPS ABI used by @value{GDBN} to debug the inferior.
15611
15612@item set mipsfpu
15613@itemx show mipsfpu
15614@xref{MIPS Embedded, set mipsfpu}.
15615
15616@item set mips mask-address @var{arg}
15617@kindex set mips mask-address
15618@cindex MIPS addresses, masking
15619This command determines whether the most-significant 32 bits of 64-bit
15620MIPS addresses are masked off. The argument @var{arg} can be
15621@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
15622setting, which lets @value{GDBN} determine the correct value.
15623
15624@item show mips mask-address
15625@kindex show mips mask-address
15626Show whether the upper 32 bits of MIPS addresses are masked off or
15627not.
15628
15629@item set remote-mips64-transfers-32bit-regs
15630@kindex set remote-mips64-transfers-32bit-regs
15631This command controls compatibility with 64-bit MIPS targets that
15632transfer data in 32-bit quantities. If you have an old MIPS 64 target
15633that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
15634and 64 bits for other registers, set this option to @samp{on}.
15635
15636@item show remote-mips64-transfers-32bit-regs
15637@kindex show remote-mips64-transfers-32bit-regs
15638Show the current setting of compatibility with older MIPS 64 targets.
15639
15640@item set debug mips
15641@kindex set debug mips
15642This command turns on and off debugging messages for the MIPS-specific
15643target code in @value{GDBN}.
15644
15645@item show debug mips
15646@kindex show debug mips
15647Show the current setting of MIPS debugging messages.
15648@end table
15649
15650
15651@node HPPA
15652@subsection HPPA
15653@cindex HPPA support
15654
15655When @value{GDBN} is debugging te HP PA architecture, it provides the
15656following special commands:
15657
15658@table @code
15659@item set debug hppa
15660@kindex set debug hppa
15661THis command determines whether HPPA architecture specific debugging
15662messages are to be displayed.
15663
15664@item show debug hppa
15665Show whether HPPA debugging messages are displayed.
15666
15667@item maint print unwind @var{address}
15668@kindex maint print unwind@r{, HPPA}
15669This command displays the contents of the unwind table entry at the
15670given @var{address}.
15671
15672@end table
15673
104c1213 15674
8e04817f
AC
15675@node Controlling GDB
15676@chapter Controlling @value{GDBN}
15677
15678You can alter the way @value{GDBN} interacts with you by using the
15679@code{set} command. For commands controlling how @value{GDBN} displays
15680data, see @ref{Print Settings, ,Print settings}. Other settings are
15681described here.
15682
15683@menu
15684* Prompt:: Prompt
15685* Editing:: Command editing
d620b259 15686* Command History:: Command history
8e04817f
AC
15687* Screen Size:: Screen size
15688* Numbers:: Numbers
1e698235 15689* ABI:: Configuring the current ABI
8e04817f
AC
15690* Messages/Warnings:: Optional warnings and messages
15691* Debugging Output:: Optional messages about internal happenings
15692@end menu
15693
15694@node Prompt
15695@section Prompt
104c1213 15696
8e04817f 15697@cindex prompt
104c1213 15698
8e04817f
AC
15699@value{GDBN} indicates its readiness to read a command by printing a string
15700called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15701can change the prompt string with the @code{set prompt} command. For
15702instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15703the prompt in one of the @value{GDBN} sessions so that you can always tell
15704which one you are talking to.
104c1213 15705
8e04817f
AC
15706@emph{Note:} @code{set prompt} does not add a space for you after the
15707prompt you set. This allows you to set a prompt which ends in a space
15708or a prompt that does not.
104c1213 15709
8e04817f
AC
15710@table @code
15711@kindex set prompt
15712@item set prompt @var{newprompt}
15713Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15714
8e04817f
AC
15715@kindex show prompt
15716@item show prompt
15717Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15718@end table
15719
8e04817f
AC
15720@node Editing
15721@section Command editing
15722@cindex readline
15723@cindex command line editing
104c1213 15724
703663ab 15725@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15726@sc{gnu} library provides consistent behavior for programs which provide a
15727command line interface to the user. Advantages are @sc{gnu} Emacs-style
15728or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15729substitution, and a storage and recall of command history across
15730debugging sessions.
104c1213 15731
8e04817f
AC
15732You may control the behavior of command line editing in @value{GDBN} with the
15733command @code{set}.
104c1213 15734
8e04817f
AC
15735@table @code
15736@kindex set editing
15737@cindex editing
15738@item set editing
15739@itemx set editing on
15740Enable command line editing (enabled by default).
104c1213 15741
8e04817f
AC
15742@item set editing off
15743Disable command line editing.
104c1213 15744
8e04817f
AC
15745@kindex show editing
15746@item show editing
15747Show whether command line editing is enabled.
104c1213
JM
15748@end table
15749
703663ab
EZ
15750@xref{Command Line Editing}, for more details about the Readline
15751interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15752encouraged to read that chapter.
15753
d620b259 15754@node Command History
8e04817f 15755@section Command history
703663ab 15756@cindex command history
8e04817f
AC
15757
15758@value{GDBN} can keep track of the commands you type during your
15759debugging sessions, so that you can be certain of precisely what
15760happened. Use these commands to manage the @value{GDBN} command
15761history facility.
104c1213 15762
703663ab
EZ
15763@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15764package, to provide the history facility. @xref{Using History
15765Interactively}, for the detailed description of the History library.
15766
d620b259
NR
15767To issue a command to @value{GDBN} without affecting certain aspects of
15768the state which is seen by users, prefix it with @samp{server }. This
15769means that this command will not affect the command history, nor will it
15770affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15771pressed on a line by itself.
15772
15773@cindex @code{server}, command prefix
15774The server prefix does not affect the recording of values into the value
15775history; to print a value without recording it into the value history,
15776use the @code{output} command instead of the @code{print} command.
15777
703663ab
EZ
15778Here is the description of @value{GDBN} commands related to command
15779history.
15780
104c1213 15781@table @code
8e04817f
AC
15782@cindex history substitution
15783@cindex history file
15784@kindex set history filename
4644b6e3 15785@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15786@item set history filename @var{fname}
15787Set the name of the @value{GDBN} command history file to @var{fname}.
15788This is the file where @value{GDBN} reads an initial command history
15789list, and where it writes the command history from this session when it
15790exits. You can access this list through history expansion or through
15791the history command editing characters listed below. This file defaults
15792to the value of the environment variable @code{GDBHISTFILE}, or to
15793@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15794is not set.
104c1213 15795
9c16f35a
EZ
15796@cindex save command history
15797@kindex set history save
8e04817f
AC
15798@item set history save
15799@itemx set history save on
15800Record command history in a file, whose name may be specified with the
15801@code{set history filename} command. By default, this option is disabled.
104c1213 15802
8e04817f
AC
15803@item set history save off
15804Stop recording command history in a file.
104c1213 15805
8e04817f 15806@cindex history size
9c16f35a 15807@kindex set history size
6fc08d32 15808@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15809@item set history size @var{size}
15810Set the number of commands which @value{GDBN} keeps in its history list.
15811This defaults to the value of the environment variable
15812@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15813@end table
15814
8e04817f 15815History expansion assigns special meaning to the character @kbd{!}.
703663ab 15816@xref{Event Designators}, for more details.
8e04817f 15817
703663ab 15818@cindex history expansion, turn on/off
8e04817f
AC
15819Since @kbd{!} is also the logical not operator in C, history expansion
15820is off by default. If you decide to enable history expansion with the
15821@code{set history expansion on} command, you may sometimes need to
15822follow @kbd{!} (when it is used as logical not, in an expression) with
15823a space or a tab to prevent it from being expanded. The readline
15824history facilities do not attempt substitution on the strings
15825@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15826
15827The commands to control history expansion are:
104c1213
JM
15828
15829@table @code
8e04817f
AC
15830@item set history expansion on
15831@itemx set history expansion
703663ab 15832@kindex set history expansion
8e04817f 15833Enable history expansion. History expansion is off by default.
104c1213 15834
8e04817f
AC
15835@item set history expansion off
15836Disable history expansion.
104c1213 15837
8e04817f
AC
15838@c @group
15839@kindex show history
15840@item show history
15841@itemx show history filename
15842@itemx show history save
15843@itemx show history size
15844@itemx show history expansion
15845These commands display the state of the @value{GDBN} history parameters.
15846@code{show history} by itself displays all four states.
15847@c @end group
15848@end table
15849
15850@table @code
9c16f35a
EZ
15851@kindex show commands
15852@cindex show last commands
15853@cindex display command history
8e04817f
AC
15854@item show commands
15855Display the last ten commands in the command history.
104c1213 15856
8e04817f
AC
15857@item show commands @var{n}
15858Print ten commands centered on command number @var{n}.
15859
15860@item show commands +
15861Print ten commands just after the commands last printed.
104c1213
JM
15862@end table
15863
8e04817f
AC
15864@node Screen Size
15865@section Screen size
15866@cindex size of screen
15867@cindex pauses in output
104c1213 15868
8e04817f
AC
15869Certain commands to @value{GDBN} may produce large amounts of
15870information output to the screen. To help you read all of it,
15871@value{GDBN} pauses and asks you for input at the end of each page of
15872output. Type @key{RET} when you want to continue the output, or @kbd{q}
15873to discard the remaining output. Also, the screen width setting
15874determines when to wrap lines of output. Depending on what is being
15875printed, @value{GDBN} tries to break the line at a readable place,
15876rather than simply letting it overflow onto the following line.
15877
15878Normally @value{GDBN} knows the size of the screen from the terminal
15879driver software. For example, on Unix @value{GDBN} uses the termcap data base
15880together with the value of the @code{TERM} environment variable and the
15881@code{stty rows} and @code{stty cols} settings. If this is not correct,
15882you can override it with the @code{set height} and @code{set
15883width} commands:
15884
15885@table @code
15886@kindex set height
15887@kindex set width
15888@kindex show width
15889@kindex show height
15890@item set height @var{lpp}
15891@itemx show height
15892@itemx set width @var{cpl}
15893@itemx show width
15894These @code{set} commands specify a screen height of @var{lpp} lines and
15895a screen width of @var{cpl} characters. The associated @code{show}
15896commands display the current settings.
104c1213 15897
8e04817f
AC
15898If you specify a height of zero lines, @value{GDBN} does not pause during
15899output no matter how long the output is. This is useful if output is to a
15900file or to an editor buffer.
104c1213 15901
8e04817f
AC
15902Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15903from wrapping its output.
9c16f35a
EZ
15904
15905@item set pagination on
15906@itemx set pagination off
15907@kindex set pagination
15908Turn the output pagination on or off; the default is on. Turning
15909pagination off is the alternative to @code{set height 0}.
15910
15911@item show pagination
15912@kindex show pagination
15913Show the current pagination mode.
104c1213
JM
15914@end table
15915
8e04817f
AC
15916@node Numbers
15917@section Numbers
15918@cindex number representation
15919@cindex entering numbers
104c1213 15920
8e04817f
AC
15921You can always enter numbers in octal, decimal, or hexadecimal in
15922@value{GDBN} by the usual conventions: octal numbers begin with
15923@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15924begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15925@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1592610; likewise, the default display for numbers---when no particular
15927format is specified---is base 10. You can change the default base for
15928both input and output with the commands described below.
104c1213 15929
8e04817f
AC
15930@table @code
15931@kindex set input-radix
15932@item set input-radix @var{base}
15933Set the default base for numeric input. Supported choices
15934for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15935specified either unambiguously or using the current input radix; for
8e04817f 15936example, any of
104c1213 15937
8e04817f 15938@smallexample
9c16f35a
EZ
15939set input-radix 012
15940set input-radix 10.
15941set input-radix 0xa
8e04817f 15942@end smallexample
104c1213 15943
8e04817f 15944@noindent
9c16f35a 15945sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15946leaves the input radix unchanged, no matter what it was, since
15947@samp{10}, being without any leading or trailing signs of its base, is
15948interpreted in the current radix. Thus, if the current radix is 16,
15949@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15950change the radix.
104c1213 15951
8e04817f
AC
15952@kindex set output-radix
15953@item set output-radix @var{base}
15954Set the default base for numeric display. Supported choices
15955for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15956specified either unambiguously or using the current input radix.
104c1213 15957
8e04817f
AC
15958@kindex show input-radix
15959@item show input-radix
15960Display the current default base for numeric input.
104c1213 15961
8e04817f
AC
15962@kindex show output-radix
15963@item show output-radix
15964Display the current default base for numeric display.
9c16f35a
EZ
15965
15966@item set radix @r{[}@var{base}@r{]}
15967@itemx show radix
15968@kindex set radix
15969@kindex show radix
15970These commands set and show the default base for both input and output
15971of numbers. @code{set radix} sets the radix of input and output to
15972the same base; without an argument, it resets the radix back to its
15973default value of 10.
15974
8e04817f 15975@end table
104c1213 15976
1e698235
DJ
15977@node ABI
15978@section Configuring the current ABI
15979
15980@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15981application automatically. However, sometimes you need to override its
15982conclusions. Use these commands to manage @value{GDBN}'s view of the
15983current ABI.
15984
98b45e30
DJ
15985@cindex OS ABI
15986@kindex set osabi
b4e9345d 15987@kindex show osabi
98b45e30
DJ
15988
15989One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15990system targets, either via remote debugging or native emulation.
98b45e30
DJ
15991@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15992but you can override its conclusion using the @code{set osabi} command.
15993One example where this is useful is in debugging of binaries which use
15994an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15995not have the same identifying marks that the standard C library for your
15996platform provides.
15997
15998@table @code
15999@item show osabi
16000Show the OS ABI currently in use.
16001
16002@item set osabi
16003With no argument, show the list of registered available OS ABI's.
16004
16005@item set osabi @var{abi}
16006Set the current OS ABI to @var{abi}.
16007@end table
16008
1e698235 16009@cindex float promotion
1e698235
DJ
16010
16011Generally, the way that an argument of type @code{float} is passed to a
16012function depends on whether the function is prototyped. For a prototyped
16013(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
16014according to the architecture's convention for @code{float}. For unprototyped
16015(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
16016@code{double} and then passed.
16017
16018Unfortunately, some forms of debug information do not reliably indicate whether
16019a function is prototyped. If @value{GDBN} calls a function that is not marked
16020as prototyped, it consults @kbd{set coerce-float-to-double}.
16021
16022@table @code
a8f24a35 16023@kindex set coerce-float-to-double
1e698235
DJ
16024@item set coerce-float-to-double
16025@itemx set coerce-float-to-double on
16026Arguments of type @code{float} will be promoted to @code{double} when passed
16027to an unprototyped function. This is the default setting.
16028
16029@item set coerce-float-to-double off
16030Arguments of type @code{float} will be passed directly to unprototyped
16031functions.
9c16f35a
EZ
16032
16033@kindex show coerce-float-to-double
16034@item show coerce-float-to-double
16035Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
16036@end table
16037
f1212245
DJ
16038@kindex set cp-abi
16039@kindex show cp-abi
16040@value{GDBN} needs to know the ABI used for your program's C@t{++}
16041objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
16042used to build your application. @value{GDBN} only fully supports
16043programs with a single C@t{++} ABI; if your program contains code using
16044multiple C@t{++} ABI's or if @value{GDBN} can not identify your
16045program's ABI correctly, you can tell @value{GDBN} which ABI to use.
16046Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
16047before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
16048``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
16049use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
16050``auto''.
16051
16052@table @code
16053@item show cp-abi
16054Show the C@t{++} ABI currently in use.
16055
16056@item set cp-abi
16057With no argument, show the list of supported C@t{++} ABI's.
16058
16059@item set cp-abi @var{abi}
16060@itemx set cp-abi auto
16061Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
16062@end table
16063
8e04817f
AC
16064@node Messages/Warnings
16065@section Optional warnings and messages
104c1213 16066
9c16f35a
EZ
16067@cindex verbose operation
16068@cindex optional warnings
8e04817f
AC
16069By default, @value{GDBN} is silent about its inner workings. If you are
16070running on a slow machine, you may want to use the @code{set verbose}
16071command. This makes @value{GDBN} tell you when it does a lengthy
16072internal operation, so you will not think it has crashed.
104c1213 16073
8e04817f
AC
16074Currently, the messages controlled by @code{set verbose} are those
16075which announce that the symbol table for a source file is being read;
16076see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 16077
8e04817f
AC
16078@table @code
16079@kindex set verbose
16080@item set verbose on
16081Enables @value{GDBN} output of certain informational messages.
104c1213 16082
8e04817f
AC
16083@item set verbose off
16084Disables @value{GDBN} output of certain informational messages.
104c1213 16085
8e04817f
AC
16086@kindex show verbose
16087@item show verbose
16088Displays whether @code{set verbose} is on or off.
16089@end table
104c1213 16090
8e04817f
AC
16091By default, if @value{GDBN} encounters bugs in the symbol table of an
16092object file, it is silent; but if you are debugging a compiler, you may
16093find this information useful (@pxref{Symbol Errors, ,Errors reading
16094symbol files}).
104c1213 16095
8e04817f 16096@table @code
104c1213 16097
8e04817f
AC
16098@kindex set complaints
16099@item set complaints @var{limit}
16100Permits @value{GDBN} to output @var{limit} complaints about each type of
16101unusual symbols before becoming silent about the problem. Set
16102@var{limit} to zero to suppress all complaints; set it to a large number
16103to prevent complaints from being suppressed.
104c1213 16104
8e04817f
AC
16105@kindex show complaints
16106@item show complaints
16107Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 16108
8e04817f 16109@end table
104c1213 16110
8e04817f
AC
16111By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
16112lot of stupid questions to confirm certain commands. For example, if
16113you try to run a program which is already running:
104c1213 16114
474c8240 16115@smallexample
8e04817f
AC
16116(@value{GDBP}) run
16117The program being debugged has been started already.
16118Start it from the beginning? (y or n)
474c8240 16119@end smallexample
104c1213 16120
8e04817f
AC
16121If you are willing to unflinchingly face the consequences of your own
16122commands, you can disable this ``feature'':
104c1213 16123
8e04817f 16124@table @code
104c1213 16125
8e04817f
AC
16126@kindex set confirm
16127@cindex flinching
16128@cindex confirmation
16129@cindex stupid questions
16130@item set confirm off
16131Disables confirmation requests.
104c1213 16132
8e04817f
AC
16133@item set confirm on
16134Enables confirmation requests (the default).
104c1213 16135
8e04817f
AC
16136@kindex show confirm
16137@item show confirm
16138Displays state of confirmation requests.
16139
16140@end table
104c1213 16141
16026cd7
AS
16142@cindex command tracing
16143If you need to debug user-defined commands or sourced files you may find it
16144useful to enable @dfn{command tracing}. In this mode each command will be
16145printed as it is executed, prefixed with one or more @samp{+} symbols, the
16146quantity denoting the call depth of each command.
16147
16148@table @code
16149@kindex set trace-commands
16150@cindex command scripts, debugging
16151@item set trace-commands on
16152Enable command tracing.
16153@item set trace-commands off
16154Disable command tracing.
16155@item show trace-commands
16156Display the current state of command tracing.
16157@end table
16158
8e04817f
AC
16159@node Debugging Output
16160@section Optional messages about internal happenings
4644b6e3
EZ
16161@cindex optional debugging messages
16162
da316a69
EZ
16163@value{GDBN} has commands that enable optional debugging messages from
16164various @value{GDBN} subsystems; normally these commands are of
16165interest to @value{GDBN} maintainers, or when reporting a bug. This
16166section documents those commands.
16167
104c1213 16168@table @code
a8f24a35
EZ
16169@kindex set exec-done-display
16170@item set exec-done-display
16171Turns on or off the notification of asynchronous commands'
16172completion. When on, @value{GDBN} will print a message when an
16173asynchronous command finishes its execution. The default is off.
16174@kindex show exec-done-display
16175@item show exec-done-display
16176Displays the current setting of asynchronous command completion
16177notification.
4644b6e3
EZ
16178@kindex set debug
16179@cindex gdbarch debugging info
a8f24a35 16180@cindex architecture debugging info
8e04817f 16181@item set debug arch
a8f24a35 16182Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 16183@kindex show debug
8e04817f
AC
16184@item show debug arch
16185Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
16186@item set debug aix-thread
16187@cindex AIX threads
16188Display debugging messages about inner workings of the AIX thread
16189module.
16190@item show debug aix-thread
16191Show the current state of AIX thread debugging info display.
8e04817f 16192@item set debug event
4644b6e3 16193@cindex event debugging info
a8f24a35 16194Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 16195default is off.
8e04817f
AC
16196@item show debug event
16197Displays the current state of displaying @value{GDBN} event debugging
16198info.
8e04817f 16199@item set debug expression
4644b6e3 16200@cindex expression debugging info
721c2651
EZ
16201Turns on or off display of debugging info about @value{GDBN}
16202expression parsing. The default is off.
8e04817f 16203@item show debug expression
721c2651
EZ
16204Displays the current state of displaying debugging info about
16205@value{GDBN} expression parsing.
7453dc06 16206@item set debug frame
4644b6e3 16207@cindex frame debugging info
7453dc06
AC
16208Turns on or off display of @value{GDBN} frame debugging info. The
16209default is off.
7453dc06
AC
16210@item show debug frame
16211Displays the current state of displaying @value{GDBN} frame debugging
16212info.
30e91e0b
RC
16213@item set debug infrun
16214@cindex inferior debugging info
16215Turns on or off display of @value{GDBN} debugging info for running the inferior.
16216The default is off. @file{infrun.c} contains GDB's runtime state machine used
16217for implementing operations such as single-stepping the inferior.
16218@item show debug infrun
16219Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
16220@item set debug lin-lwp
16221@cindex @sc{gnu}/Linux LWP debug messages
16222@cindex Linux lightweight processes
721c2651 16223Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
16224@item show debug lin-lwp
16225Show the current state of Linux LWP debugging messages.
2b4855ab 16226@item set debug observer
4644b6e3 16227@cindex observer debugging info
2b4855ab
AC
16228Turns on or off display of @value{GDBN} observer debugging. This
16229includes info such as the notification of observable events.
2b4855ab
AC
16230@item show debug observer
16231Displays the current state of observer debugging.
8e04817f 16232@item set debug overload
4644b6e3 16233@cindex C@t{++} overload debugging info
8e04817f 16234Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 16235info. This includes info such as ranking of functions, etc. The default
8e04817f 16236is off.
8e04817f
AC
16237@item show debug overload
16238Displays the current state of displaying @value{GDBN} C@t{++} overload
16239debugging info.
8e04817f
AC
16240@cindex packets, reporting on stdout
16241@cindex serial connections, debugging
605a56cb
DJ
16242@cindex debug remote protocol
16243@cindex remote protocol debugging
16244@cindex display remote packets
8e04817f
AC
16245@item set debug remote
16246Turns on or off display of reports on all packets sent back and forth across
16247the serial line to the remote machine. The info is printed on the
16248@value{GDBN} standard output stream. The default is off.
8e04817f
AC
16249@item show debug remote
16250Displays the state of display of remote packets.
8e04817f
AC
16251@item set debug serial
16252Turns on or off display of @value{GDBN} serial debugging info. The
16253default is off.
8e04817f
AC
16254@item show debug serial
16255Displays the current state of displaying @value{GDBN} serial debugging
16256info.
c45da7e6
EZ
16257@item set debug solib-frv
16258@cindex FR-V shared-library debugging
16259Turns on or off debugging messages for FR-V shared-library code.
16260@item show debug solib-frv
16261Display the current state of FR-V shared-library code debugging
16262messages.
8e04817f 16263@item set debug target
4644b6e3 16264@cindex target debugging info
8e04817f
AC
16265Turns on or off display of @value{GDBN} target debugging info. This info
16266includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
16267default is 0. Set it to 1 to track events, and to 2 to also track the
16268value of large memory transfers. Changes to this flag do not take effect
16269until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
16270@item show debug target
16271Displays the current state of displaying @value{GDBN} target debugging
16272info.
c45da7e6 16273@item set debugvarobj
4644b6e3 16274@cindex variable object debugging info
8e04817f
AC
16275Turns on or off display of @value{GDBN} variable object debugging
16276info. The default is off.
c45da7e6 16277@item show debugvarobj
8e04817f
AC
16278Displays the current state of displaying @value{GDBN} variable object
16279debugging info.
16280@end table
104c1213 16281
8e04817f
AC
16282@node Sequences
16283@chapter Canned Sequences of Commands
104c1213 16284
8e04817f
AC
16285Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
16286command lists}), @value{GDBN} provides two ways to store sequences of
16287commands for execution as a unit: user-defined commands and command
16288files.
104c1213 16289
8e04817f 16290@menu
fcc73fe3
EZ
16291* Define:: How to define your own commands
16292* Hooks:: Hooks for user-defined commands
16293* Command Files:: How to write scripts of commands to be stored in a file
16294* Output:: Commands for controlled output
8e04817f 16295@end menu
104c1213 16296
8e04817f
AC
16297@node Define
16298@section User-defined commands
104c1213 16299
8e04817f 16300@cindex user-defined command
fcc73fe3 16301@cindex arguments, to user-defined commands
8e04817f
AC
16302A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
16303which you assign a new name as a command. This is done with the
16304@code{define} command. User commands may accept up to 10 arguments
16305separated by whitespace. Arguments are accessed within the user command
c03c782f 16306via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 16307
8e04817f
AC
16308@smallexample
16309define adder
16310 print $arg0 + $arg1 + $arg2
c03c782f 16311end
8e04817f 16312@end smallexample
104c1213
JM
16313
16314@noindent
8e04817f 16315To execute the command use:
104c1213 16316
8e04817f
AC
16317@smallexample
16318adder 1 2 3
16319@end smallexample
104c1213 16320
8e04817f
AC
16321@noindent
16322This defines the command @code{adder}, which prints the sum of
16323its three arguments. Note the arguments are text substitutions, so they may
16324reference variables, use complex expressions, or even perform inferior
16325functions calls.
104c1213 16326
fcc73fe3
EZ
16327@cindex argument count in user-defined commands
16328@cindex how many arguments (user-defined commands)
c03c782f
AS
16329In addition, @code{$argc} may be used to find out how many arguments have
16330been passed. This expands to a number in the range 0@dots{}10.
16331
16332@smallexample
16333define adder
16334 if $argc == 2
16335 print $arg0 + $arg1
16336 end
16337 if $argc == 3
16338 print $arg0 + $arg1 + $arg2
16339 end
16340end
16341@end smallexample
16342
104c1213 16343@table @code
104c1213 16344
8e04817f
AC
16345@kindex define
16346@item define @var{commandname}
16347Define a command named @var{commandname}. If there is already a command
16348by that name, you are asked to confirm that you want to redefine it.
104c1213 16349
8e04817f
AC
16350The definition of the command is made up of other @value{GDBN} command lines,
16351which are given following the @code{define} command. The end of these
16352commands is marked by a line containing @code{end}.
104c1213 16353
8e04817f 16354@kindex document
ca91424e 16355@kindex end@r{ (user-defined commands)}
8e04817f
AC
16356@item document @var{commandname}
16357Document the user-defined command @var{commandname}, so that it can be
16358accessed by @code{help}. The command @var{commandname} must already be
16359defined. This command reads lines of documentation just as @code{define}
16360reads the lines of the command definition, ending with @code{end}.
16361After the @code{document} command is finished, @code{help} on command
16362@var{commandname} displays the documentation you have written.
104c1213 16363
8e04817f
AC
16364You may use the @code{document} command again to change the
16365documentation of a command. Redefining the command with @code{define}
16366does not change the documentation.
104c1213 16367
c45da7e6
EZ
16368@kindex dont-repeat
16369@cindex don't repeat command
16370@item dont-repeat
16371Used inside a user-defined command, this tells @value{GDBN} that this
16372command should not be repeated when the user hits @key{RET}
16373(@pxref{Command Syntax, repeat last command}).
16374
8e04817f
AC
16375@kindex help user-defined
16376@item help user-defined
16377List all user-defined commands, with the first line of the documentation
16378(if any) for each.
104c1213 16379
8e04817f
AC
16380@kindex show user
16381@item show user
16382@itemx show user @var{commandname}
16383Display the @value{GDBN} commands used to define @var{commandname} (but
16384not its documentation). If no @var{commandname} is given, display the
16385definitions for all user-defined commands.
104c1213 16386
fcc73fe3 16387@cindex infinite recursion in user-defined commands
20f01a46
DH
16388@kindex show max-user-call-depth
16389@kindex set max-user-call-depth
16390@item show max-user-call-depth
5ca0cb28
DH
16391@itemx set max-user-call-depth
16392The value of @code{max-user-call-depth} controls how many recursion
16393levels are allowed in user-defined commands before GDB suspects an
16394infinite recursion and aborts the command.
104c1213
JM
16395@end table
16396
fcc73fe3
EZ
16397In addition to the above commands, user-defined commands frequently
16398use control flow commands, described in @ref{Command Files}.
16399
8e04817f
AC
16400When user-defined commands are executed, the
16401commands of the definition are not printed. An error in any command
16402stops execution of the user-defined command.
104c1213 16403
8e04817f
AC
16404If used interactively, commands that would ask for confirmation proceed
16405without asking when used inside a user-defined command. Many @value{GDBN}
16406commands that normally print messages to say what they are doing omit the
16407messages when used in a user-defined command.
104c1213 16408
8e04817f
AC
16409@node Hooks
16410@section User-defined command hooks
16411@cindex command hooks
16412@cindex hooks, for commands
16413@cindex hooks, pre-command
104c1213 16414
8e04817f 16415@kindex hook
8e04817f
AC
16416You may define @dfn{hooks}, which are a special kind of user-defined
16417command. Whenever you run the command @samp{foo}, if the user-defined
16418command @samp{hook-foo} exists, it is executed (with no arguments)
16419before that command.
104c1213 16420
8e04817f
AC
16421@cindex hooks, post-command
16422@kindex hookpost
8e04817f
AC
16423A hook may also be defined which is run after the command you executed.
16424Whenever you run the command @samp{foo}, if the user-defined command
16425@samp{hookpost-foo} exists, it is executed (with no arguments) after
16426that command. Post-execution hooks may exist simultaneously with
16427pre-execution hooks, for the same command.
104c1213 16428
8e04817f 16429It is valid for a hook to call the command which it hooks. If this
9f1c6395 16430occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 16431
8e04817f
AC
16432@c It would be nice if hookpost could be passed a parameter indicating
16433@c if the command it hooks executed properly or not. FIXME!
104c1213 16434
8e04817f
AC
16435@kindex stop@r{, a pseudo-command}
16436In addition, a pseudo-command, @samp{stop} exists. Defining
16437(@samp{hook-stop}) makes the associated commands execute every time
16438execution stops in your program: before breakpoint commands are run,
16439displays are printed, or the stack frame is printed.
104c1213 16440
8e04817f
AC
16441For example, to ignore @code{SIGALRM} signals while
16442single-stepping, but treat them normally during normal execution,
16443you could define:
104c1213 16444
474c8240 16445@smallexample
8e04817f
AC
16446define hook-stop
16447handle SIGALRM nopass
16448end
104c1213 16449
8e04817f
AC
16450define hook-run
16451handle SIGALRM pass
16452end
104c1213 16453
8e04817f
AC
16454define hook-continue
16455handle SIGLARM pass
16456end
474c8240 16457@end smallexample
104c1213 16458
8e04817f 16459As a further example, to hook at the begining and end of the @code{echo}
b383017d 16460command, and to add extra text to the beginning and end of the message,
8e04817f 16461you could define:
104c1213 16462
474c8240 16463@smallexample
8e04817f
AC
16464define hook-echo
16465echo <<<---
16466end
104c1213 16467
8e04817f
AC
16468define hookpost-echo
16469echo --->>>\n
16470end
104c1213 16471
8e04817f
AC
16472(@value{GDBP}) echo Hello World
16473<<<---Hello World--->>>
16474(@value{GDBP})
104c1213 16475
474c8240 16476@end smallexample
104c1213 16477
8e04817f
AC
16478You can define a hook for any single-word command in @value{GDBN}, but
16479not for command aliases; you should define a hook for the basic command
c1468174 16480name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
16481@c FIXME! So how does Joe User discover whether a command is an alias
16482@c or not?
16483If an error occurs during the execution of your hook, execution of
16484@value{GDBN} commands stops and @value{GDBN} issues a prompt
16485(before the command that you actually typed had a chance to run).
104c1213 16486
8e04817f
AC
16487If you try to define a hook which does not match any known command, you
16488get a warning from the @code{define} command.
c906108c 16489
8e04817f
AC
16490@node Command Files
16491@section Command files
c906108c 16492
8e04817f 16493@cindex command files
fcc73fe3 16494@cindex scripting commands
6fc08d32
EZ
16495A command file for @value{GDBN} is a text file made of lines that are
16496@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
16497also be included. An empty line in a command file does nothing; it
16498does not mean to repeat the last command, as it would from the
16499terminal.
c906108c 16500
6fc08d32
EZ
16501You can request the execution of a command file with the @code{source}
16502command:
c906108c 16503
8e04817f
AC
16504@table @code
16505@kindex source
ca91424e 16506@cindex execute commands from a file
16026cd7 16507@item source [@code{-v}] @var{filename}
8e04817f 16508Execute the command file @var{filename}.
c906108c
SS
16509@end table
16510
fcc73fe3
EZ
16511The lines in a command file are generally executed sequentially,
16512unless the order of execution is changed by one of the
16513@emph{flow-control commands} described below. The commands are not
a71ec265
DH
16514printed as they are executed. An error in any command terminates
16515execution of the command file and control is returned to the console.
c906108c 16516
4b505b12
AS
16517@value{GDBN} searches for @var{filename} in the current directory and then
16518on the search path (specified with the @samp{directory} command).
16519
16026cd7
AS
16520If @code{-v}, for verbose mode, is given then @value{GDBN} displays
16521each command as it is executed. The option must be given before
16522@var{filename}, and is interpreted as part of the filename anywhere else.
16523
8e04817f
AC
16524Commands that would ask for confirmation if used interactively proceed
16525without asking when used in a command file. Many @value{GDBN} commands that
16526normally print messages to say what they are doing omit the messages
16527when called from command files.
c906108c 16528
8e04817f
AC
16529@value{GDBN} also accepts command input from standard input. In this
16530mode, normal output goes to standard output and error output goes to
16531standard error. Errors in a command file supplied on standard input do
6fc08d32 16532not terminate execution of the command file---execution continues with
8e04817f 16533the next command.
c906108c 16534
474c8240 16535@smallexample
8e04817f 16536gdb < cmds > log 2>&1
474c8240 16537@end smallexample
c906108c 16538
8e04817f
AC
16539(The syntax above will vary depending on the shell used.) This example
16540will execute commands from the file @file{cmds}. All output and errors
16541would be directed to @file{log}.
c906108c 16542
fcc73fe3
EZ
16543Since commands stored on command files tend to be more general than
16544commands typed interactively, they frequently need to deal with
16545complicated situations, such as different or unexpected values of
16546variables and symbols, changes in how the program being debugged is
16547built, etc. @value{GDBN} provides a set of flow-control commands to
16548deal with these complexities. Using these commands, you can write
16549complex scripts that loop over data structures, execute commands
16550conditionally, etc.
16551
16552@table @code
16553@kindex if
16554@kindex else
16555@item if
16556@itemx else
16557This command allows to include in your script conditionally executed
16558commands. The @code{if} command takes a single argument, which is an
16559expression to evaluate. It is followed by a series of commands that
16560are executed only if the expression is true (its value is nonzero).
16561There can then optionally be an @code{else} line, followed by a series
16562of commands that are only executed if the expression was false. The
16563end of the list is marked by a line containing @code{end}.
16564
16565@kindex while
16566@item while
16567This command allows to write loops. Its syntax is similar to
16568@code{if}: the command takes a single argument, which is an expression
16569to evaluate, and must be followed by the commands to execute, one per
16570line, terminated by an @code{end}. These commands are called the
16571@dfn{body} of the loop. The commands in the body of @code{while} are
16572executed repeatedly as long as the expression evaluates to true.
16573
16574@kindex loop_break
16575@item loop_break
16576This command exits the @code{while} loop in whose body it is included.
16577Execution of the script continues after that @code{while}s @code{end}
16578line.
16579
16580@kindex loop_continue
16581@item loop_continue
16582This command skips the execution of the rest of the body of commands
16583in the @code{while} loop in whose body it is included. Execution
16584branches to the beginning of the @code{while} loop, where it evaluates
16585the controlling expression.
ca91424e
EZ
16586
16587@kindex end@r{ (if/else/while commands)}
16588@item end
16589Terminate the block of commands that are the body of @code{if},
16590@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
16591@end table
16592
16593
8e04817f
AC
16594@node Output
16595@section Commands for controlled output
c906108c 16596
8e04817f
AC
16597During the execution of a command file or a user-defined command, normal
16598@value{GDBN} output is suppressed; the only output that appears is what is
16599explicitly printed by the commands in the definition. This section
16600describes three commands useful for generating exactly the output you
16601want.
c906108c
SS
16602
16603@table @code
8e04817f
AC
16604@kindex echo
16605@item echo @var{text}
16606@c I do not consider backslash-space a standard C escape sequence
16607@c because it is not in ANSI.
16608Print @var{text}. Nonprinting characters can be included in
16609@var{text} using C escape sequences, such as @samp{\n} to print a
16610newline. @strong{No newline is printed unless you specify one.}
16611In addition to the standard C escape sequences, a backslash followed
16612by a space stands for a space. This is useful for displaying a
16613string with spaces at the beginning or the end, since leading and
16614trailing spaces are otherwise trimmed from all arguments.
16615To print @samp{@w{ }and foo =@w{ }}, use the command
16616@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 16617
8e04817f
AC
16618A backslash at the end of @var{text} can be used, as in C, to continue
16619the command onto subsequent lines. For example,
c906108c 16620
474c8240 16621@smallexample
8e04817f
AC
16622echo This is some text\n\
16623which is continued\n\
16624onto several lines.\n
474c8240 16625@end smallexample
c906108c 16626
8e04817f 16627produces the same output as
c906108c 16628
474c8240 16629@smallexample
8e04817f
AC
16630echo This is some text\n
16631echo which is continued\n
16632echo onto several lines.\n
474c8240 16633@end smallexample
c906108c 16634
8e04817f
AC
16635@kindex output
16636@item output @var{expression}
16637Print the value of @var{expression} and nothing but that value: no
16638newlines, no @samp{$@var{nn} = }. The value is not entered in the
16639value history either. @xref{Expressions, ,Expressions}, for more information
16640on expressions.
c906108c 16641
8e04817f
AC
16642@item output/@var{fmt} @var{expression}
16643Print the value of @var{expression} in format @var{fmt}. You can use
16644the same formats as for @code{print}. @xref{Output Formats,,Output
16645formats}, for more information.
c906108c 16646
8e04817f
AC
16647@kindex printf
16648@item printf @var{string}, @var{expressions}@dots{}
16649Print the values of the @var{expressions} under the control of
16650@var{string}. The @var{expressions} are separated by commas and may be
16651either numbers or pointers. Their values are printed as specified by
16652@var{string}, exactly as if your program were to execute the C
16653subroutine
16654@c FIXME: the above implies that at least all ANSI C formats are
16655@c supported, but it isn't true: %E and %G don't work (or so it seems).
16656@c Either this is a bug, or the manual should document what formats are
16657@c supported.
c906108c 16658
474c8240 16659@smallexample
8e04817f 16660printf (@var{string}, @var{expressions}@dots{});
474c8240 16661@end smallexample
c906108c 16662
8e04817f 16663For example, you can print two values in hex like this:
c906108c 16664
8e04817f
AC
16665@smallexample
16666printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
16667@end smallexample
c906108c 16668
8e04817f
AC
16669The only backslash-escape sequences that you can use in the format
16670string are the simple ones that consist of backslash followed by a
16671letter.
c906108c
SS
16672@end table
16673
21c294e6
AC
16674@node Interpreters
16675@chapter Command Interpreters
16676@cindex command interpreters
16677
16678@value{GDBN} supports multiple command interpreters, and some command
16679infrastructure to allow users or user interface writers to switch
16680between interpreters or run commands in other interpreters.
16681
16682@value{GDBN} currently supports two command interpreters, the console
16683interpreter (sometimes called the command-line interpreter or @sc{cli})
16684and the machine interface interpreter (or @sc{gdb/mi}). This manual
16685describes both of these interfaces in great detail.
16686
16687By default, @value{GDBN} will start with the console interpreter.
16688However, the user may choose to start @value{GDBN} with another
16689interpreter by specifying the @option{-i} or @option{--interpreter}
16690startup options. Defined interpreters include:
16691
16692@table @code
16693@item console
16694@cindex console interpreter
16695The traditional console or command-line interpreter. This is the most often
16696used interpreter with @value{GDBN}. With no interpreter specified at runtime,
16697@value{GDBN} will use this interpreter.
16698
16699@item mi
16700@cindex mi interpreter
16701The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
16702by programs wishing to use @value{GDBN} as a backend for a debugger GUI
16703or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
16704Interface}.
16705
16706@item mi2
16707@cindex mi2 interpreter
16708The current @sc{gdb/mi} interface.
16709
16710@item mi1
16711@cindex mi1 interpreter
16712The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
16713
16714@end table
16715
16716@cindex invoke another interpreter
16717The interpreter being used by @value{GDBN} may not be dynamically
16718switched at runtime. Although possible, this could lead to a very
16719precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
16720enters the command "interpreter-set console" in a console view,
16721@value{GDBN} would switch to using the console interpreter, rendering
16722the IDE inoperable!
16723
16724@kindex interpreter-exec
16725Although you may only choose a single interpreter at startup, you may execute
16726commands in any interpreter from the current interpreter using the appropriate
16727command. If you are running the console interpreter, simply use the
16728@code{interpreter-exec} command:
16729
16730@smallexample
16731interpreter-exec mi "-data-list-register-names"
16732@end smallexample
16733
16734@sc{gdb/mi} has a similar command, although it is only available in versions of
16735@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16736
8e04817f
AC
16737@node TUI
16738@chapter @value{GDBN} Text User Interface
16739@cindex TUI
d0d5df6f 16740@cindex Text User Interface
c906108c 16741
8e04817f
AC
16742@menu
16743* TUI Overview:: TUI overview
16744* TUI Keys:: TUI key bindings
7cf36c78 16745* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16746* TUI Commands:: TUI specific commands
16747* TUI Configuration:: TUI configuration variables
16748@end menu
c906108c 16749
d0d5df6f
AC
16750The @value{GDBN} Text User Interface, TUI in short, is a terminal
16751interface which uses the @code{curses} library to show the source
16752file, the assembly output, the program registers and @value{GDBN}
16753commands in separate text windows.
16754
16755The TUI is enabled by invoking @value{GDBN} using either
16756@pindex gdbtui
16757@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16758
8e04817f
AC
16759@node TUI Overview
16760@section TUI overview
c906108c 16761
8e04817f
AC
16762The TUI has two display modes that can be switched while
16763@value{GDBN} runs:
c906108c 16764
8e04817f
AC
16765@itemize @bullet
16766@item
16767A curses (or TUI) mode in which it displays several text
16768windows on the terminal.
c906108c 16769
8e04817f
AC
16770@item
16771A standard mode which corresponds to the @value{GDBN} configured without
16772the TUI.
16773@end itemize
c906108c 16774
8e04817f
AC
16775In the TUI mode, @value{GDBN} can display several text window
16776on the terminal:
c906108c 16777
8e04817f
AC
16778@table @emph
16779@item command
16780This window is the @value{GDBN} command window with the @value{GDBN}
16781prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16782managed using readline but through the TUI. The @emph{command}
16783window is always visible.
c906108c 16784
8e04817f
AC
16785@item source
16786The source window shows the source file of the program. The current
16787line as well as active breakpoints are displayed in this window.
c906108c 16788
8e04817f
AC
16789@item assembly
16790The assembly window shows the disassembly output of the program.
c906108c 16791
8e04817f
AC
16792@item register
16793This window shows the processor registers. It detects when
16794a register is changed and when this is the case, registers that have
6a1b180d 16795changed are highlighted.
c906108c 16796
c906108c
SS
16797@end table
16798
269c21fe
SC
16799The source and assembly windows show the current program position
16800by highlighting the current line and marking them with the @samp{>} marker.
16801Breakpoints are also indicated with two markers. A first one
16802indicates the breakpoint type:
16803
16804@table @code
16805@item B
16806Breakpoint which was hit at least once.
16807
16808@item b
16809Breakpoint which was never hit.
16810
16811@item H
16812Hardware breakpoint which was hit at least once.
16813
16814@item h
16815Hardware breakpoint which was never hit.
16816
16817@end table
16818
16819The second marker indicates whether the breakpoint is enabled or not:
16820
16821@table @code
16822@item +
16823Breakpoint is enabled.
16824
16825@item -
16826Breakpoint is disabled.
16827
16828@end table
16829
8e04817f
AC
16830The source, assembly and register windows are attached to the thread
16831and the frame position. They are updated when the current thread
16832changes, when the frame changes or when the program counter changes.
16833These three windows are arranged by the TUI according to several
16834layouts. The layout defines which of these three windows are visible.
16835The following layouts are available:
c906108c 16836
8e04817f
AC
16837@itemize @bullet
16838@item
16839source
2df3850c 16840
8e04817f
AC
16841@item
16842assembly
16843
16844@item
16845source and assembly
16846
16847@item
16848source and registers
c906108c 16849
8e04817f
AC
16850@item
16851assembly and registers
2df3850c 16852
8e04817f 16853@end itemize
c906108c 16854
b7bb15bc
SC
16855On top of the command window a status line gives various information
16856concerning the current process begin debugged. The status line is
16857updated when the information it shows changes. The following fields
16858are displayed:
16859
16860@table @emph
16861@item target
16862Indicates the current gdb target
16863(@pxref{Targets, ,Specifying a Debugging Target}).
16864
16865@item process
16866Gives information about the current process or thread number.
16867When no process is being debugged, this field is set to @code{No process}.
16868
16869@item function
16870Gives the current function name for the selected frame.
16871The name is demangled if demangling is turned on (@pxref{Print Settings}).
16872When there is no symbol corresponding to the current program counter
16873the string @code{??} is displayed.
16874
16875@item line
16876Indicates the current line number for the selected frame.
16877When the current line number is not known the string @code{??} is displayed.
16878
16879@item pc
16880Indicates the current program counter address.
16881
16882@end table
16883
8e04817f
AC
16884@node TUI Keys
16885@section TUI Key Bindings
16886@cindex TUI key bindings
c906108c 16887
8e04817f
AC
16888The TUI installs several key bindings in the readline keymaps
16889(@pxref{Command Line Editing}).
16890They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16891directly on the TUI layout and windows. The TUI also provides
16892a @emph{SingleKey} keymap which binds several keys directly to
16893@value{GDBN} commands. The following key bindings
8e04817f 16894are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16895
8e04817f
AC
16896@table @kbd
16897@kindex C-x C-a
16898@item C-x C-a
16899@kindex C-x a
16900@itemx C-x a
16901@kindex C-x A
16902@itemx C-x A
16903Enter or leave the TUI mode. When the TUI mode is left,
16904the curses window management is left and @value{GDBN} operates using
16905its standard mode writing on the terminal directly. When the TUI
16906mode is entered, the control is given back to the curses windows.
16907The screen is then refreshed.
c906108c 16908
8e04817f
AC
16909@kindex C-x 1
16910@item C-x 1
16911Use a TUI layout with only one window. The layout will
16912either be @samp{source} or @samp{assembly}. When the TUI mode
16913is not active, it will switch to the TUI mode.
2df3850c 16914
8e04817f 16915Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16916
8e04817f
AC
16917@kindex C-x 2
16918@item C-x 2
16919Use a TUI layout with at least two windows. When the current
16920layout shows already two windows, a next layout with two windows is used.
16921When a new layout is chosen, one window will always be common to the
16922previous layout and the new one.
c906108c 16923
8e04817f 16924Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16925
72ffddc9
SC
16926@kindex C-x o
16927@item C-x o
16928Change the active window. The TUI associates several key bindings
16929(like scrolling and arrow keys) to the active window. This command
16930gives the focus to the next TUI window.
16931
16932Think of it as the Emacs @kbd{C-x o} binding.
16933
7cf36c78
SC
16934@kindex C-x s
16935@item C-x s
16936Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16937(@pxref{TUI Single Key Mode}).
16938
c906108c
SS
16939@end table
16940
8e04817f 16941The following key bindings are handled only by the TUI mode:
5d161b24 16942
8e04817f
AC
16943@table @key
16944@kindex PgUp
16945@item PgUp
16946Scroll the active window one page up.
c906108c 16947
8e04817f
AC
16948@kindex PgDn
16949@item PgDn
16950Scroll the active window one page down.
c906108c 16951
8e04817f
AC
16952@kindex Up
16953@item Up
16954Scroll the active window one line up.
c906108c 16955
8e04817f
AC
16956@kindex Down
16957@item Down
16958Scroll the active window one line down.
c906108c 16959
8e04817f
AC
16960@kindex Left
16961@item Left
16962Scroll the active window one column left.
c906108c 16963
8e04817f
AC
16964@kindex Right
16965@item Right
16966Scroll the active window one column right.
c906108c 16967
8e04817f
AC
16968@kindex C-L
16969@item C-L
16970Refresh the screen.
c906108c 16971
8e04817f 16972@end table
c906108c 16973
8e04817f 16974In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16975for scrolling. This means they are available for readline when the
16976active window is the command window. When the command window
16977does not have the focus, it is necessary to use other readline
7f9087cb 16978key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b} and @kbd{C-f}.
8e04817f 16979
7cf36c78
SC
16980@node TUI Single Key Mode
16981@section TUI Single Key Mode
16982@cindex TUI single key mode
16983
16984The TUI provides a @emph{SingleKey} mode in which it installs a particular
16985key binding in the readline keymaps to connect single keys to
b383017d 16986some gdb commands.
7cf36c78
SC
16987
16988@table @kbd
16989@kindex c @r{(SingleKey TUI key)}
16990@item c
16991continue
16992
16993@kindex d @r{(SingleKey TUI key)}
16994@item d
16995down
16996
16997@kindex f @r{(SingleKey TUI key)}
16998@item f
16999finish
17000
17001@kindex n @r{(SingleKey TUI key)}
17002@item n
17003next
17004
17005@kindex q @r{(SingleKey TUI key)}
17006@item q
17007exit the @emph{SingleKey} mode.
17008
17009@kindex r @r{(SingleKey TUI key)}
17010@item r
17011run
17012
17013@kindex s @r{(SingleKey TUI key)}
17014@item s
17015step
17016
17017@kindex u @r{(SingleKey TUI key)}
17018@item u
17019up
17020
17021@kindex v @r{(SingleKey TUI key)}
17022@item v
17023info locals
17024
17025@kindex w @r{(SingleKey TUI key)}
17026@item w
17027where
17028
17029@end table
17030
17031Other keys temporarily switch to the @value{GDBN} command prompt.
17032The key that was pressed is inserted in the editing buffer so that
17033it is possible to type most @value{GDBN} commands without interaction
17034with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
17035@emph{SingleKey} mode is restored. The only way to permanently leave
7f9087cb 17036this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
17037
17038
8e04817f
AC
17039@node TUI Commands
17040@section TUI specific commands
17041@cindex TUI commands
17042
17043The TUI has specific commands to control the text windows.
17044These commands are always available, that is they do not depend on
17045the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
17046is in the standard mode, using these commands will automatically switch
17047in the TUI mode.
c906108c
SS
17048
17049@table @code
3d757584
SC
17050@item info win
17051@kindex info win
17052List and give the size of all displayed windows.
17053
8e04817f 17054@item layout next
4644b6e3 17055@kindex layout
8e04817f 17056Display the next layout.
2df3850c 17057
8e04817f 17058@item layout prev
8e04817f 17059Display the previous layout.
c906108c 17060
8e04817f 17061@item layout src
8e04817f 17062Display the source window only.
c906108c 17063
8e04817f 17064@item layout asm
8e04817f 17065Display the assembly window only.
c906108c 17066
8e04817f 17067@item layout split
8e04817f 17068Display the source and assembly window.
c906108c 17069
8e04817f 17070@item layout regs
8e04817f
AC
17071Display the register window together with the source or assembly window.
17072
17073@item focus next | prev | src | asm | regs | split
17074@kindex focus
17075Set the focus to the named window.
17076This command allows to change the active window so that scrolling keys
17077can be affected to another window.
c906108c 17078
8e04817f
AC
17079@item refresh
17080@kindex refresh
7f9087cb 17081Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 17082
6a1b180d
SC
17083@item tui reg float
17084@kindex tui reg
17085Show the floating point registers in the register window.
17086
17087@item tui reg general
17088Show the general registers in the register window.
17089
17090@item tui reg next
17091Show the next register group. The list of register groups as well as
17092their order is target specific. The predefined register groups are the
17093following: @code{general}, @code{float}, @code{system}, @code{vector},
17094@code{all}, @code{save}, @code{restore}.
17095
17096@item tui reg system
17097Show the system registers in the register window.
17098
8e04817f
AC
17099@item update
17100@kindex update
17101Update the source window and the current execution point.
c906108c 17102
8e04817f
AC
17103@item winheight @var{name} +@var{count}
17104@itemx winheight @var{name} -@var{count}
17105@kindex winheight
17106Change the height of the window @var{name} by @var{count}
17107lines. Positive counts increase the height, while negative counts
17108decrease it.
2df3850c 17109
c45da7e6
EZ
17110@item tabset
17111@kindex tabset @var{nchars}
17112Set the width of tab stops to be @var{nchars} characters.
17113
c906108c
SS
17114@end table
17115
8e04817f
AC
17116@node TUI Configuration
17117@section TUI configuration variables
17118@cindex TUI configuration variables
c906108c 17119
8e04817f
AC
17120The TUI has several configuration variables that control the
17121appearance of windows on the terminal.
c906108c 17122
8e04817f
AC
17123@table @code
17124@item set tui border-kind @var{kind}
17125@kindex set tui border-kind
17126Select the border appearance for the source, assembly and register windows.
17127The possible values are the following:
17128@table @code
17129@item space
17130Use a space character to draw the border.
c906108c 17131
8e04817f
AC
17132@item ascii
17133Use ascii characters + - and | to draw the border.
c906108c 17134
8e04817f
AC
17135@item acs
17136Use the Alternate Character Set to draw the border. The border is
17137drawn using character line graphics if the terminal supports them.
c78b4128 17138
8e04817f 17139@end table
c78b4128 17140
8e04817f
AC
17141@item set tui active-border-mode @var{mode}
17142@kindex set tui active-border-mode
17143Select the attributes to display the border of the active window.
17144The possible values are @code{normal}, @code{standout}, @code{reverse},
17145@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 17146
8e04817f
AC
17147@item set tui border-mode @var{mode}
17148@kindex set tui border-mode
17149Select the attributes to display the border of other windows.
17150The @var{mode} can be one of the following:
17151@table @code
17152@item normal
17153Use normal attributes to display the border.
c906108c 17154
8e04817f
AC
17155@item standout
17156Use standout mode.
c906108c 17157
8e04817f
AC
17158@item reverse
17159Use reverse video mode.
c906108c 17160
8e04817f
AC
17161@item half
17162Use half bright mode.
c906108c 17163
8e04817f
AC
17164@item half-standout
17165Use half bright and standout mode.
c906108c 17166
8e04817f
AC
17167@item bold
17168Use extra bright or bold mode.
c78b4128 17169
8e04817f
AC
17170@item bold-standout
17171Use extra bright or bold and standout mode.
c78b4128 17172
8e04817f 17173@end table
c78b4128 17174
8e04817f 17175@end table
c78b4128 17176
8e04817f
AC
17177@node Emacs
17178@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 17179
8e04817f
AC
17180@cindex Emacs
17181@cindex @sc{gnu} Emacs
17182A special interface allows you to use @sc{gnu} Emacs to view (and
17183edit) the source files for the program you are debugging with
17184@value{GDBN}.
c906108c 17185
8e04817f
AC
17186To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
17187executable file you want to debug as an argument. This command starts
17188@value{GDBN} as a subprocess of Emacs, with input and output through a newly
17189created Emacs buffer.
17190@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 17191
8e04817f
AC
17192Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
17193things:
c906108c 17194
8e04817f
AC
17195@itemize @bullet
17196@item
17197All ``terminal'' input and output goes through the Emacs buffer.
17198@end itemize
c906108c 17199
8e04817f
AC
17200This applies both to @value{GDBN} commands and their output, and to the input
17201and output done by the program you are debugging.
bf0184be 17202
8e04817f
AC
17203This is useful because it means that you can copy the text of previous
17204commands and input them again; you can even use parts of the output
17205in this way.
bf0184be 17206
8e04817f
AC
17207All the facilities of Emacs' Shell mode are available for interacting
17208with your program. In particular, you can send signals the usual
17209way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
17210stop.
bf0184be 17211
8e04817f 17212@itemize @bullet
bf0184be 17213@item
8e04817f
AC
17214@value{GDBN} displays source code through Emacs.
17215@end itemize
bf0184be 17216
8e04817f
AC
17217Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
17218source file for that frame and puts an arrow (@samp{=>}) at the
17219left margin of the current line. Emacs uses a separate buffer for
17220source display, and splits the screen to show both your @value{GDBN} session
17221and the source.
bf0184be 17222
8e04817f
AC
17223Explicit @value{GDBN} @code{list} or search commands still produce output as
17224usual, but you probably have no reason to use them from Emacs.
c906108c 17225
64fabec2
AC
17226If you specify an absolute file name when prompted for the @kbd{M-x
17227gdb} argument, then Emacs sets your current working directory to where
17228your program resides. If you only specify the file name, then Emacs
17229sets your current working directory to to the directory associated
17230with the previous buffer. In this case, @value{GDBN} may find your
17231program by searching your environment's @code{PATH} variable, but on
17232some operating systems it might not find the source. So, although the
17233@value{GDBN} input and output session proceeds normally, the auxiliary
17234buffer does not display the current source and line of execution.
17235
17236The initial working directory of @value{GDBN} is printed on the top
17237line of the @value{GDBN} I/O buffer and this serves as a default for
17238the commands that specify files for @value{GDBN} to operate
17239on. @xref{Files, ,Commands to specify files}.
17240
17241By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
17242need to call @value{GDBN} by a different name (for example, if you
17243keep several configurations around, with different names) you can
17244customize the Emacs variable @code{gud-gdb-command-name} to run the
17245one you want.
8e04817f
AC
17246
17247In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
17248addition to the standard Shell mode commands:
c906108c 17249
8e04817f
AC
17250@table @kbd
17251@item C-h m
17252Describe the features of Emacs' @value{GDBN} Mode.
c906108c 17253
64fabec2 17254@item C-c C-s
8e04817f
AC
17255Execute to another source line, like the @value{GDBN} @code{step} command; also
17256update the display window to show the current file and location.
c906108c 17257
64fabec2 17258@item C-c C-n
8e04817f
AC
17259Execute to next source line in this function, skipping all function
17260calls, like the @value{GDBN} @code{next} command. Then update the display window
17261to show the current file and location.
c906108c 17262
64fabec2 17263@item C-c C-i
8e04817f
AC
17264Execute one instruction, like the @value{GDBN} @code{stepi} command; update
17265display window accordingly.
c906108c 17266
8e04817f
AC
17267@item C-c C-f
17268Execute until exit from the selected stack frame, like the @value{GDBN}
17269@code{finish} command.
c906108c 17270
64fabec2 17271@item C-c C-r
8e04817f
AC
17272Continue execution of your program, like the @value{GDBN} @code{continue}
17273command.
b433d00b 17274
64fabec2 17275@item C-c <
8e04817f
AC
17276Go up the number of frames indicated by the numeric argument
17277(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
17278like the @value{GDBN} @code{up} command.
b433d00b 17279
64fabec2 17280@item C-c >
8e04817f
AC
17281Go down the number of frames indicated by the numeric argument, like the
17282@value{GDBN} @code{down} command.
8e04817f 17283@end table
c906108c 17284
7f9087cb 17285In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 17286tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 17287
64fabec2
AC
17288If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
17289shows a backtrace when the @value{GDBN} I/O buffer is current. Move
17290point to any frame in the stack and type @key{RET} to make it become the
17291current frame and display the associated source in the source buffer.
17292Alternatively, click @kbd{Mouse-2} to make the selected frame become the
17293current one.
17294
8e04817f
AC
17295If you accidentally delete the source-display buffer, an easy way to get
17296it back is to type the command @code{f} in the @value{GDBN} buffer, to
17297request a frame display; when you run under Emacs, this recreates
17298the source buffer if necessary to show you the context of the current
17299frame.
c906108c 17300
8e04817f
AC
17301The source files displayed in Emacs are in ordinary Emacs buffers
17302which are visiting the source files in the usual way. You can edit
17303the files with these buffers if you wish; but keep in mind that @value{GDBN}
17304communicates with Emacs in terms of line numbers. If you add or
17305delete lines from the text, the line numbers that @value{GDBN} knows cease
17306to correspond properly with the code.
b383017d 17307
64fabec2
AC
17308The description given here is for GNU Emacs version 21.3 and a more
17309detailed description of its interaction with @value{GDBN} is given in
17310the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 17311
8e04817f
AC
17312@c The following dropped because Epoch is nonstandard. Reactivate
17313@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
17314@ignore
17315@kindex Emacs Epoch environment
17316@kindex Epoch
17317@kindex inspect
c906108c 17318
8e04817f
AC
17319Version 18 of @sc{gnu} Emacs has a built-in window system
17320called the @code{epoch}
17321environment. Users of this environment can use a new command,
17322@code{inspect} which performs identically to @code{print} except that
17323each value is printed in its own window.
17324@end ignore
c906108c 17325
922fbb7b
AC
17326
17327@node GDB/MI
17328@chapter The @sc{gdb/mi} Interface
17329
17330@unnumberedsec Function and Purpose
17331
17332@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
17333@sc{gdb/mi} is a line based machine oriented text interface to
17334@value{GDBN} and is activated by specifying using the
17335@option{--interpreter} command line option (@pxref{Mode Options}). It
17336is specifically intended to support the development of systems which
17337use the debugger as just one small component of a larger system.
922fbb7b
AC
17338
17339This chapter is a specification of the @sc{gdb/mi} interface. It is written
17340in the form of a reference manual.
17341
17342Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
17343features described below are incomplete and subject to change
17344(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
17345
17346@unnumberedsec Notation and Terminology
17347
17348@cindex notational conventions, for @sc{gdb/mi}
17349This chapter uses the following notation:
17350
17351@itemize @bullet
17352@item
17353@code{|} separates two alternatives.
17354
17355@item
17356@code{[ @var{something} ]} indicates that @var{something} is optional:
17357it may or may not be given.
17358
17359@item
17360@code{( @var{group} )*} means that @var{group} inside the parentheses
17361may repeat zero or more times.
17362
17363@item
17364@code{( @var{group} )+} means that @var{group} inside the parentheses
17365may repeat one or more times.
17366
17367@item
17368@code{"@var{string}"} means a literal @var{string}.
17369@end itemize
17370
17371@ignore
17372@heading Dependencies
17373@end ignore
17374
922fbb7b
AC
17375@menu
17376* GDB/MI Command Syntax::
17377* GDB/MI Compatibility with CLI::
af6eff6f 17378* GDB/MI Development and Front Ends::
922fbb7b 17379* GDB/MI Output Records::
ef21caaf 17380* GDB/MI Simple Examples::
922fbb7b 17381* GDB/MI Command Description Format::
ef21caaf 17382* GDB/MI Breakpoint Commands::
a2c02241
NR
17383* GDB/MI Program Context::
17384* GDB/MI Thread Commands::
17385* GDB/MI Program Execution::
17386* GDB/MI Stack Manipulation::
17387* GDB/MI Variable Objects::
922fbb7b 17388* GDB/MI Data Manipulation::
a2c02241
NR
17389* GDB/MI Tracepoint Commands::
17390* GDB/MI Symbol Query::
351ff01a 17391* GDB/MI File Commands::
922fbb7b
AC
17392@ignore
17393* GDB/MI Kod Commands::
17394* GDB/MI Memory Overlay Commands::
17395* GDB/MI Signal Handling Commands::
17396@end ignore
922fbb7b 17397* GDB/MI Target Manipulation::
ef21caaf 17398* GDB/MI Miscellaneous Commands::
922fbb7b
AC
17399@end menu
17400
17401@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17402@node GDB/MI Command Syntax
17403@section @sc{gdb/mi} Command Syntax
17404
17405@menu
17406* GDB/MI Input Syntax::
17407* GDB/MI Output Syntax::
922fbb7b
AC
17408@end menu
17409
17410@node GDB/MI Input Syntax
17411@subsection @sc{gdb/mi} Input Syntax
17412
17413@cindex input syntax for @sc{gdb/mi}
17414@cindex @sc{gdb/mi}, input syntax
17415@table @code
17416@item @var{command} @expansion{}
17417@code{@var{cli-command} | @var{mi-command}}
17418
17419@item @var{cli-command} @expansion{}
17420@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
17421@var{cli-command} is any existing @value{GDBN} CLI command.
17422
17423@item @var{mi-command} @expansion{}
17424@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
17425@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
17426
17427@item @var{token} @expansion{}
17428"any sequence of digits"
17429
17430@item @var{option} @expansion{}
17431@code{"-" @var{parameter} [ " " @var{parameter} ]}
17432
17433@item @var{parameter} @expansion{}
17434@code{@var{non-blank-sequence} | @var{c-string}}
17435
17436@item @var{operation} @expansion{}
17437@emph{any of the operations described in this chapter}
17438
17439@item @var{non-blank-sequence} @expansion{}
17440@emph{anything, provided it doesn't contain special characters such as
17441"-", @var{nl}, """ and of course " "}
17442
17443@item @var{c-string} @expansion{}
17444@code{""" @var{seven-bit-iso-c-string-content} """}
17445
17446@item @var{nl} @expansion{}
17447@code{CR | CR-LF}
17448@end table
17449
17450@noindent
17451Notes:
17452
17453@itemize @bullet
17454@item
17455The CLI commands are still handled by the @sc{mi} interpreter; their
17456output is described below.
17457
17458@item
17459The @code{@var{token}}, when present, is passed back when the command
17460finishes.
17461
17462@item
17463Some @sc{mi} commands accept optional arguments as part of the parameter
17464list. Each option is identified by a leading @samp{-} (dash) and may be
17465followed by an optional argument parameter. Options occur first in the
17466parameter list and can be delimited from normal parameters using
17467@samp{--} (this is useful when some parameters begin with a dash).
17468@end itemize
17469
17470Pragmatics:
17471
17472@itemize @bullet
17473@item
17474We want easy access to the existing CLI syntax (for debugging).
17475
17476@item
17477We want it to be easy to spot a @sc{mi} operation.
17478@end itemize
17479
17480@node GDB/MI Output Syntax
17481@subsection @sc{gdb/mi} Output Syntax
17482
17483@cindex output syntax of @sc{gdb/mi}
17484@cindex @sc{gdb/mi}, output syntax
17485The output from @sc{gdb/mi} consists of zero or more out-of-band records
17486followed, optionally, by a single result record. This result record
17487is for the most recent command. The sequence of output records is
594fe323 17488terminated by @samp{(gdb)}.
922fbb7b
AC
17489
17490If an input command was prefixed with a @code{@var{token}} then the
17491corresponding output for that command will also be prefixed by that same
17492@var{token}.
17493
17494@table @code
17495@item @var{output} @expansion{}
594fe323 17496@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
17497
17498@item @var{result-record} @expansion{}
17499@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
17500
17501@item @var{out-of-band-record} @expansion{}
17502@code{@var{async-record} | @var{stream-record}}
17503
17504@item @var{async-record} @expansion{}
17505@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
17506
17507@item @var{exec-async-output} @expansion{}
17508@code{[ @var{token} ] "*" @var{async-output}}
17509
17510@item @var{status-async-output} @expansion{}
17511@code{[ @var{token} ] "+" @var{async-output}}
17512
17513@item @var{notify-async-output} @expansion{}
17514@code{[ @var{token} ] "=" @var{async-output}}
17515
17516@item @var{async-output} @expansion{}
17517@code{@var{async-class} ( "," @var{result} )* @var{nl}}
17518
17519@item @var{result-class} @expansion{}
17520@code{"done" | "running" | "connected" | "error" | "exit"}
17521
17522@item @var{async-class} @expansion{}
17523@code{"stopped" | @var{others}} (where @var{others} will be added
17524depending on the needs---this is still in development).
17525
17526@item @var{result} @expansion{}
17527@code{ @var{variable} "=" @var{value}}
17528
17529@item @var{variable} @expansion{}
17530@code{ @var{string} }
17531
17532@item @var{value} @expansion{}
17533@code{ @var{const} | @var{tuple} | @var{list} }
17534
17535@item @var{const} @expansion{}
17536@code{@var{c-string}}
17537
17538@item @var{tuple} @expansion{}
17539@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
17540
17541@item @var{list} @expansion{}
17542@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
17543@var{result} ( "," @var{result} )* "]" }
17544
17545@item @var{stream-record} @expansion{}
17546@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
17547
17548@item @var{console-stream-output} @expansion{}
17549@code{"~" @var{c-string}}
17550
17551@item @var{target-stream-output} @expansion{}
17552@code{"@@" @var{c-string}}
17553
17554@item @var{log-stream-output} @expansion{}
17555@code{"&" @var{c-string}}
17556
17557@item @var{nl} @expansion{}
17558@code{CR | CR-LF}
17559
17560@item @var{token} @expansion{}
17561@emph{any sequence of digits}.
17562@end table
17563
17564@noindent
17565Notes:
17566
17567@itemize @bullet
17568@item
17569All output sequences end in a single line containing a period.
17570
17571@item
17572The @code{@var{token}} is from the corresponding request. If an execution
17573command is interrupted by the @samp{-exec-interrupt} command, the
17574@var{token} associated with the @samp{*stopped} message is the one of the
17575original execution command, not the one of the interrupt command.
17576
17577@item
17578@cindex status output in @sc{gdb/mi}
17579@var{status-async-output} contains on-going status information about the
17580progress of a slow operation. It can be discarded. All status output is
17581prefixed by @samp{+}.
17582
17583@item
17584@cindex async output in @sc{gdb/mi}
17585@var{exec-async-output} contains asynchronous state change on the target
17586(stopped, started, disappeared). All async output is prefixed by
17587@samp{*}.
17588
17589@item
17590@cindex notify output in @sc{gdb/mi}
17591@var{notify-async-output} contains supplementary information that the
17592client should handle (e.g., a new breakpoint information). All notify
17593output is prefixed by @samp{=}.
17594
17595@item
17596@cindex console output in @sc{gdb/mi}
17597@var{console-stream-output} is output that should be displayed as is in the
17598console. It is the textual response to a CLI command. All the console
17599output is prefixed by @samp{~}.
17600
17601@item
17602@cindex target output in @sc{gdb/mi}
17603@var{target-stream-output} is the output produced by the target program.
17604All the target output is prefixed by @samp{@@}.
17605
17606@item
17607@cindex log output in @sc{gdb/mi}
17608@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
17609instance messages that should be displayed as part of an error log. All
17610the log output is prefixed by @samp{&}.
17611
17612@item
17613@cindex list output in @sc{gdb/mi}
17614New @sc{gdb/mi} commands should only output @var{lists} containing
17615@var{values}.
17616
17617
17618@end itemize
17619
17620@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
17621details about the various output records.
17622
922fbb7b
AC
17623@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17624@node GDB/MI Compatibility with CLI
17625@section @sc{gdb/mi} Compatibility with CLI
17626
17627@cindex compatibility, @sc{gdb/mi} and CLI
17628@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 17629
a2c02241
NR
17630For the developers convenience CLI commands can be entered directly,
17631but there may be some unexpected behaviour. For example, commands
17632that query the user will behave as if the user replied yes, breakpoint
17633command lists are not executed and some CLI commands, such as
17634@code{if}, @code{when} and @code{define}, prompt for further input with
17635@samp{>}, which is not valid MI output.
ef21caaf
NR
17636
17637This feature may be removed at some stage in the future and it is
a2c02241
NR
17638recommended that front ends use the @code{-interpreter-exec} command
17639(@pxref{-interpreter-exec}).
922fbb7b 17640
af6eff6f
NR
17641@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17642@node GDB/MI Development and Front Ends
17643@section @sc{gdb/mi} Development and Front Ends
17644@cindex @sc{gdb/mi} development
17645
17646The application which takes the MI output and presents the state of the
17647program being debugged to the user is called a @dfn{front end}.
17648
17649Although @sc{gdb/mi} is still incomplete, it is currently being used
17650by a variety of front ends to @value{GDBN}. This makes it difficult
17651to introduce new functionality without breaking existing usage. This
17652section tries to minimize the problems by describing how the protocol
17653might change.
17654
17655Some changes in MI need not break a carefully designed front end, and
17656for these the MI version will remain unchanged. The following is a
17657list of changes that may occur within one level, so front ends should
17658parse MI output in a way that can handle them:
17659
17660@itemize @bullet
17661@item
17662New MI commands may be added.
17663
17664@item
17665New fields may be added to the output of any MI command.
17666
17667@c The format of field's content e.g type prefix, may change so parse it
17668@c at your own risk. Yes, in general?
17669
17670@c The order of fields may change? Shouldn't really matter but it might
17671@c resolve inconsistencies.
17672@end itemize
17673
17674If the changes are likely to break front ends, the MI version level
17675will be increased by one. This will allow the front end to parse the
17676output according to the MI version. Apart from mi0, new versions of
17677@value{GDBN} will not support old versions of MI and it will be the
17678responsibility of the front end to work with the new one.
17679
17680@c Starting with mi3, add a new command -mi-version that prints the MI
17681@c version?
17682
17683The best way to avoid unexpected changes in MI that might break your front
17684end is to make your project known to @value{GDBN} developers and
7a9a6b69
NR
17685follow development on @email{gdb@@sourceware.org} and
17686@email{gdb-patches@@sourceware.org}. There is also the mailing list
af6eff6f
NR
17687@email{dmi-discuss@@lists.freestandards.org}, hosted by the Free Standards
17688Group, which has the aim of creating a a more general MI protocol
17689called Debugger Machine Interface (DMI) that will become a standard
17690for all debuggers, not just @value{GDBN}.
17691@cindex mailing lists
17692
922fbb7b
AC
17693@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17694@node GDB/MI Output Records
17695@section @sc{gdb/mi} Output Records
17696
17697@menu
17698* GDB/MI Result Records::
17699* GDB/MI Stream Records::
17700* GDB/MI Out-of-band Records::
17701@end menu
17702
17703@node GDB/MI Result Records
17704@subsection @sc{gdb/mi} Result Records
17705
17706@cindex result records in @sc{gdb/mi}
17707@cindex @sc{gdb/mi}, result records
17708In addition to a number of out-of-band notifications, the response to a
17709@sc{gdb/mi} command includes one of the following result indications:
17710
17711@table @code
17712@findex ^done
17713@item "^done" [ "," @var{results} ]
17714The synchronous operation was successful, @code{@var{results}} are the return
17715values.
17716
17717@item "^running"
17718@findex ^running
17719@c Is this one correct? Should it be an out-of-band notification?
17720The asynchronous operation was successfully started. The target is
17721running.
17722
ef21caaf
NR
17723@item "^connected"
17724@findex ^connected
17725GDB has connected to a remote target.
17726
922fbb7b
AC
17727@item "^error" "," @var{c-string}
17728@findex ^error
17729The operation failed. The @code{@var{c-string}} contains the corresponding
17730error message.
ef21caaf
NR
17731
17732@item "^exit"
17733@findex ^exit
17734GDB has terminated.
17735
922fbb7b
AC
17736@end table
17737
17738@node GDB/MI Stream Records
17739@subsection @sc{gdb/mi} Stream Records
17740
17741@cindex @sc{gdb/mi}, stream records
17742@cindex stream records in @sc{gdb/mi}
17743@value{GDBN} internally maintains a number of output streams: the console, the
17744target, and the log. The output intended for each of these streams is
17745funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17746
17747Each stream record begins with a unique @dfn{prefix character} which
17748identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17749Syntax}). In addition to the prefix, each stream record contains a
17750@code{@var{string-output}}. This is either raw text (with an implicit new
17751line) or a quoted C string (which does not contain an implicit newline).
17752
17753@table @code
17754@item "~" @var{string-output}
17755The console output stream contains text that should be displayed in the
17756CLI console window. It contains the textual responses to CLI commands.
17757
17758@item "@@" @var{string-output}
17759The target output stream contains any textual output from the running
ef21caaf
NR
17760target. This is only present when GDB's event loop is truly
17761asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
17762
17763@item "&" @var{string-output}
17764The log stream contains debugging messages being produced by @value{GDBN}'s
17765internals.
17766@end table
17767
17768@node GDB/MI Out-of-band Records
17769@subsection @sc{gdb/mi} Out-of-band Records
17770
17771@cindex out-of-band records in @sc{gdb/mi}
17772@cindex @sc{gdb/mi}, out-of-band records
17773@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17774additional changes that have occurred. Those changes can either be a
17775consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17776target activity (e.g., target stopped).
17777
17778The following is a preliminary list of possible out-of-band records.
034dad6f 17779In particular, the @var{exec-async-output} records.
922fbb7b
AC
17780
17781@table @code
034dad6f
BR
17782@item *stopped,reason="@var{reason}"
17783@end table
17784
17785@var{reason} can be one of the following:
17786
17787@table @code
17788@item breakpoint-hit
17789A breakpoint was reached.
17790@item watchpoint-trigger
17791A watchpoint was triggered.
17792@item read-watchpoint-trigger
17793A read watchpoint was triggered.
17794@item access-watchpoint-trigger
17795An access watchpoint was triggered.
17796@item function-finished
17797An -exec-finish or similar CLI command was accomplished.
17798@item location-reached
17799An -exec-until or similar CLI command was accomplished.
17800@item watchpoint-scope
17801A watchpoint has gone out of scope.
17802@item end-stepping-range
17803An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17804similar CLI command was accomplished.
17805@item exited-signalled
17806The inferior exited because of a signal.
17807@item exited
17808The inferior exited.
17809@item exited-normally
17810The inferior exited normally.
17811@item signal-received
17812A signal was received by the inferior.
922fbb7b
AC
17813@end table
17814
17815
ef21caaf
NR
17816@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17817@node GDB/MI Simple Examples
17818@section Simple Examples of @sc{gdb/mi} Interaction
17819@cindex @sc{gdb/mi}, simple examples
17820
17821This subsection presents several simple examples of interaction using
17822the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
17823following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
17824the output received from @sc{gdb/mi}.
17825
17826Note the the line breaks shown in the examples are here only for
17827readability, they don't appear in the real output.
17828
17829@subheading Setting a breakpoint
17830
17831Setting a breakpoint generates synchronous output which contains detailed
17832information of the breakpoint.
17833
17834@smallexample
17835-> -break-insert main
17836<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
17837 enabled="y",addr="0x08048564",func="main",file="myprog.c",
17838 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
17839<- (gdb)
17840@end smallexample
17841
17842@subheading Program Execution
17843
17844Program execution generates asynchronous records and MI gives the
17845reason that execution stopped.
17846
17847@smallexample
17848-> -exec-run
17849<- ^running
17850<- (gdb)
17851<- *stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",
17852 frame=@{addr="0x08048564",func="main",
17853 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
17854 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
17855<- (gdb)
17856-> -exec-continue
17857<- ^running
17858<- (gdb)
17859<- *stopped,reason="exited-normally"
17860<- (gdb)
17861@end smallexample
17862
17863@subheading Quitting GDB
17864
17865Quitting GDB just prints the result class @samp{^exit}.
17866
17867@smallexample
17868-> (gdb)
17869<- -gdb-exit
17870<- ^exit
17871@end smallexample
17872
a2c02241 17873@subheading A Bad Command
ef21caaf
NR
17874
17875Here's what happens if you pass a non-existent command:
17876
17877@smallexample
17878-> -rubbish
17879<- ^error,msg="Undefined MI command: rubbish"
594fe323 17880<- (gdb)
ef21caaf
NR
17881@end smallexample
17882
17883
922fbb7b
AC
17884@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17885@node GDB/MI Command Description Format
17886@section @sc{gdb/mi} Command Description Format
17887
17888The remaining sections describe blocks of commands. Each block of
17889commands is laid out in a fashion similar to this section.
17890
922fbb7b
AC
17891@subheading Motivation
17892
17893The motivation for this collection of commands.
17894
17895@subheading Introduction
17896
17897A brief introduction to this collection of commands as a whole.
17898
17899@subheading Commands
17900
17901For each command in the block, the following is described:
17902
17903@subsubheading Synopsis
17904
17905@smallexample
17906 -command @var{args}@dots{}
17907@end smallexample
17908
922fbb7b
AC
17909@subsubheading Result
17910
265eeb58 17911@subsubheading @value{GDBN} Command
922fbb7b 17912
265eeb58 17913The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17914
17915@subsubheading Example
17916
ef21caaf
NR
17917Example(s) formatted for readability. Some of the described commands have
17918not been implemented yet and these are labeled N.A.@: (not available).
17919
17920
922fbb7b 17921@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
17922@node GDB/MI Breakpoint Commands
17923@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
17924
17925@cindex breakpoint commands for @sc{gdb/mi}
17926@cindex @sc{gdb/mi}, breakpoint commands
17927This section documents @sc{gdb/mi} commands for manipulating
17928breakpoints.
17929
17930@subheading The @code{-break-after} Command
17931@findex -break-after
17932
17933@subsubheading Synopsis
17934
17935@smallexample
17936 -break-after @var{number} @var{count}
17937@end smallexample
17938
17939The breakpoint number @var{number} is not in effect until it has been
17940hit @var{count} times. To see how this is reflected in the output of
17941the @samp{-break-list} command, see the description of the
17942@samp{-break-list} command below.
17943
17944@subsubheading @value{GDBN} Command
17945
17946The corresponding @value{GDBN} command is @samp{ignore}.
17947
17948@subsubheading Example
17949
17950@smallexample
594fe323 17951(gdb)
922fbb7b 17952-break-insert main
948d5102
NR
17953^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",
17954fullname="/home/foo/hello.c",line="5",times="0"@}
594fe323 17955(gdb)
922fbb7b
AC
17956-break-after 1 3
17957~
17958^done
594fe323 17959(gdb)
922fbb7b
AC
17960-break-list
17961^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17962hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17963@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17964@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17965@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17966@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17967@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17968body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
17969addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
17970line="5",times="0",ignore="3"@}]@}
594fe323 17971(gdb)
922fbb7b
AC
17972@end smallexample
17973
17974@ignore
17975@subheading The @code{-break-catch} Command
17976@findex -break-catch
17977
17978@subheading The @code{-break-commands} Command
17979@findex -break-commands
17980@end ignore
17981
17982
17983@subheading The @code{-break-condition} Command
17984@findex -break-condition
17985
17986@subsubheading Synopsis
17987
17988@smallexample
17989 -break-condition @var{number} @var{expr}
17990@end smallexample
17991
17992Breakpoint @var{number} will stop the program only if the condition in
17993@var{expr} is true. The condition becomes part of the
17994@samp{-break-list} output (see the description of the @samp{-break-list}
17995command below).
17996
17997@subsubheading @value{GDBN} Command
17998
17999The corresponding @value{GDBN} command is @samp{condition}.
18000
18001@subsubheading Example
18002
18003@smallexample
594fe323 18004(gdb)
922fbb7b
AC
18005-break-condition 1 1
18006^done
594fe323 18007(gdb)
922fbb7b
AC
18008-break-list
18009^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18010hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18011@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18012@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18013@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18014@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18015@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18016body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18017addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18018line="5",cond="1",times="0",ignore="3"@}]@}
594fe323 18019(gdb)
922fbb7b
AC
18020@end smallexample
18021
18022@subheading The @code{-break-delete} Command
18023@findex -break-delete
18024
18025@subsubheading Synopsis
18026
18027@smallexample
18028 -break-delete ( @var{breakpoint} )+
18029@end smallexample
18030
18031Delete the breakpoint(s) whose number(s) are specified in the argument
18032list. This is obviously reflected in the breakpoint list.
18033
18034@subsubheading @value{GDBN} command
18035
18036The corresponding @value{GDBN} command is @samp{delete}.
18037
18038@subsubheading Example
18039
18040@smallexample
594fe323 18041(gdb)
922fbb7b
AC
18042-break-delete 1
18043^done
594fe323 18044(gdb)
922fbb7b
AC
18045-break-list
18046^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18047hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18048@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18049@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18050@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18051@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18052@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18053body=[]@}
594fe323 18054(gdb)
922fbb7b
AC
18055@end smallexample
18056
18057@subheading The @code{-break-disable} Command
18058@findex -break-disable
18059
18060@subsubheading Synopsis
18061
18062@smallexample
18063 -break-disable ( @var{breakpoint} )+
18064@end smallexample
18065
18066Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
18067break list is now set to @samp{n} for the named @var{breakpoint}(s).
18068
18069@subsubheading @value{GDBN} Command
18070
18071The corresponding @value{GDBN} command is @samp{disable}.
18072
18073@subsubheading Example
18074
18075@smallexample
594fe323 18076(gdb)
922fbb7b
AC
18077-break-disable 2
18078^done
594fe323 18079(gdb)
922fbb7b
AC
18080-break-list
18081^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18082hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18083@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18084@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18085@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18086@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18087@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18088body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102
NR
18089addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18090line="5",times="0"@}]@}
594fe323 18091(gdb)
922fbb7b
AC
18092@end smallexample
18093
18094@subheading The @code{-break-enable} Command
18095@findex -break-enable
18096
18097@subsubheading Synopsis
18098
18099@smallexample
18100 -break-enable ( @var{breakpoint} )+
18101@end smallexample
18102
18103Enable (previously disabled) @var{breakpoint}(s).
18104
18105@subsubheading @value{GDBN} Command
18106
18107The corresponding @value{GDBN} command is @samp{enable}.
18108
18109@subsubheading Example
18110
18111@smallexample
594fe323 18112(gdb)
922fbb7b
AC
18113-break-enable 2
18114^done
594fe323 18115(gdb)
922fbb7b
AC
18116-break-list
18117^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18118hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18119@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18120@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18121@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18122@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18123@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18124body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18125addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18126line="5",times="0"@}]@}
594fe323 18127(gdb)
922fbb7b
AC
18128@end smallexample
18129
18130@subheading The @code{-break-info} Command
18131@findex -break-info
18132
18133@subsubheading Synopsis
18134
18135@smallexample
18136 -break-info @var{breakpoint}
18137@end smallexample
18138
18139@c REDUNDANT???
18140Get information about a single breakpoint.
18141
18142@subsubheading @value{GDBN} command
18143
18144The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
18145
18146@subsubheading Example
18147N.A.
18148
18149@subheading The @code{-break-insert} Command
18150@findex -break-insert
18151
18152@subsubheading Synopsis
18153
18154@smallexample
18155 -break-insert [ -t ] [ -h ] [ -r ]
18156 [ -c @var{condition} ] [ -i @var{ignore-count} ]
18157 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
18158@end smallexample
18159
18160@noindent
18161If specified, @var{line}, can be one of:
18162
18163@itemize @bullet
18164@item function
18165@c @item +offset
18166@c @item -offset
18167@c @item linenum
18168@item filename:linenum
18169@item filename:function
18170@item *address
18171@end itemize
18172
18173The possible optional parameters of this command are:
18174
18175@table @samp
18176@item -t
948d5102 18177Insert a temporary breakpoint.
922fbb7b
AC
18178@item -h
18179Insert a hardware breakpoint.
18180@item -c @var{condition}
18181Make the breakpoint conditional on @var{condition}.
18182@item -i @var{ignore-count}
18183Initialize the @var{ignore-count}.
18184@item -r
18185Insert a regular breakpoint in all the functions whose names match the
18186given regular expression. Other flags are not applicable to regular
18187expresson.
18188@end table
18189
18190@subsubheading Result
18191
18192The result is in the form:
18193
18194@smallexample
948d5102
NR
18195^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
18196enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
ef21caaf
NR
18197fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
18198times="@var{times}"@}
922fbb7b
AC
18199@end smallexample
18200
18201@noindent
948d5102
NR
18202where @var{number} is the @value{GDBN} number for this breakpoint,
18203@var{funcname} is the name of the function where the breakpoint was
18204inserted, @var{filename} is the name of the source file which contains
18205this function, @var{lineno} is the source line number within that file
18206and @var{times} the number of times that the breakpoint has been hit
18207(always 0 for -break-insert but may be greater for -break-info or -break-list
18208which use the same output).
922fbb7b
AC
18209
18210Note: this format is open to change.
18211@c An out-of-band breakpoint instead of part of the result?
18212
18213@subsubheading @value{GDBN} Command
18214
18215The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
18216@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
18217
18218@subsubheading Example
18219
18220@smallexample
594fe323 18221(gdb)
922fbb7b 18222-break-insert main
948d5102
NR
18223^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
18224fullname="/home/foo/recursive2.c,line="4",times="0"@}
594fe323 18225(gdb)
922fbb7b 18226-break-insert -t foo
948d5102
NR
18227^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
18228fullname="/home/foo/recursive2.c,line="11",times="0"@}
594fe323 18229(gdb)
922fbb7b
AC
18230-break-list
18231^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18232hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18233@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18234@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18235@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18236@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18237@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18238body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18239addr="0x0001072c", func="main",file="recursive2.c",
18240fullname="/home/foo/recursive2.c,"line="4",times="0"@},
922fbb7b 18241bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102
NR
18242addr="0x00010774",func="foo",file="recursive2.c",
18243fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
594fe323 18244(gdb)
922fbb7b
AC
18245-break-insert -r foo.*
18246~int foo(int, int);
948d5102
NR
18247^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
18248"fullname="/home/foo/recursive2.c",line="11",times="0"@}
594fe323 18249(gdb)
922fbb7b
AC
18250@end smallexample
18251
18252@subheading The @code{-break-list} Command
18253@findex -break-list
18254
18255@subsubheading Synopsis
18256
18257@smallexample
18258 -break-list
18259@end smallexample
18260
18261Displays the list of inserted breakpoints, showing the following fields:
18262
18263@table @samp
18264@item Number
18265number of the breakpoint
18266@item Type
18267type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
18268@item Disposition
18269should the breakpoint be deleted or disabled when it is hit: @samp{keep}
18270or @samp{nokeep}
18271@item Enabled
18272is the breakpoint enabled or no: @samp{y} or @samp{n}
18273@item Address
18274memory location at which the breakpoint is set
18275@item What
18276logical location of the breakpoint, expressed by function name, file
18277name, line number
18278@item Times
18279number of times the breakpoint has been hit
18280@end table
18281
18282If there are no breakpoints or watchpoints, the @code{BreakpointTable}
18283@code{body} field is an empty list.
18284
18285@subsubheading @value{GDBN} Command
18286
18287The corresponding @value{GDBN} command is @samp{info break}.
18288
18289@subsubheading Example
18290
18291@smallexample
594fe323 18292(gdb)
922fbb7b
AC
18293-break-list
18294^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18295hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18296@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18297@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18298@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18299@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18300@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18301body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18302addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
18303bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18304addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
18305line="13",times="0"@}]@}
594fe323 18306(gdb)
922fbb7b
AC
18307@end smallexample
18308
18309Here's an example of the result when there are no breakpoints:
18310
18311@smallexample
594fe323 18312(gdb)
922fbb7b
AC
18313-break-list
18314^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18315hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18316@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18317@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18318@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18319@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18320@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18321body=[]@}
594fe323 18322(gdb)
922fbb7b
AC
18323@end smallexample
18324
18325@subheading The @code{-break-watch} Command
18326@findex -break-watch
18327
18328@subsubheading Synopsis
18329
18330@smallexample
18331 -break-watch [ -a | -r ]
18332@end smallexample
18333
18334Create a watchpoint. With the @samp{-a} option it will create an
18335@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
18336read from or on a write to the memory location. With the @samp{-r}
18337option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
18338trigger only when the memory location is accessed for reading. Without
18339either of the options, the watchpoint created is a regular watchpoint,
18340i.e. it will trigger when the memory location is accessed for writing.
18341@xref{Set Watchpoints, , Setting watchpoints}.
18342
18343Note that @samp{-break-list} will report a single list of watchpoints and
18344breakpoints inserted.
18345
18346@subsubheading @value{GDBN} Command
18347
18348The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
18349@samp{rwatch}.
18350
18351@subsubheading Example
18352
18353Setting a watchpoint on a variable in the @code{main} function:
18354
18355@smallexample
594fe323 18356(gdb)
922fbb7b
AC
18357-break-watch x
18358^done,wpt=@{number="2",exp="x"@}
594fe323 18359(gdb)
922fbb7b
AC
18360-exec-continue
18361^running
18362^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
18363value=@{old="-268439212",new="55"@},
76ff342d 18364frame=@{func="main",args=[],file="recursive2.c",
948d5102 18365fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 18366(gdb)
922fbb7b
AC
18367@end smallexample
18368
18369Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
18370the program execution twice: first for the variable changing value, then
18371for the watchpoint going out of scope.
18372
18373@smallexample
594fe323 18374(gdb)
922fbb7b
AC
18375-break-watch C
18376^done,wpt=@{number="5",exp="C"@}
594fe323 18377(gdb)
922fbb7b
AC
18378-exec-continue
18379^running
18380^done,reason="watchpoint-trigger",
18381wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
18382frame=@{func="callee4",args=[],
76ff342d
DJ
18383file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18384fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 18385(gdb)
922fbb7b
AC
18386-exec-continue
18387^running
18388^done,reason="watchpoint-scope",wpnum="5",
18389frame=@{func="callee3",args=[@{name="strarg",
18390value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18391file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18392fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 18393(gdb)
922fbb7b
AC
18394@end smallexample
18395
18396Listing breakpoints and watchpoints, at different points in the program
18397execution. Note that once the watchpoint goes out of scope, it is
18398deleted.
18399
18400@smallexample
594fe323 18401(gdb)
922fbb7b
AC
18402-break-watch C
18403^done,wpt=@{number="2",exp="C"@}
594fe323 18404(gdb)
922fbb7b
AC
18405-break-list
18406^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18407hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18408@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18409@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18410@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18411@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18412@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18413body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18414addr="0x00010734",func="callee4",
948d5102
NR
18415file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18416fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
922fbb7b
AC
18417bkpt=@{number="2",type="watchpoint",disp="keep",
18418enabled="y",addr="",what="C",times="0"@}]@}
594fe323 18419(gdb)
922fbb7b
AC
18420-exec-continue
18421^running
18422^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
18423value=@{old="-276895068",new="3"@},
18424frame=@{func="callee4",args=[],
76ff342d
DJ
18425file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18426fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 18427(gdb)
922fbb7b
AC
18428-break-list
18429^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18430hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18431@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18432@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18433@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18434@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18435@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18436body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18437addr="0x00010734",func="callee4",
948d5102
NR
18438file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18439fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
922fbb7b
AC
18440bkpt=@{number="2",type="watchpoint",disp="keep",
18441enabled="y",addr="",what="C",times="-5"@}]@}
594fe323 18442(gdb)
922fbb7b
AC
18443-exec-continue
18444^running
18445^done,reason="watchpoint-scope",wpnum="2",
18446frame=@{func="callee3",args=[@{name="strarg",
18447value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18448file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18449fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 18450(gdb)
922fbb7b
AC
18451-break-list
18452^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18453hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18454@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18455@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18456@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18457@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18458@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18459body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18460addr="0x00010734",func="callee4",
948d5102
NR
18461file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18462fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
18463times="1"@}]@}
594fe323 18464(gdb)
922fbb7b
AC
18465@end smallexample
18466
18467@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
18468@node GDB/MI Program Context
18469@section @sc{gdb/mi} Program Context
922fbb7b 18470
a2c02241
NR
18471@subheading The @code{-exec-arguments} Command
18472@findex -exec-arguments
922fbb7b 18473
922fbb7b
AC
18474
18475@subsubheading Synopsis
18476
18477@smallexample
a2c02241 18478 -exec-arguments @var{args}
922fbb7b
AC
18479@end smallexample
18480
a2c02241
NR
18481Set the inferior program arguments, to be used in the next
18482@samp{-exec-run}.
922fbb7b 18483
a2c02241 18484@subsubheading @value{GDBN} Command
922fbb7b 18485
a2c02241 18486The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 18487
a2c02241 18488@subsubheading Example
922fbb7b 18489
a2c02241
NR
18490@c FIXME!
18491Don't have one around.
922fbb7b 18492
a2c02241
NR
18493
18494@subheading The @code{-exec-show-arguments} Command
18495@findex -exec-show-arguments
18496
18497@subsubheading Synopsis
18498
18499@smallexample
18500 -exec-show-arguments
18501@end smallexample
18502
18503Print the arguments of the program.
922fbb7b
AC
18504
18505@subsubheading @value{GDBN} Command
18506
a2c02241 18507The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
18508
18509@subsubheading Example
a2c02241 18510N.A.
922fbb7b 18511
922fbb7b 18512
a2c02241
NR
18513@subheading The @code{-environment-cd} Command
18514@findex -environment-cd
922fbb7b 18515
a2c02241 18516@subsubheading Synopsis
922fbb7b
AC
18517
18518@smallexample
a2c02241 18519 -environment-cd @var{pathdir}
922fbb7b
AC
18520@end smallexample
18521
a2c02241 18522Set @value{GDBN}'s working directory.
922fbb7b 18523
a2c02241 18524@subsubheading @value{GDBN} Command
922fbb7b 18525
a2c02241
NR
18526The corresponding @value{GDBN} command is @samp{cd}.
18527
18528@subsubheading Example
922fbb7b
AC
18529
18530@smallexample
594fe323 18531(gdb)
a2c02241
NR
18532-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18533^done
594fe323 18534(gdb)
922fbb7b
AC
18535@end smallexample
18536
18537
a2c02241
NR
18538@subheading The @code{-environment-directory} Command
18539@findex -environment-directory
922fbb7b
AC
18540
18541@subsubheading Synopsis
18542
18543@smallexample
a2c02241 18544 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
18545@end smallexample
18546
a2c02241
NR
18547Add directories @var{pathdir} to beginning of search path for source files.
18548If the @samp{-r} option is used, the search path is reset to the default
18549search path. If directories @var{pathdir} are supplied in addition to the
18550@samp{-r} option, the search path is first reset and then addition
18551occurs as normal.
18552Multiple directories may be specified, separated by blanks. Specifying
18553multiple directories in a single command
18554results in the directories added to the beginning of the
18555search path in the same order they were presented in the command.
18556If blanks are needed as
18557part of a directory name, double-quotes should be used around
18558the name. In the command output, the path will show up separated
18559by the system directory-separator character. The directory-seperator
18560character must not be used
18561in any directory name.
18562If no directories are specified, the current search path is displayed.
922fbb7b
AC
18563
18564@subsubheading @value{GDBN} Command
18565
a2c02241 18566The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
18567
18568@subsubheading Example
18569
922fbb7b 18570@smallexample
594fe323 18571(gdb)
a2c02241
NR
18572-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18573^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 18574(gdb)
a2c02241
NR
18575-environment-directory ""
18576^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 18577(gdb)
a2c02241
NR
18578-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18579^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 18580(gdb)
a2c02241
NR
18581-environment-directory -r
18582^done,source-path="$cdir:$cwd"
594fe323 18583(gdb)
922fbb7b
AC
18584@end smallexample
18585
18586
a2c02241
NR
18587@subheading The @code{-environment-path} Command
18588@findex -environment-path
922fbb7b
AC
18589
18590@subsubheading Synopsis
18591
18592@smallexample
a2c02241 18593 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
18594@end smallexample
18595
a2c02241
NR
18596Add directories @var{pathdir} to beginning of search path for object files.
18597If the @samp{-r} option is used, the search path is reset to the original
18598search path that existed at gdb start-up. If directories @var{pathdir} are
18599supplied in addition to the
18600@samp{-r} option, the search path is first reset and then addition
18601occurs as normal.
18602Multiple directories may be specified, separated by blanks. Specifying
18603multiple directories in a single command
18604results in the directories added to the beginning of the
18605search path in the same order they were presented in the command.
18606If blanks are needed as
18607part of a directory name, double-quotes should be used around
18608the name. In the command output, the path will show up separated
18609by the system directory-separator character. The directory-seperator
18610character must not be used
18611in any directory name.
18612If no directories are specified, the current path is displayed.
18613
922fbb7b
AC
18614
18615@subsubheading @value{GDBN} Command
18616
a2c02241 18617The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
18618
18619@subsubheading Example
18620
922fbb7b 18621@smallexample
594fe323 18622(gdb)
a2c02241
NR
18623-environment-path
18624^done,path="/usr/bin"
594fe323 18625(gdb)
a2c02241
NR
18626-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18627^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 18628(gdb)
a2c02241
NR
18629-environment-path -r /usr/local/bin
18630^done,path="/usr/local/bin:/usr/bin"
594fe323 18631(gdb)
922fbb7b
AC
18632@end smallexample
18633
18634
a2c02241
NR
18635@subheading The @code{-environment-pwd} Command
18636@findex -environment-pwd
922fbb7b
AC
18637
18638@subsubheading Synopsis
18639
18640@smallexample
a2c02241 18641 -environment-pwd
922fbb7b
AC
18642@end smallexample
18643
a2c02241 18644Show the current working directory.
922fbb7b 18645
a2c02241 18646@subsubheading @value{GDBN} command
922fbb7b 18647
a2c02241 18648The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
18649
18650@subsubheading Example
18651
922fbb7b 18652@smallexample
594fe323 18653(gdb)
a2c02241
NR
18654-environment-pwd
18655^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 18656(gdb)
922fbb7b
AC
18657@end smallexample
18658
a2c02241
NR
18659@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18660@node GDB/MI Thread Commands
18661@section @sc{gdb/mi} Thread Commands
18662
18663
18664@subheading The @code{-thread-info} Command
18665@findex -thread-info
922fbb7b
AC
18666
18667@subsubheading Synopsis
18668
18669@smallexample
a2c02241 18670 -thread-info
922fbb7b
AC
18671@end smallexample
18672
a2c02241 18673@subsubheading @value{GDBN} command
922fbb7b 18674
a2c02241 18675No equivalent.
922fbb7b
AC
18676
18677@subsubheading Example
a2c02241 18678N.A.
922fbb7b
AC
18679
18680
a2c02241
NR
18681@subheading The @code{-thread-list-all-threads} Command
18682@findex -thread-list-all-threads
922fbb7b
AC
18683
18684@subsubheading Synopsis
18685
18686@smallexample
a2c02241 18687 -thread-list-all-threads
922fbb7b
AC
18688@end smallexample
18689
a2c02241 18690@subsubheading @value{GDBN} Command
922fbb7b 18691
a2c02241 18692The equivalent @value{GDBN} command is @samp{info threads}.
922fbb7b 18693
a2c02241
NR
18694@subsubheading Example
18695N.A.
922fbb7b 18696
922fbb7b 18697
a2c02241
NR
18698@subheading The @code{-thread-list-ids} Command
18699@findex -thread-list-ids
922fbb7b 18700
a2c02241 18701@subsubheading Synopsis
922fbb7b 18702
a2c02241
NR
18703@smallexample
18704 -thread-list-ids
18705@end smallexample
922fbb7b 18706
a2c02241
NR
18707Produces a list of the currently known @value{GDBN} thread ids. At the
18708end of the list it also prints the total number of such threads.
922fbb7b
AC
18709
18710@subsubheading @value{GDBN} Command
18711
a2c02241 18712Part of @samp{info threads} supplies the same information.
922fbb7b
AC
18713
18714@subsubheading Example
18715
a2c02241 18716No threads present, besides the main process:
922fbb7b
AC
18717
18718@smallexample
594fe323 18719(gdb)
a2c02241
NR
18720-thread-list-ids
18721^done,thread-ids=@{@},number-of-threads="0"
594fe323 18722(gdb)
922fbb7b
AC
18723@end smallexample
18724
922fbb7b 18725
a2c02241 18726Several threads:
922fbb7b
AC
18727
18728@smallexample
594fe323 18729(gdb)
a2c02241
NR
18730-thread-list-ids
18731^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18732number-of-threads="3"
594fe323 18733(gdb)
922fbb7b
AC
18734@end smallexample
18735
a2c02241
NR
18736
18737@subheading The @code{-thread-select} Command
18738@findex -thread-select
922fbb7b
AC
18739
18740@subsubheading Synopsis
18741
18742@smallexample
a2c02241 18743 -thread-select @var{threadnum}
922fbb7b
AC
18744@end smallexample
18745
a2c02241
NR
18746Make @var{threadnum} the current thread. It prints the number of the new
18747current thread, and the topmost frame for that thread.
922fbb7b
AC
18748
18749@subsubheading @value{GDBN} Command
18750
a2c02241 18751The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
18752
18753@subsubheading Example
922fbb7b
AC
18754
18755@smallexample
594fe323 18756(gdb)
a2c02241
NR
18757-exec-next
18758^running
594fe323 18759(gdb)
a2c02241
NR
18760*stopped,reason="end-stepping-range",thread-id="2",line="187",
18761file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 18762(gdb)
a2c02241
NR
18763-thread-list-ids
18764^done,
18765thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18766number-of-threads="3"
594fe323 18767(gdb)
a2c02241
NR
18768-thread-select 3
18769^done,new-thread-id="3",
18770frame=@{level="0",func="vprintf",
18771args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18772@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 18773(gdb)
922fbb7b
AC
18774@end smallexample
18775
a2c02241
NR
18776@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18777@node GDB/MI Program Execution
18778@section @sc{gdb/mi} Program Execution
922fbb7b 18779
ef21caaf
NR
18780These are the asynchronous commands which generate the out-of-band
18781record @samp{*stopped}. Currently GDB only really executes
18782asynchronously with remote targets and this interaction is mimicked in
18783other cases.
922fbb7b 18784
922fbb7b
AC
18785@subheading The @code{-exec-continue} Command
18786@findex -exec-continue
18787
18788@subsubheading Synopsis
18789
18790@smallexample
18791 -exec-continue
18792@end smallexample
18793
ef21caaf
NR
18794Resumes the execution of the inferior program until a breakpoint is
18795encountered, or until the inferior exits.
922fbb7b
AC
18796
18797@subsubheading @value{GDBN} Command
18798
18799The corresponding @value{GDBN} corresponding is @samp{continue}.
18800
18801@subsubheading Example
18802
18803@smallexample
18804-exec-continue
18805^running
594fe323 18806(gdb)
922fbb7b
AC
18807@@Hello world
18808*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
948d5102 18809file="hello.c",fullname="/home/foo/bar/hello.c",line="13"@}
594fe323 18810(gdb)
922fbb7b
AC
18811@end smallexample
18812
18813
18814@subheading The @code{-exec-finish} Command
18815@findex -exec-finish
18816
18817@subsubheading Synopsis
18818
18819@smallexample
18820 -exec-finish
18821@end smallexample
18822
ef21caaf
NR
18823Resumes the execution of the inferior program until the current
18824function is exited. Displays the results returned by the function.
922fbb7b
AC
18825
18826@subsubheading @value{GDBN} Command
18827
18828The corresponding @value{GDBN} command is @samp{finish}.
18829
18830@subsubheading Example
18831
18832Function returning @code{void}.
18833
18834@smallexample
18835-exec-finish
18836^running
594fe323 18837(gdb)
922fbb7b
AC
18838@@hello from foo
18839*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 18840file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 18841(gdb)
922fbb7b
AC
18842@end smallexample
18843
18844Function returning other than @code{void}. The name of the internal
18845@value{GDBN} variable storing the result is printed, together with the
18846value itself.
18847
18848@smallexample
18849-exec-finish
18850^running
594fe323 18851(gdb)
922fbb7b
AC
18852*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18853args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 18854file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 18855gdb-result-var="$1",return-value="0"
594fe323 18856(gdb)
922fbb7b
AC
18857@end smallexample
18858
18859
18860@subheading The @code{-exec-interrupt} Command
18861@findex -exec-interrupt
18862
18863@subsubheading Synopsis
18864
18865@smallexample
18866 -exec-interrupt
18867@end smallexample
18868
ef21caaf
NR
18869Interrupts the background execution of the target. Note how the token
18870associated with the stop message is the one for the execution command
18871that has been interrupted. The token for the interrupt itself only
18872appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
18873interrupt a non-running program, an error message will be printed.
18874
18875@subsubheading @value{GDBN} Command
18876
18877The corresponding @value{GDBN} command is @samp{interrupt}.
18878
18879@subsubheading Example
18880
18881@smallexample
594fe323 18882(gdb)
922fbb7b
AC
18883111-exec-continue
18884111^running
18885
594fe323 18886(gdb)
922fbb7b
AC
18887222-exec-interrupt
18888222^done
594fe323 18889(gdb)
922fbb7b 18890111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 18891frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 18892fullname="/home/foo/bar/try.c",line="13"@}
594fe323 18893(gdb)
922fbb7b 18894
594fe323 18895(gdb)
922fbb7b
AC
18896-exec-interrupt
18897^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 18898(gdb)
922fbb7b
AC
18899@end smallexample
18900
18901
18902@subheading The @code{-exec-next} Command
18903@findex -exec-next
18904
18905@subsubheading Synopsis
18906
18907@smallexample
18908 -exec-next
18909@end smallexample
18910
ef21caaf
NR
18911Resumes execution of the inferior program, stopping when the beginning
18912of the next source line is reached.
922fbb7b
AC
18913
18914@subsubheading @value{GDBN} Command
18915
18916The corresponding @value{GDBN} command is @samp{next}.
18917
18918@subsubheading Example
18919
18920@smallexample
18921-exec-next
18922^running
594fe323 18923(gdb)
922fbb7b 18924*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 18925(gdb)
922fbb7b
AC
18926@end smallexample
18927
18928
18929@subheading The @code{-exec-next-instruction} Command
18930@findex -exec-next-instruction
18931
18932@subsubheading Synopsis
18933
18934@smallexample
18935 -exec-next-instruction
18936@end smallexample
18937
ef21caaf
NR
18938Executes one machine instruction. If the instruction is a function
18939call, continues until the function returns. If the program stops at an
18940instruction in the middle of a source line, the address will be
18941printed as well.
922fbb7b
AC
18942
18943@subsubheading @value{GDBN} Command
18944
18945The corresponding @value{GDBN} command is @samp{nexti}.
18946
18947@subsubheading Example
18948
18949@smallexample
594fe323 18950(gdb)
922fbb7b
AC
18951-exec-next-instruction
18952^running
18953
594fe323 18954(gdb)
922fbb7b
AC
18955*stopped,reason="end-stepping-range",
18956addr="0x000100d4",line="5",file="hello.c"
594fe323 18957(gdb)
922fbb7b
AC
18958@end smallexample
18959
18960
18961@subheading The @code{-exec-return} Command
18962@findex -exec-return
18963
18964@subsubheading Synopsis
18965
18966@smallexample
18967 -exec-return
18968@end smallexample
18969
18970Makes current function return immediately. Doesn't execute the inferior.
18971Displays the new current frame.
18972
18973@subsubheading @value{GDBN} Command
18974
18975The corresponding @value{GDBN} command is @samp{return}.
18976
18977@subsubheading Example
18978
18979@smallexample
594fe323 18980(gdb)
922fbb7b
AC
18981200-break-insert callee4
18982200^done,bkpt=@{number="1",addr="0x00010734",
18983file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 18984(gdb)
922fbb7b
AC
18985000-exec-run
18986000^running
594fe323 18987(gdb)
922fbb7b
AC
18988000*stopped,reason="breakpoint-hit",bkptno="1",
18989frame=@{func="callee4",args=[],
76ff342d
DJ
18990file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18991fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 18992(gdb)
922fbb7b
AC
18993205-break-delete
18994205^done
594fe323 18995(gdb)
922fbb7b
AC
18996111-exec-return
18997111^done,frame=@{level="0",func="callee3",
18998args=[@{name="strarg",
18999value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
19000file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19001fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 19002(gdb)
922fbb7b
AC
19003@end smallexample
19004
19005
19006@subheading The @code{-exec-run} Command
19007@findex -exec-run
19008
19009@subsubheading Synopsis
19010
19011@smallexample
19012 -exec-run
19013@end smallexample
19014
ef21caaf
NR
19015Starts execution of the inferior from the beginning. The inferior
19016executes until either a breakpoint is encountered or the program
19017exits. In the latter case the output will include an exit code, if
19018the program has exited exceptionally.
922fbb7b
AC
19019
19020@subsubheading @value{GDBN} Command
19021
19022The corresponding @value{GDBN} command is @samp{run}.
19023
ef21caaf 19024@subsubheading Examples
922fbb7b
AC
19025
19026@smallexample
594fe323 19027(gdb)
922fbb7b
AC
19028-break-insert main
19029^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 19030(gdb)
922fbb7b
AC
19031-exec-run
19032^running
594fe323 19033(gdb)
922fbb7b 19034*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d 19035frame=@{func="main",args=[],file="recursive2.c",
948d5102 19036fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 19037(gdb)
922fbb7b
AC
19038@end smallexample
19039
ef21caaf
NR
19040@noindent
19041Program exited normally:
19042
19043@smallexample
594fe323 19044(gdb)
ef21caaf
NR
19045-exec-run
19046^running
594fe323 19047(gdb)
ef21caaf
NR
19048x = 55
19049*stopped,reason="exited-normally"
594fe323 19050(gdb)
ef21caaf
NR
19051@end smallexample
19052
19053@noindent
19054Program exited exceptionally:
19055
19056@smallexample
594fe323 19057(gdb)
ef21caaf
NR
19058-exec-run
19059^running
594fe323 19060(gdb)
ef21caaf
NR
19061x = 55
19062*stopped,reason="exited",exit-code="01"
594fe323 19063(gdb)
ef21caaf
NR
19064@end smallexample
19065
19066Another way the program can terminate is if it receives a signal such as
19067@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
19068
19069@smallexample
594fe323 19070(gdb)
ef21caaf
NR
19071*stopped,reason="exited-signalled",signal-name="SIGINT",
19072signal-meaning="Interrupt"
19073@end smallexample
19074
922fbb7b 19075
a2c02241
NR
19076@c @subheading -exec-signal
19077
19078
19079@subheading The @code{-exec-step} Command
19080@findex -exec-step
922fbb7b
AC
19081
19082@subsubheading Synopsis
19083
19084@smallexample
a2c02241 19085 -exec-step
922fbb7b
AC
19086@end smallexample
19087
a2c02241
NR
19088Resumes execution of the inferior program, stopping when the beginning
19089of the next source line is reached, if the next source line is not a
19090function call. If it is, stop at the first instruction of the called
19091function.
922fbb7b
AC
19092
19093@subsubheading @value{GDBN} Command
19094
a2c02241 19095The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
19096
19097@subsubheading Example
19098
19099Stepping into a function:
19100
19101@smallexample
19102-exec-step
19103^running
594fe323 19104(gdb)
922fbb7b
AC
19105*stopped,reason="end-stepping-range",
19106frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 19107@{name="b",value="0"@}],file="recursive2.c",
948d5102 19108fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 19109(gdb)
922fbb7b
AC
19110@end smallexample
19111
19112Regular stepping:
19113
19114@smallexample
19115-exec-step
19116^running
594fe323 19117(gdb)
922fbb7b 19118*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 19119(gdb)
922fbb7b
AC
19120@end smallexample
19121
19122
19123@subheading The @code{-exec-step-instruction} Command
19124@findex -exec-step-instruction
19125
19126@subsubheading Synopsis
19127
19128@smallexample
19129 -exec-step-instruction
19130@end smallexample
19131
ef21caaf
NR
19132Resumes the inferior which executes one machine instruction. The
19133output, once @value{GDBN} has stopped, will vary depending on whether
19134we have stopped in the middle of a source line or not. In the former
19135case, the address at which the program stopped will be printed as
922fbb7b
AC
19136well.
19137
19138@subsubheading @value{GDBN} Command
19139
19140The corresponding @value{GDBN} command is @samp{stepi}.
19141
19142@subsubheading Example
19143
19144@smallexample
594fe323 19145(gdb)
922fbb7b
AC
19146-exec-step-instruction
19147^running
19148
594fe323 19149(gdb)
922fbb7b 19150*stopped,reason="end-stepping-range",
76ff342d 19151frame=@{func="foo",args=[],file="try.c",
948d5102 19152fullname="/home/foo/bar/try.c",line="10"@}
594fe323 19153(gdb)
922fbb7b
AC
19154-exec-step-instruction
19155^running
19156
594fe323 19157(gdb)
922fbb7b 19158*stopped,reason="end-stepping-range",
76ff342d 19159frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 19160fullname="/home/foo/bar/try.c",line="10"@}
594fe323 19161(gdb)
922fbb7b
AC
19162@end smallexample
19163
19164
19165@subheading The @code{-exec-until} Command
19166@findex -exec-until
19167
19168@subsubheading Synopsis
19169
19170@smallexample
19171 -exec-until [ @var{location} ]
19172@end smallexample
19173
ef21caaf
NR
19174Executes the inferior until the @var{location} specified in the
19175argument is reached. If there is no argument, the inferior executes
19176until a source line greater than the current one is reached. The
19177reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
19178
19179@subsubheading @value{GDBN} Command
19180
19181The corresponding @value{GDBN} command is @samp{until}.
19182
19183@subsubheading Example
19184
19185@smallexample
594fe323 19186(gdb)
922fbb7b
AC
19187-exec-until recursive2.c:6
19188^running
594fe323 19189(gdb)
922fbb7b
AC
19190x = 55
19191*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 19192file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 19193(gdb)
922fbb7b
AC
19194@end smallexample
19195
19196@ignore
19197@subheading -file-clear
19198Is this going away????
19199@end ignore
19200
351ff01a 19201@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
19202@node GDB/MI Stack Manipulation
19203@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 19204
922fbb7b 19205
a2c02241
NR
19206@subheading The @code{-stack-info-frame} Command
19207@findex -stack-info-frame
922fbb7b
AC
19208
19209@subsubheading Synopsis
19210
19211@smallexample
a2c02241 19212 -stack-info-frame
922fbb7b
AC
19213@end smallexample
19214
a2c02241 19215Get info on the selected frame.
922fbb7b
AC
19216
19217@subsubheading @value{GDBN} Command
19218
a2c02241
NR
19219The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19220(without arguments).
922fbb7b
AC
19221
19222@subsubheading Example
19223
19224@smallexample
594fe323 19225(gdb)
a2c02241
NR
19226-stack-info-frame
19227^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19228file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19229fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 19230(gdb)
922fbb7b
AC
19231@end smallexample
19232
a2c02241
NR
19233@subheading The @code{-stack-info-depth} Command
19234@findex -stack-info-depth
922fbb7b
AC
19235
19236@subsubheading Synopsis
19237
19238@smallexample
a2c02241 19239 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
19240@end smallexample
19241
a2c02241
NR
19242Return the depth of the stack. If the integer argument @var{max-depth}
19243is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
19244
19245@subsubheading @value{GDBN} Command
19246
a2c02241 19247There's no equivalent @value{GDBN} command.
922fbb7b
AC
19248
19249@subsubheading Example
19250
a2c02241
NR
19251For a stack with frame levels 0 through 11:
19252
922fbb7b 19253@smallexample
594fe323 19254(gdb)
a2c02241
NR
19255-stack-info-depth
19256^done,depth="12"
594fe323 19257(gdb)
a2c02241
NR
19258-stack-info-depth 4
19259^done,depth="4"
594fe323 19260(gdb)
a2c02241
NR
19261-stack-info-depth 12
19262^done,depth="12"
594fe323 19263(gdb)
a2c02241
NR
19264-stack-info-depth 11
19265^done,depth="11"
594fe323 19266(gdb)
a2c02241
NR
19267-stack-info-depth 13
19268^done,depth="12"
594fe323 19269(gdb)
922fbb7b
AC
19270@end smallexample
19271
a2c02241
NR
19272@subheading The @code{-stack-list-arguments} Command
19273@findex -stack-list-arguments
922fbb7b
AC
19274
19275@subsubheading Synopsis
19276
19277@smallexample
a2c02241
NR
19278 -stack-list-arguments @var{show-values}
19279 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
19280@end smallexample
19281
a2c02241
NR
19282Display a list of the arguments for the frames between @var{low-frame}
19283and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
19284@var{high-frame} are not provided, list the arguments for the whole
19285call stack. If the two arguments are equal, show the single frame
19286at the corresponding level. It is an error if @var{low-frame} is
19287larger than the actual number of frames. On the other hand,
19288@var{high-frame} may be larger than the actual number of frames, in
19289which case only existing frames will be returned.
a2c02241
NR
19290
19291The @var{show-values} argument must have a value of 0 or 1. A value of
192920 means that only the names of the arguments are listed, a value of 1
19293means that both names and values of the arguments are printed.
922fbb7b
AC
19294
19295@subsubheading @value{GDBN} Command
19296
a2c02241
NR
19297@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19298@samp{gdb_get_args} command which partially overlaps with the
19299functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
19300
19301@subsubheading Example
922fbb7b 19302
a2c02241 19303@smallexample
594fe323 19304(gdb)
a2c02241
NR
19305-stack-list-frames
19306^done,
19307stack=[
19308frame=@{level="0",addr="0x00010734",func="callee4",
19309file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19310fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
19311frame=@{level="1",addr="0x0001076c",func="callee3",
19312file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19313fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
19314frame=@{level="2",addr="0x0001078c",func="callee2",
19315file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19316fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
19317frame=@{level="3",addr="0x000107b4",func="callee1",
19318file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19319fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
19320frame=@{level="4",addr="0x000107e0",func="main",
19321file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19322fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 19323(gdb)
a2c02241
NR
19324-stack-list-arguments 0
19325^done,
19326stack-args=[
19327frame=@{level="0",args=[]@},
19328frame=@{level="1",args=[name="strarg"]@},
19329frame=@{level="2",args=[name="intarg",name="strarg"]@},
19330frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19331frame=@{level="4",args=[]@}]
594fe323 19332(gdb)
a2c02241
NR
19333-stack-list-arguments 1
19334^done,
19335stack-args=[
19336frame=@{level="0",args=[]@},
19337frame=@{level="1",
19338 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19339frame=@{level="2",args=[
19340@{name="intarg",value="2"@},
19341@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19342@{frame=@{level="3",args=[
19343@{name="intarg",value="2"@},
19344@{name="strarg",value="0x11940 \"A string argument.\""@},
19345@{name="fltarg",value="3.5"@}]@},
19346frame=@{level="4",args=[]@}]
594fe323 19347(gdb)
a2c02241
NR
19348-stack-list-arguments 0 2 2
19349^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 19350(gdb)
a2c02241
NR
19351-stack-list-arguments 1 2 2
19352^done,stack-args=[frame=@{level="2",
19353args=[@{name="intarg",value="2"@},
19354@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 19355(gdb)
a2c02241
NR
19356@end smallexample
19357
19358@c @subheading -stack-list-exception-handlers
922fbb7b 19359
a2c02241
NR
19360
19361@subheading The @code{-stack-list-frames} Command
19362@findex -stack-list-frames
1abaf70c
BR
19363
19364@subsubheading Synopsis
19365
19366@smallexample
a2c02241 19367 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
19368@end smallexample
19369
a2c02241
NR
19370List the frames currently on the stack. For each frame it displays the
19371following info:
19372
19373@table @samp
19374@item @var{level}
19375The frame number, 0 being the topmost frame, i.e. the innermost function.
19376@item @var{addr}
19377The @code{$pc} value for that frame.
19378@item @var{func}
19379Function name.
19380@item @var{file}
19381File name of the source file where the function lives.
19382@item @var{line}
19383Line number corresponding to the @code{$pc}.
19384@end table
19385
19386If invoked without arguments, this command prints a backtrace for the
19387whole stack. If given two integer arguments, it shows the frames whose
19388levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
19389are equal, it shows the single frame at the corresponding level. It is
19390an error if @var{low-frame} is larger than the actual number of
a5451f4e 19391frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 19392actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
19393
19394@subsubheading @value{GDBN} Command
19395
a2c02241 19396The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
19397
19398@subsubheading Example
19399
a2c02241
NR
19400Full stack backtrace:
19401
1abaf70c 19402@smallexample
594fe323 19403(gdb)
a2c02241
NR
19404-stack-list-frames
19405^done,stack=
19406[frame=@{level="0",addr="0x0001076c",func="foo",
19407 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
19408frame=@{level="1",addr="0x000107a4",func="foo",
19409 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19410frame=@{level="2",addr="0x000107a4",func="foo",
19411 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19412frame=@{level="3",addr="0x000107a4",func="foo",
19413 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19414frame=@{level="4",addr="0x000107a4",func="foo",
19415 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19416frame=@{level="5",addr="0x000107a4",func="foo",
19417 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19418frame=@{level="6",addr="0x000107a4",func="foo",
19419 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19420frame=@{level="7",addr="0x000107a4",func="foo",
19421 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19422frame=@{level="8",addr="0x000107a4",func="foo",
19423 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19424frame=@{level="9",addr="0x000107a4",func="foo",
19425 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19426frame=@{level="10",addr="0x000107a4",func="foo",
19427 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19428frame=@{level="11",addr="0x00010738",func="main",
19429 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 19430(gdb)
1abaf70c
BR
19431@end smallexample
19432
a2c02241 19433Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 19434
a2c02241 19435@smallexample
594fe323 19436(gdb)
a2c02241
NR
19437-stack-list-frames 3 5
19438^done,stack=
19439[frame=@{level="3",addr="0x000107a4",func="foo",
19440 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19441frame=@{level="4",addr="0x000107a4",func="foo",
19442 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19443frame=@{level="5",addr="0x000107a4",func="foo",
19444 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 19445(gdb)
a2c02241 19446@end smallexample
922fbb7b 19447
a2c02241 19448Show a single frame:
922fbb7b
AC
19449
19450@smallexample
594fe323 19451(gdb)
a2c02241
NR
19452-stack-list-frames 3 3
19453^done,stack=
19454[frame=@{level="3",addr="0x000107a4",func="foo",
19455 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 19456(gdb)
922fbb7b
AC
19457@end smallexample
19458
922fbb7b 19459
a2c02241
NR
19460@subheading The @code{-stack-list-locals} Command
19461@findex -stack-list-locals
57c22c6c 19462
a2c02241 19463@subsubheading Synopsis
922fbb7b
AC
19464
19465@smallexample
a2c02241 19466 -stack-list-locals @var{print-values}
922fbb7b
AC
19467@end smallexample
19468
a2c02241
NR
19469Display the local variable names for the selected frame. If
19470@var{print-values} is 0 or @code{--no-values}, print only the names of
19471the variables; if it is 1 or @code{--all-values}, print also their
19472values; and if it is 2 or @code{--simple-values}, print the name,
19473type and value for simple data types and the name and type for arrays,
19474structures and unions. In this last case, a frontend can immediately
19475display the value of simple data types and create variable objects for
19476other data types when the the user wishes to explore their values in
19477more detail.
922fbb7b
AC
19478
19479@subsubheading @value{GDBN} Command
19480
a2c02241 19481@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
19482
19483@subsubheading Example
922fbb7b
AC
19484
19485@smallexample
594fe323 19486(gdb)
a2c02241
NR
19487-stack-list-locals 0
19488^done,locals=[name="A",name="B",name="C"]
594fe323 19489(gdb)
a2c02241
NR
19490-stack-list-locals --all-values
19491^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
19492 @{name="C",value="@{1, 2, 3@}"@}]
19493-stack-list-locals --simple-values
19494^done,locals=[@{name="A",type="int",value="1"@},
19495 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 19496(gdb)
922fbb7b
AC
19497@end smallexample
19498
922fbb7b 19499
a2c02241
NR
19500@subheading The @code{-stack-select-frame} Command
19501@findex -stack-select-frame
922fbb7b
AC
19502
19503@subsubheading Synopsis
19504
19505@smallexample
a2c02241 19506 -stack-select-frame @var{framenum}
922fbb7b
AC
19507@end smallexample
19508
a2c02241
NR
19509Change the selected frame. Select a different frame @var{framenum} on
19510the stack.
922fbb7b
AC
19511
19512@subsubheading @value{GDBN} Command
19513
a2c02241
NR
19514The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19515@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
19516
19517@subsubheading Example
19518
19519@smallexample
594fe323 19520(gdb)
a2c02241 19521-stack-select-frame 2
922fbb7b 19522^done
594fe323 19523(gdb)
922fbb7b
AC
19524@end smallexample
19525
19526@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
19527@node GDB/MI Variable Objects
19528@section @sc{gdb/mi} Variable Objects
922fbb7b 19529
922fbb7b 19530
a2c02241 19531@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 19532
a2c02241
NR
19533For the implementation of a variable debugger window (locals, watched
19534expressions, etc.), we are proposing the adaptation of the existing code
19535used by @code{Insight}.
922fbb7b 19536
a2c02241 19537The two main reasons for that are:
922fbb7b 19538
a2c02241
NR
19539@enumerate 1
19540@item
19541It has been proven in practice (it is already on its second generation).
922fbb7b 19542
a2c02241
NR
19543@item
19544It will shorten development time (needless to say how important it is
19545now).
19546@end enumerate
922fbb7b 19547
a2c02241
NR
19548The original interface was designed to be used by Tcl code, so it was
19549slightly changed so it could be used through @sc{gdb/mi}. This section
19550describes the @sc{gdb/mi} operations that will be available and gives some
19551hints about their use.
922fbb7b 19552
a2c02241
NR
19553@emph{Note}: In addition to the set of operations described here, we
19554expect the @sc{gui} implementation of a variable window to require, at
19555least, the following operations:
922fbb7b 19556
a2c02241
NR
19557@itemize @bullet
19558@item @code{-gdb-show} @code{output-radix}
19559@item @code{-stack-list-arguments}
19560@item @code{-stack-list-locals}
19561@item @code{-stack-select-frame}
19562@end itemize
922fbb7b 19563
a2c02241 19564@subheading Introduction to Variable Objects in @sc{gdb/mi}
922fbb7b 19565
a2c02241
NR
19566@cindex variable objects in @sc{gdb/mi}
19567The basic idea behind variable objects is the creation of a named object
19568to represent a variable, an expression, a memory location or even a CPU
19569register. For each object created, a set of operations is available for
19570examining or changing its properties.
922fbb7b 19571
a2c02241
NR
19572Furthermore, complex data types, such as C structures, are represented
19573in a tree format. For instance, the @code{struct} type variable is the
19574root and the children will represent the struct members. If a child
19575is itself of a complex type, it will also have children of its own.
19576Appropriate language differences are handled for C, C@t{++} and Java.
922fbb7b 19577
a2c02241
NR
19578When returning the actual values of the objects, this facility allows
19579for the individual selection of the display format used in the result
19580creation. It can be chosen among: binary, decimal, hexadecimal, octal
19581and natural. Natural refers to a default format automatically
19582chosen based on the variable type (like decimal for an @code{int}, hex
19583for pointers, etc.).
922fbb7b 19584
a2c02241
NR
19585The following is the complete set of @sc{gdb/mi} operations defined to
19586access this functionality:
922fbb7b 19587
a2c02241
NR
19588@multitable @columnfractions .4 .6
19589@item @strong{Operation}
19590@tab @strong{Description}
922fbb7b 19591
a2c02241
NR
19592@item @code{-var-create}
19593@tab create a variable object
19594@item @code{-var-delete}
19595@tab delete the variable object and its children
19596@item @code{-var-set-format}
19597@tab set the display format of this variable
19598@item @code{-var-show-format}
19599@tab show the display format of this variable
19600@item @code{-var-info-num-children}
19601@tab tells how many children this object has
19602@item @code{-var-list-children}
19603@tab return a list of the object's children
19604@item @code{-var-info-type}
19605@tab show the type of this variable object
19606@item @code{-var-info-expression}
19607@tab print what this variable object represents
19608@item @code{-var-show-attributes}
19609@tab is this variable editable? does it exist here?
19610@item @code{-var-evaluate-expression}
19611@tab get the value of this variable
19612@item @code{-var-assign}
19613@tab set the value of this variable
19614@item @code{-var-update}
19615@tab update the variable and its children
19616@end multitable
922fbb7b 19617
a2c02241
NR
19618In the next subsection we describe each operation in detail and suggest
19619how it can be used.
922fbb7b 19620
a2c02241 19621@subheading Description And Use of Operations on Variable Objects
922fbb7b 19622
a2c02241
NR
19623@subheading The @code{-var-create} Command
19624@findex -var-create
ef21caaf 19625
a2c02241 19626@subsubheading Synopsis
ef21caaf 19627
a2c02241
NR
19628@smallexample
19629 -var-create @{@var{name} | "-"@}
19630 @{@var{frame-addr} | "*"@} @var{expression}
19631@end smallexample
19632
19633This operation creates a variable object, which allows the monitoring of
19634a variable, the result of an expression, a memory cell or a CPU
19635register.
ef21caaf 19636
a2c02241
NR
19637The @var{name} parameter is the string by which the object can be
19638referenced. It must be unique. If @samp{-} is specified, the varobj
19639system will generate a string ``varNNNNNN'' automatically. It will be
19640unique provided that one does not specify @var{name} on that format.
19641The command fails if a duplicate name is found.
ef21caaf 19642
a2c02241
NR
19643The frame under which the expression should be evaluated can be
19644specified by @var{frame-addr}. A @samp{*} indicates that the current
19645frame should be used.
922fbb7b 19646
a2c02241
NR
19647@var{expression} is any expression valid on the current language set (must not
19648begin with a @samp{*}), or one of the following:
922fbb7b 19649
a2c02241
NR
19650@itemize @bullet
19651@item
19652@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 19653
a2c02241
NR
19654@item
19655@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 19656
a2c02241
NR
19657@item
19658@samp{$@var{regname}} --- a CPU register name
19659@end itemize
922fbb7b 19660
a2c02241 19661@subsubheading Result
922fbb7b 19662
a2c02241
NR
19663This operation returns the name, number of children and the type of the
19664object created. Type is returned as a string as the ones generated by
19665the @value{GDBN} CLI:
922fbb7b
AC
19666
19667@smallexample
a2c02241 19668 name="@var{name}",numchild="N",type="@var{type}"
dcaaae04
NR
19669@end smallexample
19670
a2c02241
NR
19671
19672@subheading The @code{-var-delete} Command
19673@findex -var-delete
922fbb7b
AC
19674
19675@subsubheading Synopsis
19676
19677@smallexample
a2c02241 19678 -var-delete @var{name}
922fbb7b
AC
19679@end smallexample
19680
a2c02241 19681Deletes a previously created variable object and all of its children.
922fbb7b 19682
a2c02241 19683Returns an error if the object @var{name} is not found.
922fbb7b 19684
922fbb7b 19685
a2c02241
NR
19686@subheading The @code{-var-set-format} Command
19687@findex -var-set-format
922fbb7b 19688
a2c02241 19689@subsubheading Synopsis
922fbb7b
AC
19690
19691@smallexample
a2c02241 19692 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
19693@end smallexample
19694
a2c02241
NR
19695Sets the output format for the value of the object @var{name} to be
19696@var{format-spec}.
19697
19698The syntax for the @var{format-spec} is as follows:
19699
19700@smallexample
19701 @var{format-spec} @expansion{}
19702 @{binary | decimal | hexadecimal | octal | natural@}
19703@end smallexample
19704
19705
19706@subheading The @code{-var-show-format} Command
19707@findex -var-show-format
922fbb7b
AC
19708
19709@subsubheading Synopsis
19710
19711@smallexample
a2c02241 19712 -var-show-format @var{name}
922fbb7b
AC
19713@end smallexample
19714
a2c02241 19715Returns the format used to display the value of the object @var{name}.
922fbb7b 19716
a2c02241
NR
19717@smallexample
19718 @var{format} @expansion{}
19719 @var{format-spec}
19720@end smallexample
922fbb7b 19721
922fbb7b 19722
a2c02241
NR
19723@subheading The @code{-var-info-num-children} Command
19724@findex -var-info-num-children
19725
19726@subsubheading Synopsis
19727
19728@smallexample
19729 -var-info-num-children @var{name}
19730@end smallexample
19731
19732Returns the number of children of a variable object @var{name}:
19733
19734@smallexample
19735 numchild=@var{n}
19736@end smallexample
19737
19738
19739@subheading The @code{-var-list-children} Command
19740@findex -var-list-children
19741
19742@subsubheading Synopsis
19743
19744@smallexample
19745 -var-list-children [@var{print-values}] @var{name}
19746@end smallexample
19747@anchor{-var-list-children}
19748
19749Return a list of the children of the specified variable object and
19750create variable objects for them, if they do not already exist. With
19751a single argument or if @var{print-values} has a value for of 0 or
19752@code{--no-values}, print only the names of the variables; if
19753@var{print-values} is 1 or @code{--all-values}, also print their
19754values; and if it is 2 or @code{--simple-values} print the name and
19755value for simple data types and just the name for arrays, structures
19756and unions.
922fbb7b
AC
19757
19758@subsubheading Example
19759
19760@smallexample
594fe323 19761(gdb)
a2c02241
NR
19762 -var-list-children n
19763 ^done,numchild=@var{n},children=[@{name=@var{name},
19764 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 19765(gdb)
a2c02241
NR
19766 -var-list-children --all-values n
19767 ^done,numchild=@var{n},children=[@{name=@var{name},
19768 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
19769@end smallexample
19770
922fbb7b 19771
a2c02241
NR
19772@subheading The @code{-var-info-type} Command
19773@findex -var-info-type
922fbb7b 19774
a2c02241
NR
19775@subsubheading Synopsis
19776
19777@smallexample
19778 -var-info-type @var{name}
19779@end smallexample
19780
19781Returns the type of the specified variable @var{name}. The type is
19782returned as a string in the same format as it is output by the
19783@value{GDBN} CLI:
19784
19785@smallexample
19786 type=@var{typename}
19787@end smallexample
19788
19789
19790@subheading The @code{-var-info-expression} Command
19791@findex -var-info-expression
922fbb7b
AC
19792
19793@subsubheading Synopsis
19794
19795@smallexample
a2c02241 19796 -var-info-expression @var{name}
922fbb7b
AC
19797@end smallexample
19798
a2c02241 19799Returns what is represented by the variable object @var{name}:
922fbb7b 19800
a2c02241
NR
19801@smallexample
19802 lang=@var{lang-spec},exp=@var{expression}
19803@end smallexample
922fbb7b 19804
a2c02241
NR
19805@noindent
19806where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
922fbb7b 19807
a2c02241
NR
19808@subheading The @code{-var-show-attributes} Command
19809@findex -var-show-attributes
922fbb7b 19810
a2c02241 19811@subsubheading Synopsis
922fbb7b 19812
a2c02241
NR
19813@smallexample
19814 -var-show-attributes @var{name}
19815@end smallexample
922fbb7b 19816
a2c02241 19817List attributes of the specified variable object @var{name}:
922fbb7b
AC
19818
19819@smallexample
a2c02241 19820 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
19821@end smallexample
19822
a2c02241
NR
19823@noindent
19824where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
19825
19826@subheading The @code{-var-evaluate-expression} Command
19827@findex -var-evaluate-expression
19828
19829@subsubheading Synopsis
19830
19831@smallexample
19832 -var-evaluate-expression @var{name}
19833@end smallexample
19834
19835Evaluates the expression that is represented by the specified variable
19836object and returns its value as a string in the current format specified
19837for the object:
19838
19839@smallexample
19840 value=@var{value}
19841@end smallexample
19842
19843Note that one must invoke @code{-var-list-children} for a variable
19844before the value of a child variable can be evaluated.
19845
19846@subheading The @code{-var-assign} Command
19847@findex -var-assign
19848
19849@subsubheading Synopsis
19850
19851@smallexample
19852 -var-assign @var{name} @var{expression}
19853@end smallexample
19854
19855Assigns the value of @var{expression} to the variable object specified
19856by @var{name}. The object must be @samp{editable}. If the variable's
19857value is altered by the assign, the variable will show up in any
19858subsequent @code{-var-update} list.
19859
19860@subsubheading Example
922fbb7b
AC
19861
19862@smallexample
594fe323 19863(gdb)
a2c02241
NR
19864-var-assign var1 3
19865^done,value="3"
594fe323 19866(gdb)
a2c02241
NR
19867-var-update *
19868^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 19869(gdb)
922fbb7b
AC
19870@end smallexample
19871
a2c02241
NR
19872@subheading The @code{-var-update} Command
19873@findex -var-update
19874
19875@subsubheading Synopsis
19876
19877@smallexample
19878 -var-update [@var{print-values}] @{@var{name} | "*"@}
19879@end smallexample
19880
19881Update the value of the variable object @var{name} by evaluating its
19882expression after fetching all the new values from memory or registers.
19883A @samp{*} causes all existing variable objects to be updated. The
19884option @var{print-values} determines whether names both and values, or
19885just names are printed in the manner described for
19886@code{-var-list-children} (@pxref{-var-list-children}).
19887
19888@subsubheading Example
922fbb7b
AC
19889
19890@smallexample
594fe323 19891(gdb)
a2c02241
NR
19892-var-assign var1 3
19893^done,value="3"
594fe323 19894(gdb)
a2c02241
NR
19895-var-update --all-values var1
19896^done,changelist=[@{name="var1",value="3",in_scope="true",
19897type_changed="false"@}]
594fe323 19898(gdb)
922fbb7b
AC
19899@end smallexample
19900
a2c02241
NR
19901@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19902@node GDB/MI Data Manipulation
19903@section @sc{gdb/mi} Data Manipulation
922fbb7b 19904
a2c02241
NR
19905@cindex data manipulation, in @sc{gdb/mi}
19906@cindex @sc{gdb/mi}, data manipulation
19907This section describes the @sc{gdb/mi} commands that manipulate data:
19908examine memory and registers, evaluate expressions, etc.
19909
19910@c REMOVED FROM THE INTERFACE.
19911@c @subheading -data-assign
19912@c Change the value of a program variable. Plenty of side effects.
19913@c @subsubheading GDB command
19914@c set variable
19915@c @subsubheading Example
19916@c N.A.
19917
19918@subheading The @code{-data-disassemble} Command
19919@findex -data-disassemble
922fbb7b
AC
19920
19921@subsubheading Synopsis
19922
19923@smallexample
a2c02241
NR
19924 -data-disassemble
19925 [ -s @var{start-addr} -e @var{end-addr} ]
19926 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
19927 -- @var{mode}
922fbb7b
AC
19928@end smallexample
19929
a2c02241
NR
19930@noindent
19931Where:
19932
19933@table @samp
19934@item @var{start-addr}
19935is the beginning address (or @code{$pc})
19936@item @var{end-addr}
19937is the end address
19938@item @var{filename}
19939is the name of the file to disassemble
19940@item @var{linenum}
19941is the line number to disassemble around
19942@item @var{lines}
19943is the the number of disassembly lines to be produced. If it is -1,
19944the whole function will be disassembled, in case no @var{end-addr} is
19945specified. If @var{end-addr} is specified as a non-zero value, and
19946@var{lines} is lower than the number of disassembly lines between
19947@var{start-addr} and @var{end-addr}, only @var{lines} lines are
19948displayed; if @var{lines} is higher than the number of lines between
19949@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
19950are displayed.
19951@item @var{mode}
19952is either 0 (meaning only disassembly) or 1 (meaning mixed source and
19953disassembly).
19954@end table
19955
19956@subsubheading Result
19957
19958The output for each instruction is composed of four fields:
19959
19960@itemize @bullet
19961@item Address
19962@item Func-name
19963@item Offset
19964@item Instruction
19965@end itemize
19966
19967Note that whatever included in the instruction field, is not manipulated
19968directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
922fbb7b
AC
19969
19970@subsubheading @value{GDBN} Command
19971
a2c02241 19972There's no direct mapping from this command to the CLI.
922fbb7b
AC
19973
19974@subsubheading Example
19975
a2c02241
NR
19976Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
19977
922fbb7b 19978@smallexample
594fe323 19979(gdb)
a2c02241
NR
19980-data-disassemble -s $pc -e "$pc + 20" -- 0
19981^done,
19982asm_insns=[
19983@{address="0x000107c0",func-name="main",offset="4",
19984inst="mov 2, %o0"@},
19985@{address="0x000107c4",func-name="main",offset="8",
19986inst="sethi %hi(0x11800), %o2"@},
19987@{address="0x000107c8",func-name="main",offset="12",
19988inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
19989@{address="0x000107cc",func-name="main",offset="16",
19990inst="sethi %hi(0x11800), %o2"@},
19991@{address="0x000107d0",func-name="main",offset="20",
19992inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 19993(gdb)
a2c02241
NR
19994@end smallexample
19995
19996Disassemble the whole @code{main} function. Line 32 is part of
19997@code{main}.
19998
19999@smallexample
20000-data-disassemble -f basics.c -l 32 -- 0
20001^done,asm_insns=[
20002@{address="0x000107bc",func-name="main",offset="0",
20003inst="save %sp, -112, %sp"@},
20004@{address="0x000107c0",func-name="main",offset="4",
20005inst="mov 2, %o0"@},
20006@{address="0x000107c4",func-name="main",offset="8",
20007inst="sethi %hi(0x11800), %o2"@},
20008[@dots{}]
20009@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
20010@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 20011(gdb)
922fbb7b
AC
20012@end smallexample
20013
a2c02241 20014Disassemble 3 instructions from the start of @code{main}:
922fbb7b 20015
a2c02241 20016@smallexample
594fe323 20017(gdb)
a2c02241
NR
20018-data-disassemble -f basics.c -l 32 -n 3 -- 0
20019^done,asm_insns=[
20020@{address="0x000107bc",func-name="main",offset="0",
20021inst="save %sp, -112, %sp"@},
20022@{address="0x000107c0",func-name="main",offset="4",
20023inst="mov 2, %o0"@},
20024@{address="0x000107c4",func-name="main",offset="8",
20025inst="sethi %hi(0x11800), %o2"@}]
594fe323 20026(gdb)
a2c02241
NR
20027@end smallexample
20028
20029Disassemble 3 instructions from the start of @code{main} in mixed mode:
20030
20031@smallexample
594fe323 20032(gdb)
a2c02241
NR
20033-data-disassemble -f basics.c -l 32 -n 3 -- 1
20034^done,asm_insns=[
20035src_and_asm_line=@{line="31",
20036file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20037 testsuite/gdb.mi/basics.c",line_asm_insn=[
20038@{address="0x000107bc",func-name="main",offset="0",
20039inst="save %sp, -112, %sp"@}]@},
20040src_and_asm_line=@{line="32",
20041file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20042 testsuite/gdb.mi/basics.c",line_asm_insn=[
20043@{address="0x000107c0",func-name="main",offset="4",
20044inst="mov 2, %o0"@},
20045@{address="0x000107c4",func-name="main",offset="8",
20046inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 20047(gdb)
a2c02241
NR
20048@end smallexample
20049
20050
20051@subheading The @code{-data-evaluate-expression} Command
20052@findex -data-evaluate-expression
922fbb7b
AC
20053
20054@subsubheading Synopsis
20055
20056@smallexample
a2c02241 20057 -data-evaluate-expression @var{expr}
922fbb7b
AC
20058@end smallexample
20059
a2c02241
NR
20060Evaluate @var{expr} as an expression. The expression could contain an
20061inferior function call. The function call will execute synchronously.
20062If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
20063
20064@subsubheading @value{GDBN} Command
20065
a2c02241
NR
20066The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
20067@samp{call}. In @code{gdbtk} only, there's a corresponding
20068@samp{gdb_eval} command.
922fbb7b
AC
20069
20070@subsubheading Example
20071
a2c02241
NR
20072In the following example, the numbers that precede the commands are the
20073@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
20074Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
20075output.
20076
922fbb7b 20077@smallexample
a2c02241
NR
20078211-data-evaluate-expression A
20079211^done,value="1"
594fe323 20080(gdb)
a2c02241
NR
20081311-data-evaluate-expression &A
20082311^done,value="0xefffeb7c"
594fe323 20083(gdb)
a2c02241
NR
20084411-data-evaluate-expression A+3
20085411^done,value="4"
594fe323 20086(gdb)
a2c02241
NR
20087511-data-evaluate-expression "A + 3"
20088511^done,value="4"
594fe323 20089(gdb)
a2c02241 20090@end smallexample
922fbb7b
AC
20091
20092
a2c02241
NR
20093@subheading The @code{-data-list-changed-registers} Command
20094@findex -data-list-changed-registers
922fbb7b
AC
20095
20096@subsubheading Synopsis
20097
20098@smallexample
a2c02241 20099 -data-list-changed-registers
922fbb7b
AC
20100@end smallexample
20101
a2c02241 20102Display a list of the registers that have changed.
922fbb7b
AC
20103
20104@subsubheading @value{GDBN} Command
20105
a2c02241
NR
20106@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
20107has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
20108
20109@subsubheading Example
922fbb7b 20110
a2c02241 20111On a PPC MBX board:
922fbb7b
AC
20112
20113@smallexample
594fe323 20114(gdb)
a2c02241
NR
20115-exec-continue
20116^running
922fbb7b 20117
594fe323 20118(gdb)
a2c02241
NR
20119*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
20120args=[],file="try.c",fullname="/home/foo/bar/try.c",line="5"@}
594fe323 20121(gdb)
a2c02241
NR
20122-data-list-changed-registers
20123^done,changed-registers=["0","1","2","4","5","6","7","8","9",
20124"10","11","13","14","15","16","17","18","19","20","21","22","23",
20125"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 20126(gdb)
a2c02241 20127@end smallexample
922fbb7b
AC
20128
20129
a2c02241
NR
20130@subheading The @code{-data-list-register-names} Command
20131@findex -data-list-register-names
922fbb7b
AC
20132
20133@subsubheading Synopsis
20134
20135@smallexample
a2c02241 20136 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
20137@end smallexample
20138
a2c02241
NR
20139Show a list of register names for the current target. If no arguments
20140are given, it shows a list of the names of all the registers. If
20141integer numbers are given as arguments, it will print a list of the
20142names of the registers corresponding to the arguments. To ensure
20143consistency between a register name and its number, the output list may
20144include empty register names.
922fbb7b
AC
20145
20146@subsubheading @value{GDBN} Command
20147
a2c02241
NR
20148@value{GDBN} does not have a command which corresponds to
20149@samp{-data-list-register-names}. In @code{gdbtk} there is a
20150corresponding command @samp{gdb_regnames}.
922fbb7b
AC
20151
20152@subsubheading Example
922fbb7b 20153
a2c02241
NR
20154For the PPC MBX board:
20155@smallexample
594fe323 20156(gdb)
a2c02241
NR
20157-data-list-register-names
20158^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
20159"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
20160"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
20161"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
20162"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
20163"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
20164"", "pc","ps","cr","lr","ctr","xer"]
594fe323 20165(gdb)
a2c02241
NR
20166-data-list-register-names 1 2 3
20167^done,register-names=["r1","r2","r3"]
594fe323 20168(gdb)
a2c02241 20169@end smallexample
922fbb7b 20170
a2c02241
NR
20171@subheading The @code{-data-list-register-values} Command
20172@findex -data-list-register-values
922fbb7b
AC
20173
20174@subsubheading Synopsis
20175
20176@smallexample
a2c02241 20177 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
20178@end smallexample
20179
a2c02241
NR
20180Display the registers' contents. @var{fmt} is the format according to
20181which the registers' contents are to be returned, followed by an optional
20182list of numbers specifying the registers to display. A missing list of
20183numbers indicates that the contents of all the registers must be returned.
20184
20185Allowed formats for @var{fmt} are:
20186
20187@table @code
20188@item x
20189Hexadecimal
20190@item o
20191Octal
20192@item t
20193Binary
20194@item d
20195Decimal
20196@item r
20197Raw
20198@item N
20199Natural
20200@end table
922fbb7b
AC
20201
20202@subsubheading @value{GDBN} Command
20203
a2c02241
NR
20204The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
20205all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
20206
20207@subsubheading Example
922fbb7b 20208
a2c02241
NR
20209For a PPC MBX board (note: line breaks are for readability only, they
20210don't appear in the actual output):
20211
20212@smallexample
594fe323 20213(gdb)
a2c02241
NR
20214-data-list-register-values r 64 65
20215^done,register-values=[@{number="64",value="0xfe00a300"@},
20216@{number="65",value="0x00029002"@}]
594fe323 20217(gdb)
a2c02241
NR
20218-data-list-register-values x
20219^done,register-values=[@{number="0",value="0xfe0043c8"@},
20220@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
20221@{number="3",value="0x0"@},@{number="4",value="0xa"@},
20222@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
20223@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
20224@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
20225@{number="11",value="0x1"@},@{number="12",value="0x0"@},
20226@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
20227@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
20228@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
20229@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
20230@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
20231@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
20232@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
20233@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
20234@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
20235@{number="31",value="0x0"@},@{number="32",value="0x0"@},
20236@{number="33",value="0x0"@},@{number="34",value="0x0"@},
20237@{number="35",value="0x0"@},@{number="36",value="0x0"@},
20238@{number="37",value="0x0"@},@{number="38",value="0x0"@},
20239@{number="39",value="0x0"@},@{number="40",value="0x0"@},
20240@{number="41",value="0x0"@},@{number="42",value="0x0"@},
20241@{number="43",value="0x0"@},@{number="44",value="0x0"@},
20242@{number="45",value="0x0"@},@{number="46",value="0x0"@},
20243@{number="47",value="0x0"@},@{number="48",value="0x0"@},
20244@{number="49",value="0x0"@},@{number="50",value="0x0"@},
20245@{number="51",value="0x0"@},@{number="52",value="0x0"@},
20246@{number="53",value="0x0"@},@{number="54",value="0x0"@},
20247@{number="55",value="0x0"@},@{number="56",value="0x0"@},
20248@{number="57",value="0x0"@},@{number="58",value="0x0"@},
20249@{number="59",value="0x0"@},@{number="60",value="0x0"@},
20250@{number="61",value="0x0"@},@{number="62",value="0x0"@},
20251@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
20252@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
20253@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
20254@{number="69",value="0x20002b03"@}]
594fe323 20255(gdb)
a2c02241 20256@end smallexample
922fbb7b 20257
a2c02241
NR
20258
20259@subheading The @code{-data-read-memory} Command
20260@findex -data-read-memory
922fbb7b
AC
20261
20262@subsubheading Synopsis
20263
20264@smallexample
a2c02241
NR
20265 -data-read-memory [ -o @var{byte-offset} ]
20266 @var{address} @var{word-format} @var{word-size}
20267 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
20268@end smallexample
20269
a2c02241
NR
20270@noindent
20271where:
922fbb7b 20272
a2c02241
NR
20273@table @samp
20274@item @var{address}
20275An expression specifying the address of the first memory word to be
20276read. Complex expressions containing embedded white space should be
20277quoted using the C convention.
922fbb7b 20278
a2c02241
NR
20279@item @var{word-format}
20280The format to be used to print the memory words. The notation is the
20281same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
20282,Output formats}).
922fbb7b 20283
a2c02241
NR
20284@item @var{word-size}
20285The size of each memory word in bytes.
922fbb7b 20286
a2c02241
NR
20287@item @var{nr-rows}
20288The number of rows in the output table.
922fbb7b 20289
a2c02241
NR
20290@item @var{nr-cols}
20291The number of columns in the output table.
922fbb7b 20292
a2c02241
NR
20293@item @var{aschar}
20294If present, indicates that each row should include an @sc{ascii} dump. The
20295value of @var{aschar} is used as a padding character when a byte is not a
20296member of the printable @sc{ascii} character set (printable @sc{ascii}
20297characters are those whose code is between 32 and 126, inclusively).
922fbb7b 20298
a2c02241
NR
20299@item @var{byte-offset}
20300An offset to add to the @var{address} before fetching memory.
20301@end table
922fbb7b 20302
a2c02241
NR
20303This command displays memory contents as a table of @var{nr-rows} by
20304@var{nr-cols} words, each word being @var{word-size} bytes. In total,
20305@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
20306(returned as @samp{total-bytes}). Should less than the requested number
20307of bytes be returned by the target, the missing words are identified
20308using @samp{N/A}. The number of bytes read from the target is returned
20309in @samp{nr-bytes} and the starting address used to read memory in
20310@samp{addr}.
20311
20312The address of the next/previous row or page is available in
20313@samp{next-row} and @samp{prev-row}, @samp{next-page} and
20314@samp{prev-page}.
922fbb7b
AC
20315
20316@subsubheading @value{GDBN} Command
20317
a2c02241
NR
20318The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
20319@samp{gdb_get_mem} memory read command.
922fbb7b
AC
20320
20321@subsubheading Example
32e7087d 20322
a2c02241
NR
20323Read six bytes of memory starting at @code{bytes+6} but then offset by
20324@code{-6} bytes. Format as three rows of two columns. One byte per
20325word. Display each word in hex.
32e7087d
JB
20326
20327@smallexample
594fe323 20328(gdb)
a2c02241
NR
203299-data-read-memory -o -6 -- bytes+6 x 1 3 2
203309^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
20331next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
20332prev-page="0x0000138a",memory=[
20333@{addr="0x00001390",data=["0x00","0x01"]@},
20334@{addr="0x00001392",data=["0x02","0x03"]@},
20335@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 20336(gdb)
32e7087d
JB
20337@end smallexample
20338
a2c02241
NR
20339Read two bytes of memory starting at address @code{shorts + 64} and
20340display as a single word formatted in decimal.
32e7087d 20341
32e7087d 20342@smallexample
594fe323 20343(gdb)
a2c02241
NR
203445-data-read-memory shorts+64 d 2 1 1
203455^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
20346next-row="0x00001512",prev-row="0x0000150e",
20347next-page="0x00001512",prev-page="0x0000150e",memory=[
20348@{addr="0x00001510",data=["128"]@}]
594fe323 20349(gdb)
32e7087d
JB
20350@end smallexample
20351
a2c02241
NR
20352Read thirty two bytes of memory starting at @code{bytes+16} and format
20353as eight rows of four columns. Include a string encoding with @samp{x}
20354used as the non-printable character.
922fbb7b
AC
20355
20356@smallexample
594fe323 20357(gdb)
a2c02241
NR
203584-data-read-memory bytes+16 x 1 8 4 x
203594^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
20360next-row="0x000013c0",prev-row="0x0000139c",
20361next-page="0x000013c0",prev-page="0x00001380",memory=[
20362@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
20363@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
20364@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
20365@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
20366@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
20367@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
20368@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
20369@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 20370(gdb)
922fbb7b
AC
20371@end smallexample
20372
a2c02241
NR
20373@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20374@node GDB/MI Tracepoint Commands
20375@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 20376
a2c02241 20377The tracepoint commands are not yet implemented.
922fbb7b 20378
a2c02241 20379@c @subheading -trace-actions
922fbb7b 20380
a2c02241 20381@c @subheading -trace-delete
922fbb7b 20382
a2c02241 20383@c @subheading -trace-disable
922fbb7b 20384
a2c02241 20385@c @subheading -trace-dump
922fbb7b 20386
a2c02241 20387@c @subheading -trace-enable
922fbb7b 20388
a2c02241 20389@c @subheading -trace-exists
922fbb7b 20390
a2c02241 20391@c @subheading -trace-find
922fbb7b 20392
a2c02241 20393@c @subheading -trace-frame-number
922fbb7b 20394
a2c02241 20395@c @subheading -trace-info
922fbb7b 20396
a2c02241 20397@c @subheading -trace-insert
922fbb7b 20398
a2c02241 20399@c @subheading -trace-list
922fbb7b 20400
a2c02241 20401@c @subheading -trace-pass-count
922fbb7b 20402
a2c02241 20403@c @subheading -trace-save
922fbb7b 20404
a2c02241 20405@c @subheading -trace-start
922fbb7b 20406
a2c02241 20407@c @subheading -trace-stop
922fbb7b 20408
922fbb7b 20409
a2c02241
NR
20410@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20411@node GDB/MI Symbol Query
20412@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
20413
20414
a2c02241
NR
20415@subheading The @code{-symbol-info-address} Command
20416@findex -symbol-info-address
922fbb7b
AC
20417
20418@subsubheading Synopsis
20419
20420@smallexample
a2c02241 20421 -symbol-info-address @var{symbol}
922fbb7b
AC
20422@end smallexample
20423
a2c02241 20424Describe where @var{symbol} is stored.
922fbb7b
AC
20425
20426@subsubheading @value{GDBN} Command
20427
a2c02241 20428The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
20429
20430@subsubheading Example
20431N.A.
20432
20433
a2c02241
NR
20434@subheading The @code{-symbol-info-file} Command
20435@findex -symbol-info-file
922fbb7b
AC
20436
20437@subsubheading Synopsis
20438
20439@smallexample
a2c02241 20440 -symbol-info-file
922fbb7b
AC
20441@end smallexample
20442
a2c02241 20443Show the file for the symbol.
922fbb7b 20444
a2c02241 20445@subsubheading @value{GDBN} Command
922fbb7b 20446
a2c02241
NR
20447There's no equivalent @value{GDBN} command. @code{gdbtk} has
20448@samp{gdb_find_file}.
922fbb7b
AC
20449
20450@subsubheading Example
20451N.A.
20452
20453
a2c02241
NR
20454@subheading The @code{-symbol-info-function} Command
20455@findex -symbol-info-function
922fbb7b
AC
20456
20457@subsubheading Synopsis
20458
20459@smallexample
a2c02241 20460 -symbol-info-function
922fbb7b
AC
20461@end smallexample
20462
a2c02241 20463Show which function the symbol lives in.
922fbb7b
AC
20464
20465@subsubheading @value{GDBN} Command
20466
a2c02241 20467@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
20468
20469@subsubheading Example
20470N.A.
20471
20472
a2c02241
NR
20473@subheading The @code{-symbol-info-line} Command
20474@findex -symbol-info-line
922fbb7b
AC
20475
20476@subsubheading Synopsis
20477
20478@smallexample
a2c02241 20479 -symbol-info-line
922fbb7b
AC
20480@end smallexample
20481
a2c02241 20482Show the core addresses of the code for a source line.
922fbb7b 20483
a2c02241 20484@subsubheading @value{GDBN} Command
922fbb7b 20485
a2c02241
NR
20486The corresponding @value{GDBN} command is @samp{info line}.
20487@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
20488
20489@subsubheading Example
a2c02241 20490N.A.
922fbb7b
AC
20491
20492
a2c02241
NR
20493@subheading The @code{-symbol-info-symbol} Command
20494@findex -symbol-info-symbol
07f31aa6
DJ
20495
20496@subsubheading Synopsis
20497
a2c02241
NR
20498@smallexample
20499 -symbol-info-symbol @var{addr}
20500@end smallexample
07f31aa6 20501
a2c02241 20502Describe what symbol is at location @var{addr}.
07f31aa6 20503
a2c02241 20504@subsubheading @value{GDBN} Command
07f31aa6 20505
a2c02241 20506The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
20507
20508@subsubheading Example
a2c02241 20509N.A.
07f31aa6
DJ
20510
20511
a2c02241
NR
20512@subheading The @code{-symbol-list-functions} Command
20513@findex -symbol-list-functions
922fbb7b
AC
20514
20515@subsubheading Synopsis
20516
20517@smallexample
a2c02241 20518 -symbol-list-functions
922fbb7b
AC
20519@end smallexample
20520
a2c02241 20521List the functions in the executable.
922fbb7b
AC
20522
20523@subsubheading @value{GDBN} Command
20524
a2c02241
NR
20525@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
20526@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
20527
20528@subsubheading Example
a2c02241 20529N.A.
922fbb7b
AC
20530
20531
a2c02241
NR
20532@subheading The @code{-symbol-list-lines} Command
20533@findex -symbol-list-lines
922fbb7b
AC
20534
20535@subsubheading Synopsis
20536
20537@smallexample
a2c02241 20538 -symbol-list-lines @var{filename}
922fbb7b
AC
20539@end smallexample
20540
a2c02241
NR
20541Print the list of lines that contain code and their associated program
20542addresses for the given source filename. The entries are sorted in
20543ascending PC order.
922fbb7b
AC
20544
20545@subsubheading @value{GDBN} Command
20546
a2c02241 20547There is no corresponding @value{GDBN} command.
922fbb7b
AC
20548
20549@subsubheading Example
a2c02241 20550@smallexample
594fe323 20551(gdb)
a2c02241
NR
20552-symbol-list-lines basics.c
20553^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 20554(gdb)
a2c02241 20555@end smallexample
922fbb7b
AC
20556
20557
a2c02241
NR
20558@subheading The @code{-symbol-list-types} Command
20559@findex -symbol-list-types
922fbb7b
AC
20560
20561@subsubheading Synopsis
20562
20563@smallexample
a2c02241 20564 -symbol-list-types
922fbb7b
AC
20565@end smallexample
20566
a2c02241 20567List all the type names.
922fbb7b
AC
20568
20569@subsubheading @value{GDBN} Command
20570
a2c02241
NR
20571The corresponding commands are @samp{info types} in @value{GDBN},
20572@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
20573
20574@subsubheading Example
20575N.A.
20576
20577
a2c02241
NR
20578@subheading The @code{-symbol-list-variables} Command
20579@findex -symbol-list-variables
922fbb7b
AC
20580
20581@subsubheading Synopsis
20582
20583@smallexample
a2c02241 20584 -symbol-list-variables
922fbb7b
AC
20585@end smallexample
20586
a2c02241 20587List all the global and static variable names.
922fbb7b
AC
20588
20589@subsubheading @value{GDBN} Command
20590
a2c02241 20591@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
20592
20593@subsubheading Example
20594N.A.
20595
20596
a2c02241
NR
20597@subheading The @code{-symbol-locate} Command
20598@findex -symbol-locate
922fbb7b
AC
20599
20600@subsubheading Synopsis
20601
20602@smallexample
a2c02241 20603 -symbol-locate
922fbb7b
AC
20604@end smallexample
20605
922fbb7b
AC
20606@subsubheading @value{GDBN} Command
20607
a2c02241 20608@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
20609
20610@subsubheading Example
20611N.A.
20612
20613
a2c02241
NR
20614@subheading The @code{-symbol-type} Command
20615@findex -symbol-type
922fbb7b
AC
20616
20617@subsubheading Synopsis
20618
20619@smallexample
a2c02241 20620 -symbol-type @var{variable}
922fbb7b
AC
20621@end smallexample
20622
a2c02241 20623Show type of @var{variable}.
922fbb7b 20624
a2c02241 20625@subsubheading @value{GDBN} Command
922fbb7b 20626
a2c02241
NR
20627The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
20628@samp{gdb_obj_variable}.
20629
20630@subsubheading Example
20631N.A.
20632
20633
20634@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20635@node GDB/MI File Commands
20636@section @sc{gdb/mi} File Commands
20637
20638This section describes the GDB/MI commands to specify executable file names
20639and to read in and obtain symbol table information.
20640
20641@subheading The @code{-file-exec-and-symbols} Command
20642@findex -file-exec-and-symbols
20643
20644@subsubheading Synopsis
922fbb7b
AC
20645
20646@smallexample
a2c02241 20647 -file-exec-and-symbols @var{file}
922fbb7b
AC
20648@end smallexample
20649
a2c02241
NR
20650Specify the executable file to be debugged. This file is the one from
20651which the symbol table is also read. If no file is specified, the
20652command clears the executable and symbol information. If breakpoints
20653are set when using this command with no arguments, @value{GDBN} will produce
20654error messages. Otherwise, no output is produced, except a completion
20655notification.
20656
922fbb7b
AC
20657@subsubheading @value{GDBN} Command
20658
a2c02241 20659The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
20660
20661@subsubheading Example
20662
20663@smallexample
594fe323 20664(gdb)
a2c02241
NR
20665-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
20666^done
594fe323 20667(gdb)
922fbb7b
AC
20668@end smallexample
20669
922fbb7b 20670
a2c02241
NR
20671@subheading The @code{-file-exec-file} Command
20672@findex -file-exec-file
922fbb7b
AC
20673
20674@subsubheading Synopsis
20675
20676@smallexample
a2c02241 20677 -file-exec-file @var{file}
922fbb7b
AC
20678@end smallexample
20679
a2c02241
NR
20680Specify the executable file to be debugged. Unlike
20681@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
20682from this file. If used without argument, @value{GDBN} clears the information
20683about the executable file. No output is produced, except a completion
20684notification.
922fbb7b 20685
a2c02241
NR
20686@subsubheading @value{GDBN} Command
20687
20688The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
20689
20690@subsubheading Example
a2c02241
NR
20691
20692@smallexample
594fe323 20693(gdb)
a2c02241
NR
20694-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
20695^done
594fe323 20696(gdb)
a2c02241 20697@end smallexample
922fbb7b
AC
20698
20699
a2c02241
NR
20700@subheading The @code{-file-list-exec-sections} Command
20701@findex -file-list-exec-sections
922fbb7b
AC
20702
20703@subsubheading Synopsis
20704
20705@smallexample
a2c02241 20706 -file-list-exec-sections
922fbb7b
AC
20707@end smallexample
20708
a2c02241
NR
20709List the sections of the current executable file.
20710
922fbb7b
AC
20711@subsubheading @value{GDBN} Command
20712
a2c02241
NR
20713The @value{GDBN} command @samp{info file} shows, among the rest, the same
20714information as this command. @code{gdbtk} has a corresponding command
20715@samp{gdb_load_info}.
922fbb7b
AC
20716
20717@subsubheading Example
20718N.A.
20719
20720
a2c02241
NR
20721@subheading The @code{-file-list-exec-source-file} Command
20722@findex -file-list-exec-source-file
922fbb7b
AC
20723
20724@subsubheading Synopsis
20725
20726@smallexample
a2c02241 20727 -file-list-exec-source-file
922fbb7b
AC
20728@end smallexample
20729
a2c02241
NR
20730List the line number, the current source file, and the absolute path
20731to the current source file for the current executable.
922fbb7b
AC
20732
20733@subsubheading @value{GDBN} Command
20734
a2c02241 20735The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
20736
20737@subsubheading Example
20738
922fbb7b 20739@smallexample
594fe323 20740(gdb)
a2c02241
NR
20741123-file-list-exec-source-file
20742123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
594fe323 20743(gdb)
922fbb7b
AC
20744@end smallexample
20745
20746
a2c02241
NR
20747@subheading The @code{-file-list-exec-source-files} Command
20748@findex -file-list-exec-source-files
922fbb7b
AC
20749
20750@subsubheading Synopsis
20751
20752@smallexample
a2c02241 20753 -file-list-exec-source-files
922fbb7b
AC
20754@end smallexample
20755
a2c02241
NR
20756List the source files for the current executable.
20757
20758It will always output the filename, but only when GDB can find the absolute
20759file name of a source file, will it output the fullname.
922fbb7b
AC
20760
20761@subsubheading @value{GDBN} Command
20762
a2c02241
NR
20763The @value{GDBN} equivalent is @samp{info sources}.
20764@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
20765
20766@subsubheading Example
922fbb7b 20767@smallexample
594fe323 20768(gdb)
a2c02241
NR
20769-file-list-exec-source-files
20770^done,files=[
20771@{file=foo.c,fullname=/home/foo.c@},
20772@{file=/home/bar.c,fullname=/home/bar.c@},
20773@{file=gdb_could_not_find_fullpath.c@}]
594fe323 20774(gdb)
922fbb7b
AC
20775@end smallexample
20776
a2c02241
NR
20777@subheading The @code{-file-list-shared-libraries} Command
20778@findex -file-list-shared-libraries
922fbb7b 20779
a2c02241 20780@subsubheading Synopsis
922fbb7b 20781
a2c02241
NR
20782@smallexample
20783 -file-list-shared-libraries
20784@end smallexample
922fbb7b 20785
a2c02241 20786List the shared libraries in the program.
922fbb7b 20787
a2c02241 20788@subsubheading @value{GDBN} Command
922fbb7b 20789
a2c02241 20790The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 20791
a2c02241
NR
20792@subsubheading Example
20793N.A.
922fbb7b
AC
20794
20795
a2c02241
NR
20796@subheading The @code{-file-list-symbol-files} Command
20797@findex -file-list-symbol-files
922fbb7b 20798
a2c02241 20799@subsubheading Synopsis
922fbb7b 20800
a2c02241
NR
20801@smallexample
20802 -file-list-symbol-files
20803@end smallexample
922fbb7b 20804
a2c02241 20805List symbol files.
922fbb7b 20806
a2c02241 20807@subsubheading @value{GDBN} Command
922fbb7b 20808
a2c02241 20809The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 20810
a2c02241
NR
20811@subsubheading Example
20812N.A.
922fbb7b 20813
922fbb7b 20814
a2c02241
NR
20815@subheading The @code{-file-symbol-file} Command
20816@findex -file-symbol-file
922fbb7b 20817
a2c02241 20818@subsubheading Synopsis
922fbb7b 20819
a2c02241
NR
20820@smallexample
20821 -file-symbol-file @var{file}
20822@end smallexample
922fbb7b 20823
a2c02241
NR
20824Read symbol table info from the specified @var{file} argument. When
20825used without arguments, clears @value{GDBN}'s symbol table info. No output is
20826produced, except for a completion notification.
922fbb7b 20827
a2c02241 20828@subsubheading @value{GDBN} Command
922fbb7b 20829
a2c02241 20830The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 20831
a2c02241 20832@subsubheading Example
922fbb7b 20833
a2c02241 20834@smallexample
594fe323 20835(gdb)
a2c02241
NR
20836-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
20837^done
594fe323 20838(gdb)
a2c02241 20839@end smallexample
922fbb7b 20840
a2c02241 20841@ignore
a2c02241
NR
20842@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20843@node GDB/MI Memory Overlay Commands
20844@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 20845
a2c02241 20846The memory overlay commands are not implemented.
922fbb7b 20847
a2c02241 20848@c @subheading -overlay-auto
922fbb7b 20849
a2c02241 20850@c @subheading -overlay-list-mapping-state
922fbb7b 20851
a2c02241 20852@c @subheading -overlay-list-overlays
922fbb7b 20853
a2c02241 20854@c @subheading -overlay-map
922fbb7b 20855
a2c02241 20856@c @subheading -overlay-off
922fbb7b 20857
a2c02241 20858@c @subheading -overlay-on
922fbb7b 20859
a2c02241 20860@c @subheading -overlay-unmap
922fbb7b 20861
a2c02241
NR
20862@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20863@node GDB/MI Signal Handling Commands
20864@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 20865
a2c02241 20866Signal handling commands are not implemented.
922fbb7b 20867
a2c02241 20868@c @subheading -signal-handle
922fbb7b 20869
a2c02241 20870@c @subheading -signal-list-handle-actions
922fbb7b 20871
a2c02241
NR
20872@c @subheading -signal-list-signal-types
20873@end ignore
922fbb7b 20874
922fbb7b 20875
a2c02241
NR
20876@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20877@node GDB/MI Target Manipulation
20878@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
20879
20880
a2c02241
NR
20881@subheading The @code{-target-attach} Command
20882@findex -target-attach
922fbb7b
AC
20883
20884@subsubheading Synopsis
20885
20886@smallexample
a2c02241 20887 -target-attach @var{pid} | @var{file}
922fbb7b
AC
20888@end smallexample
20889
a2c02241 20890Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
922fbb7b 20891
a2c02241 20892@subsubheading @value{GDBN} command
922fbb7b 20893
a2c02241 20894The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 20895
a2c02241
NR
20896@subsubheading Example
20897N.A.
922fbb7b 20898
a2c02241
NR
20899
20900@subheading The @code{-target-compare-sections} Command
20901@findex -target-compare-sections
922fbb7b
AC
20902
20903@subsubheading Synopsis
20904
20905@smallexample
a2c02241 20906 -target-compare-sections [ @var{section} ]
922fbb7b
AC
20907@end smallexample
20908
a2c02241
NR
20909Compare data of section @var{section} on target to the exec file.
20910Without the argument, all sections are compared.
922fbb7b 20911
a2c02241 20912@subsubheading @value{GDBN} Command
922fbb7b 20913
a2c02241 20914The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 20915
a2c02241
NR
20916@subsubheading Example
20917N.A.
20918
20919
20920@subheading The @code{-target-detach} Command
20921@findex -target-detach
922fbb7b
AC
20922
20923@subsubheading Synopsis
20924
20925@smallexample
a2c02241 20926 -target-detach
922fbb7b
AC
20927@end smallexample
20928
a2c02241
NR
20929Detach from the remote target which normally resumes its execution.
20930There's no output.
20931
20932@subsubheading @value{GDBN} command
20933
20934The corresponding @value{GDBN} command is @samp{detach}.
20935
20936@subsubheading Example
922fbb7b
AC
20937
20938@smallexample
594fe323 20939(gdb)
a2c02241
NR
20940-target-detach
20941^done
594fe323 20942(gdb)
922fbb7b
AC
20943@end smallexample
20944
20945
a2c02241
NR
20946@subheading The @code{-target-disconnect} Command
20947@findex -target-disconnect
922fbb7b
AC
20948
20949@subsubheading Synopsis
20950
a2c02241
NR
20951@example
20952 -target-disconnect
20953@end example
922fbb7b 20954
a2c02241
NR
20955Disconnect from the remote target. There's no output and the target is
20956generally not resumed.
20957
20958@subsubheading @value{GDBN} command
20959
20960The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
20961
20962@subsubheading Example
922fbb7b
AC
20963
20964@smallexample
594fe323 20965(gdb)
a2c02241
NR
20966-target-disconnect
20967^done
594fe323 20968(gdb)
922fbb7b
AC
20969@end smallexample
20970
20971
a2c02241
NR
20972@subheading The @code{-target-download} Command
20973@findex -target-download
922fbb7b
AC
20974
20975@subsubheading Synopsis
20976
20977@smallexample
a2c02241 20978 -target-download
922fbb7b
AC
20979@end smallexample
20980
a2c02241
NR
20981Loads the executable onto the remote target.
20982It prints out an update message every half second, which includes the fields:
20983
20984@table @samp
20985@item section
20986The name of the section.
20987@item section-sent
20988The size of what has been sent so far for that section.
20989@item section-size
20990The size of the section.
20991@item total-sent
20992The total size of what was sent so far (the current and the previous sections).
20993@item total-size
20994The size of the overall executable to download.
20995@end table
20996
20997@noindent
20998Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
20999@sc{gdb/mi} Output Syntax}).
21000
21001In addition, it prints the name and size of the sections, as they are
21002downloaded. These messages include the following fields:
21003
21004@table @samp
21005@item section
21006The name of the section.
21007@item section-size
21008The size of the section.
21009@item total-size
21010The size of the overall executable to download.
21011@end table
21012
21013@noindent
21014At the end, a summary is printed.
21015
21016@subsubheading @value{GDBN} Command
21017
21018The corresponding @value{GDBN} command is @samp{load}.
21019
21020@subsubheading Example
21021
21022Note: each status message appears on a single line. Here the messages
21023have been broken down so that they can fit onto a page.
922fbb7b
AC
21024
21025@smallexample
594fe323 21026(gdb)
a2c02241
NR
21027-target-download
21028+download,@{section=".text",section-size="6668",total-size="9880"@}
21029+download,@{section=".text",section-sent="512",section-size="6668",
21030total-sent="512",total-size="9880"@}
21031+download,@{section=".text",section-sent="1024",section-size="6668",
21032total-sent="1024",total-size="9880"@}
21033+download,@{section=".text",section-sent="1536",section-size="6668",
21034total-sent="1536",total-size="9880"@}
21035+download,@{section=".text",section-sent="2048",section-size="6668",
21036total-sent="2048",total-size="9880"@}
21037+download,@{section=".text",section-sent="2560",section-size="6668",
21038total-sent="2560",total-size="9880"@}
21039+download,@{section=".text",section-sent="3072",section-size="6668",
21040total-sent="3072",total-size="9880"@}
21041+download,@{section=".text",section-sent="3584",section-size="6668",
21042total-sent="3584",total-size="9880"@}
21043+download,@{section=".text",section-sent="4096",section-size="6668",
21044total-sent="4096",total-size="9880"@}
21045+download,@{section=".text",section-sent="4608",section-size="6668",
21046total-sent="4608",total-size="9880"@}
21047+download,@{section=".text",section-sent="5120",section-size="6668",
21048total-sent="5120",total-size="9880"@}
21049+download,@{section=".text",section-sent="5632",section-size="6668",
21050total-sent="5632",total-size="9880"@}
21051+download,@{section=".text",section-sent="6144",section-size="6668",
21052total-sent="6144",total-size="9880"@}
21053+download,@{section=".text",section-sent="6656",section-size="6668",
21054total-sent="6656",total-size="9880"@}
21055+download,@{section=".init",section-size="28",total-size="9880"@}
21056+download,@{section=".fini",section-size="28",total-size="9880"@}
21057+download,@{section=".data",section-size="3156",total-size="9880"@}
21058+download,@{section=".data",section-sent="512",section-size="3156",
21059total-sent="7236",total-size="9880"@}
21060+download,@{section=".data",section-sent="1024",section-size="3156",
21061total-sent="7748",total-size="9880"@}
21062+download,@{section=".data",section-sent="1536",section-size="3156",
21063total-sent="8260",total-size="9880"@}
21064+download,@{section=".data",section-sent="2048",section-size="3156",
21065total-sent="8772",total-size="9880"@}
21066+download,@{section=".data",section-sent="2560",section-size="3156",
21067total-sent="9284",total-size="9880"@}
21068+download,@{section=".data",section-sent="3072",section-size="3156",
21069total-sent="9796",total-size="9880"@}
21070^done,address="0x10004",load-size="9880",transfer-rate="6586",
21071write-rate="429"
594fe323 21072(gdb)
922fbb7b
AC
21073@end smallexample
21074
21075
a2c02241
NR
21076@subheading The @code{-target-exec-status} Command
21077@findex -target-exec-status
922fbb7b
AC
21078
21079@subsubheading Synopsis
21080
21081@smallexample
a2c02241 21082 -target-exec-status
922fbb7b
AC
21083@end smallexample
21084
a2c02241
NR
21085Provide information on the state of the target (whether it is running or
21086not, for instance).
922fbb7b 21087
a2c02241 21088@subsubheading @value{GDBN} Command
922fbb7b 21089
a2c02241
NR
21090There's no equivalent @value{GDBN} command.
21091
21092@subsubheading Example
21093N.A.
922fbb7b 21094
a2c02241
NR
21095
21096@subheading The @code{-target-list-available-targets} Command
21097@findex -target-list-available-targets
922fbb7b
AC
21098
21099@subsubheading Synopsis
21100
21101@smallexample
a2c02241 21102 -target-list-available-targets
922fbb7b
AC
21103@end smallexample
21104
a2c02241 21105List the possible targets to connect to.
922fbb7b 21106
a2c02241 21107@subsubheading @value{GDBN} Command
922fbb7b 21108
a2c02241 21109The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 21110
a2c02241
NR
21111@subsubheading Example
21112N.A.
21113
21114
21115@subheading The @code{-target-list-current-targets} Command
21116@findex -target-list-current-targets
922fbb7b
AC
21117
21118@subsubheading Synopsis
21119
21120@smallexample
a2c02241 21121 -target-list-current-targets
922fbb7b
AC
21122@end smallexample
21123
a2c02241 21124Describe the current target.
922fbb7b 21125
a2c02241 21126@subsubheading @value{GDBN} Command
922fbb7b 21127
a2c02241
NR
21128The corresponding information is printed by @samp{info file} (among
21129other things).
922fbb7b 21130
a2c02241
NR
21131@subsubheading Example
21132N.A.
21133
21134
21135@subheading The @code{-target-list-parameters} Command
21136@findex -target-list-parameters
922fbb7b
AC
21137
21138@subsubheading Synopsis
21139
21140@smallexample
a2c02241 21141 -target-list-parameters
922fbb7b
AC
21142@end smallexample
21143
a2c02241
NR
21144@c ????
21145
21146@subsubheading @value{GDBN} Command
21147
21148No equivalent.
922fbb7b
AC
21149
21150@subsubheading Example
a2c02241
NR
21151N.A.
21152
21153
21154@subheading The @code{-target-select} Command
21155@findex -target-select
21156
21157@subsubheading Synopsis
922fbb7b
AC
21158
21159@smallexample
a2c02241 21160 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
21161@end smallexample
21162
a2c02241 21163Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 21164
a2c02241
NR
21165@table @samp
21166@item @var{type}
21167The type of target, for instance @samp{async}, @samp{remote}, etc.
21168@item @var{parameters}
21169Device names, host names and the like. @xref{Target Commands, ,
21170Commands for managing targets}, for more details.
21171@end table
21172
21173The output is a connection notification, followed by the address at
21174which the target program is, in the following form:
922fbb7b
AC
21175
21176@smallexample
a2c02241
NR
21177^connected,addr="@var{address}",func="@var{function name}",
21178 args=[@var{arg list}]
922fbb7b
AC
21179@end smallexample
21180
a2c02241
NR
21181@subsubheading @value{GDBN} Command
21182
21183The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
21184
21185@subsubheading Example
922fbb7b 21186
265eeb58 21187@smallexample
594fe323 21188(gdb)
a2c02241
NR
21189-target-select async /dev/ttya
21190^connected,addr="0xfe00a300",func="??",args=[]
594fe323 21191(gdb)
265eeb58 21192@end smallexample
ef21caaf
NR
21193
21194@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21195@node GDB/MI Miscellaneous Commands
21196@section Miscellaneous @sc{gdb/mi} Commands
21197
21198@c @subheading -gdb-complete
21199
21200@subheading The @code{-gdb-exit} Command
21201@findex -gdb-exit
21202
21203@subsubheading Synopsis
21204
21205@smallexample
21206 -gdb-exit
21207@end smallexample
21208
21209Exit @value{GDBN} immediately.
21210
21211@subsubheading @value{GDBN} Command
21212
21213Approximately corresponds to @samp{quit}.
21214
21215@subsubheading Example
21216
21217@smallexample
594fe323 21218(gdb)
ef21caaf
NR
21219-gdb-exit
21220^exit
21221@end smallexample
21222
a2c02241
NR
21223
21224@subheading The @code{-exec-abort} Command
21225@findex -exec-abort
21226
21227@subsubheading Synopsis
21228
21229@smallexample
21230 -exec-abort
21231@end smallexample
21232
21233Kill the inferior running program.
21234
21235@subsubheading @value{GDBN} Command
21236
21237The corresponding @value{GDBN} command is @samp{kill}.
21238
21239@subsubheading Example
21240N.A.
21241
21242
ef21caaf
NR
21243@subheading The @code{-gdb-set} Command
21244@findex -gdb-set
21245
21246@subsubheading Synopsis
21247
21248@smallexample
21249 -gdb-set
21250@end smallexample
21251
21252Set an internal @value{GDBN} variable.
21253@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
21254
21255@subsubheading @value{GDBN} Command
21256
21257The corresponding @value{GDBN} command is @samp{set}.
21258
21259@subsubheading Example
21260
21261@smallexample
594fe323 21262(gdb)
ef21caaf
NR
21263-gdb-set $foo=3
21264^done
594fe323 21265(gdb)
ef21caaf
NR
21266@end smallexample
21267
21268
21269@subheading The @code{-gdb-show} Command
21270@findex -gdb-show
21271
21272@subsubheading Synopsis
21273
21274@smallexample
21275 -gdb-show
21276@end smallexample
21277
21278Show the current value of a @value{GDBN} variable.
21279
21280@subsubheading @value{GDBN} command
21281
21282The corresponding @value{GDBN} command is @samp{show}.
21283
21284@subsubheading Example
21285
21286@smallexample
594fe323 21287(gdb)
ef21caaf
NR
21288-gdb-show annotate
21289^done,value="0"
594fe323 21290(gdb)
ef21caaf
NR
21291@end smallexample
21292
21293@c @subheading -gdb-source
21294
21295
21296@subheading The @code{-gdb-version} Command
21297@findex -gdb-version
21298
21299@subsubheading Synopsis
21300
21301@smallexample
21302 -gdb-version
21303@end smallexample
21304
21305Show version information for @value{GDBN}. Used mostly in testing.
21306
21307@subsubheading @value{GDBN} Command
21308
21309The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
21310default shows this information when you start an interactive session.
21311
21312@subsubheading Example
21313
21314@c This example modifies the actual output from GDB to avoid overfull
21315@c box in TeX.
21316@smallexample
594fe323 21317(gdb)
ef21caaf
NR
21318-gdb-version
21319~GNU gdb 5.2.1
21320~Copyright 2000 Free Software Foundation, Inc.
21321~GDB is free software, covered by the GNU General Public License, and
21322~you are welcome to change it and/or distribute copies of it under
21323~ certain conditions.
21324~Type "show copying" to see the conditions.
21325~There is absolutely no warranty for GDB. Type "show warranty" for
21326~ details.
21327~This GDB was configured as
21328 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
21329^done
594fe323 21330(gdb)
ef21caaf
NR
21331@end smallexample
21332
21333@subheading The @code{-interpreter-exec} Command
21334@findex -interpreter-exec
21335
21336@subheading Synopsis
21337
21338@smallexample
21339-interpreter-exec @var{interpreter} @var{command}
21340@end smallexample
a2c02241 21341@anchor{-interpreter-exec}
ef21caaf
NR
21342
21343Execute the specified @var{command} in the given @var{interpreter}.
21344
21345@subheading @value{GDBN} Command
21346
21347The corresponding @value{GDBN} command is @samp{interpreter-exec}.
21348
21349@subheading Example
21350
21351@smallexample
594fe323 21352(gdb)
ef21caaf
NR
21353-interpreter-exec console "break main"
21354&"During symbol reading, couldn't parse type; debugger out of date?.\n"
21355&"During symbol reading, bad structure-type format.\n"
21356~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
21357^done
594fe323 21358(gdb)
ef21caaf
NR
21359@end smallexample
21360
21361@subheading The @code{-inferior-tty-set} Command
21362@findex -inferior-tty-set
21363
21364@subheading Synopsis
21365
21366@smallexample
21367-inferior-tty-set /dev/pts/1
21368@end smallexample
21369
21370Set terminal for future runs of the program being debugged.
21371
21372@subheading @value{GDBN} Command
21373
21374The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
21375
21376@subheading Example
21377
21378@smallexample
594fe323 21379(gdb)
ef21caaf
NR
21380-inferior-tty-set /dev/pts/1
21381^done
594fe323 21382(gdb)
ef21caaf
NR
21383@end smallexample
21384
21385@subheading The @code{-inferior-tty-show} Command
21386@findex -inferior-tty-show
21387
21388@subheading Synopsis
21389
21390@smallexample
21391-inferior-tty-show
21392@end smallexample
21393
21394Show terminal for future runs of program being debugged.
21395
21396@subheading @value{GDBN} Command
21397
21398The corresponding @value{GDBN} command is @samp{show inferior-tty}.
21399
21400@subheading Example
21401
21402@smallexample
594fe323 21403(gdb)
ef21caaf
NR
21404-inferior-tty-set /dev/pts/1
21405^done
594fe323 21406(gdb)
ef21caaf
NR
21407-inferior-tty-show
21408^done,inferior_tty_terminal="/dev/pts/1"
594fe323 21409(gdb)
ef21caaf 21410@end smallexample
922fbb7b
AC
21411
21412@node Annotations
21413@chapter @value{GDBN} Annotations
21414
086432e2
AC
21415This chapter describes annotations in @value{GDBN}. Annotations were
21416designed to interface @value{GDBN} to graphical user interfaces or other
21417similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
21418relatively high level.
21419
086432e2
AC
21420The annotation mechanism has largely been superseeded by @sc{gdb/mi}
21421(@pxref{GDB/MI}).
21422
922fbb7b
AC
21423@ignore
21424This is Edition @value{EDITION}, @value{DATE}.
21425@end ignore
21426
21427@menu
21428* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
21429* Prompting:: Annotations marking @value{GDBN}'s need for input.
21430* Errors:: Annotations for error messages.
922fbb7b
AC
21431* Invalidation:: Some annotations describe things now invalid.
21432* Annotations for Running::
21433 Whether the program is running, how it stopped, etc.
21434* Source Annotations:: Annotations describing source code.
922fbb7b
AC
21435@end menu
21436
21437@node Annotations Overview
21438@section What is an Annotation?
21439@cindex annotations
21440
922fbb7b
AC
21441Annotations start with a newline character, two @samp{control-z}
21442characters, and the name of the annotation. If there is no additional
21443information associated with this annotation, the name of the annotation
21444is followed immediately by a newline. If there is additional
21445information, the name of the annotation is followed by a space, the
21446additional information, and a newline. The additional information
21447cannot contain newline characters.
21448
21449Any output not beginning with a newline and two @samp{control-z}
21450characters denotes literal output from @value{GDBN}. Currently there is
21451no need for @value{GDBN} to output a newline followed by two
21452@samp{control-z} characters, but if there was such a need, the
21453annotations could be extended with an @samp{escape} annotation which
21454means those three characters as output.
21455
086432e2
AC
21456The annotation @var{level}, which is specified using the
21457@option{--annotate} command line option (@pxref{Mode Options}), controls
21458how much information @value{GDBN} prints together with its prompt,
21459values of expressions, source lines, and other types of output. Level 0
21460is for no anntations, level 1 is for use when @value{GDBN} is run as a
21461subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
21462for programs that control @value{GDBN}, and level 2 annotations have
21463been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
21464Interface, annotate, GDB's Obsolete Annotations}).
21465
21466@table @code
21467@kindex set annotate
21468@item set annotate @var{level}
e09f16f9 21469The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 21470annotations to the specified @var{level}.
9c16f35a
EZ
21471
21472@item show annotate
21473@kindex show annotate
21474Show the current annotation level.
09d4efe1
EZ
21475@end table
21476
21477This chapter describes level 3 annotations.
086432e2 21478
922fbb7b
AC
21479A simple example of starting up @value{GDBN} with annotations is:
21480
21481@smallexample
086432e2
AC
21482$ @kbd{gdb --annotate=3}
21483GNU gdb 6.0
21484Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
21485GDB is free software, covered by the GNU General Public License,
21486and you are welcome to change it and/or distribute copies of it
21487under certain conditions.
21488Type "show copying" to see the conditions.
21489There is absolutely no warranty for GDB. Type "show warranty"
21490for details.
086432e2 21491This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
21492
21493^Z^Zpre-prompt
f7dc1244 21494(@value{GDBP})
922fbb7b 21495^Z^Zprompt
086432e2 21496@kbd{quit}
922fbb7b
AC
21497
21498^Z^Zpost-prompt
b383017d 21499$
922fbb7b
AC
21500@end smallexample
21501
21502Here @samp{quit} is input to @value{GDBN}; the rest is output from
21503@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
21504denotes a @samp{control-z} character) are annotations; the rest is
21505output from @value{GDBN}.
21506
922fbb7b
AC
21507@node Prompting
21508@section Annotation for @value{GDBN} Input
21509
21510@cindex annotations for prompts
21511When @value{GDBN} prompts for input, it annotates this fact so it is possible
21512to know when to send output, when the output from a given command is
21513over, etc.
21514
21515Different kinds of input each have a different @dfn{input type}. Each
21516input type has three annotations: a @code{pre-} annotation, which
21517denotes the beginning of any prompt which is being output, a plain
21518annotation, which denotes the end of the prompt, and then a @code{post-}
21519annotation which denotes the end of any echo which may (or may not) be
21520associated with the input. For example, the @code{prompt} input type
21521features the following annotations:
21522
21523@smallexample
21524^Z^Zpre-prompt
21525^Z^Zprompt
21526^Z^Zpost-prompt
21527@end smallexample
21528
21529The input types are
21530
21531@table @code
21532@findex pre-prompt
21533@findex prompt
21534@findex post-prompt
21535@item prompt
21536When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
21537
21538@findex pre-commands
21539@findex commands
21540@findex post-commands
21541@item commands
21542When @value{GDBN} prompts for a set of commands, like in the @code{commands}
21543command. The annotations are repeated for each command which is input.
21544
21545@findex pre-overload-choice
21546@findex overload-choice
21547@findex post-overload-choice
21548@item overload-choice
21549When @value{GDBN} wants the user to select between various overloaded functions.
21550
21551@findex pre-query
21552@findex query
21553@findex post-query
21554@item query
21555When @value{GDBN} wants the user to confirm a potentially dangerous operation.
21556
21557@findex pre-prompt-for-continue
21558@findex prompt-for-continue
21559@findex post-prompt-for-continue
21560@item prompt-for-continue
21561When @value{GDBN} is asking the user to press return to continue. Note: Don't
21562expect this to work well; instead use @code{set height 0} to disable
21563prompting. This is because the counting of lines is buggy in the
21564presence of annotations.
21565@end table
21566
21567@node Errors
21568@section Errors
21569@cindex annotations for errors, warnings and interrupts
21570
21571@findex quit
21572@smallexample
21573^Z^Zquit
21574@end smallexample
21575
21576This annotation occurs right before @value{GDBN} responds to an interrupt.
21577
21578@findex error
21579@smallexample
21580^Z^Zerror
21581@end smallexample
21582
21583This annotation occurs right before @value{GDBN} responds to an error.
21584
21585Quit and error annotations indicate that any annotations which @value{GDBN} was
21586in the middle of may end abruptly. For example, if a
21587@code{value-history-begin} annotation is followed by a @code{error}, one
21588cannot expect to receive the matching @code{value-history-end}. One
21589cannot expect not to receive it either, however; an error annotation
21590does not necessarily mean that @value{GDBN} is immediately returning all the way
21591to the top level.
21592
21593@findex error-begin
21594A quit or error annotation may be preceded by
21595
21596@smallexample
21597^Z^Zerror-begin
21598@end smallexample
21599
21600Any output between that and the quit or error annotation is the error
21601message.
21602
21603Warning messages are not yet annotated.
21604@c If we want to change that, need to fix warning(), type_error(),
21605@c range_error(), and possibly other places.
21606
922fbb7b
AC
21607@node Invalidation
21608@section Invalidation Notices
21609
21610@cindex annotations for invalidation messages
21611The following annotations say that certain pieces of state may have
21612changed.
21613
21614@table @code
21615@findex frames-invalid
21616@item ^Z^Zframes-invalid
21617
21618The frames (for example, output from the @code{backtrace} command) may
21619have changed.
21620
21621@findex breakpoints-invalid
21622@item ^Z^Zbreakpoints-invalid
21623
21624The breakpoints may have changed. For example, the user just added or
21625deleted a breakpoint.
21626@end table
21627
21628@node Annotations for Running
21629@section Running the Program
21630@cindex annotations for running programs
21631
21632@findex starting
21633@findex stopping
21634When the program starts executing due to a @value{GDBN} command such as
b383017d 21635@code{step} or @code{continue},
922fbb7b
AC
21636
21637@smallexample
21638^Z^Zstarting
21639@end smallexample
21640
b383017d 21641is output. When the program stops,
922fbb7b
AC
21642
21643@smallexample
21644^Z^Zstopped
21645@end smallexample
21646
21647is output. Before the @code{stopped} annotation, a variety of
21648annotations describe how the program stopped.
21649
21650@table @code
21651@findex exited
21652@item ^Z^Zexited @var{exit-status}
21653The program exited, and @var{exit-status} is the exit status (zero for
21654successful exit, otherwise nonzero).
21655
21656@findex signalled
21657@findex signal-name
21658@findex signal-name-end
21659@findex signal-string
21660@findex signal-string-end
21661@item ^Z^Zsignalled
21662The program exited with a signal. After the @code{^Z^Zsignalled}, the
21663annotation continues:
21664
21665@smallexample
21666@var{intro-text}
21667^Z^Zsignal-name
21668@var{name}
21669^Z^Zsignal-name-end
21670@var{middle-text}
21671^Z^Zsignal-string
21672@var{string}
21673^Z^Zsignal-string-end
21674@var{end-text}
21675@end smallexample
21676
21677@noindent
21678where @var{name} is the name of the signal, such as @code{SIGILL} or
21679@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
21680as @code{Illegal Instruction} or @code{Segmentation fault}.
21681@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
21682user's benefit and have no particular format.
21683
21684@findex signal
21685@item ^Z^Zsignal
21686The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
21687just saying that the program received the signal, not that it was
21688terminated with it.
21689
21690@findex breakpoint
21691@item ^Z^Zbreakpoint @var{number}
21692The program hit breakpoint number @var{number}.
21693
21694@findex watchpoint
21695@item ^Z^Zwatchpoint @var{number}
21696The program hit watchpoint number @var{number}.
21697@end table
21698
21699@node Source Annotations
21700@section Displaying Source
21701@cindex annotations for source display
21702
21703@findex source
21704The following annotation is used instead of displaying source code:
21705
21706@smallexample
21707^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
21708@end smallexample
21709
21710where @var{filename} is an absolute file name indicating which source
21711file, @var{line} is the line number within that file (where 1 is the
21712first line in the file), @var{character} is the character position
21713within the file (where 0 is the first character in the file) (for most
21714debug formats this will necessarily point to the beginning of a line),
21715@var{middle} is @samp{middle} if @var{addr} is in the middle of the
21716line, or @samp{beg} if @var{addr} is at the beginning of the line, and
21717@var{addr} is the address in the target program associated with the
21718source which is being displayed. @var{addr} is in the form @samp{0x}
21719followed by one or more lowercase hex digits (note that this does not
21720depend on the language).
21721
8e04817f
AC
21722@node GDB Bugs
21723@chapter Reporting Bugs in @value{GDBN}
21724@cindex bugs in @value{GDBN}
21725@cindex reporting bugs in @value{GDBN}
c906108c 21726
8e04817f 21727Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 21728
8e04817f
AC
21729Reporting a bug may help you by bringing a solution to your problem, or it
21730may not. But in any case the principal function of a bug report is to help
21731the entire community by making the next version of @value{GDBN} work better. Bug
21732reports are your contribution to the maintenance of @value{GDBN}.
c906108c 21733
8e04817f
AC
21734In order for a bug report to serve its purpose, you must include the
21735information that enables us to fix the bug.
c4555f82
SC
21736
21737@menu
8e04817f
AC
21738* Bug Criteria:: Have you found a bug?
21739* Bug Reporting:: How to report bugs
c4555f82
SC
21740@end menu
21741
8e04817f
AC
21742@node Bug Criteria
21743@section Have you found a bug?
21744@cindex bug criteria
c4555f82 21745
8e04817f 21746If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
21747
21748@itemize @bullet
8e04817f
AC
21749@cindex fatal signal
21750@cindex debugger crash
21751@cindex crash of debugger
c4555f82 21752@item
8e04817f
AC
21753If the debugger gets a fatal signal, for any input whatever, that is a
21754@value{GDBN} bug. Reliable debuggers never crash.
21755
21756@cindex error on valid input
21757@item
21758If @value{GDBN} produces an error message for valid input, that is a
21759bug. (Note that if you're cross debugging, the problem may also be
21760somewhere in the connection to the target.)
c4555f82 21761
8e04817f 21762@cindex invalid input
c4555f82 21763@item
8e04817f
AC
21764If @value{GDBN} does not produce an error message for invalid input,
21765that is a bug. However, you should note that your idea of
21766``invalid input'' might be our idea of ``an extension'' or ``support
21767for traditional practice''.
21768
21769@item
21770If you are an experienced user of debugging tools, your suggestions
21771for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21772@end itemize
21773
8e04817f
AC
21774@node Bug Reporting
21775@section How to report bugs
21776@cindex bug reports
21777@cindex @value{GDBN} bugs, reporting
21778
21779A number of companies and individuals offer support for @sc{gnu} products.
21780If you obtained @value{GDBN} from a support organization, we recommend you
21781contact that organization first.
21782
21783You can find contact information for many support companies and
21784individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21785distribution.
21786@c should add a web page ref...
21787
129188f6
AC
21788In any event, we also recommend that you submit bug reports for
21789@value{GDBN}. The prefered method is to submit them directly using
21790@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21791page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21792be used.
8e04817f
AC
21793
21794@strong{Do not send bug reports to @samp{info-gdb}, or to
21795@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21796not want to receive bug reports. Those that do have arranged to receive
21797@samp{bug-gdb}.
21798
21799The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21800serves as a repeater. The mailing list and the newsgroup carry exactly
21801the same messages. Often people think of posting bug reports to the
21802newsgroup instead of mailing them. This appears to work, but it has one
21803problem which can be crucial: a newsgroup posting often lacks a mail
21804path back to the sender. Thus, if we need to ask for more information,
21805we may be unable to reach you. For this reason, it is better to send
21806bug reports to the mailing list.
c4555f82 21807
8e04817f
AC
21808The fundamental principle of reporting bugs usefully is this:
21809@strong{report all the facts}. If you are not sure whether to state a
21810fact or leave it out, state it!
c4555f82 21811
8e04817f
AC
21812Often people omit facts because they think they know what causes the
21813problem and assume that some details do not matter. Thus, you might
21814assume that the name of the variable you use in an example does not matter.
21815Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21816stray memory reference which happens to fetch from the location where that
21817name is stored in memory; perhaps, if the name were different, the contents
21818of that location would fool the debugger into doing the right thing despite
21819the bug. Play it safe and give a specific, complete example. That is the
21820easiest thing for you to do, and the most helpful.
c4555f82 21821
8e04817f
AC
21822Keep in mind that the purpose of a bug report is to enable us to fix the
21823bug. It may be that the bug has been reported previously, but neither
21824you nor we can know that unless your bug report is complete and
21825self-contained.
c4555f82 21826
8e04817f
AC
21827Sometimes people give a few sketchy facts and ask, ``Does this ring a
21828bell?'' Those bug reports are useless, and we urge everyone to
21829@emph{refuse to respond to them} except to chide the sender to report
21830bugs properly.
21831
21832To enable us to fix the bug, you should include all these things:
c4555f82
SC
21833
21834@itemize @bullet
21835@item
8e04817f
AC
21836The version of @value{GDBN}. @value{GDBN} announces it if you start
21837with no arguments; you can also print it at any time using @code{show
21838version}.
c4555f82 21839
8e04817f
AC
21840Without this, we will not know whether there is any point in looking for
21841the bug in the current version of @value{GDBN}.
c4555f82
SC
21842
21843@item
8e04817f
AC
21844The type of machine you are using, and the operating system name and
21845version number.
c4555f82
SC
21846
21847@item
c1468174 21848What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 21849``@value{GCC}--2.8.1''.
c4555f82
SC
21850
21851@item
8e04817f 21852What compiler (and its version) was used to compile the program you are
c1468174 21853debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
8e04817f
AC
21854C Compiler''. For GCC, you can say @code{gcc --version} to get this
21855information; for other compilers, see the documentation for those
21856compilers.
c4555f82 21857
8e04817f
AC
21858@item
21859The command arguments you gave the compiler to compile your example and
21860observe the bug. For example, did you use @samp{-O}? To guarantee
21861you will not omit something important, list them all. A copy of the
21862Makefile (or the output from make) is sufficient.
c4555f82 21863
8e04817f
AC
21864If we were to try to guess the arguments, we would probably guess wrong
21865and then we might not encounter the bug.
c4555f82 21866
8e04817f
AC
21867@item
21868A complete input script, and all necessary source files, that will
21869reproduce the bug.
c4555f82 21870
8e04817f
AC
21871@item
21872A description of what behavior you observe that you believe is
21873incorrect. For example, ``It gets a fatal signal.''
c4555f82 21874
8e04817f
AC
21875Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21876will certainly notice it. But if the bug is incorrect output, we might
21877not notice unless it is glaringly wrong. You might as well not give us
21878a chance to make a mistake.
c4555f82 21879
8e04817f
AC
21880Even if the problem you experience is a fatal signal, you should still
21881say so explicitly. Suppose something strange is going on, such as, your
21882copy of @value{GDBN} is out of synch, or you have encountered a bug in
21883the C library on your system. (This has happened!) Your copy might
21884crash and ours would not. If you told us to expect a crash, then when
21885ours fails to crash, we would know that the bug was not happening for
21886us. If you had not told us to expect a crash, then we would not be able
21887to draw any conclusion from our observations.
c4555f82 21888
e0c07bf0
MC
21889@pindex script
21890@cindex recording a session script
21891To collect all this information, you can use a session recording program
21892such as @command{script}, which is available on many Unix systems.
21893Just run your @value{GDBN} session inside @command{script} and then
21894include the @file{typescript} file with your bug report.
21895
21896Another way to record a @value{GDBN} session is to run @value{GDBN}
21897inside Emacs and then save the entire buffer to a file.
21898
8e04817f
AC
21899@item
21900If you wish to suggest changes to the @value{GDBN} source, send us context
21901diffs. If you even discuss something in the @value{GDBN} source, refer to
21902it by context, not by line number.
c4555f82 21903
8e04817f
AC
21904The line numbers in our development sources will not match those in your
21905sources. Your line numbers would convey no useful information to us.
c4555f82 21906
8e04817f 21907@end itemize
c4555f82 21908
8e04817f 21909Here are some things that are not necessary:
c4555f82 21910
8e04817f
AC
21911@itemize @bullet
21912@item
21913A description of the envelope of the bug.
c4555f82 21914
8e04817f
AC
21915Often people who encounter a bug spend a lot of time investigating
21916which changes to the input file will make the bug go away and which
21917changes will not affect it.
c4555f82 21918
8e04817f
AC
21919This is often time consuming and not very useful, because the way we
21920will find the bug is by running a single example under the debugger
21921with breakpoints, not by pure deduction from a series of examples.
21922We recommend that you save your time for something else.
c4555f82 21923
8e04817f
AC
21924Of course, if you can find a simpler example to report @emph{instead}
21925of the original one, that is a convenience for us. Errors in the
21926output will be easier to spot, running under the debugger will take
21927less time, and so on.
c4555f82 21928
8e04817f
AC
21929However, simplification is not vital; if you do not want to do this,
21930report the bug anyway and send us the entire test case you used.
c4555f82 21931
8e04817f
AC
21932@item
21933A patch for the bug.
c4555f82 21934
8e04817f
AC
21935A patch for the bug does help us if it is a good one. But do not omit
21936the necessary information, such as the test case, on the assumption that
21937a patch is all we need. We might see problems with your patch and decide
21938to fix the problem another way, or we might not understand it at all.
c4555f82 21939
8e04817f
AC
21940Sometimes with a program as complicated as @value{GDBN} it is very hard to
21941construct an example that will make the program follow a certain path
21942through the code. If you do not send us the example, we will not be able
21943to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21944
8e04817f
AC
21945And if we cannot understand what bug you are trying to fix, or why your
21946patch should be an improvement, we will not install it. A test case will
21947help us to understand.
c4555f82 21948
8e04817f
AC
21949@item
21950A guess about what the bug is or what it depends on.
c4555f82 21951
8e04817f
AC
21952Such guesses are usually wrong. Even we cannot guess right about such
21953things without first using the debugger to find the facts.
21954@end itemize
c4555f82 21955
8e04817f
AC
21956@c The readline documentation is distributed with the readline code
21957@c and consists of the two following files:
21958@c rluser.texinfo
21959@c inc-hist.texinfo
21960@c Use -I with makeinfo to point to the appropriate directory,
21961@c environment var TEXINPUTS with TeX.
5bdf8622 21962@include rluser.texi
8e04817f 21963@include inc-hist.texinfo
c4555f82 21964
c4555f82 21965
8e04817f
AC
21966@node Formatting Documentation
21967@appendix Formatting Documentation
c4555f82 21968
8e04817f
AC
21969@cindex @value{GDBN} reference card
21970@cindex reference card
21971The @value{GDBN} 4 release includes an already-formatted reference card, ready
21972for printing with PostScript or Ghostscript, in the @file{gdb}
21973subdirectory of the main source directory@footnote{In
21974@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21975release.}. If you can use PostScript or Ghostscript with your printer,
21976you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21977
8e04817f
AC
21978The release also includes the source for the reference card. You
21979can format it, using @TeX{}, by typing:
c4555f82 21980
474c8240 21981@smallexample
8e04817f 21982make refcard.dvi
474c8240 21983@end smallexample
c4555f82 21984
8e04817f
AC
21985The @value{GDBN} reference card is designed to print in @dfn{landscape}
21986mode on US ``letter'' size paper;
21987that is, on a sheet 11 inches wide by 8.5 inches
21988high. You will need to specify this form of printing as an option to
21989your @sc{dvi} output program.
c4555f82 21990
8e04817f 21991@cindex documentation
c4555f82 21992
8e04817f
AC
21993All the documentation for @value{GDBN} comes as part of the machine-readable
21994distribution. The documentation is written in Texinfo format, which is
21995a documentation system that uses a single source file to produce both
21996on-line information and a printed manual. You can use one of the Info
21997formatting commands to create the on-line version of the documentation
21998and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21999
8e04817f
AC
22000@value{GDBN} includes an already formatted copy of the on-line Info
22001version of this manual in the @file{gdb} subdirectory. The main Info
22002file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
22003subordinate files matching @samp{gdb.info*} in the same directory. If
22004necessary, you can print out these files, or read them with any editor;
22005but they are easier to read using the @code{info} subsystem in @sc{gnu}
22006Emacs or the standalone @code{info} program, available as part of the
22007@sc{gnu} Texinfo distribution.
c4555f82 22008
8e04817f
AC
22009If you want to format these Info files yourself, you need one of the
22010Info formatting programs, such as @code{texinfo-format-buffer} or
22011@code{makeinfo}.
c4555f82 22012
8e04817f
AC
22013If you have @code{makeinfo} installed, and are in the top level
22014@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
22015version @value{GDBVN}), you can make the Info file by typing:
c4555f82 22016
474c8240 22017@smallexample
8e04817f
AC
22018cd gdb
22019make gdb.info
474c8240 22020@end smallexample
c4555f82 22021
8e04817f
AC
22022If you want to typeset and print copies of this manual, you need @TeX{},
22023a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
22024Texinfo definitions file.
c4555f82 22025
8e04817f
AC
22026@TeX{} is a typesetting program; it does not print files directly, but
22027produces output files called @sc{dvi} files. To print a typeset
22028document, you need a program to print @sc{dvi} files. If your system
22029has @TeX{} installed, chances are it has such a program. The precise
22030command to use depends on your system; @kbd{lpr -d} is common; another
22031(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
22032require a file name without any extension or a @samp{.dvi} extension.
c4555f82 22033
8e04817f
AC
22034@TeX{} also requires a macro definitions file called
22035@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
22036written in Texinfo format. On its own, @TeX{} cannot either read or
22037typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
22038and is located in the @file{gdb-@var{version-number}/texinfo}
22039directory.
c4555f82 22040
8e04817f
AC
22041If you have @TeX{} and a @sc{dvi} printer program installed, you can
22042typeset and print this manual. First switch to the the @file{gdb}
22043subdirectory of the main source directory (for example, to
22044@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 22045
474c8240 22046@smallexample
8e04817f 22047make gdb.dvi
474c8240 22048@end smallexample
c4555f82 22049
8e04817f 22050Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 22051
8e04817f
AC
22052@node Installing GDB
22053@appendix Installing @value{GDBN}
8e04817f 22054@cindex installation
c4555f82 22055
7fa2210b
DJ
22056@menu
22057* Requirements:: Requirements for building @value{GDBN}
22058* Running Configure:: Invoking the @value{GDBN} @code{configure} script
22059* Separate Objdir:: Compiling @value{GDBN} in another directory
22060* Config Names:: Specifying names for hosts and targets
22061* Configure Options:: Summary of options for configure
22062@end menu
22063
22064@node Requirements
22065@section Requirements for building @value{GDBN}
22066@cindex building @value{GDBN}, requirements for
22067
22068Building @value{GDBN} requires various tools and packages to be available.
22069Other packages will be used only if they are found.
22070
22071@heading Tools/packages necessary for building @value{GDBN}
22072@table @asis
22073@item ISO C90 compiler
22074@value{GDBN} is written in ISO C90. It should be buildable with any
22075working C90 compiler, e.g.@: GCC.
22076
22077@end table
22078
22079@heading Tools/packages optional for building @value{GDBN}
22080@table @asis
22081@item Expat
22082@value{GDBN} can use the Expat XML parsing library. This library may be
22083included with your operating system distribution; if it is not, you
22084can get the latest version from @url{http://expat.sourceforge.net}.
22085The @code{configure} script will search for this library in several
22086standard locations; if it is installed in an unusual path, you can
22087use the @option{--with-libexpat-prefix} option to specify its location.
22088
22089Expat is used currently only used to implement some remote-specific
22090features.
22091
22092@end table
22093
22094@node Running Configure
22095@section Invoking the @value{GDBN} @code{configure} script
22096@cindex configuring @value{GDBN}
8e04817f
AC
22097@value{GDBN} comes with a @code{configure} script that automates the process
22098of preparing @value{GDBN} for installation; you can then use @code{make} to
22099build the @code{gdb} program.
22100@iftex
22101@c irrelevant in info file; it's as current as the code it lives with.
22102@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
22103look at the @file{README} file in the sources; we may have improved the
22104installation procedures since publishing this manual.}
22105@end iftex
c4555f82 22106
8e04817f
AC
22107The @value{GDBN} distribution includes all the source code you need for
22108@value{GDBN} in a single directory, whose name is usually composed by
22109appending the version number to @samp{gdb}.
c4555f82 22110
8e04817f
AC
22111For example, the @value{GDBN} version @value{GDBVN} distribution is in the
22112@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 22113
8e04817f
AC
22114@table @code
22115@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
22116script for configuring @value{GDBN} and all its supporting libraries
c4555f82 22117
8e04817f
AC
22118@item gdb-@value{GDBVN}/gdb
22119the source specific to @value{GDBN} itself
c4555f82 22120
8e04817f
AC
22121@item gdb-@value{GDBVN}/bfd
22122source for the Binary File Descriptor library
c906108c 22123
8e04817f
AC
22124@item gdb-@value{GDBVN}/include
22125@sc{gnu} include files
c906108c 22126
8e04817f
AC
22127@item gdb-@value{GDBVN}/libiberty
22128source for the @samp{-liberty} free software library
c906108c 22129
8e04817f
AC
22130@item gdb-@value{GDBVN}/opcodes
22131source for the library of opcode tables and disassemblers
c906108c 22132
8e04817f
AC
22133@item gdb-@value{GDBVN}/readline
22134source for the @sc{gnu} command-line interface
c906108c 22135
8e04817f
AC
22136@item gdb-@value{GDBVN}/glob
22137source for the @sc{gnu} filename pattern-matching subroutine
c906108c 22138
8e04817f
AC
22139@item gdb-@value{GDBVN}/mmalloc
22140source for the @sc{gnu} memory-mapped malloc package
22141@end table
c906108c 22142
8e04817f
AC
22143The simplest way to configure and build @value{GDBN} is to run @code{configure}
22144from the @file{gdb-@var{version-number}} source directory, which in
22145this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 22146
8e04817f
AC
22147First switch to the @file{gdb-@var{version-number}} source directory
22148if you are not already in it; then run @code{configure}. Pass the
22149identifier for the platform on which @value{GDBN} will run as an
22150argument.
c906108c 22151
8e04817f 22152For example:
c906108c 22153
474c8240 22154@smallexample
8e04817f
AC
22155cd gdb-@value{GDBVN}
22156./configure @var{host}
22157make
474c8240 22158@end smallexample
c906108c 22159
8e04817f
AC
22160@noindent
22161where @var{host} is an identifier such as @samp{sun4} or
22162@samp{decstation}, that identifies the platform where @value{GDBN} will run.
22163(You can often leave off @var{host}; @code{configure} tries to guess the
22164correct value by examining your system.)
c906108c 22165
8e04817f
AC
22166Running @samp{configure @var{host}} and then running @code{make} builds the
22167@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
22168libraries, then @code{gdb} itself. The configured source files, and the
22169binaries, are left in the corresponding source directories.
c906108c 22170
8e04817f
AC
22171@need 750
22172@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
22173system does not recognize this automatically when you run a different
22174shell, you may need to run @code{sh} on it explicitly:
c906108c 22175
474c8240 22176@smallexample
8e04817f 22177sh configure @var{host}
474c8240 22178@end smallexample
c906108c 22179
8e04817f
AC
22180If you run @code{configure} from a directory that contains source
22181directories for multiple libraries or programs, such as the
22182@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
22183creates configuration files for every directory level underneath (unless
22184you tell it not to, with the @samp{--norecursion} option).
22185
94e91d6d
MC
22186You should run the @code{configure} script from the top directory in the
22187source tree, the @file{gdb-@var{version-number}} directory. If you run
22188@code{configure} from one of the subdirectories, you will configure only
22189that subdirectory. That is usually not what you want. In particular,
22190if you run the first @code{configure} from the @file{gdb} subdirectory
22191of the @file{gdb-@var{version-number}} directory, you will omit the
22192configuration of @file{bfd}, @file{readline}, and other sibling
22193directories of the @file{gdb} subdirectory. This leads to build errors
22194about missing include files such as @file{bfd/bfd.h}.
c906108c 22195
8e04817f
AC
22196You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
22197However, you should make sure that the shell on your path (named by
22198the @samp{SHELL} environment variable) is publicly readable. Remember
22199that @value{GDBN} uses the shell to start your program---some systems refuse to
22200let @value{GDBN} debug child processes whose programs are not readable.
c906108c 22201
8e04817f
AC
22202@node Separate Objdir
22203@section Compiling @value{GDBN} in another directory
c906108c 22204
8e04817f
AC
22205If you want to run @value{GDBN} versions for several host or target machines,
22206you need a different @code{gdb} compiled for each combination of
22207host and target. @code{configure} is designed to make this easy by
22208allowing you to generate each configuration in a separate subdirectory,
22209rather than in the source directory. If your @code{make} program
22210handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
22211@code{make} in each of these directories builds the @code{gdb}
22212program specified there.
c906108c 22213
8e04817f
AC
22214To build @code{gdb} in a separate directory, run @code{configure}
22215with the @samp{--srcdir} option to specify where to find the source.
22216(You also need to specify a path to find @code{configure}
22217itself from your working directory. If the path to @code{configure}
22218would be the same as the argument to @samp{--srcdir}, you can leave out
22219the @samp{--srcdir} option; it is assumed.)
c906108c 22220
8e04817f
AC
22221For example, with version @value{GDBVN}, you can build @value{GDBN} in a
22222separate directory for a Sun 4 like this:
c906108c 22223
474c8240 22224@smallexample
8e04817f
AC
22225@group
22226cd gdb-@value{GDBVN}
22227mkdir ../gdb-sun4
22228cd ../gdb-sun4
22229../gdb-@value{GDBVN}/configure sun4
22230make
22231@end group
474c8240 22232@end smallexample
c906108c 22233
8e04817f
AC
22234When @code{configure} builds a configuration using a remote source
22235directory, it creates a tree for the binaries with the same structure
22236(and using the same names) as the tree under the source directory. In
22237the example, you'd find the Sun 4 library @file{libiberty.a} in the
22238directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
22239@file{gdb-sun4/gdb}.
c906108c 22240
94e91d6d
MC
22241Make sure that your path to the @file{configure} script has just one
22242instance of @file{gdb} in it. If your path to @file{configure} looks
22243like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
22244one subdirectory of @value{GDBN}, not the whole package. This leads to
22245build errors about missing include files such as @file{bfd/bfd.h}.
22246
8e04817f
AC
22247One popular reason to build several @value{GDBN} configurations in separate
22248directories is to configure @value{GDBN} for cross-compiling (where
22249@value{GDBN} runs on one machine---the @dfn{host}---while debugging
22250programs that run on another machine---the @dfn{target}).
22251You specify a cross-debugging target by
22252giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 22253
8e04817f
AC
22254When you run @code{make} to build a program or library, you must run
22255it in a configured directory---whatever directory you were in when you
22256called @code{configure} (or one of its subdirectories).
c906108c 22257
8e04817f
AC
22258The @code{Makefile} that @code{configure} generates in each source
22259directory also runs recursively. If you type @code{make} in a source
22260directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
22261directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
22262will build all the required libraries, and then build GDB.
c906108c 22263
8e04817f
AC
22264When you have multiple hosts or targets configured in separate
22265directories, you can run @code{make} on them in parallel (for example,
22266if they are NFS-mounted on each of the hosts); they will not interfere
22267with each other.
c906108c 22268
8e04817f
AC
22269@node Config Names
22270@section Specifying names for hosts and targets
c906108c 22271
8e04817f
AC
22272The specifications used for hosts and targets in the @code{configure}
22273script are based on a three-part naming scheme, but some short predefined
22274aliases are also supported. The full naming scheme encodes three pieces
22275of information in the following pattern:
c906108c 22276
474c8240 22277@smallexample
8e04817f 22278@var{architecture}-@var{vendor}-@var{os}
474c8240 22279@end smallexample
c906108c 22280
8e04817f
AC
22281For example, you can use the alias @code{sun4} as a @var{host} argument,
22282or as the value for @var{target} in a @code{--target=@var{target}}
22283option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 22284
8e04817f
AC
22285The @code{configure} script accompanying @value{GDBN} does not provide
22286any query facility to list all supported host and target names or
22287aliases. @code{configure} calls the Bourne shell script
22288@code{config.sub} to map abbreviations to full names; you can read the
22289script, if you wish, or you can use it to test your guesses on
22290abbreviations---for example:
c906108c 22291
8e04817f
AC
22292@smallexample
22293% sh config.sub i386-linux
22294i386-pc-linux-gnu
22295% sh config.sub alpha-linux
22296alpha-unknown-linux-gnu
22297% sh config.sub hp9k700
22298hppa1.1-hp-hpux
22299% sh config.sub sun4
22300sparc-sun-sunos4.1.1
22301% sh config.sub sun3
22302m68k-sun-sunos4.1.1
22303% sh config.sub i986v
22304Invalid configuration `i986v': machine `i986v' not recognized
22305@end smallexample
c906108c 22306
8e04817f
AC
22307@noindent
22308@code{config.sub} is also distributed in the @value{GDBN} source
22309directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 22310
8e04817f
AC
22311@node Configure Options
22312@section @code{configure} options
c906108c 22313
8e04817f
AC
22314Here is a summary of the @code{configure} options and arguments that
22315are most often useful for building @value{GDBN}. @code{configure} also has
22316several other options not listed here. @inforef{What Configure
22317Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 22318
474c8240 22319@smallexample
8e04817f
AC
22320configure @r{[}--help@r{]}
22321 @r{[}--prefix=@var{dir}@r{]}
22322 @r{[}--exec-prefix=@var{dir}@r{]}
22323 @r{[}--srcdir=@var{dirname}@r{]}
22324 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
22325 @r{[}--target=@var{target}@r{]}
22326 @var{host}
474c8240 22327@end smallexample
c906108c 22328
8e04817f
AC
22329@noindent
22330You may introduce options with a single @samp{-} rather than
22331@samp{--} if you prefer; but you may abbreviate option names if you use
22332@samp{--}.
c906108c 22333
8e04817f
AC
22334@table @code
22335@item --help
22336Display a quick summary of how to invoke @code{configure}.
c906108c 22337
8e04817f
AC
22338@item --prefix=@var{dir}
22339Configure the source to install programs and files under directory
22340@file{@var{dir}}.
c906108c 22341
8e04817f
AC
22342@item --exec-prefix=@var{dir}
22343Configure the source to install programs under directory
22344@file{@var{dir}}.
c906108c 22345
8e04817f
AC
22346@c avoid splitting the warning from the explanation:
22347@need 2000
22348@item --srcdir=@var{dirname}
22349@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
22350@code{make} that implements the @code{VPATH} feature.}@*
22351Use this option to make configurations in directories separate from the
22352@value{GDBN} source directories. Among other things, you can use this to
22353build (or maintain) several configurations simultaneously, in separate
22354directories. @code{configure} writes configuration specific files in
22355the current directory, but arranges for them to use the source in the
22356directory @var{dirname}. @code{configure} creates directories under
22357the working directory in parallel to the source directories below
22358@var{dirname}.
c906108c 22359
8e04817f
AC
22360@item --norecursion
22361Configure only the directory level where @code{configure} is executed; do not
22362propagate configuration to subdirectories.
c906108c 22363
8e04817f
AC
22364@item --target=@var{target}
22365Configure @value{GDBN} for cross-debugging programs running on the specified
22366@var{target}. Without this option, @value{GDBN} is configured to debug
22367programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 22368
8e04817f 22369There is no convenient way to generate a list of all available targets.
c906108c 22370
8e04817f
AC
22371@item @var{host} @dots{}
22372Configure @value{GDBN} to run on the specified @var{host}.
c906108c 22373
8e04817f
AC
22374There is no convenient way to generate a list of all available hosts.
22375@end table
c906108c 22376
8e04817f
AC
22377There are many other options available as well, but they are generally
22378needed for special purposes only.
c906108c 22379
8e04817f
AC
22380@node Maintenance Commands
22381@appendix Maintenance Commands
22382@cindex maintenance commands
22383@cindex internal commands
c906108c 22384
8e04817f 22385In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
22386includes a number of commands intended for @value{GDBN} developers,
22387that are not documented elsewhere in this manual. These commands are
da316a69
EZ
22388provided here for reference. (For commands that turn on debugging
22389messages, see @ref{Debugging Output}.)
c906108c 22390
8e04817f 22391@table @code
09d4efe1
EZ
22392@kindex maint agent
22393@item maint agent @var{expression}
22394Translate the given @var{expression} into remote agent bytecodes.
22395This command is useful for debugging the Agent Expression mechanism
22396(@pxref{Agent Expressions}).
22397
8e04817f
AC
22398@kindex maint info breakpoints
22399@item @anchor{maint info breakpoints}maint info breakpoints
22400Using the same format as @samp{info breakpoints}, display both the
22401breakpoints you've set explicitly, and those @value{GDBN} is using for
22402internal purposes. Internal breakpoints are shown with negative
22403breakpoint numbers. The type column identifies what kind of breakpoint
22404is shown:
c906108c 22405
8e04817f
AC
22406@table @code
22407@item breakpoint
22408Normal, explicitly set breakpoint.
c906108c 22409
8e04817f
AC
22410@item watchpoint
22411Normal, explicitly set watchpoint.
c906108c 22412
8e04817f
AC
22413@item longjmp
22414Internal breakpoint, used to handle correctly stepping through
22415@code{longjmp} calls.
c906108c 22416
8e04817f
AC
22417@item longjmp resume
22418Internal breakpoint at the target of a @code{longjmp}.
c906108c 22419
8e04817f
AC
22420@item until
22421Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 22422
8e04817f
AC
22423@item finish
22424Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 22425
8e04817f
AC
22426@item shlib events
22427Shared library events.
c906108c 22428
8e04817f 22429@end table
c906108c 22430
09d4efe1
EZ
22431@kindex maint check-symtabs
22432@item maint check-symtabs
22433Check the consistency of psymtabs and symtabs.
22434
22435@kindex maint cplus first_component
22436@item maint cplus first_component @var{name}
22437Print the first C@t{++} class/namespace component of @var{name}.
22438
22439@kindex maint cplus namespace
22440@item maint cplus namespace
22441Print the list of possible C@t{++} namespaces.
22442
22443@kindex maint demangle
22444@item maint demangle @var{name}
22445Demangle a C@t{++} or Objective-C manled @var{name}.
22446
22447@kindex maint deprecate
22448@kindex maint undeprecate
22449@cindex deprecated commands
22450@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
22451@itemx maint undeprecate @var{command}
22452Deprecate or undeprecate the named @var{command}. Deprecated commands
22453cause @value{GDBN} to issue a warning when you use them. The optional
22454argument @var{replacement} says which newer command should be used in
22455favor of the deprecated one; if it is given, @value{GDBN} will mention
22456the replacement as part of the warning.
22457
22458@kindex maint dump-me
22459@item maint dump-me
721c2651 22460@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 22461Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
22462This is supported only on systems which support aborting a program
22463with the @code{SIGQUIT} signal.
09d4efe1 22464
8d30a00d
AC
22465@kindex maint internal-error
22466@kindex maint internal-warning
09d4efe1
EZ
22467@item maint internal-error @r{[}@var{message-text}@r{]}
22468@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
22469Cause @value{GDBN} to call the internal function @code{internal_error}
22470or @code{internal_warning} and hence behave as though an internal error
22471or internal warning has been detected. In addition to reporting the
22472internal problem, these functions give the user the opportunity to
22473either quit @value{GDBN} or create a core file of the current
22474@value{GDBN} session.
22475
09d4efe1
EZ
22476These commands take an optional parameter @var{message-text} that is
22477used as the text of the error or warning message.
22478
22479Here's an example of using @code{indernal-error}:
22480
8d30a00d 22481@smallexample
f7dc1244 22482(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
22483@dots{}/maint.c:121: internal-error: testing, 1, 2
22484A problem internal to GDB has been detected. Further
22485debugging may prove unreliable.
22486Quit this debugging session? (y or n) @kbd{n}
22487Create a core file? (y or n) @kbd{n}
f7dc1244 22488(@value{GDBP})
8d30a00d
AC
22489@end smallexample
22490
09d4efe1
EZ
22491@kindex maint packet
22492@item maint packet @var{text}
22493If @value{GDBN} is talking to an inferior via the serial protocol,
22494then this command sends the string @var{text} to the inferior, and
22495displays the response packet. @value{GDBN} supplies the initial
22496@samp{$} character, the terminating @samp{#} character, and the
22497checksum.
22498
22499@kindex maint print architecture
22500@item maint print architecture @r{[}@var{file}@r{]}
22501Print the entire architecture configuration. The optional argument
22502@var{file} names the file where the output goes.
8d30a00d 22503
00905d52
AC
22504@kindex maint print dummy-frames
22505@item maint print dummy-frames
00905d52
AC
22506Prints the contents of @value{GDBN}'s internal dummy-frame stack.
22507
22508@smallexample
f7dc1244 22509(@value{GDBP}) @kbd{b add}
00905d52 22510@dots{}
f7dc1244 22511(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
22512Breakpoint 2, add (a=2, b=3) at @dots{}
2251358 return (a + b);
22514The program being debugged stopped while in a function called from GDB.
22515@dots{}
f7dc1244 22516(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
225170x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
22518 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
22519 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 22520(@value{GDBP})
00905d52
AC
22521@end smallexample
22522
22523Takes an optional file parameter.
22524
0680b120
AC
22525@kindex maint print registers
22526@kindex maint print raw-registers
22527@kindex maint print cooked-registers
617073a9 22528@kindex maint print register-groups
09d4efe1
EZ
22529@item maint print registers @r{[}@var{file}@r{]}
22530@itemx maint print raw-registers @r{[}@var{file}@r{]}
22531@itemx maint print cooked-registers @r{[}@var{file}@r{]}
22532@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
22533Print @value{GDBN}'s internal register data structures.
22534
617073a9
AC
22535The command @code{maint print raw-registers} includes the contents of
22536the raw register cache; the command @code{maint print cooked-registers}
22537includes the (cooked) value of all registers; and the command
22538@code{maint print register-groups} includes the groups that each
22539register is a member of. @xref{Registers,, Registers, gdbint,
22540@value{GDBN} Internals}.
0680b120 22541
09d4efe1
EZ
22542These commands take an optional parameter, a file name to which to
22543write the information.
0680b120 22544
617073a9 22545@kindex maint print reggroups
09d4efe1
EZ
22546@item maint print reggroups @r{[}@var{file}@r{]}
22547Print @value{GDBN}'s internal register group data structures. The
22548optional argument @var{file} tells to what file to write the
22549information.
617073a9 22550
09d4efe1 22551The register groups info looks like this:
617073a9
AC
22552
22553@smallexample
f7dc1244 22554(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
22555 Group Type
22556 general user
22557 float user
22558 all user
22559 vector user
22560 system user
22561 save internal
22562 restore internal
617073a9
AC
22563@end smallexample
22564
09d4efe1
EZ
22565@kindex flushregs
22566@item flushregs
22567This command forces @value{GDBN} to flush its internal register cache.
22568
22569@kindex maint print objfiles
22570@cindex info for known object files
22571@item maint print objfiles
22572Print a dump of all known object files. For each object file, this
22573command prints its name, address in memory, and all of its psymtabs
22574and symtabs.
22575
22576@kindex maint print statistics
22577@cindex bcache statistics
22578@item maint print statistics
22579This command prints, for each object file in the program, various data
22580about that object file followed by the byte cache (@dfn{bcache})
22581statistics for the object file. The objfile data includes the number
22582of minimal, partical, full, and stabs symbols, the number of types
22583defined by the objfile, the number of as yet unexpanded psym tables,
22584the number of line tables and string tables, and the amount of memory
22585used by the various tables. The bcache statistics include the counts,
22586sizes, and counts of duplicates of all and unique objects, max,
22587average, and median entry size, total memory used and its overhead and
22588savings, and various measures of the hash table size and chain
22589lengths.
22590
22591@kindex maint print type
22592@cindex type chain of a data type
22593@item maint print type @var{expr}
22594Print the type chain for a type specified by @var{expr}. The argument
22595can be either a type name or a symbol. If it is a symbol, the type of
22596that symbol is described. The type chain produced by this command is
22597a recursive definition of the data type as stored in @value{GDBN}'s
22598data structures, including its flags and contained types.
22599
22600@kindex maint set dwarf2 max-cache-age
22601@kindex maint show dwarf2 max-cache-age
22602@item maint set dwarf2 max-cache-age
22603@itemx maint show dwarf2 max-cache-age
22604Control the DWARF 2 compilation unit cache.
22605
22606@cindex DWARF 2 compilation units cache
22607In object files with inter-compilation-unit references, such as those
22608produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
22609reader needs to frequently refer to previously read compilation units.
22610This setting controls how long a compilation unit will remain in the
22611cache if it is not referenced. A higher limit means that cached
22612compilation units will be stored in memory longer, and more total
22613memory will be used. Setting it to zero disables caching, which will
22614slow down @value{GDBN} startup, but reduce memory consumption.
22615
e7ba9c65
DJ
22616@kindex maint set profile
22617@kindex maint show profile
22618@cindex profiling GDB
22619@item maint set profile
22620@itemx maint show profile
22621Control profiling of @value{GDBN}.
22622
22623Profiling will be disabled until you use the @samp{maint set profile}
22624command to enable it. When you enable profiling, the system will begin
22625collecting timing and execution count data; when you disable profiling or
22626exit @value{GDBN}, the results will be written to a log file. Remember that
22627if you use profiling, @value{GDBN} will overwrite the profiling log file
22628(often called @file{gmon.out}). If you have a record of important profiling
22629data in a @file{gmon.out} file, be sure to move it to a safe location.
22630
22631Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 22632compiled with the @samp{-pg} compiler option.
e7ba9c65 22633
09d4efe1
EZ
22634@kindex maint show-debug-regs
22635@cindex x86 hardware debug registers
22636@item maint show-debug-regs
22637Control whether to show variables that mirror the x86 hardware debug
22638registers. Use @code{ON} to enable, @code{OFF} to disable. If
22639enabled, the debug registers values are shown when GDB inserts or
22640removes a hardware breakpoint or watchpoint, and when the inferior
22641triggers a hardware-assisted breakpoint or watchpoint.
22642
22643@kindex maint space
22644@cindex memory used by commands
22645@item maint space
22646Control whether to display memory usage for each command. If set to a
22647nonzero value, @value{GDBN} will display how much memory each command
22648took, following the command's own output. This can also be requested
22649by invoking @value{GDBN} with the @option{--statistics} command-line
22650switch (@pxref{Mode Options}).
22651
22652@kindex maint time
22653@cindex time of command execution
22654@item maint time
22655Control whether to display the execution time for each command. If
22656set to a nonzero value, @value{GDBN} will display how much time it
22657took to execute each command, following the command's own output.
22658This can also be requested by invoking @value{GDBN} with the
22659@option{--statistics} command-line switch (@pxref{Mode Options}).
22660
22661@kindex maint translate-address
22662@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
22663Find the symbol stored at the location specified by the address
22664@var{addr} and an optional section name @var{section}. If found,
22665@value{GDBN} prints the name of the closest symbol and an offset from
22666the symbol's location to the specified address. This is similar to
22667the @code{info address} command (@pxref{Symbols}), except that this
22668command also allows to find symbols in other sections.
ae038cb0 22669
8e04817f 22670@end table
c906108c 22671
9c16f35a
EZ
22672The following command is useful for non-interactive invocations of
22673@value{GDBN}, such as in the test suite.
22674
22675@table @code
22676@item set watchdog @var{nsec}
22677@kindex set watchdog
22678@cindex watchdog timer
22679@cindex timeout for commands
22680Set the maximum number of seconds @value{GDBN} will wait for the
22681target operation to finish. If this time expires, @value{GDBN}
22682reports and error and the command is aborted.
22683
22684@item show watchdog
22685Show the current setting of the target wait timeout.
22686@end table
c906108c 22687
e0ce93ac 22688@node Remote Protocol
8e04817f 22689@appendix @value{GDBN} Remote Serial Protocol
c906108c 22690
ee2d5c50
AC
22691@menu
22692* Overview::
22693* Packets::
22694* Stop Reply Packets::
22695* General Query Packets::
22696* Register Packet Format::
9d29849a 22697* Tracepoint Packets::
9a6253be 22698* Interrupts::
ee2d5c50 22699* Examples::
0ce1b118 22700* File-I/O remote protocol extension::
68437a39 22701* Memory map format::
ee2d5c50
AC
22702@end menu
22703
22704@node Overview
22705@section Overview
22706
8e04817f
AC
22707There may be occasions when you need to know something about the
22708protocol---for example, if there is only one serial port to your target
22709machine, you might want your program to do something special if it
22710recognizes a packet meant for @value{GDBN}.
c906108c 22711
d2c6833e 22712In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 22713transmitted and received data respectfully.
c906108c 22714
8e04817f
AC
22715@cindex protocol, @value{GDBN} remote serial
22716@cindex serial protocol, @value{GDBN} remote
22717@cindex remote serial protocol
22718All @value{GDBN} commands and responses (other than acknowledgments) are
22719sent as a @var{packet}. A @var{packet} is introduced with the character
22720@samp{$}, the actual @var{packet-data}, and the terminating character
22721@samp{#} followed by a two-digit @var{checksum}:
c906108c 22722
474c8240 22723@smallexample
8e04817f 22724@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 22725@end smallexample
8e04817f 22726@noindent
c906108c 22727
8e04817f
AC
22728@cindex checksum, for @value{GDBN} remote
22729@noindent
22730The two-digit @var{checksum} is computed as the modulo 256 sum of all
22731characters between the leading @samp{$} and the trailing @samp{#} (an
22732eight bit unsigned checksum).
c906108c 22733
8e04817f
AC
22734Implementors should note that prior to @value{GDBN} 5.0 the protocol
22735specification also included an optional two-digit @var{sequence-id}:
c906108c 22736
474c8240 22737@smallexample
8e04817f 22738@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 22739@end smallexample
c906108c 22740
8e04817f
AC
22741@cindex sequence-id, for @value{GDBN} remote
22742@noindent
22743That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
22744has never output @var{sequence-id}s. Stubs that handle packets added
22745since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 22746
8e04817f
AC
22747@cindex acknowledgment, for @value{GDBN} remote
22748When either the host or the target machine receives a packet, the first
22749response expected is an acknowledgment: either @samp{+} (to indicate
22750the package was received correctly) or @samp{-} (to request
22751retransmission):
c906108c 22752
474c8240 22753@smallexample
d2c6833e
AC
22754-> @code{$}@var{packet-data}@code{#}@var{checksum}
22755<- @code{+}
474c8240 22756@end smallexample
8e04817f 22757@noindent
53a5351d 22758
8e04817f
AC
22759The host (@value{GDBN}) sends @var{command}s, and the target (the
22760debugging stub incorporated in your program) sends a @var{response}. In
22761the case of step and continue @var{command}s, the response is only sent
22762when the operation has completed (the target has again stopped).
c906108c 22763
8e04817f
AC
22764@var{packet-data} consists of a sequence of characters with the
22765exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
22766exceptions).
c906108c 22767
ee2d5c50 22768@cindex remote protocol, field separator
0876f84a 22769Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 22770@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 22771@sc{hex} with leading zeros suppressed.
c906108c 22772
8e04817f
AC
22773Implementors should note that prior to @value{GDBN} 5.0, the character
22774@samp{:} could not appear as the third character in a packet (as it
22775would potentially conflict with the @var{sequence-id}).
c906108c 22776
0876f84a
DJ
22777@cindex remote protocol, binary data
22778@anchor{Binary Data}
22779Binary data in most packets is encoded either as two hexadecimal
22780digits per byte of binary data. This allowed the traditional remote
22781protocol to work over connections which were only seven-bit clean.
22782Some packets designed more recently assume an eight-bit clean
22783connection, and use a more efficient encoding to send and receive
22784binary data.
22785
22786The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
22787as an escape character. Any escaped byte is transmitted as the escape
22788character followed by the original character XORed with @code{0x20}.
22789For example, the byte @code{0x7d} would be transmitted as the two
22790bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
22791@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
22792@samp{@}}) must always be escaped. Responses sent by the stub
22793must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
22794is not interpreted as the start of a run-length encoded sequence
22795(described next).
22796
8e04817f
AC
22797Response @var{data} can be run-length encoded to save space. A @samp{*}
22798means that the next character is an @sc{ascii} encoding giving a repeat count
22799which stands for that many repetitions of the character preceding the
22800@samp{*}. The encoding is @code{n+29}, yielding a printable character
22801where @code{n >=3} (which is where rle starts to win). The printable
22802characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22803value greater than 126 should not be used.
c906108c 22804
8e04817f 22805So:
474c8240 22806@smallexample
8e04817f 22807"@code{0* }"
474c8240 22808@end smallexample
8e04817f
AC
22809@noindent
22810means the same as "0000".
c906108c 22811
8e04817f
AC
22812The error response returned for some packets includes a two character
22813error number. That number is not well defined.
c906108c 22814
f8da2bff 22815@cindex empty response, for unsupported packets
8e04817f
AC
22816For any @var{command} not supported by the stub, an empty response
22817(@samp{$#00}) should be returned. That way it is possible to extend the
22818protocol. A newer @value{GDBN} can tell if a packet is supported based
22819on that response.
c906108c 22820
b383017d
RM
22821A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22822@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22823optional.
c906108c 22824
ee2d5c50
AC
22825@node Packets
22826@section Packets
22827
22828The following table provides a complete list of all currently defined
22829@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22830@xref{File-I/O remote protocol extension}, for details about the File
22831I/O extension of the remote protocol.
ee2d5c50 22832
b8ff78ce
JB
22833Each packet's description has a template showing the packet's overall
22834syntax, followed by an explanation of the packet's meaning. We
22835include spaces in some of the templates for clarity; these are not
22836part of the packet's syntax. No @value{GDBN} packet uses spaces to
22837separate its components. For example, a template like @samp{foo
22838@var{bar} @var{baz}} describes a packet beginning with the three ASCII
22839bytes @samp{foo}, followed by a @var{bar}, followed directly by a
22840@var{baz}. GDB does not transmit a space character between the
22841@samp{foo} and the @var{bar}, or between the @var{bar} and the
22842@var{baz}.
22843
8ffe2530
JB
22844Note that all packet forms beginning with an upper- or lower-case
22845letter, other than those described here, are reserved for future use.
22846
b8ff78ce 22847Here are the packet descriptions.
ee2d5c50 22848
b8ff78ce 22849@table @samp
ee2d5c50 22850
b8ff78ce
JB
22851@item !
22852@cindex @samp{!} packet
8e04817f
AC
22853Enable extended mode. In extended mode, the remote server is made
22854persistent. The @samp{R} packet is used to restart the program being
22855debugged.
ee2d5c50
AC
22856
22857Reply:
22858@table @samp
22859@item OK
8e04817f 22860The remote target both supports and has enabled extended mode.
ee2d5c50 22861@end table
c906108c 22862
b8ff78ce
JB
22863@item ?
22864@cindex @samp{?} packet
ee2d5c50
AC
22865Indicate the reason the target halted. The reply is the same as for
22866step and continue.
c906108c 22867
ee2d5c50
AC
22868Reply:
22869@xref{Stop Reply Packets}, for the reply specifications.
22870
b8ff78ce
JB
22871@item A @var{arglen},@var{argnum},@var{arg},@dots{}
22872@cindex @samp{A} packet
22873Initialized @code{argv[]} array passed into program. @var{arglen}
22874specifies the number of bytes in the hex encoded byte stream
22875@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
22876
22877Reply:
22878@table @samp
22879@item OK
b8ff78ce
JB
22880The arguments were set.
22881@item E @var{NN}
22882An error occurred.
ee2d5c50
AC
22883@end table
22884
b8ff78ce
JB
22885@item b @var{baud}
22886@cindex @samp{b} packet
22887(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
22888Change the serial line speed to @var{baud}.
22889
22890JTC: @emph{When does the transport layer state change? When it's
22891received, or after the ACK is transmitted. In either case, there are
22892problems if the command or the acknowledgment packet is dropped.}
22893
22894Stan: @emph{If people really wanted to add something like this, and get
22895it working for the first time, they ought to modify ser-unix.c to send
22896some kind of out-of-band message to a specially-setup stub and have the
22897switch happen "in between" packets, so that from remote protocol's point
22898of view, nothing actually happened.}
22899
b8ff78ce
JB
22900@item B @var{addr},@var{mode}
22901@cindex @samp{B} packet
8e04817f 22902Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22903breakpoint at @var{addr}.
22904
b8ff78ce 22905Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 22906(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22907
4f553f88 22908@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
22909@cindex @samp{c} packet
22910Continue. @var{addr} is address to resume. If @var{addr} is omitted,
22911resume at current address.
c906108c 22912
ee2d5c50
AC
22913Reply:
22914@xref{Stop Reply Packets}, for the reply specifications.
22915
4f553f88 22916@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 22917@cindex @samp{C} packet
8e04817f 22918Continue with signal @var{sig} (hex signal number). If
b8ff78ce 22919@samp{;@var{addr}} is omitted, resume at same address.
c906108c 22920
ee2d5c50
AC
22921Reply:
22922@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22923
b8ff78ce
JB
22924@item d
22925@cindex @samp{d} packet
ee2d5c50
AC
22926Toggle debug flag.
22927
b8ff78ce
JB
22928Don't use this packet; instead, define a general set packet
22929(@pxref{General Query Packets}).
ee2d5c50 22930
b8ff78ce
JB
22931@item D
22932@cindex @samp{D} packet
ee2d5c50 22933Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22934before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22935
22936Reply:
22937@table @samp
10fac096
NW
22938@item OK
22939for success
b8ff78ce 22940@item E @var{NN}
10fac096 22941for an error
ee2d5c50 22942@end table
c906108c 22943
b8ff78ce
JB
22944@item F @var{RC},@var{EE},@var{CF};@var{XX}
22945@cindex @samp{F} packet
22946A reply from @value{GDBN} to an @samp{F} packet sent by the target.
22947This is part of the File-I/O protocol extension. @xref{File-I/O
22948remote protocol extension}, for the specification.
ee2d5c50 22949
b8ff78ce 22950@item g
ee2d5c50 22951@anchor{read registers packet}
b8ff78ce 22952@cindex @samp{g} packet
ee2d5c50
AC
22953Read general registers.
22954
22955Reply:
22956@table @samp
22957@item @var{XX@dots{}}
8e04817f
AC
22958Each byte of register data is described by two hex digits. The bytes
22959with the register are transmitted in target byte order. The size of
b8ff78ce 22960each register and their position within the @samp{g} packet are
12c266ea 22961determined by the @value{GDBN} internal macros
b8ff78ce
JB
22962@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{REGISTER_NAME} macros. The
22963specification of several standard @samp{g} packets is specified below.
22964@item E @var{NN}
ee2d5c50
AC
22965for an error.
22966@end table
c906108c 22967
b8ff78ce
JB
22968@item G @var{XX@dots{}}
22969@cindex @samp{G} packet
22970Write general registers. @xref{read registers packet}, for a
22971description of the @var{XX@dots{}} data.
ee2d5c50
AC
22972
22973Reply:
22974@table @samp
22975@item OK
22976for success
b8ff78ce 22977@item E @var{NN}
ee2d5c50
AC
22978for an error
22979@end table
22980
b8ff78ce
JB
22981@item H @var{c} @var{t}
22982@cindex @samp{H} packet
8e04817f 22983Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22984@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22985should be @samp{c} for step and continue operations, @samp{g} for other
b8ff78ce
JB
22986operations. The thread designator @var{t} may be @samp{-1}, meaning all
22987the threads, a thread number, or @samp{0} which means pick any thread.
ee2d5c50
AC
22988
22989Reply:
22990@table @samp
22991@item OK
22992for success
b8ff78ce 22993@item E @var{NN}
ee2d5c50
AC
22994for an error
22995@end table
c906108c 22996
8e04817f
AC
22997@c FIXME: JTC:
22998@c 'H': How restrictive (or permissive) is the thread model. If a
22999@c thread is selected and stopped, are other threads allowed
23000@c to continue to execute? As I mentioned above, I think the
23001@c semantics of each command when a thread is selected must be
23002@c described. For example:
23003@c
23004@c 'g': If the stub supports threads and a specific thread is
23005@c selected, returns the register block from that thread;
23006@c otherwise returns current registers.
23007@c
23008@c 'G' If the stub supports threads and a specific thread is
23009@c selected, sets the registers of the register block of
23010@c that thread; otherwise sets current registers.
c906108c 23011
b8ff78ce 23012@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 23013@anchor{cycle step packet}
b8ff78ce
JB
23014@cindex @samp{i} packet
23015Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
23016present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
23017step starting at that address.
c906108c 23018
b8ff78ce
JB
23019@item I
23020@cindex @samp{I} packet
23021Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
23022step packet}.
ee2d5c50 23023
b8ff78ce
JB
23024@item k
23025@cindex @samp{k} packet
23026Kill request.
c906108c 23027
ac282366 23028FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
23029thread context has been selected (i.e.@: does 'k' kill only that
23030thread?)}.
c906108c 23031
b8ff78ce
JB
23032@item m @var{addr},@var{length}
23033@cindex @samp{m} packet
8e04817f 23034Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
23035Note that @var{addr} may not be aligned to any particular boundary.
23036
23037The stub need not use any particular size or alignment when gathering
23038data from memory for the response; even if @var{addr} is word-aligned
23039and @var{length} is a multiple of the word size, the stub is free to
23040use byte accesses, or not. For this reason, this packet may not be
23041suitable for accessing memory-mapped I/O devices.
c43c5473
JB
23042@cindex alignment of remote memory accesses
23043@cindex size of remote memory accesses
23044@cindex memory, alignment and size of remote accesses
c906108c 23045
ee2d5c50
AC
23046Reply:
23047@table @samp
23048@item @var{XX@dots{}}
599b237a 23049Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
23050number. The reply may contain fewer bytes than requested if the
23051server was able to read only part of the region of memory.
23052@item E @var{NN}
ee2d5c50
AC
23053@var{NN} is errno
23054@end table
23055
b8ff78ce
JB
23056@item M @var{addr},@var{length}:@var{XX@dots{}}
23057@cindex @samp{M} packet
8e04817f 23058Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 23059@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 23060hexadecimal number.
ee2d5c50
AC
23061
23062Reply:
23063@table @samp
23064@item OK
23065for success
b8ff78ce 23066@item E @var{NN}
8e04817f
AC
23067for an error (this includes the case where only part of the data was
23068written).
ee2d5c50 23069@end table
c906108c 23070
b8ff78ce
JB
23071@item p @var{n}
23072@cindex @samp{p} packet
23073Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
23074@xref{read registers packet}, for a description of how the returned
23075register value is encoded.
ee2d5c50
AC
23076
23077Reply:
23078@table @samp
2e868123
AC
23079@item @var{XX@dots{}}
23080the register's value
b8ff78ce 23081@item E @var{NN}
2e868123
AC
23082for an error
23083@item
23084Indicating an unrecognized @var{query}.
ee2d5c50
AC
23085@end table
23086
b8ff78ce 23087@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 23088@anchor{write register packet}
b8ff78ce
JB
23089@cindex @samp{P} packet
23090Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 23091number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 23092digits for each byte in the register (target byte order).
c906108c 23093
ee2d5c50
AC
23094Reply:
23095@table @samp
23096@item OK
23097for success
b8ff78ce 23098@item E @var{NN}
ee2d5c50
AC
23099for an error
23100@end table
23101
5f3bebba
JB
23102@item q @var{name} @var{params}@dots{}
23103@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 23104@cindex @samp{q} packet
b8ff78ce 23105@cindex @samp{Q} packet
5f3bebba
JB
23106General query (@samp{q}) and set (@samp{Q}). These packets are
23107described fully in @ref{General Query Packets}.
c906108c 23108
b8ff78ce
JB
23109@item r
23110@cindex @samp{r} packet
8e04817f 23111Reset the entire system.
c906108c 23112
b8ff78ce 23113Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 23114
b8ff78ce
JB
23115@item R @var{XX}
23116@cindex @samp{R} packet
8e04817f
AC
23117Restart the program being debugged. @var{XX}, while needed, is ignored.
23118This packet is only available in extended mode.
ee2d5c50 23119
8e04817f 23120The @samp{R} packet has no reply.
ee2d5c50 23121
4f553f88 23122@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
23123@cindex @samp{s} packet
23124Single step. @var{addr} is the address at which to resume. If
23125@var{addr} is omitted, resume at same address.
c906108c 23126
ee2d5c50
AC
23127Reply:
23128@xref{Stop Reply Packets}, for the reply specifications.
23129
4f553f88 23130@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 23131@anchor{step with signal packet}
b8ff78ce
JB
23132@cindex @samp{S} packet
23133Step with signal. This is analogous to the @samp{C} packet, but
23134requests a single-step, rather than a normal resumption of execution.
c906108c 23135
ee2d5c50
AC
23136Reply:
23137@xref{Stop Reply Packets}, for the reply specifications.
23138
b8ff78ce
JB
23139@item t @var{addr}:@var{PP},@var{MM}
23140@cindex @samp{t} packet
8e04817f 23141Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
23142@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
23143@var{addr} must be at least 3 digits.
c906108c 23144
b8ff78ce
JB
23145@item T @var{XX}
23146@cindex @samp{T} packet
ee2d5c50 23147Find out if the thread XX is alive.
c906108c 23148
ee2d5c50
AC
23149Reply:
23150@table @samp
23151@item OK
23152thread is still alive
b8ff78ce 23153@item E @var{NN}
ee2d5c50
AC
23154thread is dead
23155@end table
23156
b8ff78ce
JB
23157@item v
23158Packets starting with @samp{v} are identified by a multi-letter name,
23159up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 23160
b8ff78ce
JB
23161@item vCont@r{[};@var{action}@r{[}:@var{tid}@r{]]}@dots{}
23162@cindex @samp{vCont} packet
23163Resume the inferior, specifying different actions for each thread.
86d30acc
DJ
23164If an action is specified with no @var{tid}, then it is applied to any
23165threads that don't have a specific action specified; if no default action is
23166specified then other threads should remain stopped. Specifying multiple
23167default actions is an error; specifying no actions is also an error.
23168Thread IDs are specified in hexadecimal. Currently supported actions are:
23169
b8ff78ce 23170@table @samp
86d30acc
DJ
23171@item c
23172Continue.
b8ff78ce 23173@item C @var{sig}
86d30acc
DJ
23174Continue with signal @var{sig}. @var{sig} should be two hex digits.
23175@item s
23176Step.
b8ff78ce 23177@item S @var{sig}
86d30acc
DJ
23178Step with signal @var{sig}. @var{sig} should be two hex digits.
23179@end table
23180
23181The optional @var{addr} argument normally associated with these packets is
b8ff78ce 23182not supported in @samp{vCont}.
86d30acc
DJ
23183
23184Reply:
23185@xref{Stop Reply Packets}, for the reply specifications.
23186
b8ff78ce
JB
23187@item vCont?
23188@cindex @samp{vCont?} packet
23189Request a list of actions supporetd by the @samp{vCont} packet.
86d30acc
DJ
23190
23191Reply:
23192@table @samp
b8ff78ce
JB
23193@item vCont@r{[};@var{action}@dots{}@r{]}
23194The @samp{vCont} packet is supported. Each @var{action} is a supported
23195command in the @samp{vCont} packet.
86d30acc 23196@item
b8ff78ce 23197The @samp{vCont} packet is not supported.
86d30acc 23198@end table
ee2d5c50 23199
68437a39
DJ
23200@item vFlashErase:@var{addr},@var{length}
23201@cindex @samp{vFlashErase} packet
23202Direct the stub to erase @var{length} bytes of flash starting at
23203@var{addr}. The region may enclose any number of flash blocks, but
23204its start and end must fall on block boundaries, as indicated by the
23205flash block size appearing in the memory map (@pxref{Memory map
23206format}). @value{GDBN} groups flash memory programming operations
23207together, and sends a @samp{vFlashDone} request after each group; the
23208stub is allowed to delay erase operation until the @samp{vFlashDone}
23209packet is received.
23210
23211Reply:
23212@table @samp
23213@item OK
23214for success
23215@item E @var{NN}
23216for an error
23217@end table
23218
23219@item vFlashWrite:@var{addr}:@var{XX@dots{}}
23220@cindex @samp{vFlashWrite} packet
23221Direct the stub to write data to flash address @var{addr}. The data
23222is passed in binary form using the same encoding as for the @samp{X}
23223packet (@pxref{Binary Data}). The memory ranges specified by
23224@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
23225not overlap, and must appear in order of increasing addresses
23226(although @samp{vFlashErase} packets for higher addresses may already
23227have been received; the ordering is guaranteed only between
23228@samp{vFlashWrite} packets). If a packet writes to an address that was
23229neither erased by a preceding @samp{vFlashErase} packet nor by some other
23230target-specific method, the results are unpredictable.
23231
23232
23233Reply:
23234@table @samp
23235@item OK
23236for success
23237@item E.memtype
23238for vFlashWrite addressing non-flash memory
23239@item E @var{NN}
23240for an error
23241@end table
23242
23243@item vFlashDone
23244@cindex @samp{vFlashDone} packet
23245Indicate to the stub that flash programming operation is finished.
23246The stub is permitted to delay or batch the effects of a group of
23247@samp{vFlashErase} and @samp{vFlashWrite} packets until a
23248@samp{vFlashDone} packet is received. The contents of the affected
23249regions of flash memory are unpredictable until the @samp{vFlashDone}
23250request is completed.
23251
b8ff78ce 23252@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 23253@anchor{X packet}
b8ff78ce
JB
23254@cindex @samp{X} packet
23255Write data to memory, where the data is transmitted in binary.
23256@var{addr} is address, @var{length} is number of bytes,
0876f84a 23257@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 23258
ee2d5c50
AC
23259Reply:
23260@table @samp
23261@item OK
23262for success
b8ff78ce 23263@item E @var{NN}
ee2d5c50
AC
23264for an error
23265@end table
23266
b8ff78ce
JB
23267@item z @var{type},@var{addr},@var{length}
23268@itemx Z @var{type},@var{addr},@var{length}
2f870471 23269@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
23270@cindex @samp{z} packet
23271@cindex @samp{Z} packets
23272Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
2f870471
AC
23273watchpoint starting at address @var{address} and covering the next
23274@var{length} bytes.
ee2d5c50 23275
2f870471
AC
23276Each breakpoint and watchpoint packet @var{type} is documented
23277separately.
23278
512217c7
AC
23279@emph{Implementation notes: A remote target shall return an empty string
23280for an unrecognized breakpoint or watchpoint packet @var{type}. A
23281remote target shall support either both or neither of a given
b8ff78ce 23282@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
23283avoid potential problems with duplicate packets, the operations should
23284be implemented in an idempotent way.}
23285
b8ff78ce
JB
23286@item z0,@var{addr},@var{length}
23287@itemx Z0,@var{addr},@var{length}
23288@cindex @samp{z0} packet
23289@cindex @samp{Z0} packet
23290Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
23291@var{addr} of size @var{length}.
2f870471
AC
23292
23293A memory breakpoint is implemented by replacing the instruction at
23294@var{addr} with a software breakpoint or trap instruction. The
b8ff78ce 23295@var{length} is used by targets that indicates the size of the
2f870471
AC
23296breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
23297@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 23298
2f870471
AC
23299@emph{Implementation note: It is possible for a target to copy or move
23300code that contains memory breakpoints (e.g., when implementing
23301overlays). The behavior of this packet, in the presence of such a
23302target, is not defined.}
c906108c 23303
ee2d5c50
AC
23304Reply:
23305@table @samp
2f870471
AC
23306@item OK
23307success
23308@item
23309not supported
b8ff78ce 23310@item E @var{NN}
ee2d5c50 23311for an error
2f870471
AC
23312@end table
23313
b8ff78ce
JB
23314@item z1,@var{addr},@var{length}
23315@itemx Z1,@var{addr},@var{length}
23316@cindex @samp{z1} packet
23317@cindex @samp{Z1} packet
23318Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
23319address @var{addr} of size @var{length}.
2f870471
AC
23320
23321A hardware breakpoint is implemented using a mechanism that is not
23322dependant on being able to modify the target's memory.
23323
23324@emph{Implementation note: A hardware breakpoint is not affected by code
23325movement.}
23326
23327Reply:
23328@table @samp
ee2d5c50 23329@item OK
2f870471
AC
23330success
23331@item
23332not supported
b8ff78ce 23333@item E @var{NN}
2f870471
AC
23334for an error
23335@end table
23336
b8ff78ce
JB
23337@item z2,@var{addr},@var{length}
23338@itemx Z2,@var{addr},@var{length}
23339@cindex @samp{z2} packet
23340@cindex @samp{Z2} packet
23341Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
2f870471
AC
23342
23343Reply:
23344@table @samp
23345@item OK
23346success
23347@item
23348not supported
b8ff78ce 23349@item E @var{NN}
2f870471
AC
23350for an error
23351@end table
23352
b8ff78ce
JB
23353@item z3,@var{addr},@var{length}
23354@itemx Z3,@var{addr},@var{length}
23355@cindex @samp{z3} packet
23356@cindex @samp{Z3} packet
23357Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
2f870471
AC
23358
23359Reply:
23360@table @samp
23361@item OK
23362success
23363@item
23364not supported
b8ff78ce 23365@item E @var{NN}
2f870471
AC
23366for an error
23367@end table
23368
b8ff78ce
JB
23369@item z4,@var{addr},@var{length}
23370@itemx Z4,@var{addr},@var{length}
23371@cindex @samp{z4} packet
23372@cindex @samp{Z4} packet
23373Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
2f870471
AC
23374
23375Reply:
23376@table @samp
23377@item OK
23378success
23379@item
23380not supported
b8ff78ce 23381@item E @var{NN}
2f870471 23382for an error
ee2d5c50
AC
23383@end table
23384
23385@end table
c906108c 23386
ee2d5c50
AC
23387@node Stop Reply Packets
23388@section Stop Reply Packets
23389@cindex stop reply packets
c906108c 23390
8e04817f
AC
23391The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
23392receive any of the below as a reply. In the case of the @samp{C},
23393@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
b8ff78ce
JB
23394when the target halts. In the below the exact meaning of @dfn{signal
23395number} is poorly defined. In general one of the UNIX signal
23396numbering conventions is used.
c906108c 23397
b8ff78ce
JB
23398As in the description of request packets, we include spaces in the
23399reply templates for clarity; these are not part of the reply packet's
23400syntax. No @value{GDBN} stop reply packet uses spaces to separate its
23401components.
c906108c 23402
b8ff78ce 23403@table @samp
ee2d5c50 23404
b8ff78ce 23405@item S @var{AA}
599b237a 23406The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
23407number). This is equivalent to a @samp{T} response with no
23408@var{n}:@var{r} pairs.
c906108c 23409
b8ff78ce
JB
23410@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
23411@cindex @samp{T} packet reply
599b237a 23412The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
23413number). This is equivalent to an @samp{S} response, except that the
23414@samp{@var{n}:@var{r}} pairs can carry values of important registers
23415and other information directly in the stop reply packet, reducing
23416round-trip latency. Single-step and breakpoint traps are reported
23417this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
b8ff78ce
JB
23418@enumerate
23419@item
599b237a 23420If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
23421corresponding @var{r} gives that register's value. @var{r} is a
23422series of bytes in target byte order, with each byte given by a
23423two-digit hex number.
23424@item
23425If @var{n} is @samp{thread}, then @var{r} is the thread process ID, in
23426hex.
23427@item
23428If @var{n} is @samp{watch}, @samp{rwatch}, or @samp{awatch}, then the
23429packet indicates a watchpoint hit, and @var{r} is the data address, in
23430hex.
23431@item
23432Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
23433and go on to the next; this allows us to extend the protocol in the
23434future.
23435@end enumerate
ee2d5c50 23436
b8ff78ce 23437@item W @var{AA}
8e04817f 23438The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
23439applicable to certain targets.
23440
b8ff78ce 23441@item X @var{AA}
8e04817f 23442The process terminated with signal @var{AA}.
c906108c 23443
b8ff78ce
JB
23444@item O @var{XX}@dots{}
23445@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
23446written as the program's console output. This can happen at any time
23447while the program is running and the debugger should continue to wait
23448for @samp{W}, @samp{T}, etc.
0ce1b118 23449
b8ff78ce 23450@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
23451@var{call-id} is the identifier which says which host system call should
23452be called. This is just the name of the function. Translation into the
23453correct system call is only applicable as it's defined in @value{GDBN}.
23454@xref{File-I/O remote protocol extension}, for a list of implemented
23455system calls.
23456
b8ff78ce
JB
23457@samp{@var{parameter}@dots{}} is a list of parameters as defined for
23458this very system call.
0ce1b118 23459
b8ff78ce
JB
23460The target replies with this packet when it expects @value{GDBN} to
23461call a host system call on behalf of the target. @value{GDBN} replies
23462with an appropriate @samp{F} packet and keeps up waiting for the next
23463reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
23464or @samp{s} action is expected to be continued. @xref{File-I/O remote
23465protocol extension}, for more details.
0ce1b118 23466
ee2d5c50
AC
23467@end table
23468
23469@node General Query Packets
23470@section General Query Packets
9c16f35a 23471@cindex remote query requests
c906108c 23472
5f3bebba
JB
23473Packets starting with @samp{q} are @dfn{general query packets};
23474packets starting with @samp{Q} are @dfn{general set packets}. General
23475query and set packets are a semi-unified form for retrieving and
23476sending information to and from the stub.
23477
23478The initial letter of a query or set packet is followed by a name
23479indicating what sort of thing the packet applies to. For example,
23480@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
23481definitions with the stub. These packet names follow some
23482conventions:
23483
23484@itemize @bullet
23485@item
23486The name must not contain commas, colons or semicolons.
23487@item
23488Most @value{GDBN} query and set packets have a leading upper case
23489letter.
23490@item
23491The names of custom vendor packets should use a company prefix, in
23492lower case, followed by a period. For example, packets designed at
23493the Acme Corporation might begin with @samp{qacme.foo} (for querying
23494foos) or @samp{Qacme.bar} (for setting bars).
23495@end itemize
23496
aa56d27a
JB
23497The name of a query or set packet should be separated from any
23498parameters by a @samp{:}; the parameters themselves should be
23499separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
23500full packet name, and check for a separator or the end of the packet,
23501in case two packet names share a common prefix. New packets should not begin
23502with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
23503packets predate these conventions, and have arguments without any terminator
23504for the packet name; we suspect they are in widespread use in places that
23505are difficult to upgrade. The @samp{qC} packet has no arguments, but some
23506existing stubs (e.g.@: RedBoot) are known to not check for the end of the
23507packet.}.
c906108c 23508
b8ff78ce
JB
23509Like the descriptions of the other packets, each description here
23510has a template showing the packet's overall syntax, followed by an
23511explanation of the packet's meaning. We include spaces in some of the
23512templates for clarity; these are not part of the packet's syntax. No
23513@value{GDBN} packet uses spaces to separate its components.
23514
5f3bebba
JB
23515Here are the currently defined query and set packets:
23516
b8ff78ce 23517@table @samp
c906108c 23518
b8ff78ce 23519@item qC
9c16f35a 23520@cindex current thread, remote request
b8ff78ce 23521@cindex @samp{qC} packet
ee2d5c50
AC
23522Return the current thread id.
23523
23524Reply:
23525@table @samp
b8ff78ce 23526@item QC @var{pid}
599b237a 23527Where @var{pid} is an unsigned hexadecimal process id.
b8ff78ce 23528@item @r{(anything else)}
ee2d5c50
AC
23529Any other reply implies the old pid.
23530@end table
23531
b8ff78ce 23532@item qCRC:@var{addr},@var{length}
ff2587ec 23533@cindex CRC of memory block, remote request
b8ff78ce
JB
23534@cindex @samp{qCRC} packet
23535Compute the CRC checksum of a block of memory.
ff2587ec
WZ
23536Reply:
23537@table @samp
b8ff78ce 23538@item E @var{NN}
ff2587ec 23539An error (such as memory fault)
b8ff78ce
JB
23540@item C @var{crc32}
23541The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
23542@end table
23543
b8ff78ce
JB
23544@item qfThreadInfo
23545@itemx qsThreadInfo
9c16f35a 23546@cindex list active threads, remote request
b8ff78ce
JB
23547@cindex @samp{qfThreadInfo} packet
23548@cindex @samp{qsThreadInfo} packet
23549Obtain a list of all active thread ids from the target (OS). Since there
8e04817f
AC
23550may be too many active threads to fit into one reply packet, this query
23551works iteratively: it may require more than one query/reply sequence to
23552obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
23553be the @samp{qfThreadInfo} query; subsequent queries in the
23554sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 23555
b8ff78ce 23556NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
23557
23558Reply:
23559@table @samp
b8ff78ce 23560@item m @var{id}
ee2d5c50 23561A single thread id
b8ff78ce 23562@item m @var{id},@var{id}@dots{}
ee2d5c50 23563a comma-separated list of thread ids
b8ff78ce
JB
23564@item l
23565(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
23566@end table
23567
23568In response to each query, the target will reply with a list of one or
e1aac25b
JB
23569more thread ids, in big-endian unsigned hex, separated by commas.
23570@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce
JB
23571ids (using the @samp{qs} form of the query), until the target responds
23572with @samp{l} (lower-case el, for @dfn{last}).
c906108c 23573
b8ff78ce 23574@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 23575@cindex get thread-local storage address, remote request
b8ff78ce 23576@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
23577Fetch the address associated with thread local storage specified
23578by @var{thread-id}, @var{offset}, and @var{lm}.
23579
23580@var{thread-id} is the (big endian, hex encoded) thread id associated with the
23581thread for which to fetch the TLS address.
23582
23583@var{offset} is the (big endian, hex encoded) offset associated with the
23584thread local variable. (This offset is obtained from the debug
23585information associated with the variable.)
23586
23587@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
23588the load module associated with the thread local storage. For example,
23589a @sc{gnu}/Linux system will pass the link map address of the shared
23590object associated with the thread local storage under consideration.
23591Other operating environments may choose to represent the load module
23592differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
23593
23594Reply:
b8ff78ce
JB
23595@table @samp
23596@item @var{XX}@dots{}
ff2587ec
WZ
23597Hex encoded (big endian) bytes representing the address of the thread
23598local storage requested.
23599
b8ff78ce
JB
23600@item E @var{nn}
23601An error occurred. @var{nn} are hex digits.
ff2587ec 23602
b8ff78ce
JB
23603@item
23604An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
23605@end table
23606
ff2587ec
WZ
23607Use of this request packet is controlled by the @code{set remote
23608get-thread-local-storage-address} command (@pxref{Remote
23609configuration, set remote get-thread-local-storage-address}).
23610
b8ff78ce 23611@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
23612Obtain thread information from RTOS. Where: @var{startflag} (one hex
23613digit) is one to indicate the first query and zero to indicate a
23614subsequent query; @var{threadcount} (two hex digits) is the maximum
23615number of threads the response packet can contain; and @var{nextthread}
23616(eight hex digits), for subsequent queries (@var{startflag} is zero), is
23617returned in the response as @var{argthread}.
ee2d5c50 23618
b8ff78ce 23619Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
23620
23621Reply:
23622@table @samp
b8ff78ce 23623@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
23624Where: @var{count} (two hex digits) is the number of threads being
23625returned; @var{done} (one hex digit) is zero to indicate more threads
23626and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 23627digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 23628is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 23629digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 23630@end table
c906108c 23631
b8ff78ce 23632@item qOffsets
9c16f35a 23633@cindex section offsets, remote request
b8ff78ce 23634@cindex @samp{qOffsets} packet
8e04817f
AC
23635Get section offsets that the target used when re-locating the downloaded
23636image. @emph{Note: while a @code{Bss} offset is included in the
23637response, @value{GDBN} ignores this and instead applies the @code{Data}
23638offset to the @code{Bss} section.}
c906108c 23639
ee2d5c50
AC
23640Reply:
23641@table @samp
b8ff78ce 23642@item Text=@var{xxx};Data=@var{yyy};Bss=@var{zzz}
ee2d5c50
AC
23643@end table
23644
b8ff78ce 23645@item qP @var{mode} @var{threadid}
9c16f35a 23646@cindex thread information, remote request
b8ff78ce 23647@cindex @samp{qP} packet
8e04817f
AC
23648Returns information on @var{threadid}. Where: @var{mode} is a hex
23649encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50 23650
aa56d27a
JB
23651Don't use this packet; use the @samp{qThreadExtraInfo} query instead
23652(see below).
23653
b8ff78ce 23654Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 23655
b8ff78ce 23656@item qRcmd,@var{command}
ff2587ec 23657@cindex execute remote command, remote request
b8ff78ce 23658@cindex @samp{qRcmd} packet
ff2587ec 23659@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
23660execution. Invalid commands should be reported using the output
23661string. Before the final result packet, the target may also respond
23662with a number of intermediate @samp{O@var{output}} console output
23663packets. @emph{Implementors should note that providing access to a
23664stubs's interpreter may have security implications}.
fa93a9d8 23665
ff2587ec
WZ
23666Reply:
23667@table @samp
23668@item OK
23669A command response with no output.
23670@item @var{OUTPUT}
23671A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 23672@item E @var{NN}
ff2587ec 23673Indicate a badly formed request.
b8ff78ce
JB
23674@item
23675An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 23676@end table
fa93a9d8 23677
aa56d27a
JB
23678(Note that the @code{qRcmd} packet's name is separated from the
23679command by a @samp{,}, not a @samp{:}, contrary to the naming
23680conventions above. Please don't use this packet as a model for new
23681packets.)
23682
be2a5f71
DJ
23683@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
23684@cindex supported packets, remote query
23685@cindex features of the remote protocol
23686@cindex @samp{qSupported} packet
0876f84a 23687@anchor{qSupported}
be2a5f71
DJ
23688Tell the remote stub about features supported by @value{GDBN}, and
23689query the stub for features it supports. This packet allows
23690@value{GDBN} and the remote stub to take advantage of each others'
23691features. @samp{qSupported} also consolidates multiple feature probes
23692at startup, to improve @value{GDBN} performance---a single larger
23693packet performs better than multiple smaller probe packets on
23694high-latency links. Some features may enable behavior which must not
23695be on by default, e.g.@: because it would confuse older clients or
23696stubs. Other features may describe packets which could be
23697automatically probed for, but are not. These features must be
23698reported before @value{GDBN} will use them. This ``default
23699unsupported'' behavior is not appropriate for all packets, but it
23700helps to keep the initial connection time under control with new
23701versions of @value{GDBN} which support increasing numbers of packets.
23702
23703Reply:
23704@table @samp
23705@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
23706The stub supports or does not support each returned @var{stubfeature},
23707depending on the form of each @var{stubfeature} (see below for the
23708possible forms).
23709@item
23710An empty reply indicates that @samp{qSupported} is not recognized,
23711or that no features needed to be reported to @value{GDBN}.
23712@end table
23713
23714The allowed forms for each feature (either a @var{gdbfeature} in the
23715@samp{qSupported} packet, or a @var{stubfeature} in the response)
23716are:
23717
23718@table @samp
23719@item @var{name}=@var{value}
23720The remote protocol feature @var{name} is supported, and associated
23721with the specified @var{value}. The format of @var{value} depends
23722on the feature, but it must not include a semicolon.
23723@item @var{name}+
23724The remote protocol feature @var{name} is supported, and does not
23725need an associated value.
23726@item @var{name}-
23727The remote protocol feature @var{name} is not supported.
23728@item @var{name}?
23729The remote protocol feature @var{name} may be supported, and
23730@value{GDBN} should auto-detect support in some other way when it is
23731needed. This form will not be used for @var{gdbfeature} notifications,
23732but may be used for @var{stubfeature} responses.
23733@end table
23734
23735Whenever the stub receives a @samp{qSupported} request, the
23736supplied set of @value{GDBN} features should override any previous
23737request. This allows @value{GDBN} to put the stub in a known
23738state, even if the stub had previously been communicating with
23739a different version of @value{GDBN}.
23740
23741No values of @var{gdbfeature} (for the packet sent by @value{GDBN})
23742are defined yet. Stubs should ignore any unknown values for
23743@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
23744packet supports receiving packets of unlimited length (earlier
23745versions of @value{GDBN} may reject overly long responses). Values
23746for @var{gdbfeature} may be defined in the future to let the stub take
23747advantage of new features in @value{GDBN}, e.g.@: incompatible
23748improvements in the remote protocol---support for unlimited length
23749responses would be a @var{gdbfeature} example, if it were not implied by
23750the @samp{qSupported} query. The stub's reply should be independent
23751of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
23752describes all the features it supports, and then the stub replies with
23753all the features it supports.
23754
23755Similarly, @value{GDBN} will silently ignore unrecognized stub feature
23756responses, as long as each response uses one of the standard forms.
23757
23758Some features are flags. A stub which supports a flag feature
23759should respond with a @samp{+} form response. Other features
23760require values, and the stub should respond with an @samp{=}
23761form response.
23762
23763Each feature has a default value, which @value{GDBN} will use if
23764@samp{qSupported} is not available or if the feature is not mentioned
23765in the @samp{qSupported} response. The default values are fixed; a
23766stub is free to omit any feature responses that match the defaults.
23767
23768Not all features can be probed, but for those which can, the probing
23769mechanism is useful: in some cases, a stub's internal
23770architecture may not allow the protocol layer to know some information
23771about the underlying target in advance. This is especially common in
23772stubs which may be configured for multiple targets.
23773
23774These are the currently defined stub features and their properties:
23775
23776@multitable @columnfractions 0.25 0.2 0.2 0.2
23777@c NOTE: The first row should be @headitem, but we do not yet require
23778@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 23779@item Feature Name
be2a5f71
DJ
23780@tab Value Required
23781@tab Default
23782@tab Probe Allowed
23783
23784@item @samp{PacketSize}
23785@tab Yes
23786@tab @samp{-}
23787@tab No
23788
0876f84a
DJ
23789@item @samp{qXfer:auxv:read}
23790@tab No
23791@tab @samp{-}
23792@tab Yes
23793
68437a39
DJ
23794@item @samp{qXfer:memory-map:read}
23795@tab No
23796@tab @samp{-}
23797@tab Yes
23798
be2a5f71
DJ
23799@end multitable
23800
23801These are the currently defined stub features, in more detail:
23802
23803@table @samp
23804@cindex packet size, remote protocol
23805@item PacketSize=@var{bytes}
23806The remote stub can accept packets up to at least @var{bytes} in
23807length. @value{GDBN} will send packets up to this size for bulk
23808transfers, and will never send larger packets. This is a limit on the
23809data characters in the packet, including the frame and checksum.
23810There is no trailing NUL byte in a remote protocol packet; if the stub
23811stores packets in a NUL-terminated format, it should allow an extra
23812byte in its buffer for the NUL. If this stub feature is not supported,
23813@value{GDBN} guesses based on the size of the @samp{g} packet response.
23814
0876f84a
DJ
23815@item qXfer:auxv:read
23816The remote stub understands the @samp{qXfer:auxv:read} packet
23817(@pxref{qXfer auxiliary vector read}).
23818
be2a5f71
DJ
23819@end table
23820
b8ff78ce 23821@item qSymbol::
ff2587ec 23822@cindex symbol lookup, remote request
b8ff78ce 23823@cindex @samp{qSymbol} packet
ff2587ec
WZ
23824Notify the target that @value{GDBN} is prepared to serve symbol lookup
23825requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
23826
23827Reply:
ff2587ec 23828@table @samp
b8ff78ce 23829@item OK
ff2587ec 23830The target does not need to look up any (more) symbols.
b8ff78ce 23831@item qSymbol:@var{sym_name}
ff2587ec
WZ
23832The target requests the value of symbol @var{sym_name} (hex encoded).
23833@value{GDBN} may provide the value by using the
b8ff78ce
JB
23834@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
23835below.
ff2587ec 23836@end table
83761cbd 23837
b8ff78ce 23838@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
23839Set the value of @var{sym_name} to @var{sym_value}.
23840
23841@var{sym_name} (hex encoded) is the name of a symbol whose value the
23842target has previously requested.
23843
23844@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
23845@value{GDBN} cannot supply a value for @var{sym_name}, then this field
23846will be empty.
23847
23848Reply:
23849@table @samp
b8ff78ce 23850@item OK
ff2587ec 23851The target does not need to look up any (more) symbols.
b8ff78ce 23852@item qSymbol:@var{sym_name}
ff2587ec
WZ
23853The target requests the value of a new symbol @var{sym_name} (hex
23854encoded). @value{GDBN} will continue to supply the values of symbols
23855(if available), until the target ceases to request them.
fa93a9d8 23856@end table
0abb7bc7 23857
9d29849a
JB
23858@item QTDP
23859@itemx QTFrame
23860@xref{Tracepoint Packets}.
23861
b8ff78ce 23862@item qThreadExtraInfo,@var{id}
ff2587ec 23863@cindex thread attributes info, remote request
b8ff78ce
JB
23864@cindex @samp{qThreadExtraInfo} packet
23865Obtain a printable string description of a thread's attributes from
23866the target OS. @var{id} is a thread-id in big-endian hex. This
23867string may contain anything that the target OS thinks is interesting
23868for @value{GDBN} to tell the user about the thread. The string is
23869displayed in @value{GDBN}'s @code{info threads} display. Some
23870examples of possible thread extra info strings are @samp{Runnable}, or
23871@samp{Blocked on Mutex}.
ff2587ec
WZ
23872
23873Reply:
23874@table @samp
b8ff78ce
JB
23875@item @var{XX}@dots{}
23876Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
23877comprising the printable string containing the extra information about
23878the thread's attributes.
ff2587ec 23879@end table
814e32d7 23880
aa56d27a
JB
23881(Note that the @code{qThreadExtraInfo} packet's name is separated from
23882the command by a @samp{,}, not a @samp{:}, contrary to the naming
23883conventions above. Please don't use this packet as a model for new
23884packets.)
23885
9d29849a
JB
23886@item QTStart
23887@itemx QTStop
23888@itemx QTinit
23889@itemx QTro
23890@itemx qTStatus
23891@xref{Tracepoint Packets}.
23892
0876f84a
DJ
23893@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
23894@cindex read special object, remote request
23895@cindex @samp{qXfer} packet
68437a39 23896@anchor{qXfer read}
0876f84a
DJ
23897Read uninterpreted bytes from the target's special data area
23898identified by the keyword @var{object}. Request @var{length} bytes
23899starting at @var{offset} bytes into the data. The content and
23900encoding of @var{annex} is specific to the object; it can supply
23901additional details about what data to access.
23902
23903Here are the specific requests of this form defined so far. All
23904@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
23905formats, listed below.
23906
23907@table @samp
23908@item qXfer:auxv:read::@var{offset},@var{length}
23909@anchor{qXfer auxiliary vector read}
23910Access the target's @dfn{auxiliary vector}. @xref{OS Information,
23911auxiliary vector}, and @ref{Remote configuration,
23912read-aux-vector-packet}. Note @var{annex} must be empty.
23913
23914This packet is not probed by default; the remote stub must request it,
23915by suppling an appropriate @samp{qSupported} response (@pxref{qSupported}).
23916@end table
23917
68437a39
DJ
23918@table @samp
23919@item qXfer:memory-map:read::@var{offset},@var{length}
23920@anchor{qXfer memory map read}
23921Access the target's @dfn{memory-map}. @xref{Memory map format}. The
23922annex part of the generic @samp{qXfer} packet must be empty
23923(@pxref{qXfer read}).
23924
23925This packet is not probed by default; the remote stub must request it,
23926by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
23927@end table
23928
0876f84a
DJ
23929Reply:
23930@table @samp
23931@item m @var{data}
23932Data @var{data} (@pxref{Binary Data}) has been read from the
23933target. There may be more data at a higher address (although
23934it is permitted to return @samp{m} even for the last valid
23935block of data, as long as at least one byte of data was read).
23936@var{data} may have fewer bytes than the @var{length} in the
23937request.
23938
23939@item l @var{data}
23940Data @var{data} (@pxref{Binary Data}) has been read from the target.
23941There is no more data to be read. @var{data} may have fewer bytes
23942than the @var{length} in the request.
23943
23944@item l
23945The @var{offset} in the request is at the end of the data.
23946There is no more data to be read.
23947
23948@item E00
23949The request was malformed, or @var{annex} was invalid.
23950
23951@item E @var{nn}
23952The offset was invalid, or there was an error encountered reading the data.
23953@var{nn} is a hex-encoded @code{errno} value.
23954
23955@item
23956An empty reply indicates the @var{object} string was not recognized by
23957the stub, or that the object does not support reading.
23958@end table
23959
23960@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
23961@cindex write data into object, remote request
23962Write uninterpreted bytes into the target's special data area
23963identified by the keyword @var{object}, starting at @var{offset} bytes
23964into the data. @samp{@var{data}@dots{}} is the binary-encoded data
23965(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
23966is specific to the object; it can supply additional details about what data
23967to access.
23968
23969No requests of this form are presently in use. This specification
23970serves as a placeholder to document the common format that new
23971specific request specifications ought to use.
23972
23973Reply:
23974@table @samp
23975@item @var{nn}
23976@var{nn} (hex encoded) is the number of bytes written.
23977This may be fewer bytes than supplied in the request.
23978
23979@item E00
23980The request was malformed, or @var{annex} was invalid.
23981
23982@item E @var{nn}
23983The offset was invalid, or there was an error encountered writing the data.
23984@var{nn} is a hex-encoded @code{errno} value.
23985
23986@item
23987An empty reply indicates the @var{object} string was not
23988recognized by the stub, or that the object does not support writing.
23989@end table
23990
23991@item qXfer:@var{object}:@var{operation}:@dots{}
23992Requests of this form may be added in the future. When a stub does
23993not recognize the @var{object} keyword, or its support for
23994@var{object} does not recognize the @var{operation} keyword, the stub
23995must respond with an empty packet.
23996
ee2d5c50
AC
23997@end table
23998
23999@node Register Packet Format
24000@section Register Packet Format
eb12ee30 24001
b8ff78ce 24002The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
24003In the below, some thirty-two bit registers are transferred as
24004sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
24005to fill the space allocated. Register bytes are transferred in target
24006byte order. The two nibbles within a register byte are transferred
ee2d5c50 24007most-significant - least-significant.
eb12ee30 24008
ee2d5c50 24009@table @r
eb12ee30 24010
8e04817f 24011@item MIPS32
ee2d5c50 24012
599b237a 24013All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
2401432 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
24015registers; fsr; fir; fp.
eb12ee30 24016
8e04817f 24017@item MIPS64
ee2d5c50 24018
599b237a 24019All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
24020thirty-two bit registers such as @code{sr}). The ordering is the same
24021as @code{MIPS32}.
eb12ee30 24022
ee2d5c50
AC
24023@end table
24024
9d29849a
JB
24025@node Tracepoint Packets
24026@section Tracepoint Packets
24027@cindex tracepoint packets
24028@cindex packets, tracepoint
24029
24030Here we describe the packets @value{GDBN} uses to implement
24031tracepoints (@pxref{Tracepoints}).
24032
24033@table @samp
24034
24035@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
24036Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
24037is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
24038the tracepoint is disabled. @var{step} is the tracepoint's step
24039count, and @var{pass} is its pass count. If the trailing @samp{-} is
24040present, further @samp{QTDP} packets will follow to specify this
24041tracepoint's actions.
24042
24043Replies:
24044@table @samp
24045@item OK
24046The packet was understood and carried out.
24047@item
24048The packet was not recognized.
24049@end table
24050
24051@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
24052Define actions to be taken when a tracepoint is hit. @var{n} and
24053@var{addr} must be the same as in the initial @samp{QTDP} packet for
24054this tracepoint. This packet may only be sent immediately after
24055another @samp{QTDP} packet that ended with a @samp{-}. If the
24056trailing @samp{-} is present, further @samp{QTDP} packets will follow,
24057specifying more actions for this tracepoint.
24058
24059In the series of action packets for a given tracepoint, at most one
24060can have an @samp{S} before its first @var{action}. If such a packet
24061is sent, it and the following packets define ``while-stepping''
24062actions. Any prior packets define ordinary actions --- that is, those
24063taken when the tracepoint is first hit. If no action packet has an
24064@samp{S}, then all the packets in the series specify ordinary
24065tracepoint actions.
24066
24067The @samp{@var{action}@dots{}} portion of the packet is a series of
24068actions, concatenated without separators. Each action has one of the
24069following forms:
24070
24071@table @samp
24072
24073@item R @var{mask}
24074Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 24075a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
24076@var{i} should be collected. (The least significant bit is numbered
24077zero.) Note that @var{mask} may be any number of digits long; it may
24078not fit in a 32-bit word.
24079
24080@item M @var{basereg},@var{offset},@var{len}
24081Collect @var{len} bytes of memory starting at the address in register
24082number @var{basereg}, plus @var{offset}. If @var{basereg} is
24083@samp{-1}, then the range has a fixed address: @var{offset} is the
24084address of the lowest byte to collect. The @var{basereg},
599b237a 24085@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
24086values (the @samp{-1} value for @var{basereg} is a special case).
24087
24088@item X @var{len},@var{expr}
24089Evaluate @var{expr}, whose length is @var{len}, and collect memory as
24090it directs. @var{expr} is an agent expression, as described in
24091@ref{Agent Expressions}. Each byte of the expression is encoded as a
24092two-digit hex number in the packet; @var{len} is the number of bytes
24093in the expression (and thus one-half the number of hex digits in the
24094packet).
24095
24096@end table
24097
24098Any number of actions may be packed together in a single @samp{QTDP}
24099packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
24100length (400 bytes, for many stubs). There may be only one @samp{R}
24101action per tracepoint, and it must precede any @samp{M} or @samp{X}
24102actions. Any registers referred to by @samp{M} and @samp{X} actions
24103must be collected by a preceding @samp{R} action. (The
24104``while-stepping'' actions are treated as if they were attached to a
24105separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
24106
24107Replies:
24108@table @samp
24109@item OK
24110The packet was understood and carried out.
24111@item
24112The packet was not recognized.
24113@end table
24114
24115@item QTFrame:@var{n}
24116Select the @var{n}'th tracepoint frame from the buffer, and use the
24117register and memory contents recorded there to answer subsequent
24118request packets from @value{GDBN}.
24119
24120A successful reply from the stub indicates that the stub has found the
24121requested frame. The response is a series of parts, concatenated
24122without separators, describing the frame we selected. Each part has
24123one of the following forms:
24124
24125@table @samp
24126@item F @var{f}
24127The selected frame is number @var{n} in the trace frame buffer;
599b237a 24128@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
24129was no frame matching the criteria in the request packet.
24130
24131@item T @var{t}
24132The selected trace frame records a hit of tracepoint number @var{t};
599b237a 24133@var{t} is a hexadecimal number.
9d29849a
JB
24134
24135@end table
24136
24137@item QTFrame:pc:@var{addr}
24138Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24139currently selected frame whose PC is @var{addr};
599b237a 24140@var{addr} is a hexadecimal number.
9d29849a
JB
24141
24142@item QTFrame:tdp:@var{t}
24143Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24144currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 24145is a hexadecimal number.
9d29849a
JB
24146
24147@item QTFrame:range:@var{start}:@var{end}
24148Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24149currently selected frame whose PC is between @var{start} (inclusive)
599b237a 24150and @var{end} (exclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
24151numbers.
24152
24153@item QTFrame:outside:@var{start}:@var{end}
24154Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
24155frame @emph{outside} the given range of addresses.
24156
24157@item QTStart
24158Begin the tracepoint experiment. Begin collecting data from tracepoint
24159hits in the trace frame buffer.
24160
24161@item QTStop
24162End the tracepoint experiment. Stop collecting trace frames.
24163
24164@item QTinit
24165Clear the table of tracepoints, and empty the trace frame buffer.
24166
24167@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
24168Establish the given ranges of memory as ``transparent''. The stub
24169will answer requests for these ranges from memory's current contents,
24170if they were not collected as part of the tracepoint hit.
24171
24172@value{GDBN} uses this to mark read-only regions of memory, like those
24173containing program code. Since these areas never change, they should
24174still have the same contents they did when the tracepoint was hit, so
24175there's no reason for the stub to refuse to provide their contents.
24176
24177@item qTStatus
24178Ask the stub if there is a trace experiment running right now.
24179
24180Replies:
24181@table @samp
24182@item T0
24183There is no trace experiment running.
24184@item T1
24185There is a trace experiment running.
24186@end table
24187
24188@end table
24189
24190
9a6253be
KB
24191@node Interrupts
24192@section Interrupts
24193@cindex interrupts (remote protocol)
24194
24195When a program on the remote target is running, @value{GDBN} may
24196attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
24197control of which is specified via @value{GDBN}'s @samp{remotebreak}
24198setting (@pxref{set remotebreak}).
24199
24200The precise meaning of @code{BREAK} is defined by the transport
24201mechanism and may, in fact, be undefined. @value{GDBN} does
24202not currently define a @code{BREAK} mechanism for any of the network
24203interfaces.
24204
24205@samp{Ctrl-C}, on the other hand, is defined and implemented for all
24206transport mechanisms. It is represented by sending the single byte
24207@code{0x03} without any of the usual packet overhead described in
24208the Overview section (@pxref{Overview}). When a @code{0x03} byte is
24209transmitted as part of a packet, it is considered to be packet data
24210and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 24211(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
24212@code{0x03} as part of its packet.
24213
24214Stubs are not required to recognize these interrupt mechanisms and the
24215precise meaning associated with receipt of the interrupt is
24216implementation defined. If the stub is successful at interrupting the
24217running program, it is expected that it will send one of the Stop
24218Reply Packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
24219of successfully stopping the program. Interrupts received while the
24220program is stopped will be discarded.
24221
ee2d5c50
AC
24222@node Examples
24223@section Examples
eb12ee30 24224
8e04817f
AC
24225Example sequence of a target being re-started. Notice how the restart
24226does not get any direct output:
eb12ee30 24227
474c8240 24228@smallexample
d2c6833e
AC
24229-> @code{R00}
24230<- @code{+}
8e04817f 24231@emph{target restarts}
d2c6833e 24232-> @code{?}
8e04817f 24233<- @code{+}
d2c6833e
AC
24234<- @code{T001:1234123412341234}
24235-> @code{+}
474c8240 24236@end smallexample
eb12ee30 24237
8e04817f 24238Example sequence of a target being stepped by a single instruction:
eb12ee30 24239
474c8240 24240@smallexample
d2c6833e 24241-> @code{G1445@dots{}}
8e04817f 24242<- @code{+}
d2c6833e
AC
24243-> @code{s}
24244<- @code{+}
24245@emph{time passes}
24246<- @code{T001:1234123412341234}
8e04817f 24247-> @code{+}
d2c6833e 24248-> @code{g}
8e04817f 24249<- @code{+}
d2c6833e
AC
24250<- @code{1455@dots{}}
24251-> @code{+}
474c8240 24252@end smallexample
eb12ee30 24253
0ce1b118
CV
24254@node File-I/O remote protocol extension
24255@section File-I/O remote protocol extension
24256@cindex File-I/O remote protocol extension
24257
24258@menu
24259* File-I/O Overview::
24260* Protocol basics::
1d8b2f28
JB
24261* The F request packet::
24262* The F reply packet::
0ce1b118
CV
24263* The Ctrl-C message::
24264* Console I/O::
0ce1b118
CV
24265* List of supported calls::
24266* Protocol specific representation of datatypes::
24267* Constants::
24268* File-I/O Examples::
24269@end menu
24270
24271@node File-I/O Overview
24272@subsection File-I/O Overview
24273@cindex file-i/o overview
24274
9c16f35a 24275The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 24276target to use the host's file system and console I/O to perform various
0ce1b118 24277system calls. System calls on the target system are translated into a
fc320d37
SL
24278remote protocol packet to the host system, which then performs the needed
24279actions and returns a response packet to the target system.
0ce1b118
CV
24280This simulates file system operations even on targets that lack file systems.
24281
fc320d37
SL
24282The protocol is defined to be independent of both the host and target systems.
24283It uses its own internal representation of datatypes and values. Both
0ce1b118 24284@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
24285translating the system-dependent value representations into the internal
24286protocol representations when data is transmitted.
0ce1b118 24287
fc320d37
SL
24288The communication is synchronous. A system call is possible only when
24289@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
24290or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 24291the target is stopped to allow deterministic access to the target's
fc320d37
SL
24292memory. Therefore File-I/O is not interruptible by target signals. On
24293the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 24294(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
24295
24296The target's request to perform a host system call does not finish
24297the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
24298after finishing the system call, the target returns to continuing the
24299previous activity (continue, step). No additional continue or step
24300request from @value{GDBN} is required.
24301
24302@smallexample
f7dc1244 24303(@value{GDBP}) continue
0ce1b118
CV
24304 <- target requests 'system call X'
24305 target is stopped, @value{GDBN} executes system call
24306 -> GDB returns result
24307 ... target continues, GDB returns to wait for the target
24308 <- target hits breakpoint and sends a Txx packet
24309@end smallexample
24310
fc320d37
SL
24311The protocol only supports I/O on the console and to regular files on
24312the host file system. Character or block special devices, pipes,
24313named pipes, sockets or any other communication method on the host
0ce1b118
CV
24314system are not supported by this protocol.
24315
24316@node Protocol basics
24317@subsection Protocol basics
24318@cindex protocol basics, file-i/o
24319
fc320d37
SL
24320The File-I/O protocol uses the @code{F} packet as the request as well
24321as reply packet. Since a File-I/O system call can only occur when
24322@value{GDBN} is waiting for a response from the continuing or stepping target,
24323the File-I/O request is a reply that @value{GDBN} has to expect as a result
24324of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
24325This @code{F} packet contains all information needed to allow @value{GDBN}
24326to call the appropriate host system call:
24327
24328@itemize @bullet
b383017d 24329@item
0ce1b118
CV
24330A unique identifier for the requested system call.
24331
24332@item
24333All parameters to the system call. Pointers are given as addresses
24334in the target memory address space. Pointers to strings are given as
b383017d 24335pointer/length pair. Numerical values are given as they are.
fc320d37 24336Numerical control flags are given in a protocol specific representation.
0ce1b118
CV
24337
24338@end itemize
24339
fc320d37 24340At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
24341
24342@itemize @bullet
b383017d 24343@item
fc320d37
SL
24344If the parameters include pointer values to data needed as input to a
24345system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
24346standard @code{m} packet request. This additional communication has to be
24347expected by the target implementation and is handled as any other @code{m}
24348packet.
24349
24350@item
24351@value{GDBN} translates all value from protocol representation to host
24352representation as needed. Datatypes are coerced into the host types.
24353
24354@item
fc320d37 24355@value{GDBN} calls the system call.
0ce1b118
CV
24356
24357@item
24358It then coerces datatypes back to protocol representation.
24359
24360@item
fc320d37
SL
24361If the system call is expected to return data in buffer space specified
24362by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
24363target using a @code{M} or @code{X} packet. This packet has to be expected
24364by the target implementation and is handled as any other @code{M} or @code{X}
24365packet.
24366
24367@end itemize
24368
24369Eventually @value{GDBN} replies with another @code{F} packet which contains all
24370necessary information for the target to continue. This at least contains
24371
24372@itemize @bullet
24373@item
24374Return value.
24375
24376@item
24377@code{errno}, if has been changed by the system call.
24378
24379@item
24380``Ctrl-C'' flag.
24381
24382@end itemize
24383
24384After having done the needed type and value coercion, the target continues
24385the latest continue or step action.
24386
1d8b2f28 24387@node The F request packet
0ce1b118
CV
24388@subsection The @code{F} request packet
24389@cindex file-i/o request packet
24390@cindex @code{F} request packet
24391
24392The @code{F} request packet has the following format:
24393
24394@table @samp
fc320d37 24395@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
24396
24397@var{call-id} is the identifier to indicate the host system call to be called.
24398This is just the name of the function.
24399
fc320d37
SL
24400@var{parameter@dots{}} are the parameters to the system call.
24401Parameters are hexadecimal integer values, either the actual values in case
24402of scalar datatypes, pointers to target buffer space in case of compound
24403datatypes and unspecified memory areas, or pointer/length pairs in case
24404of string parameters. These are appended to the @var{call-id} as a
24405comma-delimited list. All values are transmitted in ASCII
24406string representation, pointer/length pairs separated by a slash.
0ce1b118 24407
b383017d 24408@end table
0ce1b118 24409
fc320d37 24410
0ce1b118 24411
1d8b2f28 24412@node The F reply packet
0ce1b118
CV
24413@subsection The @code{F} reply packet
24414@cindex file-i/o reply packet
24415@cindex @code{F} reply packet
24416
24417The @code{F} reply packet has the following format:
24418
24419@table @samp
24420
fc320d37 24421@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call specific attachment}
0ce1b118
CV
24422
24423@var{retcode} is the return code of the system call as hexadecimal value.
24424
fc320d37 24425@var{errno} is the @code{errno} set by the call, in protocol specific representation.
0ce1b118
CV
24426This parameter can be omitted if the call was successful.
24427
fc320d37
SL
24428@var{Ctrl-C flag} is only sent if the user requested a break. In this
24429case, @var{errno} must be sent as well, even if the call was successful.
24430The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
24431
24432@smallexample
24433F0,0,C
24434@end smallexample
24435
24436@noindent
fc320d37 24437or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
24438
24439@smallexample
24440F-1,4,C
24441@end smallexample
24442
24443@noindent
24444assuming 4 is the protocol specific representation of @code{EINTR}.
24445
24446@end table
24447
0ce1b118
CV
24448
24449@node The Ctrl-C message
c8aa23ab 24450@subsection The @samp{Ctrl-C} message
0ce1b118
CV
24451@cindex ctrl-c message, in file-i/o protocol
24452
c8aa23ab
EZ
24453If the @samp{Ctrl-C} flag is set in the @value{GDBN}
24454reply packet (@pxref{The F reply packet}),
fc320d37 24455the target should behave as if it had
0ce1b118 24456gotten a break message. The meaning for the target is ``system call
fc320d37 24457interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 24458(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 24459packet.
fc320d37
SL
24460
24461It's important for the target to know in which
24462state the system call was interrupted. There are two possible cases:
0ce1b118
CV
24463
24464@itemize @bullet
24465@item
24466The system call hasn't been performed on the host yet.
24467
24468@item
24469The system call on the host has been finished.
24470
24471@end itemize
24472
24473These two states can be distinguished by the target by the value of the
24474returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
24475call hasn't been performed. This is equivalent to the @code{EINTR} handling
24476on POSIX systems. In any other case, the target may presume that the
fc320d37 24477system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
24478as if the break message arrived right after the system call.
24479
fc320d37 24480@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
24481yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
24482@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
24483before the user requests a break, the full action must be finished by
24484@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
24485The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
24486or the full action has been completed.
24487
24488@node Console I/O
24489@subsection Console I/O
24490@cindex console i/o as part of file-i/o
24491
24492By default and if not explicitely closed by the target system, the file
24493descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
24494on the @value{GDBN} console is handled as any other file output operation
24495(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
24496by @value{GDBN} so that after the target read request from file descriptor
244970 all following typing is buffered until either one of the following
24498conditions is met:
24499
24500@itemize @bullet
24501@item
c8aa23ab 24502The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
24503@code{read}
24504system call is treated as finished.
24505
24506@item
7f9087cb 24507The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 24508newline.
0ce1b118
CV
24509
24510@item
c8aa23ab
EZ
24511The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
24512character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
24513
24514@end itemize
24515
fc320d37
SL
24516If the user has typed more characters than fit in the buffer given to
24517the @code{read} call, the trailing characters are buffered in @value{GDBN} until
24518either another @code{read(0, @dots{})} is requested by the target, or debugging
24519is stopped at the user's request.
0ce1b118 24520
0ce1b118
CV
24521
24522@node List of supported calls
24523@subsection List of supported calls
24524@cindex list of supported file-i/o calls
24525
24526@menu
24527* open::
24528* close::
24529* read::
24530* write::
24531* lseek::
24532* rename::
24533* unlink::
24534* stat/fstat::
24535* gettimeofday::
24536* isatty::
24537* system::
24538@end menu
24539
24540@node open
24541@unnumberedsubsubsec open
24542@cindex open, file-i/o system call
24543
fc320d37
SL
24544@table @asis
24545@item Synopsis:
0ce1b118 24546@smallexample
0ce1b118
CV
24547int open(const char *pathname, int flags);
24548int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
24549@end smallexample
24550
fc320d37
SL
24551@item Request:
24552@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
24553
0ce1b118 24554@noindent
fc320d37 24555@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
24556
24557@table @code
b383017d 24558@item O_CREAT
0ce1b118
CV
24559If the file does not exist it will be created. The host
24560rules apply as far as file ownership and time stamps
24561are concerned.
24562
b383017d 24563@item O_EXCL
fc320d37 24564When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
24565an error and open() fails.
24566
b383017d 24567@item O_TRUNC
0ce1b118 24568If the file already exists and the open mode allows
fc320d37
SL
24569writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
24570truncated to zero length.
0ce1b118 24571
b383017d 24572@item O_APPEND
0ce1b118
CV
24573The file is opened in append mode.
24574
b383017d 24575@item O_RDONLY
0ce1b118
CV
24576The file is opened for reading only.
24577
b383017d 24578@item O_WRONLY
0ce1b118
CV
24579The file is opened for writing only.
24580
b383017d 24581@item O_RDWR
0ce1b118 24582The file is opened for reading and writing.
fc320d37 24583@end table
0ce1b118
CV
24584
24585@noindent
fc320d37 24586Other bits are silently ignored.
0ce1b118 24587
0ce1b118
CV
24588
24589@noindent
fc320d37 24590@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
24591
24592@table @code
b383017d 24593@item S_IRUSR
0ce1b118
CV
24594User has read permission.
24595
b383017d 24596@item S_IWUSR
0ce1b118
CV
24597User has write permission.
24598
b383017d 24599@item S_IRGRP
0ce1b118
CV
24600Group has read permission.
24601
b383017d 24602@item S_IWGRP
0ce1b118
CV
24603Group has write permission.
24604
b383017d 24605@item S_IROTH
0ce1b118
CV
24606Others have read permission.
24607
b383017d 24608@item S_IWOTH
0ce1b118 24609Others have write permission.
fc320d37 24610@end table
0ce1b118
CV
24611
24612@noindent
fc320d37 24613Other bits are silently ignored.
0ce1b118 24614
0ce1b118 24615
fc320d37
SL
24616@item Return value:
24617@code{open} returns the new file descriptor or -1 if an error
24618occurred.
0ce1b118 24619
fc320d37 24620@item Errors:
0ce1b118
CV
24621
24622@table @code
b383017d 24623@item EEXIST
fc320d37 24624@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 24625
b383017d 24626@item EISDIR
fc320d37 24627@var{pathname} refers to a directory.
0ce1b118 24628
b383017d 24629@item EACCES
0ce1b118
CV
24630The requested access is not allowed.
24631
24632@item ENAMETOOLONG
fc320d37 24633@var{pathname} was too long.
0ce1b118 24634
b383017d 24635@item ENOENT
fc320d37 24636A directory component in @var{pathname} does not exist.
0ce1b118 24637
b383017d 24638@item ENODEV
fc320d37 24639@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 24640
b383017d 24641@item EROFS
fc320d37 24642@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
24643write access was requested.
24644
b383017d 24645@item EFAULT
fc320d37 24646@var{pathname} is an invalid pointer value.
0ce1b118 24647
b383017d 24648@item ENOSPC
0ce1b118
CV
24649No space on device to create the file.
24650
b383017d 24651@item EMFILE
0ce1b118
CV
24652The process already has the maximum number of files open.
24653
b383017d 24654@item ENFILE
0ce1b118
CV
24655The limit on the total number of files open on the system
24656has been reached.
24657
b383017d 24658@item EINTR
0ce1b118
CV
24659The call was interrupted by the user.
24660@end table
24661
fc320d37
SL
24662@end table
24663
0ce1b118
CV
24664@node close
24665@unnumberedsubsubsec close
24666@cindex close, file-i/o system call
24667
fc320d37
SL
24668@table @asis
24669@item Synopsis:
0ce1b118 24670@smallexample
0ce1b118 24671int close(int fd);
fc320d37 24672@end smallexample
0ce1b118 24673
fc320d37
SL
24674@item Request:
24675@samp{Fclose,@var{fd}}
0ce1b118 24676
fc320d37
SL
24677@item Return value:
24678@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 24679
fc320d37 24680@item Errors:
0ce1b118
CV
24681
24682@table @code
b383017d 24683@item EBADF
fc320d37 24684@var{fd} isn't a valid open file descriptor.
0ce1b118 24685
b383017d 24686@item EINTR
0ce1b118
CV
24687The call was interrupted by the user.
24688@end table
24689
fc320d37
SL
24690@end table
24691
0ce1b118
CV
24692@node read
24693@unnumberedsubsubsec read
24694@cindex read, file-i/o system call
24695
fc320d37
SL
24696@table @asis
24697@item Synopsis:
0ce1b118 24698@smallexample
0ce1b118 24699int read(int fd, void *buf, unsigned int count);
fc320d37 24700@end smallexample
0ce1b118 24701
fc320d37
SL
24702@item Request:
24703@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 24704
fc320d37 24705@item Return value:
0ce1b118
CV
24706On success, the number of bytes read is returned.
24707Zero indicates end of file. If count is zero, read
b383017d 24708returns zero as well. On error, -1 is returned.
0ce1b118 24709
fc320d37 24710@item Errors:
0ce1b118
CV
24711
24712@table @code
b383017d 24713@item EBADF
fc320d37 24714@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
24715reading.
24716
b383017d 24717@item EFAULT
fc320d37 24718@var{bufptr} is an invalid pointer value.
0ce1b118 24719
b383017d 24720@item EINTR
0ce1b118
CV
24721The call was interrupted by the user.
24722@end table
24723
fc320d37
SL
24724@end table
24725
0ce1b118
CV
24726@node write
24727@unnumberedsubsubsec write
24728@cindex write, file-i/o system call
24729
fc320d37
SL
24730@table @asis
24731@item Synopsis:
0ce1b118 24732@smallexample
0ce1b118 24733int write(int fd, const void *buf, unsigned int count);
fc320d37 24734@end smallexample
0ce1b118 24735
fc320d37
SL
24736@item Request:
24737@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 24738
fc320d37 24739@item Return value:
0ce1b118
CV
24740On success, the number of bytes written are returned.
24741Zero indicates nothing was written. On error, -1
24742is returned.
24743
fc320d37 24744@item Errors:
0ce1b118
CV
24745
24746@table @code
b383017d 24747@item EBADF
fc320d37 24748@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
24749writing.
24750
b383017d 24751@item EFAULT
fc320d37 24752@var{bufptr} is an invalid pointer value.
0ce1b118 24753
b383017d 24754@item EFBIG
0ce1b118
CV
24755An attempt was made to write a file that exceeds the
24756host specific maximum file size allowed.
24757
b383017d 24758@item ENOSPC
0ce1b118
CV
24759No space on device to write the data.
24760
b383017d 24761@item EINTR
0ce1b118
CV
24762The call was interrupted by the user.
24763@end table
24764
fc320d37
SL
24765@end table
24766
0ce1b118
CV
24767@node lseek
24768@unnumberedsubsubsec lseek
24769@cindex lseek, file-i/o system call
24770
fc320d37
SL
24771@table @asis
24772@item Synopsis:
0ce1b118 24773@smallexample
0ce1b118 24774long lseek (int fd, long offset, int flag);
0ce1b118
CV
24775@end smallexample
24776
fc320d37
SL
24777@item Request:
24778@samp{Flseek,@var{fd},@var{offset},@var{flag}}
24779
24780@var{flag} is one of:
0ce1b118
CV
24781
24782@table @code
b383017d 24783@item SEEK_SET
fc320d37 24784The offset is set to @var{offset} bytes.
0ce1b118 24785
b383017d 24786@item SEEK_CUR
fc320d37 24787The offset is set to its current location plus @var{offset}
0ce1b118
CV
24788bytes.
24789
b383017d 24790@item SEEK_END
fc320d37 24791The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
24792bytes.
24793@end table
24794
fc320d37 24795@item Return value:
0ce1b118
CV
24796On success, the resulting unsigned offset in bytes from
24797the beginning of the file is returned. Otherwise, a
24798value of -1 is returned.
24799
fc320d37 24800@item Errors:
0ce1b118
CV
24801
24802@table @code
b383017d 24803@item EBADF
fc320d37 24804@var{fd} is not a valid open file descriptor.
0ce1b118 24805
b383017d 24806@item ESPIPE
fc320d37 24807@var{fd} is associated with the @value{GDBN} console.
0ce1b118 24808
b383017d 24809@item EINVAL
fc320d37 24810@var{flag} is not a proper value.
0ce1b118 24811
b383017d 24812@item EINTR
0ce1b118
CV
24813The call was interrupted by the user.
24814@end table
24815
fc320d37
SL
24816@end table
24817
0ce1b118
CV
24818@node rename
24819@unnumberedsubsubsec rename
24820@cindex rename, file-i/o system call
24821
fc320d37
SL
24822@table @asis
24823@item Synopsis:
0ce1b118 24824@smallexample
0ce1b118 24825int rename(const char *oldpath, const char *newpath);
fc320d37 24826@end smallexample
0ce1b118 24827
fc320d37
SL
24828@item Request:
24829@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 24830
fc320d37 24831@item Return value:
0ce1b118
CV
24832On success, zero is returned. On error, -1 is returned.
24833
fc320d37 24834@item Errors:
0ce1b118
CV
24835
24836@table @code
b383017d 24837@item EISDIR
fc320d37 24838@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
24839directory.
24840
b383017d 24841@item EEXIST
fc320d37 24842@var{newpath} is a non-empty directory.
0ce1b118 24843
b383017d 24844@item EBUSY
fc320d37 24845@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
24846process.
24847
b383017d 24848@item EINVAL
0ce1b118
CV
24849An attempt was made to make a directory a subdirectory
24850of itself.
24851
b383017d 24852@item ENOTDIR
fc320d37
SL
24853A component used as a directory in @var{oldpath} or new
24854path is not a directory. Or @var{oldpath} is a directory
24855and @var{newpath} exists but is not a directory.
0ce1b118 24856
b383017d 24857@item EFAULT
fc320d37 24858@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 24859
b383017d 24860@item EACCES
0ce1b118
CV
24861No access to the file or the path of the file.
24862
24863@item ENAMETOOLONG
b383017d 24864
fc320d37 24865@var{oldpath} or @var{newpath} was too long.
0ce1b118 24866
b383017d 24867@item ENOENT
fc320d37 24868A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 24869
b383017d 24870@item EROFS
0ce1b118
CV
24871The file is on a read-only filesystem.
24872
b383017d 24873@item ENOSPC
0ce1b118
CV
24874The device containing the file has no room for the new
24875directory entry.
24876
b383017d 24877@item EINTR
0ce1b118
CV
24878The call was interrupted by the user.
24879@end table
24880
fc320d37
SL
24881@end table
24882
0ce1b118
CV
24883@node unlink
24884@unnumberedsubsubsec unlink
24885@cindex unlink, file-i/o system call
24886
fc320d37
SL
24887@table @asis
24888@item Synopsis:
0ce1b118 24889@smallexample
0ce1b118 24890int unlink(const char *pathname);
fc320d37 24891@end smallexample
0ce1b118 24892
fc320d37
SL
24893@item Request:
24894@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 24895
fc320d37 24896@item Return value:
0ce1b118
CV
24897On success, zero is returned. On error, -1 is returned.
24898
fc320d37 24899@item Errors:
0ce1b118
CV
24900
24901@table @code
b383017d 24902@item EACCES
0ce1b118
CV
24903No access to the file or the path of the file.
24904
b383017d 24905@item EPERM
0ce1b118
CV
24906The system does not allow unlinking of directories.
24907
b383017d 24908@item EBUSY
fc320d37 24909The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
24910being used by another process.
24911
b383017d 24912@item EFAULT
fc320d37 24913@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
24914
24915@item ENAMETOOLONG
fc320d37 24916@var{pathname} was too long.
0ce1b118 24917
b383017d 24918@item ENOENT
fc320d37 24919A directory component in @var{pathname} does not exist.
0ce1b118 24920
b383017d 24921@item ENOTDIR
0ce1b118
CV
24922A component of the path is not a directory.
24923
b383017d 24924@item EROFS
0ce1b118
CV
24925The file is on a read-only filesystem.
24926
b383017d 24927@item EINTR
0ce1b118
CV
24928The call was interrupted by the user.
24929@end table
24930
fc320d37
SL
24931@end table
24932
0ce1b118
CV
24933@node stat/fstat
24934@unnumberedsubsubsec stat/fstat
24935@cindex fstat, file-i/o system call
24936@cindex stat, file-i/o system call
24937
fc320d37
SL
24938@table @asis
24939@item Synopsis:
0ce1b118 24940@smallexample
0ce1b118
CV
24941int stat(const char *pathname, struct stat *buf);
24942int fstat(int fd, struct stat *buf);
fc320d37 24943@end smallexample
0ce1b118 24944
fc320d37
SL
24945@item Request:
24946@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
24947@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 24948
fc320d37 24949@item Return value:
0ce1b118
CV
24950On success, zero is returned. On error, -1 is returned.
24951
fc320d37 24952@item Errors:
0ce1b118
CV
24953
24954@table @code
b383017d 24955@item EBADF
fc320d37 24956@var{fd} is not a valid open file.
0ce1b118 24957
b383017d 24958@item ENOENT
fc320d37 24959A directory component in @var{pathname} does not exist or the
0ce1b118
CV
24960path is an empty string.
24961
b383017d 24962@item ENOTDIR
0ce1b118
CV
24963A component of the path is not a directory.
24964
b383017d 24965@item EFAULT
fc320d37 24966@var{pathnameptr} is an invalid pointer value.
0ce1b118 24967
b383017d 24968@item EACCES
0ce1b118
CV
24969No access to the file or the path of the file.
24970
24971@item ENAMETOOLONG
fc320d37 24972@var{pathname} was too long.
0ce1b118 24973
b383017d 24974@item EINTR
0ce1b118
CV
24975The call was interrupted by the user.
24976@end table
24977
fc320d37
SL
24978@end table
24979
0ce1b118
CV
24980@node gettimeofday
24981@unnumberedsubsubsec gettimeofday
24982@cindex gettimeofday, file-i/o system call
24983
fc320d37
SL
24984@table @asis
24985@item Synopsis:
0ce1b118 24986@smallexample
0ce1b118 24987int gettimeofday(struct timeval *tv, void *tz);
fc320d37 24988@end smallexample
0ce1b118 24989
fc320d37
SL
24990@item Request:
24991@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 24992
fc320d37 24993@item Return value:
0ce1b118
CV
24994On success, 0 is returned, -1 otherwise.
24995
fc320d37 24996@item Errors:
0ce1b118
CV
24997
24998@table @code
b383017d 24999@item EINVAL
fc320d37 25000@var{tz} is a non-NULL pointer.
0ce1b118 25001
b383017d 25002@item EFAULT
fc320d37
SL
25003@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
25004@end table
25005
0ce1b118
CV
25006@end table
25007
25008@node isatty
25009@unnumberedsubsubsec isatty
25010@cindex isatty, file-i/o system call
25011
fc320d37
SL
25012@table @asis
25013@item Synopsis:
0ce1b118 25014@smallexample
0ce1b118 25015int isatty(int fd);
fc320d37 25016@end smallexample
0ce1b118 25017
fc320d37
SL
25018@item Request:
25019@samp{Fisatty,@var{fd}}
0ce1b118 25020
fc320d37
SL
25021@item Return value:
25022Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 25023
fc320d37 25024@item Errors:
0ce1b118
CV
25025
25026@table @code
b383017d 25027@item EINTR
0ce1b118
CV
25028The call was interrupted by the user.
25029@end table
25030
fc320d37
SL
25031@end table
25032
25033Note that the @code{isatty} call is treated as a special case: it returns
250341 to the target if the file descriptor is attached
25035to the @value{GDBN} console, 0 otherwise. Implementing through system calls
25036would require implementing @code{ioctl} and would be more complex than
25037needed.
25038
25039
0ce1b118
CV
25040@node system
25041@unnumberedsubsubsec system
25042@cindex system, file-i/o system call
25043
fc320d37
SL
25044@table @asis
25045@item Synopsis:
0ce1b118 25046@smallexample
0ce1b118 25047int system(const char *command);
fc320d37 25048@end smallexample
0ce1b118 25049
fc320d37
SL
25050@item Request:
25051@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 25052
fc320d37 25053@item Return value:
5600ea19
NS
25054If @var{len} is zero, the return value indicates whether a shell is
25055available. A zero return value indicates a shell is not available.
25056For non-zero @var{len}, the value returned is -1 on error and the
25057return status of the command otherwise. Only the exit status of the
25058command is returned, which is extracted from the host's @code{system}
25059return value by calling @code{WEXITSTATUS(retval)}. In case
25060@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 25061
fc320d37 25062@item Errors:
0ce1b118
CV
25063
25064@table @code
b383017d 25065@item EINTR
0ce1b118
CV
25066The call was interrupted by the user.
25067@end table
25068
fc320d37
SL
25069@end table
25070
25071@value{GDBN} takes over the full task of calling the necessary host calls
25072to perform the @code{system} call. The return value of @code{system} on
25073the host is simplified before it's returned
25074to the target. Any termination signal information from the child process
25075is discarded, and the return value consists
25076entirely of the exit status of the called command.
25077
25078Due to security concerns, the @code{system} call is by default refused
25079by @value{GDBN}. The user has to allow this call explicitly with the
25080@code{set remote system-call-allowed 1} command.
25081
25082@table @code
25083@item set remote system-call-allowed
25084@kindex set remote system-call-allowed
25085Control whether to allow the @code{system} calls in the File I/O
25086protocol for the remote target. The default is zero (disabled).
25087
25088@item show remote system-call-allowed
25089@kindex show remote system-call-allowed
25090Show whether the @code{system} calls are allowed in the File I/O
25091protocol.
25092@end table
25093
0ce1b118
CV
25094@node Protocol specific representation of datatypes
25095@subsection Protocol specific representation of datatypes
25096@cindex protocol specific representation of datatypes, in file-i/o protocol
25097
25098@menu
25099* Integral datatypes::
25100* Pointer values::
fc320d37 25101* Memory transfer::
0ce1b118
CV
25102* struct stat::
25103* struct timeval::
25104@end menu
25105
25106@node Integral datatypes
25107@unnumberedsubsubsec Integral datatypes
25108@cindex integral datatypes, in file-i/o protocol
25109
fc320d37
SL
25110The integral datatypes used in the system calls are @code{int},
25111@code{unsigned int}, @code{long}, @code{unsigned long},
25112@code{mode_t}, and @code{time_t}.
0ce1b118 25113
fc320d37 25114@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
25115implemented as 32 bit values in this protocol.
25116
fc320d37 25117@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 25118
0ce1b118
CV
25119@xref{Limits}, for corresponding MIN and MAX values (similar to those
25120in @file{limits.h}) to allow range checking on host and target.
25121
25122@code{time_t} datatypes are defined as seconds since the Epoch.
25123
25124All integral datatypes transferred as part of a memory read or write of a
25125structured datatype e.g.@: a @code{struct stat} have to be given in big endian
25126byte order.
25127
25128@node Pointer values
25129@unnumberedsubsubsec Pointer values
25130@cindex pointer values, in file-i/o protocol
25131
25132Pointers to target data are transmitted as they are. An exception
25133is made for pointers to buffers for which the length isn't
25134transmitted as part of the function call, namely strings. Strings
25135are transmitted as a pointer/length pair, both as hex values, e.g.@:
25136
25137@smallexample
25138@code{1aaf/12}
25139@end smallexample
25140
25141@noindent
25142which is a pointer to data of length 18 bytes at position 0x1aaf.
25143The length is defined as the full string length in bytes, including
fc320d37
SL
25144the trailing null byte. For example, the string @code{"hello world"}
25145at address 0x123456 is transmitted as
0ce1b118
CV
25146
25147@smallexample
fc320d37 25148@code{123456/d}
0ce1b118
CV
25149@end smallexample
25150
fc320d37
SL
25151@node Memory transfer
25152@unnumberedsubsubsec Memory transfer
25153@cindex memory transfer, in file-i/o protocol
25154
25155Structured data which is transferred using a memory read or write (for
25156example, a @code{struct stat}) is expected to be in a protocol specific format
25157with all scalar multibyte datatypes being big endian. Translation to
25158this representation needs to be done both by the target before the @code{F}
25159packet is sent, and by @value{GDBN} before
25160it transfers memory to the target. Transferred pointers to structured
25161data should point to the already-coerced data at any time.
0ce1b118 25162
0ce1b118
CV
25163
25164@node struct stat
25165@unnumberedsubsubsec struct stat
25166@cindex struct stat, in file-i/o protocol
25167
fc320d37
SL
25168The buffer of type @code{struct stat} used by the target and @value{GDBN}
25169is defined as follows:
0ce1b118
CV
25170
25171@smallexample
25172struct stat @{
25173 unsigned int st_dev; /* device */
25174 unsigned int st_ino; /* inode */
25175 mode_t st_mode; /* protection */
25176 unsigned int st_nlink; /* number of hard links */
25177 unsigned int st_uid; /* user ID of owner */
25178 unsigned int st_gid; /* group ID of owner */
25179 unsigned int st_rdev; /* device type (if inode device) */
25180 unsigned long st_size; /* total size, in bytes */
25181 unsigned long st_blksize; /* blocksize for filesystem I/O */
25182 unsigned long st_blocks; /* number of blocks allocated */
25183 time_t st_atime; /* time of last access */
25184 time_t st_mtime; /* time of last modification */
25185 time_t st_ctime; /* time of last change */
25186@};
25187@end smallexample
25188
fc320d37
SL
25189The integral datatypes conform to the definitions given in the
25190appropriate section (see @ref{Integral datatypes}, for details) so this
0ce1b118
CV
25191structure is of size 64 bytes.
25192
25193The values of several fields have a restricted meaning and/or
25194range of values.
25195
fc320d37 25196@table @code
0ce1b118 25197
fc320d37
SL
25198@item st_dev
25199A value of 0 represents a file, 1 the console.
0ce1b118 25200
fc320d37
SL
25201@item st_ino
25202No valid meaning for the target. Transmitted unchanged.
0ce1b118 25203
fc320d37
SL
25204@item st_mode
25205Valid mode bits are described in @ref{Constants}. Any other
25206bits have currently no meaning for the target.
0ce1b118 25207
fc320d37
SL
25208@item st_uid
25209@itemx st_gid
25210@itemx st_rdev
25211No valid meaning for the target. Transmitted unchanged.
0ce1b118 25212
fc320d37
SL
25213@item st_atime
25214@itemx st_mtime
25215@itemx st_ctime
25216These values have a host and file system dependent
25217accuracy. Especially on Windows hosts, the file system may not
25218support exact timing values.
25219@end table
0ce1b118 25220
fc320d37
SL
25221The target gets a @code{struct stat} of the above representation and is
25222responsible for coercing it to the target representation before
0ce1b118
CV
25223continuing.
25224
fc320d37
SL
25225Note that due to size differences between the host, target, and protocol
25226representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
25227get truncated on the target.
25228
25229@node struct timeval
25230@unnumberedsubsubsec struct timeval
25231@cindex struct timeval, in file-i/o protocol
25232
fc320d37 25233The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
25234is defined as follows:
25235
25236@smallexample
b383017d 25237struct timeval @{
0ce1b118
CV
25238 time_t tv_sec; /* second */
25239 long tv_usec; /* microsecond */
25240@};
25241@end smallexample
25242
fc320d37
SL
25243The integral datatypes conform to the definitions given in the
25244appropriate section (see @ref{Integral datatypes}, for details) so this
0ce1b118
CV
25245structure is of size 8 bytes.
25246
25247@node Constants
25248@subsection Constants
25249@cindex constants, in file-i/o protocol
25250
25251The following values are used for the constants inside of the
fc320d37 25252protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
25253values before and after the call as needed.
25254
25255@menu
25256* Open flags::
25257* mode_t values::
25258* Errno values::
25259* Lseek flags::
25260* Limits::
25261@end menu
25262
25263@node Open flags
25264@unnumberedsubsubsec Open flags
25265@cindex open flags, in file-i/o protocol
25266
25267All values are given in hexadecimal representation.
25268
25269@smallexample
25270 O_RDONLY 0x0
25271 O_WRONLY 0x1
25272 O_RDWR 0x2
25273 O_APPEND 0x8
25274 O_CREAT 0x200
25275 O_TRUNC 0x400
25276 O_EXCL 0x800
25277@end smallexample
25278
25279@node mode_t values
25280@unnumberedsubsubsec mode_t values
25281@cindex mode_t values, in file-i/o protocol
25282
25283All values are given in octal representation.
25284
25285@smallexample
25286 S_IFREG 0100000
25287 S_IFDIR 040000
25288 S_IRUSR 0400
25289 S_IWUSR 0200
25290 S_IXUSR 0100
25291 S_IRGRP 040
25292 S_IWGRP 020
25293 S_IXGRP 010
25294 S_IROTH 04
25295 S_IWOTH 02
25296 S_IXOTH 01
25297@end smallexample
25298
25299@node Errno values
25300@unnumberedsubsubsec Errno values
25301@cindex errno values, in file-i/o protocol
25302
25303All values are given in decimal representation.
25304
25305@smallexample
25306 EPERM 1
25307 ENOENT 2
25308 EINTR 4
25309 EBADF 9
25310 EACCES 13
25311 EFAULT 14
25312 EBUSY 16
25313 EEXIST 17
25314 ENODEV 19
25315 ENOTDIR 20
25316 EISDIR 21
25317 EINVAL 22
25318 ENFILE 23
25319 EMFILE 24
25320 EFBIG 27
25321 ENOSPC 28
25322 ESPIPE 29
25323 EROFS 30
25324 ENAMETOOLONG 91
25325 EUNKNOWN 9999
25326@end smallexample
25327
fc320d37 25328 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
25329 any error value not in the list of supported error numbers.
25330
25331@node Lseek flags
25332@unnumberedsubsubsec Lseek flags
25333@cindex lseek flags, in file-i/o protocol
25334
25335@smallexample
25336 SEEK_SET 0
25337 SEEK_CUR 1
25338 SEEK_END 2
25339@end smallexample
25340
25341@node Limits
25342@unnumberedsubsubsec Limits
25343@cindex limits, in file-i/o protocol
25344
25345All values are given in decimal representation.
25346
25347@smallexample
25348 INT_MIN -2147483648
25349 INT_MAX 2147483647
25350 UINT_MAX 4294967295
25351 LONG_MIN -9223372036854775808
25352 LONG_MAX 9223372036854775807
25353 ULONG_MAX 18446744073709551615
25354@end smallexample
25355
25356@node File-I/O Examples
25357@subsection File-I/O Examples
25358@cindex file-i/o examples
25359
25360Example sequence of a write call, file descriptor 3, buffer is at target
25361address 0x1234, 6 bytes should be written:
25362
25363@smallexample
25364<- @code{Fwrite,3,1234,6}
25365@emph{request memory read from target}
25366-> @code{m1234,6}
25367<- XXXXXX
25368@emph{return "6 bytes written"}
25369-> @code{F6}
25370@end smallexample
25371
25372Example sequence of a read call, file descriptor 3, buffer is at target
25373address 0x1234, 6 bytes should be read:
25374
25375@smallexample
25376<- @code{Fread,3,1234,6}
25377@emph{request memory write to target}
25378-> @code{X1234,6:XXXXXX}
25379@emph{return "6 bytes read"}
25380-> @code{F6}
25381@end smallexample
25382
25383Example sequence of a read call, call fails on the host due to invalid
fc320d37 25384file descriptor (@code{EBADF}):
0ce1b118
CV
25385
25386@smallexample
25387<- @code{Fread,3,1234,6}
25388-> @code{F-1,9}
25389@end smallexample
25390
c8aa23ab 25391Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
25392host is called:
25393
25394@smallexample
25395<- @code{Fread,3,1234,6}
25396-> @code{F-1,4,C}
25397<- @code{T02}
25398@end smallexample
25399
c8aa23ab 25400Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
25401host is called:
25402
25403@smallexample
25404<- @code{Fread,3,1234,6}
25405-> @code{X1234,6:XXXXXX}
25406<- @code{T02}
25407@end smallexample
25408
68437a39
DJ
25409@node Memory map format
25410@section Memory map format
25411@cindex memory map format
25412
25413To be able to write into flash memory, @value{GDBN} needs to obtain a
25414memory map from the target. This section describes the format of the
25415memory map.
25416
25417The memory map is obtained using the @samp{qXfer:memory-map:read}
25418(@pxref{qXfer memory map read}) packet and is an XML document that
25419lists memory regions. The top-level structure of the document is shown below:
25420
25421@smallexample
25422<?xml version="1.0"?>
25423<!DOCTYPE memory-map
25424 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
25425 "http://sourceware.org/gdb/gdb-memory-map.dtd">
25426<memory-map>
25427 region...
25428</memory-map>
25429@end smallexample
25430
25431Each region can be either:
25432
25433@itemize
25434
25435@item
25436A region of RAM starting at @var{addr} and extending for @var{length}
25437bytes from there:
25438
25439@smallexample
25440<memory type="ram" start="@var{addr}" length="@var{length}"/>
25441@end smallexample
25442
25443
25444@item
25445A region of read-only memory:
25446
25447@smallexample
25448<memory type="rom" start="@var{addr}" length="@var{length}"/>
25449@end smallexample
25450
25451
25452@item
25453A region of flash memory, with erasure blocks @var{blocksize}
25454bytes in length:
25455
25456@smallexample
25457<memory type="flash" start="@var{addr}" length="@var{length}">
25458 <property name="blocksize">@var{blocksize}</property>
25459</memory>
25460@end smallexample
25461
25462@end itemize
25463
25464Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
25465by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
25466packets to write to addresses in such ranges.
25467
25468The formal DTD for memory map format is given below:
25469
25470@smallexample
25471<!-- ................................................... -->
25472<!-- Memory Map XML DTD ................................ -->
25473<!-- File: memory-map.dtd .............................. -->
25474<!-- .................................... .............. -->
25475<!-- memory-map.dtd -->
25476<!-- memory-map: Root element with versioning -->
25477<!ELEMENT memory-map (memory | property)>
25478<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
25479<!ELEMENT memory (property)>
25480<!-- memory: Specifies a memory region,
25481 and its type, or device. -->
25482<!ATTLIST memory type CDATA #REQUIRED
25483 start CDATA #REQUIRED
25484 length CDATA #REQUIRED
25485 device CDATA #IMPLIED>
25486<!-- property: Generic attribute tag -->
25487<!ELEMENT property (#PCDATA | property)*>
25488<!ATTLIST property name CDATA #REQUIRED>
25489@end smallexample
25490
f418dd93
DJ
25491@include agentexpr.texi
25492
aab4e0ec 25493@include gpl.texi
eb12ee30 25494
2154891a 25495@raisesections
6826cf00 25496@include fdl.texi
2154891a 25497@lowersections
6826cf00 25498
6d2ebf8b 25499@node Index
c906108c
SS
25500@unnumbered Index
25501
25502@printindex cp
25503
25504@tex
25505% I think something like @colophon should be in texinfo. In the
25506% meantime:
25507\long\def\colophon{\hbox to0pt{}\vfill
25508\centerline{The body of this manual is set in}
25509\centerline{\fontname\tenrm,}
25510\centerline{with headings in {\bf\fontname\tenbf}}
25511\centerline{and examples in {\tt\fontname\tentt}.}
25512\centerline{{\it\fontname\tenit\/},}
25513\centerline{{\bf\fontname\tenbf}, and}
25514\centerline{{\sl\fontname\tensl\/}}
25515\centerline{are used for emphasis.}\vfill}
25516\page\colophon
25517% Blame: doc@cygnus.com, 1991.
25518@end tex
25519
c906108c 25520@bye
This page took 3.112218 seconds and 4 git commands to generate.