/tmp/foo.diff
[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
b8533aec
DJ
65(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
66this GNU Manual. Buying copies from GNU Press supports the FSF in
67developing GNU and promoting software freedom.''
c906108c
SS
68@end ifinfo
69
70@titlepage
71@title Debugging with @value{GDBN}
72@subtitle The @sc{gnu} Source-Level Debugger
c906108c 73@sp 1
c906108c 74@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 75@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 76@page
c906108c
SS
77@tex
78{\parskip=0pt
53a5351d 79\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
80\hfill {\it Debugging with @value{GDBN}}\par
81\hfill \TeX{}info \texinfoversion\par
82}
83@end tex
53a5351d 84
c906108c 85@vskip 0pt plus 1filll
8a037dd7 86Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
b620eb07 871996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
7d51c7de 88Free Software Foundation, Inc.
c906108c 89@sp 2
c906108c 90Published by the Free Software Foundation @*
c02a867d
EZ
9151 Franklin Street, Fifth Floor,
92Boston, MA 02110-1301, USA@*
6d2ebf8b 93ISBN 1-882114-77-9 @*
e9c75b65
EZ
94
95Permission is granted to copy, distribute and/or modify this document
96under the terms of the GNU Free Documentation License, Version 1.1 or
97any later version published by the Free Software Foundation; with the
959acfd1
EZ
98Invariant Sections being ``Free Software'' and ``Free Software Needs
99Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
100and with the Back-Cover Texts as in (a) below.
e9c75b65 101
b8533aec
DJ
102(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
103this GNU Manual. Buying copies from GNU Press supports the FSF in
104developing GNU and promoting software freedom.''
3fb6a982
JB
105@page
106This edition of the GDB manual is dedicated to the memory of Fred
107Fish. Fred was a long-standing contributor to GDB and to Free
108software in general. We will miss him.
c906108c
SS
109@end titlepage
110@page
111
6c0e9fb3 112@ifnottex
6d2ebf8b
SS
113@node Top, Summary, (dir), (dir)
114
c906108c
SS
115@top Debugging with @value{GDBN}
116
117This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
118
9fe8321b 119This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
120@value{GDBVN}.
121
b620eb07 122Copyright (C) 1988-2006 Free Software Foundation, Inc.
6d2ebf8b 123
3fb6a982
JB
124This edition of the GDB manual is dedicated to the memory of Fred
125Fish. Fred was a long-standing contributor to GDB and to Free
126software in general. We will miss him.
127
6d2ebf8b
SS
128@menu
129* Summary:: Summary of @value{GDBN}
130* Sample Session:: A sample @value{GDBN} session
131
132* Invocation:: Getting in and out of @value{GDBN}
133* Commands:: @value{GDBN} commands
134* Running:: Running programs under @value{GDBN}
135* Stopping:: Stopping and continuing
136* Stack:: Examining the stack
137* Source:: Examining source files
138* Data:: Examining data
e2e0bcd1 139* Macros:: Preprocessor Macros
b37052ae 140* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 141* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
142
143* Languages:: Using @value{GDBN} with different languages
144
145* Symbols:: Examining the symbol table
146* Altering:: Altering execution
147* GDB Files:: @value{GDBN} files
148* Targets:: Specifying a debugging target
6b2f586d 149* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
150* Configurations:: Configuration-specific information
151* Controlling GDB:: Controlling @value{GDBN}
152* Sequences:: Canned sequences of commands
21c294e6 153* Interpreters:: Command Interpreters
c8f4133a 154* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 155* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 156* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 157* Annotations:: @value{GDBN}'s annotation interface.
6d2ebf8b
SS
158
159* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b
SS
160
161* Command Line Editing:: Command Line Editing
162* Using History Interactively:: Using History Interactively
0869d01b 163* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 164* Installing GDB:: Installing GDB
eb12ee30 165* Maintenance Commands:: Maintenance Commands
e0ce93ac 166* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 167* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
168* Target Descriptions:: How targets can describe themselves to
169 @value{GDBN}
aab4e0ec
AC
170* Copying:: GNU General Public License says
171 how you can copy and share GDB
6826cf00 172* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
173* Index:: Index
174@end menu
175
6c0e9fb3 176@end ifnottex
c906108c 177
449f3b6c 178@contents
449f3b6c 179
6d2ebf8b 180@node Summary
c906108c
SS
181@unnumbered Summary of @value{GDBN}
182
183The purpose of a debugger such as @value{GDBN} is to allow you to see what is
184going on ``inside'' another program while it executes---or what another
185program was doing at the moment it crashed.
186
187@value{GDBN} can do four main kinds of things (plus other things in support of
188these) to help you catch bugs in the act:
189
190@itemize @bullet
191@item
192Start your program, specifying anything that might affect its behavior.
193
194@item
195Make your program stop on specified conditions.
196
197@item
198Examine what has happened, when your program has stopped.
199
200@item
201Change things in your program, so you can experiment with correcting the
202effects of one bug and go on to learn about another.
203@end itemize
204
49efadf5 205You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 206For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
207For more information, see @ref{C,,C and C++}.
208
cce74817 209@cindex Modula-2
e632838e
AC
210Support for Modula-2 is partial. For information on Modula-2, see
211@ref{Modula-2,,Modula-2}.
c906108c 212
cce74817
JM
213@cindex Pascal
214Debugging Pascal programs which use sets, subranges, file variables, or
215nested functions does not currently work. @value{GDBN} does not support
216entering expressions, printing values, or similar features using Pascal
217syntax.
c906108c 218
c906108c
SS
219@cindex Fortran
220@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 221it may be necessary to refer to some variables with a trailing
cce74817 222underscore.
c906108c 223
b37303ee
AF
224@value{GDBN} can be used to debug programs written in Objective-C,
225using either the Apple/NeXT or the GNU Objective-C runtime.
226
c906108c
SS
227@menu
228* Free Software:: Freely redistributable software
229* Contributors:: Contributors to GDB
230@end menu
231
6d2ebf8b 232@node Free Software
79a6e687 233@unnumberedsec Free Software
c906108c 234
5d161b24 235@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
236General Public License
237(GPL). The GPL gives you the freedom to copy or adapt a licensed
238program---but every person getting a copy also gets with it the
239freedom to modify that copy (which means that they must get access to
240the source code), and the freedom to distribute further copies.
241Typical software companies use copyrights to limit your freedoms; the
242Free Software Foundation uses the GPL to preserve these freedoms.
243
244Fundamentally, the General Public License is a license which says that
245you have these freedoms and that you cannot take these freedoms away
246from anyone else.
247
2666264b 248@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
249
250The biggest deficiency in the free software community today is not in
251the software---it is the lack of good free documentation that we can
252include with the free software. Many of our most important
253programs do not come with free reference manuals and free introductory
254texts. Documentation is an essential part of any software package;
255when an important free software package does not come with a free
256manual and a free tutorial, that is a major gap. We have many such
257gaps today.
258
259Consider Perl, for instance. The tutorial manuals that people
260normally use are non-free. How did this come about? Because the
261authors of those manuals published them with restrictive terms---no
262copying, no modification, source files not available---which exclude
263them from the free software world.
264
265That wasn't the first time this sort of thing happened, and it was far
266from the last. Many times we have heard a GNU user eagerly describe a
267manual that he is writing, his intended contribution to the community,
268only to learn that he had ruined everything by signing a publication
269contract to make it non-free.
270
271Free documentation, like free software, is a matter of freedom, not
272price. The problem with the non-free manual is not that publishers
273charge a price for printed copies---that in itself is fine. (The Free
274Software Foundation sells printed copies of manuals, too.) The
275problem is the restrictions on the use of the manual. Free manuals
276are available in source code form, and give you permission to copy and
277modify. Non-free manuals do not allow this.
278
279The criteria of freedom for a free manual are roughly the same as for
280free software. Redistribution (including the normal kinds of
281commercial redistribution) must be permitted, so that the manual can
282accompany every copy of the program, both on-line and on paper.
283
284Permission for modification of the technical content is crucial too.
285When people modify the software, adding or changing features, if they
286are conscientious they will change the manual too---so they can
287provide accurate and clear documentation for the modified program. A
288manual that leaves you no choice but to write a new manual to document
289a changed version of the program is not really available to our
290community.
291
292Some kinds of limits on the way modification is handled are
293acceptable. For example, requirements to preserve the original
294author's copyright notice, the distribution terms, or the list of
295authors, are ok. It is also no problem to require modified versions
296to include notice that they were modified. Even entire sections that
297may not be deleted or changed are acceptable, as long as they deal
298with nontechnical topics (like this one). These kinds of restrictions
299are acceptable because they don't obstruct the community's normal use
300of the manual.
301
302However, it must be possible to modify all the @emph{technical}
303content of the manual, and then distribute the result in all the usual
304media, through all the usual channels. Otherwise, the restrictions
305obstruct the use of the manual, it is not free, and we need another
306manual to replace it.
307
308Please spread the word about this issue. Our community continues to
309lose manuals to proprietary publishing. If we spread the word that
310free software needs free reference manuals and free tutorials, perhaps
311the next person who wants to contribute by writing documentation will
312realize, before it is too late, that only free manuals contribute to
313the free software community.
314
315If you are writing documentation, please insist on publishing it under
316the GNU Free Documentation License or another free documentation
317license. Remember that this decision requires your approval---you
318don't have to let the publisher decide. Some commercial publishers
319will use a free license if you insist, but they will not propose the
320option; it is up to you to raise the issue and say firmly that this is
321what you want. If the publisher you are dealing with refuses, please
322try other publishers. If you're not sure whether a proposed license
42584a72 323is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
324
325You can encourage commercial publishers to sell more free, copylefted
326manuals and tutorials by buying them, and particularly by buying
327copies from the publishers that paid for their writing or for major
328improvements. Meanwhile, try to avoid buying non-free documentation
329at all. Check the distribution terms of a manual before you buy it,
330and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
331Check the history of the book, and try to reward the publishers that
332have paid or pay the authors to work on it.
959acfd1
EZ
333
334The Free Software Foundation maintains a list of free documentation
335published by other publishers, at
336@url{http://www.fsf.org/doc/other-free-books.html}.
337
6d2ebf8b 338@node Contributors
96a2c332
SS
339@unnumberedsec Contributors to @value{GDBN}
340
341Richard Stallman was the original author of @value{GDBN}, and of many
342other @sc{gnu} programs. Many others have contributed to its
343development. This section attempts to credit major contributors. One
344of the virtues of free software is that everyone is free to contribute
345to it; with regret, we cannot actually acknowledge everyone here. The
346file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
347blow-by-blow account.
348
349Changes much prior to version 2.0 are lost in the mists of time.
350
351@quotation
352@emph{Plea:} Additions to this section are particularly welcome. If you
353or your friends (or enemies, to be evenhanded) have been unfairly
354omitted from this list, we would like to add your names!
355@end quotation
356
357So that they may not regard their many labors as thankless, we
358particularly thank those who shepherded @value{GDBN} through major
359releases:
7ba3cf9c 360Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
361Jim Blandy (release 4.18);
362Jason Molenda (release 4.17);
363Stan Shebs (release 4.14);
364Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
365Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
366John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
367Jim Kingdon (releases 3.5, 3.4, and 3.3);
368and Randy Smith (releases 3.2, 3.1, and 3.0).
369
370Richard Stallman, assisted at various times by Peter TerMaat, Chris
371Hanson, and Richard Mlynarik, handled releases through 2.8.
372
b37052ae
EZ
373Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
374in @value{GDBN}, with significant additional contributions from Per
375Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
376demangler. Early work on C@t{++} was by Peter TerMaat (who also did
377much general update work leading to release 3.0).
c906108c 378
b37052ae 379@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
380object-file formats; BFD was a joint project of David V.
381Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
382
383David Johnson wrote the original COFF support; Pace Willison did
384the original support for encapsulated COFF.
385
0179ffac 386Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
387
388Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
389Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
390support.
391Jean-Daniel Fekete contributed Sun 386i support.
392Chris Hanson improved the HP9000 support.
393Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
394David Johnson contributed Encore Umax support.
395Jyrki Kuoppala contributed Altos 3068 support.
396Jeff Law contributed HP PA and SOM support.
397Keith Packard contributed NS32K support.
398Doug Rabson contributed Acorn Risc Machine support.
399Bob Rusk contributed Harris Nighthawk CX-UX support.
400Chris Smith contributed Convex support (and Fortran debugging).
401Jonathan Stone contributed Pyramid support.
402Michael Tiemann contributed SPARC support.
403Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
404Pace Willison contributed Intel 386 support.
405Jay Vosburgh contributed Symmetry support.
a37295f9 406Marko Mlinar contributed OpenRISC 1000 support.
c906108c 407
1104b9e7 408Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
409
410Rich Schaefer and Peter Schauer helped with support of SunOS shared
411libraries.
412
413Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
414about several machine instruction sets.
415
416Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
417remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
418contributed remote debugging modules for the i960, VxWorks, A29K UDI,
419and RDI targets, respectively.
420
421Brian Fox is the author of the readline libraries providing
422command-line editing and command history.
423
7a292a7a
SS
424Andrew Beers of SUNY Buffalo wrote the language-switching code, the
425Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 426
5d161b24 427Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 428He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 429symbols.
c906108c 430
f24c5e49
KI
431Hitachi America (now Renesas America), Ltd. sponsored the support for
432H8/300, H8/500, and Super-H processors.
c906108c
SS
433
434NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
435
f24c5e49
KI
436Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
437processors.
c906108c
SS
438
439Toshiba sponsored the support for the TX39 Mips processor.
440
441Matsushita sponsored the support for the MN10200 and MN10300 processors.
442
96a2c332 443Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
444
445Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
446watchpoints.
447
448Michael Snyder added support for tracepoints.
449
450Stu Grossman wrote gdbserver.
451
452Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 453nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
454
455The following people at the Hewlett-Packard Company contributed
456support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 457(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
458compiler, and the Text User Interface (nee Terminal User Interface):
459Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
460Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
461provided HP-specific information in this manual.
c906108c 462
b37052ae
EZ
463DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
464Robert Hoehne made significant contributions to the DJGPP port.
465
96a2c332
SS
466Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
467development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
468fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
469Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
470Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
471Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
472Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
473addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
474JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
475Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
476Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
477Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
478Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
479Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
480Zuhn have made contributions both large and small.
c906108c 481
ffed4509
AC
482Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
483Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
484
e2e0bcd1
JB
485Jim Blandy added support for preprocessor macros, while working for Red
486Hat.
c906108c 487
a9967aef
AC
488Andrew Cagney designed @value{GDBN}'s architecture vector. Many
489people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
490Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
491Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
492Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
493with the migration of old architectures to this new framework.
494
c5e30d01
AC
495Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
496unwinder framework, this consisting of a fresh new design featuring
497frame IDs, independent frame sniffers, and the sentinel frame. Mark
498Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
499libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 500trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
501complete rewrite of the architecture's frame code, were carried out by
502Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
503Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
504Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
505Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
506Weigand.
507
ca3bf3bd
DJ
508Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
509Tensilica, Inc.@: contributed support for Xtensa processors. Others
510who have worked on the Xtensa port of @value{GDBN} in the past include
511Steve Tjiang, John Newlin, and Scott Foehner.
512
6d2ebf8b 513@node Sample Session
c906108c
SS
514@chapter A Sample @value{GDBN} Session
515
516You can use this manual at your leisure to read all about @value{GDBN}.
517However, a handful of commands are enough to get started using the
518debugger. This chapter illustrates those commands.
519
520@iftex
521In this sample session, we emphasize user input like this: @b{input},
522to make it easier to pick out from the surrounding output.
523@end iftex
524
525@c FIXME: this example may not be appropriate for some configs, where
526@c FIXME...primary interest is in remote use.
527
528One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
529processor) exhibits the following bug: sometimes, when we change its
530quote strings from the default, the commands used to capture one macro
531definition within another stop working. In the following short @code{m4}
532session, we define a macro @code{foo} which expands to @code{0000}; we
533then use the @code{m4} built-in @code{defn} to define @code{bar} as the
534same thing. However, when we change the open quote string to
535@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
536procedure fails to define a new synonym @code{baz}:
537
538@smallexample
539$ @b{cd gnu/m4}
540$ @b{./m4}
541@b{define(foo,0000)}
542
543@b{foo}
5440000
545@b{define(bar,defn(`foo'))}
546
547@b{bar}
5480000
549@b{changequote(<QUOTE>,<UNQUOTE>)}
550
551@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
552@b{baz}
c8aa23ab 553@b{Ctrl-d}
c906108c
SS
554m4: End of input: 0: fatal error: EOF in string
555@end smallexample
556
557@noindent
558Let us use @value{GDBN} to try to see what is going on.
559
c906108c
SS
560@smallexample
561$ @b{@value{GDBP} m4}
562@c FIXME: this falsifies the exact text played out, to permit smallbook
563@c FIXME... format to come out better.
564@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 565 of it under certain conditions; type "show copying" to see
c906108c 566 the conditions.
5d161b24 567There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
568 for details.
569
570@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
571(@value{GDBP})
572@end smallexample
c906108c
SS
573
574@noindent
575@value{GDBN} reads only enough symbol data to know where to find the
576rest when needed; as a result, the first prompt comes up very quickly.
577We now tell @value{GDBN} to use a narrower display width than usual, so
578that examples fit in this manual.
579
580@smallexample
581(@value{GDBP}) @b{set width 70}
582@end smallexample
583
584@noindent
585We need to see how the @code{m4} built-in @code{changequote} works.
586Having looked at the source, we know the relevant subroutine is
587@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
588@code{break} command.
589
590@smallexample
591(@value{GDBP}) @b{break m4_changequote}
592Breakpoint 1 at 0x62f4: file builtin.c, line 879.
593@end smallexample
594
595@noindent
596Using the @code{run} command, we start @code{m4} running under @value{GDBN}
597control; as long as control does not reach the @code{m4_changequote}
598subroutine, the program runs as usual:
599
600@smallexample
601(@value{GDBP}) @b{run}
602Starting program: /work/Editorial/gdb/gnu/m4/m4
603@b{define(foo,0000)}
604
605@b{foo}
6060000
607@end smallexample
608
609@noindent
610To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
611suspends execution of @code{m4}, displaying information about the
612context where it stops.
613
614@smallexample
615@b{changequote(<QUOTE>,<UNQUOTE>)}
616
5d161b24 617Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
618 at builtin.c:879
619879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
620@end smallexample
621
622@noindent
623Now we use the command @code{n} (@code{next}) to advance execution to
624the next line of the current function.
625
626@smallexample
627(@value{GDBP}) @b{n}
628882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
629 : nil,
630@end smallexample
631
632@noindent
633@code{set_quotes} looks like a promising subroutine. We can go into it
634by using the command @code{s} (@code{step}) instead of @code{next}.
635@code{step} goes to the next line to be executed in @emph{any}
636subroutine, so it steps into @code{set_quotes}.
637
638@smallexample
639(@value{GDBP}) @b{s}
640set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
641 at input.c:530
642530 if (lquote != def_lquote)
643@end smallexample
644
645@noindent
646The display that shows the subroutine where @code{m4} is now
647suspended (and its arguments) is called a stack frame display. It
648shows a summary of the stack. We can use the @code{backtrace}
649command (which can also be spelled @code{bt}), to see where we are
650in the stack as a whole: the @code{backtrace} command displays a
651stack frame for each active subroutine.
652
653@smallexample
654(@value{GDBP}) @b{bt}
655#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
656 at input.c:530
5d161b24 657#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
658 at builtin.c:882
659#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
660#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
661 at macro.c:71
662#4 0x79dc in expand_input () at macro.c:40
663#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
664@end smallexample
665
666@noindent
667We step through a few more lines to see what happens. The first two
668times, we can use @samp{s}; the next two times we use @code{n} to avoid
669falling into the @code{xstrdup} subroutine.
670
671@smallexample
672(@value{GDBP}) @b{s}
6730x3b5c 532 if (rquote != def_rquote)
674(@value{GDBP}) @b{s}
6750x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
676def_lquote : xstrdup(lq);
677(@value{GDBP}) @b{n}
678536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
679 : xstrdup(rq);
680(@value{GDBP}) @b{n}
681538 len_lquote = strlen(rquote);
682@end smallexample
683
684@noindent
685The last line displayed looks a little odd; we can examine the variables
686@code{lquote} and @code{rquote} to see if they are in fact the new left
687and right quotes we specified. We use the command @code{p}
688(@code{print}) to see their values.
689
690@smallexample
691(@value{GDBP}) @b{p lquote}
692$1 = 0x35d40 "<QUOTE>"
693(@value{GDBP}) @b{p rquote}
694$2 = 0x35d50 "<UNQUOTE>"
695@end smallexample
696
697@noindent
698@code{lquote} and @code{rquote} are indeed the new left and right quotes.
699To look at some context, we can display ten lines of source
700surrounding the current line with the @code{l} (@code{list}) command.
701
702@smallexample
703(@value{GDBP}) @b{l}
704533 xfree(rquote);
705534
706535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
707 : xstrdup (lq);
708536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
709 : xstrdup (rq);
710537
711538 len_lquote = strlen(rquote);
712539 len_rquote = strlen(lquote);
713540 @}
714541
715542 void
716@end smallexample
717
718@noindent
719Let us step past the two lines that set @code{len_lquote} and
720@code{len_rquote}, and then examine the values of those variables.
721
722@smallexample
723(@value{GDBP}) @b{n}
724539 len_rquote = strlen(lquote);
725(@value{GDBP}) @b{n}
726540 @}
727(@value{GDBP}) @b{p len_lquote}
728$3 = 9
729(@value{GDBP}) @b{p len_rquote}
730$4 = 7
731@end smallexample
732
733@noindent
734That certainly looks wrong, assuming @code{len_lquote} and
735@code{len_rquote} are meant to be the lengths of @code{lquote} and
736@code{rquote} respectively. We can set them to better values using
737the @code{p} command, since it can print the value of
738any expression---and that expression can include subroutine calls and
739assignments.
740
741@smallexample
742(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
743$5 = 7
744(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
745$6 = 9
746@end smallexample
747
748@noindent
749Is that enough to fix the problem of using the new quotes with the
750@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
751executing with the @code{c} (@code{continue}) command, and then try the
752example that caused trouble initially:
753
754@smallexample
755(@value{GDBP}) @b{c}
756Continuing.
757
758@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
759
760baz
7610000
762@end smallexample
763
764@noindent
765Success! The new quotes now work just as well as the default ones. The
766problem seems to have been just the two typos defining the wrong
767lengths. We allow @code{m4} exit by giving it an EOF as input:
768
769@smallexample
c8aa23ab 770@b{Ctrl-d}
c906108c
SS
771Program exited normally.
772@end smallexample
773
774@noindent
775The message @samp{Program exited normally.} is from @value{GDBN}; it
776indicates @code{m4} has finished executing. We can end our @value{GDBN}
777session with the @value{GDBN} @code{quit} command.
778
779@smallexample
780(@value{GDBP}) @b{quit}
781@end smallexample
c906108c 782
6d2ebf8b 783@node Invocation
c906108c
SS
784@chapter Getting In and Out of @value{GDBN}
785
786This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 787The essentials are:
c906108c 788@itemize @bullet
5d161b24 789@item
53a5351d 790type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 791@item
c8aa23ab 792type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
793@end itemize
794
795@menu
796* Invoking GDB:: How to start @value{GDBN}
797* Quitting GDB:: How to quit @value{GDBN}
798* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 799* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
800@end menu
801
6d2ebf8b 802@node Invoking GDB
c906108c
SS
803@section Invoking @value{GDBN}
804
c906108c
SS
805Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
806@value{GDBN} reads commands from the terminal until you tell it to exit.
807
808You can also run @code{@value{GDBP}} with a variety of arguments and options,
809to specify more of your debugging environment at the outset.
810
c906108c
SS
811The command-line options described here are designed
812to cover a variety of situations; in some environments, some of these
5d161b24 813options may effectively be unavailable.
c906108c
SS
814
815The most usual way to start @value{GDBN} is with one argument,
816specifying an executable program:
817
474c8240 818@smallexample
c906108c 819@value{GDBP} @var{program}
474c8240 820@end smallexample
c906108c 821
c906108c
SS
822@noindent
823You can also start with both an executable program and a core file
824specified:
825
474c8240 826@smallexample
c906108c 827@value{GDBP} @var{program} @var{core}
474c8240 828@end smallexample
c906108c
SS
829
830You can, instead, specify a process ID as a second argument, if you want
831to debug a running process:
832
474c8240 833@smallexample
c906108c 834@value{GDBP} @var{program} 1234
474c8240 835@end smallexample
c906108c
SS
836
837@noindent
838would attach @value{GDBN} to process @code{1234} (unless you also have a file
839named @file{1234}; @value{GDBN} does check for a core file first).
840
c906108c 841Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
842complete operating system; when you use @value{GDBN} as a remote
843debugger attached to a bare board, there may not be any notion of
844``process'', and there is often no way to get a core dump. @value{GDBN}
845will warn you if it is unable to attach or to read core dumps.
c906108c 846
aa26fa3a
TT
847You can optionally have @code{@value{GDBP}} pass any arguments after the
848executable file to the inferior using @code{--args}. This option stops
849option processing.
474c8240 850@smallexample
3f94c067 851@value{GDBP} --args gcc -O2 -c foo.c
474c8240 852@end smallexample
aa26fa3a
TT
853This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
854@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
855
96a2c332 856You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
857@value{GDBN}'s non-warranty, by specifying @code{-silent}:
858
859@smallexample
860@value{GDBP} -silent
861@end smallexample
862
863@noindent
864You can further control how @value{GDBN} starts up by using command-line
865options. @value{GDBN} itself can remind you of the options available.
866
867@noindent
868Type
869
474c8240 870@smallexample
c906108c 871@value{GDBP} -help
474c8240 872@end smallexample
c906108c
SS
873
874@noindent
875to display all available options and briefly describe their use
876(@samp{@value{GDBP} -h} is a shorter equivalent).
877
878All options and command line arguments you give are processed
879in sequential order. The order makes a difference when the
880@samp{-x} option is used.
881
882
883@menu
c906108c
SS
884* File Options:: Choosing files
885* Mode Options:: Choosing modes
6fc08d32 886* Startup:: What @value{GDBN} does during startup
c906108c
SS
887@end menu
888
6d2ebf8b 889@node File Options
79a6e687 890@subsection Choosing Files
c906108c 891
2df3850c 892When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
893specifying an executable file and core file (or process ID). This is
894the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 895@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
896first argument that does not have an associated option flag as
897equivalent to the @samp{-se} option followed by that argument; and the
898second argument that does not have an associated option flag, if any, as
899equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
900If the second argument begins with a decimal digit, @value{GDBN} will
901first attempt to attach to it as a process, and if that fails, attempt
902to open it as a corefile. If you have a corefile whose name begins with
b383017d 903a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 904prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
905
906If @value{GDBN} has not been configured to included core file support,
907such as for most embedded targets, then it will complain about a second
908argument and ignore it.
c906108c
SS
909
910Many options have both long and short forms; both are shown in the
911following list. @value{GDBN} also recognizes the long forms if you truncate
912them, so long as enough of the option is present to be unambiguous.
913(If you prefer, you can flag option arguments with @samp{--} rather
914than @samp{-}, though we illustrate the more usual convention.)
915
d700128c
EZ
916@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
917@c way, both those who look for -foo and --foo in the index, will find
918@c it.
919
c906108c
SS
920@table @code
921@item -symbols @var{file}
922@itemx -s @var{file}
d700128c
EZ
923@cindex @code{--symbols}
924@cindex @code{-s}
c906108c
SS
925Read symbol table from file @var{file}.
926
927@item -exec @var{file}
928@itemx -e @var{file}
d700128c
EZ
929@cindex @code{--exec}
930@cindex @code{-e}
7a292a7a
SS
931Use file @var{file} as the executable file to execute when appropriate,
932and for examining pure data in conjunction with a core dump.
c906108c
SS
933
934@item -se @var{file}
d700128c 935@cindex @code{--se}
c906108c
SS
936Read symbol table from file @var{file} and use it as the executable
937file.
938
c906108c
SS
939@item -core @var{file}
940@itemx -c @var{file}
d700128c
EZ
941@cindex @code{--core}
942@cindex @code{-c}
b383017d 943Use file @var{file} as a core dump to examine.
c906108c
SS
944
945@item -c @var{number}
19837790
MS
946@item -pid @var{number}
947@itemx -p @var{number}
948@cindex @code{--pid}
949@cindex @code{-p}
950Connect to process ID @var{number}, as with the @code{attach} command.
951If there is no such process, @value{GDBN} will attempt to open a core
952file named @var{number}.
c906108c
SS
953
954@item -command @var{file}
955@itemx -x @var{file}
d700128c
EZ
956@cindex @code{--command}
957@cindex @code{-x}
c906108c
SS
958Execute @value{GDBN} commands from file @var{file}. @xref{Command
959Files,, Command files}.
960
8a5a3c82
AS
961@item -eval-command @var{command}
962@itemx -ex @var{command}
963@cindex @code{--eval-command}
964@cindex @code{-ex}
965Execute a single @value{GDBN} command.
966
967This option may be used multiple times to call multiple commands. It may
968also be interleaved with @samp{-command} as required.
969
970@smallexample
971@value{GDBP} -ex 'target sim' -ex 'load' \
972 -x setbreakpoints -ex 'run' a.out
973@end smallexample
974
c906108c
SS
975@item -directory @var{directory}
976@itemx -d @var{directory}
d700128c
EZ
977@cindex @code{--directory}
978@cindex @code{-d}
4b505b12 979Add @var{directory} to the path to search for source and script files.
c906108c 980
c906108c
SS
981@item -r
982@itemx -readnow
d700128c
EZ
983@cindex @code{--readnow}
984@cindex @code{-r}
c906108c
SS
985Read each symbol file's entire symbol table immediately, rather than
986the default, which is to read it incrementally as it is needed.
987This makes startup slower, but makes future operations faster.
53a5351d 988
c906108c
SS
989@end table
990
6d2ebf8b 991@node Mode Options
79a6e687 992@subsection Choosing Modes
c906108c
SS
993
994You can run @value{GDBN} in various alternative modes---for example, in
995batch mode or quiet mode.
996
997@table @code
998@item -nx
999@itemx -n
d700128c
EZ
1000@cindex @code{--nx}
1001@cindex @code{-n}
96565e91 1002Do not execute commands found in any initialization files. Normally,
2df3850c
JM
1003@value{GDBN} executes the commands in these files after all the command
1004options and arguments have been processed. @xref{Command Files,,Command
79a6e687 1005Files}.
c906108c
SS
1006
1007@item -quiet
d700128c 1008@itemx -silent
c906108c 1009@itemx -q
d700128c
EZ
1010@cindex @code{--quiet}
1011@cindex @code{--silent}
1012@cindex @code{-q}
c906108c
SS
1013``Quiet''. Do not print the introductory and copyright messages. These
1014messages are also suppressed in batch mode.
1015
1016@item -batch
d700128c 1017@cindex @code{--batch}
c906108c
SS
1018Run in batch mode. Exit with status @code{0} after processing all the
1019command files specified with @samp{-x} (and all commands from
1020initialization files, if not inhibited with @samp{-n}). Exit with
1021nonzero status if an error occurs in executing the @value{GDBN} commands
1022in the command files.
1023
2df3850c
JM
1024Batch mode may be useful for running @value{GDBN} as a filter, for
1025example to download and run a program on another computer; in order to
1026make this more useful, the message
c906108c 1027
474c8240 1028@smallexample
c906108c 1029Program exited normally.
474c8240 1030@end smallexample
c906108c
SS
1031
1032@noindent
2df3850c
JM
1033(which is ordinarily issued whenever a program running under
1034@value{GDBN} control terminates) is not issued when running in batch
1035mode.
1036
1a088d06
AS
1037@item -batch-silent
1038@cindex @code{--batch-silent}
1039Run in batch mode exactly like @samp{-batch}, but totally silently. All
1040@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1041unaffected). This is much quieter than @samp{-silent} and would be useless
1042for an interactive session.
1043
1044This is particularly useful when using targets that give @samp{Loading section}
1045messages, for example.
1046
1047Note that targets that give their output via @value{GDBN}, as opposed to
1048writing directly to @code{stdout}, will also be made silent.
1049
4b0ad762
AS
1050@item -return-child-result
1051@cindex @code{--return-child-result}
1052The return code from @value{GDBN} will be the return code from the child
1053process (the process being debugged), with the following exceptions:
1054
1055@itemize @bullet
1056@item
1057@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1058internal error. In this case the exit code is the same as it would have been
1059without @samp{-return-child-result}.
1060@item
1061The user quits with an explicit value. E.g., @samp{quit 1}.
1062@item
1063The child process never runs, or is not allowed to terminate, in which case
1064the exit code will be -1.
1065@end itemize
1066
1067This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1068when @value{GDBN} is being used as a remote program loader or simulator
1069interface.
1070
2df3850c
JM
1071@item -nowindows
1072@itemx -nw
d700128c
EZ
1073@cindex @code{--nowindows}
1074@cindex @code{-nw}
2df3850c 1075``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1076(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1077interface. If no GUI is available, this option has no effect.
1078
1079@item -windows
1080@itemx -w
d700128c
EZ
1081@cindex @code{--windows}
1082@cindex @code{-w}
2df3850c
JM
1083If @value{GDBN} includes a GUI, then this option requires it to be
1084used if possible.
c906108c
SS
1085
1086@item -cd @var{directory}
d700128c 1087@cindex @code{--cd}
c906108c
SS
1088Run @value{GDBN} using @var{directory} as its working directory,
1089instead of the current directory.
1090
c906108c
SS
1091@item -fullname
1092@itemx -f
d700128c
EZ
1093@cindex @code{--fullname}
1094@cindex @code{-f}
7a292a7a
SS
1095@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1096subprocess. It tells @value{GDBN} to output the full file name and line
1097number in a standard, recognizable fashion each time a stack frame is
1098displayed (which includes each time your program stops). This
1099recognizable format looks like two @samp{\032} characters, followed by
1100the file name, line number and character position separated by colons,
1101and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1102@samp{\032} characters as a signal to display the source code for the
1103frame.
c906108c 1104
d700128c
EZ
1105@item -epoch
1106@cindex @code{--epoch}
1107The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1108@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1109routines so as to allow Epoch to display values of expressions in a
1110separate window.
1111
1112@item -annotate @var{level}
1113@cindex @code{--annotate}
1114This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1115effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1116(@pxref{Annotations}). The annotation @var{level} controls how much
1117information @value{GDBN} prints together with its prompt, values of
1118expressions, source lines, and other types of output. Level 0 is the
1119normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1120@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1121that control @value{GDBN}, and level 2 has been deprecated.
1122
265eeb58 1123The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1124(@pxref{GDB/MI}).
d700128c 1125
aa26fa3a
TT
1126@item --args
1127@cindex @code{--args}
1128Change interpretation of command line so that arguments following the
1129executable file are passed as command line arguments to the inferior.
1130This option stops option processing.
1131
2df3850c
JM
1132@item -baud @var{bps}
1133@itemx -b @var{bps}
d700128c
EZ
1134@cindex @code{--baud}
1135@cindex @code{-b}
c906108c
SS
1136Set the line speed (baud rate or bits per second) of any serial
1137interface used by @value{GDBN} for remote debugging.
c906108c 1138
f47b1503
AS
1139@item -l @var{timeout}
1140@cindex @code{-l}
1141Set the timeout (in seconds) of any communication used by @value{GDBN}
1142for remote debugging.
1143
c906108c 1144@item -tty @var{device}
d700128c
EZ
1145@itemx -t @var{device}
1146@cindex @code{--tty}
1147@cindex @code{-t}
c906108c
SS
1148Run using @var{device} for your program's standard input and output.
1149@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1150
53a5351d 1151@c resolve the situation of these eventually
c4555f82
SC
1152@item -tui
1153@cindex @code{--tui}
d0d5df6f
AC
1154Activate the @dfn{Text User Interface} when starting. The Text User
1155Interface manages several text windows on the terminal, showing
1156source, assembly, registers and @value{GDBN} command outputs
1157(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1158Text User Interface can be enabled by invoking the program
46ba6afa 1159@samp{@value{GDBTUI}}. Do not use this option if you run @value{GDBN} from
d0d5df6f 1160Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1161
1162@c @item -xdb
d700128c 1163@c @cindex @code{--xdb}
53a5351d
JM
1164@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1165@c For information, see the file @file{xdb_trans.html}, which is usually
1166@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1167@c systems.
1168
d700128c
EZ
1169@item -interpreter @var{interp}
1170@cindex @code{--interpreter}
1171Use the interpreter @var{interp} for interface with the controlling
1172program or device. This option is meant to be set by programs which
94bbb2c0 1173communicate with @value{GDBN} using it as a back end.
21c294e6 1174@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1175
da0f9dcd 1176@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1177@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1178The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1179previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1180selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1181@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1182
1183@item -write
1184@cindex @code{--write}
1185Open the executable and core files for both reading and writing. This
1186is equivalent to the @samp{set write on} command inside @value{GDBN}
1187(@pxref{Patching}).
1188
1189@item -statistics
1190@cindex @code{--statistics}
1191This option causes @value{GDBN} to print statistics about time and
1192memory usage after it completes each command and returns to the prompt.
1193
1194@item -version
1195@cindex @code{--version}
1196This option causes @value{GDBN} to print its version number and
1197no-warranty blurb, and exit.
1198
c906108c
SS
1199@end table
1200
6fc08d32 1201@node Startup
79a6e687 1202@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1203@cindex @value{GDBN} startup
1204
1205Here's the description of what @value{GDBN} does during session startup:
1206
1207@enumerate
1208@item
1209Sets up the command interpreter as specified by the command line
1210(@pxref{Mode Options, interpreter}).
1211
1212@item
1213@cindex init file
1214Reads the @dfn{init file} (if any) in your home directory@footnote{On
1215DOS/Windows systems, the home directory is the one pointed to by the
1216@code{HOME} environment variable.} and executes all the commands in
1217that file.
1218
1219@item
1220Processes command line options and operands.
1221
1222@item
1223Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1224working directory. This is only done if the current directory is
1225different from your home directory. Thus, you can have more than one
1226init file, one generic in your home directory, and another, specific
1227to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1228@value{GDBN}.
1229
1230@item
1231Reads command files specified by the @samp{-x} option. @xref{Command
1232Files}, for more details about @value{GDBN} command files.
1233
1234@item
1235Reads the command history recorded in the @dfn{history file}.
d620b259 1236@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1237files where @value{GDBN} records it.
1238@end enumerate
1239
1240Init files use the same syntax as @dfn{command files} (@pxref{Command
1241Files}) and are processed by @value{GDBN} in the same way. The init
1242file in your home directory can set options (such as @samp{set
1243complaints}) that affect subsequent processing of command line options
1244and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1245option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32
EZ
1246
1247@cindex init file name
1248@cindex @file{.gdbinit}
119b882a 1249@cindex @file{gdb.ini}
8807d78b 1250The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1251The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1252the limitations of file names imposed by DOS filesystems. The Windows
1253ports of @value{GDBN} use the standard name, but if they find a
1254@file{gdb.ini} file, they warn you about that and suggest to rename
1255the file to the standard name.
1256
6fc08d32 1257
6d2ebf8b 1258@node Quitting GDB
c906108c
SS
1259@section Quitting @value{GDBN}
1260@cindex exiting @value{GDBN}
1261@cindex leaving @value{GDBN}
1262
1263@table @code
1264@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1265@kindex q @r{(@code{quit})}
96a2c332
SS
1266@item quit @r{[}@var{expression}@r{]}
1267@itemx q
1268To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1269@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1270do not supply @var{expression}, @value{GDBN} will terminate normally;
1271otherwise it will terminate using the result of @var{expression} as the
1272error code.
c906108c
SS
1273@end table
1274
1275@cindex interrupt
c8aa23ab 1276An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1277terminates the action of any @value{GDBN} command that is in progress and
1278returns to @value{GDBN} command level. It is safe to type the interrupt
1279character at any time because @value{GDBN} does not allow it to take effect
1280until a time when it is safe.
1281
c906108c
SS
1282If you have been using @value{GDBN} to control an attached process or
1283device, you can release it with the @code{detach} command
79a6e687 1284(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1285
6d2ebf8b 1286@node Shell Commands
79a6e687 1287@section Shell Commands
c906108c
SS
1288
1289If you need to execute occasional shell commands during your
1290debugging session, there is no need to leave or suspend @value{GDBN}; you can
1291just use the @code{shell} command.
1292
1293@table @code
1294@kindex shell
1295@cindex shell escape
1296@item shell @var{command string}
1297Invoke a standard shell to execute @var{command string}.
c906108c 1298If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1299shell to run. Otherwise @value{GDBN} uses the default shell
1300(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1301@end table
1302
1303The utility @code{make} is often needed in development environments.
1304You do not have to use the @code{shell} command for this purpose in
1305@value{GDBN}:
1306
1307@table @code
1308@kindex make
1309@cindex calling make
1310@item make @var{make-args}
1311Execute the @code{make} program with the specified
1312arguments. This is equivalent to @samp{shell make @var{make-args}}.
1313@end table
1314
79a6e687
BW
1315@node Logging Output
1316@section Logging Output
0fac0b41 1317@cindex logging @value{GDBN} output
9c16f35a 1318@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1319
1320You may want to save the output of @value{GDBN} commands to a file.
1321There are several commands to control @value{GDBN}'s logging.
1322
1323@table @code
1324@kindex set logging
1325@item set logging on
1326Enable logging.
1327@item set logging off
1328Disable logging.
9c16f35a 1329@cindex logging file name
0fac0b41
DJ
1330@item set logging file @var{file}
1331Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1332@item set logging overwrite [on|off]
1333By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1334you want @code{set logging on} to overwrite the logfile instead.
1335@item set logging redirect [on|off]
1336By default, @value{GDBN} output will go to both the terminal and the logfile.
1337Set @code{redirect} if you want output to go only to the log file.
1338@kindex show logging
1339@item show logging
1340Show the current values of the logging settings.
1341@end table
1342
6d2ebf8b 1343@node Commands
c906108c
SS
1344@chapter @value{GDBN} Commands
1345
1346You can abbreviate a @value{GDBN} command to the first few letters of the command
1347name, if that abbreviation is unambiguous; and you can repeat certain
1348@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1349key to get @value{GDBN} to fill out the rest of a word in a command (or to
1350show you the alternatives available, if there is more than one possibility).
1351
1352@menu
1353* Command Syntax:: How to give commands to @value{GDBN}
1354* Completion:: Command completion
1355* Help:: How to ask @value{GDBN} for help
1356@end menu
1357
6d2ebf8b 1358@node Command Syntax
79a6e687 1359@section Command Syntax
c906108c
SS
1360
1361A @value{GDBN} command is a single line of input. There is no limit on
1362how long it can be. It starts with a command name, which is followed by
1363arguments whose meaning depends on the command name. For example, the
1364command @code{step} accepts an argument which is the number of times to
1365step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1366with no arguments. Some commands do not allow any arguments.
c906108c
SS
1367
1368@cindex abbreviation
1369@value{GDBN} command names may always be truncated if that abbreviation is
1370unambiguous. Other possible command abbreviations are listed in the
1371documentation for individual commands. In some cases, even ambiguous
1372abbreviations are allowed; for example, @code{s} is specially defined as
1373equivalent to @code{step} even though there are other commands whose
1374names start with @code{s}. You can test abbreviations by using them as
1375arguments to the @code{help} command.
1376
1377@cindex repeating commands
41afff9a 1378@kindex RET @r{(repeat last command)}
c906108c 1379A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1380repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1381will not repeat this way; these are commands whose unintentional
1382repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1383repeat. User-defined commands can disable this feature; see
1384@ref{Define, dont-repeat}.
c906108c
SS
1385
1386The @code{list} and @code{x} commands, when you repeat them with
1387@key{RET}, construct new arguments rather than repeating
1388exactly as typed. This permits easy scanning of source or memory.
1389
1390@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1391output, in a way similar to the common utility @code{more}
79a6e687 1392(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1393@key{RET} too many in this situation, @value{GDBN} disables command
1394repetition after any command that generates this sort of display.
1395
41afff9a 1396@kindex # @r{(a comment)}
c906108c
SS
1397@cindex comment
1398Any text from a @kbd{#} to the end of the line is a comment; it does
1399nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1400Files,,Command Files}).
c906108c 1401
88118b3a 1402@cindex repeating command sequences
c8aa23ab
EZ
1403@kindex Ctrl-o @r{(operate-and-get-next)}
1404The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1405commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1406then fetches the next line relative to the current line from the history
1407for editing.
1408
6d2ebf8b 1409@node Completion
79a6e687 1410@section Command Completion
c906108c
SS
1411
1412@cindex completion
1413@cindex word completion
1414@value{GDBN} can fill in the rest of a word in a command for you, if there is
1415only one possibility; it can also show you what the valid possibilities
1416are for the next word in a command, at any time. This works for @value{GDBN}
1417commands, @value{GDBN} subcommands, and the names of symbols in your program.
1418
1419Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1420of a word. If there is only one possibility, @value{GDBN} fills in the
1421word, and waits for you to finish the command (or press @key{RET} to
1422enter it). For example, if you type
1423
1424@c FIXME "@key" does not distinguish its argument sufficiently to permit
1425@c complete accuracy in these examples; space introduced for clarity.
1426@c If texinfo enhancements make it unnecessary, it would be nice to
1427@c replace " @key" by "@key" in the following...
474c8240 1428@smallexample
c906108c 1429(@value{GDBP}) info bre @key{TAB}
474c8240 1430@end smallexample
c906108c
SS
1431
1432@noindent
1433@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1434the only @code{info} subcommand beginning with @samp{bre}:
1435
474c8240 1436@smallexample
c906108c 1437(@value{GDBP}) info breakpoints
474c8240 1438@end smallexample
c906108c
SS
1439
1440@noindent
1441You can either press @key{RET} at this point, to run the @code{info
1442breakpoints} command, or backspace and enter something else, if
1443@samp{breakpoints} does not look like the command you expected. (If you
1444were sure you wanted @code{info breakpoints} in the first place, you
1445might as well just type @key{RET} immediately after @samp{info bre},
1446to exploit command abbreviations rather than command completion).
1447
1448If there is more than one possibility for the next word when you press
1449@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1450characters and try again, or just press @key{TAB} a second time;
1451@value{GDBN} displays all the possible completions for that word. For
1452example, you might want to set a breakpoint on a subroutine whose name
1453begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1454just sounds the bell. Typing @key{TAB} again displays all the
1455function names in your program that begin with those characters, for
1456example:
1457
474c8240 1458@smallexample
c906108c
SS
1459(@value{GDBP}) b make_ @key{TAB}
1460@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1461make_a_section_from_file make_environ
1462make_abs_section make_function_type
1463make_blockvector make_pointer_type
1464make_cleanup make_reference_type
c906108c
SS
1465make_command make_symbol_completion_list
1466(@value{GDBP}) b make_
474c8240 1467@end smallexample
c906108c
SS
1468
1469@noindent
1470After displaying the available possibilities, @value{GDBN} copies your
1471partial input (@samp{b make_} in the example) so you can finish the
1472command.
1473
1474If you just want to see the list of alternatives in the first place, you
b37052ae 1475can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1476means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1477key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1478one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1479
1480@cindex quotes in commands
1481@cindex completion of quoted strings
1482Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1483parentheses or other characters that @value{GDBN} normally excludes from
1484its notion of a word. To permit word completion to work in this
1485situation, you may enclose words in @code{'} (single quote marks) in
1486@value{GDBN} commands.
c906108c 1487
c906108c 1488The most likely situation where you might need this is in typing the
b37052ae
EZ
1489name of a C@t{++} function. This is because C@t{++} allows function
1490overloading (multiple definitions of the same function, distinguished
1491by argument type). For example, when you want to set a breakpoint you
1492may need to distinguish whether you mean the version of @code{name}
1493that takes an @code{int} parameter, @code{name(int)}, or the version
1494that takes a @code{float} parameter, @code{name(float)}. To use the
1495word-completion facilities in this situation, type a single quote
1496@code{'} at the beginning of the function name. This alerts
1497@value{GDBN} that it may need to consider more information than usual
1498when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1499
474c8240 1500@smallexample
96a2c332 1501(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1502bubble(double,double) bubble(int,int)
1503(@value{GDBP}) b 'bubble(
474c8240 1504@end smallexample
c906108c
SS
1505
1506In some cases, @value{GDBN} can tell that completing a name requires using
1507quotes. When this happens, @value{GDBN} inserts the quote for you (while
1508completing as much as it can) if you do not type the quote in the first
1509place:
1510
474c8240 1511@smallexample
c906108c
SS
1512(@value{GDBP}) b bub @key{TAB}
1513@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1514(@value{GDBP}) b 'bubble(
474c8240 1515@end smallexample
c906108c
SS
1516
1517@noindent
1518In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1519you have not yet started typing the argument list when you ask for
1520completion on an overloaded symbol.
1521
79a6e687
BW
1522For more information about overloaded functions, see @ref{C Plus Plus
1523Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1524overload-resolution off} to disable overload resolution;
79a6e687 1525see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c
SS
1526
1527
6d2ebf8b 1528@node Help
79a6e687 1529@section Getting Help
c906108c
SS
1530@cindex online documentation
1531@kindex help
1532
5d161b24 1533You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1534using the command @code{help}.
1535
1536@table @code
41afff9a 1537@kindex h @r{(@code{help})}
c906108c
SS
1538@item help
1539@itemx h
1540You can use @code{help} (abbreviated @code{h}) with no arguments to
1541display a short list of named classes of commands:
1542
1543@smallexample
1544(@value{GDBP}) help
1545List of classes of commands:
1546
2df3850c 1547aliases -- Aliases of other commands
c906108c 1548breakpoints -- Making program stop at certain points
2df3850c 1549data -- Examining data
c906108c 1550files -- Specifying and examining files
2df3850c
JM
1551internals -- Maintenance commands
1552obscure -- Obscure features
1553running -- Running the program
1554stack -- Examining the stack
c906108c
SS
1555status -- Status inquiries
1556support -- Support facilities
12c27660 1557tracepoints -- Tracing of program execution without
96a2c332 1558 stopping the program
c906108c 1559user-defined -- User-defined commands
c906108c 1560
5d161b24 1561Type "help" followed by a class name for a list of
c906108c 1562commands in that class.
5d161b24 1563Type "help" followed by command name for full
c906108c
SS
1564documentation.
1565Command name abbreviations are allowed if unambiguous.
1566(@value{GDBP})
1567@end smallexample
96a2c332 1568@c the above line break eliminates huge line overfull...
c906108c
SS
1569
1570@item help @var{class}
1571Using one of the general help classes as an argument, you can get a
1572list of the individual commands in that class. For example, here is the
1573help display for the class @code{status}:
1574
1575@smallexample
1576(@value{GDBP}) help status
1577Status inquiries.
1578
1579List of commands:
1580
1581@c Line break in "show" line falsifies real output, but needed
1582@c to fit in smallbook page size.
2df3850c 1583info -- Generic command for showing things
12c27660 1584 about the program being debugged
2df3850c 1585show -- Generic command for showing things
12c27660 1586 about the debugger
c906108c 1587
5d161b24 1588Type "help" followed by command name for full
c906108c
SS
1589documentation.
1590Command name abbreviations are allowed if unambiguous.
1591(@value{GDBP})
1592@end smallexample
1593
1594@item help @var{command}
1595With a command name as @code{help} argument, @value{GDBN} displays a
1596short paragraph on how to use that command.
1597
6837a0a2
DB
1598@kindex apropos
1599@item apropos @var{args}
09d4efe1 1600The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1601commands, and their documentation, for the regular expression specified in
1602@var{args}. It prints out all matches found. For example:
1603
1604@smallexample
1605apropos reload
1606@end smallexample
1607
b37052ae
EZ
1608@noindent
1609results in:
6837a0a2
DB
1610
1611@smallexample
6d2ebf8b
SS
1612@c @group
1613set symbol-reloading -- Set dynamic symbol table reloading
12c27660 1614 multiple times in one run
6d2ebf8b 1615show symbol-reloading -- Show dynamic symbol table reloading
12c27660 1616 multiple times in one run
6d2ebf8b 1617@c @end group
6837a0a2
DB
1618@end smallexample
1619
c906108c
SS
1620@kindex complete
1621@item complete @var{args}
1622The @code{complete @var{args}} command lists all the possible completions
1623for the beginning of a command. Use @var{args} to specify the beginning of the
1624command you want completed. For example:
1625
1626@smallexample
1627complete i
1628@end smallexample
1629
1630@noindent results in:
1631
1632@smallexample
1633@group
2df3850c
JM
1634if
1635ignore
c906108c
SS
1636info
1637inspect
c906108c
SS
1638@end group
1639@end smallexample
1640
1641@noindent This is intended for use by @sc{gnu} Emacs.
1642@end table
1643
1644In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1645and @code{show} to inquire about the state of your program, or the state
1646of @value{GDBN} itself. Each command supports many topics of inquiry; this
1647manual introduces each of them in the appropriate context. The listings
1648under @code{info} and under @code{show} in the Index point to
1649all the sub-commands. @xref{Index}.
1650
1651@c @group
1652@table @code
1653@kindex info
41afff9a 1654@kindex i @r{(@code{info})}
c906108c
SS
1655@item info
1656This command (abbreviated @code{i}) is for describing the state of your
1657program. For example, you can list the arguments given to your program
1658with @code{info args}, list the registers currently in use with @code{info
1659registers}, or list the breakpoints you have set with @code{info breakpoints}.
1660You can get a complete list of the @code{info} sub-commands with
1661@w{@code{help info}}.
1662
1663@kindex set
1664@item set
5d161b24 1665You can assign the result of an expression to an environment variable with
c906108c
SS
1666@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1667@code{set prompt $}.
1668
1669@kindex show
1670@item show
5d161b24 1671In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1672@value{GDBN} itself.
1673You can change most of the things you can @code{show}, by using the
1674related command @code{set}; for example, you can control what number
1675system is used for displays with @code{set radix}, or simply inquire
1676which is currently in use with @code{show radix}.
1677
1678@kindex info set
1679To display all the settable parameters and their current
1680values, you can use @code{show} with no arguments; you may also use
1681@code{info set}. Both commands produce the same display.
1682@c FIXME: "info set" violates the rule that "info" is for state of
1683@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1684@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1685@end table
1686@c @end group
1687
1688Here are three miscellaneous @code{show} subcommands, all of which are
1689exceptional in lacking corresponding @code{set} commands:
1690
1691@table @code
1692@kindex show version
9c16f35a 1693@cindex @value{GDBN} version number
c906108c
SS
1694@item show version
1695Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1696information in @value{GDBN} bug-reports. If multiple versions of
1697@value{GDBN} are in use at your site, you may need to determine which
1698version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1699commands are introduced, and old ones may wither away. Also, many
1700system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1701variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1702The version number is the same as the one announced when you start
1703@value{GDBN}.
c906108c
SS
1704
1705@kindex show copying
09d4efe1 1706@kindex info copying
9c16f35a 1707@cindex display @value{GDBN} copyright
c906108c 1708@item show copying
09d4efe1 1709@itemx info copying
c906108c
SS
1710Display information about permission for copying @value{GDBN}.
1711
1712@kindex show warranty
09d4efe1 1713@kindex info warranty
c906108c 1714@item show warranty
09d4efe1 1715@itemx info warranty
2df3850c 1716Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1717if your version of @value{GDBN} comes with one.
2df3850c 1718
c906108c
SS
1719@end table
1720
6d2ebf8b 1721@node Running
c906108c
SS
1722@chapter Running Programs Under @value{GDBN}
1723
1724When you run a program under @value{GDBN}, you must first generate
1725debugging information when you compile it.
7a292a7a
SS
1726
1727You may start @value{GDBN} with its arguments, if any, in an environment
1728of your choice. If you are doing native debugging, you may redirect
1729your program's input and output, debug an already running process, or
1730kill a child process.
c906108c
SS
1731
1732@menu
1733* Compilation:: Compiling for debugging
1734* Starting:: Starting your program
c906108c
SS
1735* Arguments:: Your program's arguments
1736* Environment:: Your program's environment
c906108c
SS
1737
1738* Working Directory:: Your program's working directory
1739* Input/Output:: Your program's input and output
1740* Attach:: Debugging an already-running process
1741* Kill Process:: Killing the child process
c906108c
SS
1742
1743* Threads:: Debugging programs with multiple threads
1744* Processes:: Debugging programs with multiple processes
5c95884b 1745* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1746@end menu
1747
6d2ebf8b 1748@node Compilation
79a6e687 1749@section Compiling for Debugging
c906108c
SS
1750
1751In order to debug a program effectively, you need to generate
1752debugging information when you compile it. This debugging information
1753is stored in the object file; it describes the data type of each
1754variable or function and the correspondence between source line numbers
1755and addresses in the executable code.
1756
1757To request debugging information, specify the @samp{-g} option when you run
1758the compiler.
1759
514c4d71
EZ
1760Programs that are to be shipped to your customers are compiled with
1761optimizations, using the @samp{-O} compiler option. However, many
1762compilers are unable to handle the @samp{-g} and @samp{-O} options
1763together. Using those compilers, you cannot generate optimized
c906108c
SS
1764executables containing debugging information.
1765
514c4d71 1766@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1767without @samp{-O}, making it possible to debug optimized code. We
1768recommend that you @emph{always} use @samp{-g} whenever you compile a
1769program. You may think your program is correct, but there is no sense
1770in pushing your luck.
c906108c
SS
1771
1772@cindex optimized code, debugging
1773@cindex debugging optimized code
1774When you debug a program compiled with @samp{-g -O}, remember that the
1775optimizer is rearranging your code; the debugger shows you what is
1776really there. Do not be too surprised when the execution path does not
1777exactly match your source file! An extreme example: if you define a
1778variable, but never use it, @value{GDBN} never sees that
1779variable---because the compiler optimizes it out of existence.
1780
1781Some things do not work as well with @samp{-g -O} as with just
1782@samp{-g}, particularly on machines with instruction scheduling. If in
1783doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1784please report it to us as a bug (including a test case!).
15387254 1785@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1786
1787Older versions of the @sc{gnu} C compiler permitted a variant option
1788@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1789format; if your @sc{gnu} C compiler has this option, do not use it.
1790
514c4d71
EZ
1791@value{GDBN} knows about preprocessor macros and can show you their
1792expansion (@pxref{Macros}). Most compilers do not include information
1793about preprocessor macros in the debugging information if you specify
1794the @option{-g} flag alone, because this information is rather large.
1795Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1796provides macro information if you specify the options
1797@option{-gdwarf-2} and @option{-g3}; the former option requests
1798debugging information in the Dwarf 2 format, and the latter requests
1799``extra information''. In the future, we hope to find more compact
1800ways to represent macro information, so that it can be included with
1801@option{-g} alone.
1802
c906108c 1803@need 2000
6d2ebf8b 1804@node Starting
79a6e687 1805@section Starting your Program
c906108c
SS
1806@cindex starting
1807@cindex running
1808
1809@table @code
1810@kindex run
41afff9a 1811@kindex r @r{(@code{run})}
c906108c
SS
1812@item run
1813@itemx r
7a292a7a
SS
1814Use the @code{run} command to start your program under @value{GDBN}.
1815You must first specify the program name (except on VxWorks) with an
1816argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1817@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
79a6e687 1818(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
1819
1820@end table
1821
c906108c
SS
1822If you are running your program in an execution environment that
1823supports processes, @code{run} creates an inferior process and makes
1824that process run your program. (In environments without processes,
1825@code{run} jumps to the start of your program.)
1826
1827The execution of a program is affected by certain information it
1828receives from its superior. @value{GDBN} provides ways to specify this
1829information, which you must do @emph{before} starting your program. (You
1830can change it after starting your program, but such changes only affect
1831your program the next time you start it.) This information may be
1832divided into four categories:
1833
1834@table @asis
1835@item The @emph{arguments.}
1836Specify the arguments to give your program as the arguments of the
1837@code{run} command. If a shell is available on your target, the shell
1838is used to pass the arguments, so that you may use normal conventions
1839(such as wildcard expansion or variable substitution) in describing
1840the arguments.
1841In Unix systems, you can control which shell is used with the
1842@code{SHELL} environment variable.
79a6e687 1843@xref{Arguments, ,Your Program's Arguments}.
c906108c
SS
1844
1845@item The @emph{environment.}
1846Your program normally inherits its environment from @value{GDBN}, but you can
1847use the @value{GDBN} commands @code{set environment} and @code{unset
1848environment} to change parts of the environment that affect
79a6e687 1849your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
1850
1851@item The @emph{working directory.}
1852Your program inherits its working directory from @value{GDBN}. You can set
1853the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 1854@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
1855
1856@item The @emph{standard input and output.}
1857Your program normally uses the same device for standard input and
1858standard output as @value{GDBN} is using. You can redirect input and output
1859in the @code{run} command line, or you can use the @code{tty} command to
1860set a different device for your program.
79a6e687 1861@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
1862
1863@cindex pipes
1864@emph{Warning:} While input and output redirection work, you cannot use
1865pipes to pass the output of the program you are debugging to another
1866program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1867wrong program.
1868@end table
c906108c
SS
1869
1870When you issue the @code{run} command, your program begins to execute
79a6e687 1871immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
1872of how to arrange for your program to stop. Once your program has
1873stopped, you may call functions in your program, using the @code{print}
1874or @code{call} commands. @xref{Data, ,Examining Data}.
1875
1876If the modification time of your symbol file has changed since the last
1877time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1878table, and reads it again. When it does this, @value{GDBN} tries to retain
1879your current breakpoints.
1880
4e8b0763
JB
1881@table @code
1882@kindex start
1883@item start
1884@cindex run to main procedure
1885The name of the main procedure can vary from language to language.
1886With C or C@t{++}, the main procedure name is always @code{main}, but
1887other languages such as Ada do not require a specific name for their
1888main procedure. The debugger provides a convenient way to start the
1889execution of the program and to stop at the beginning of the main
1890procedure, depending on the language used.
1891
1892The @samp{start} command does the equivalent of setting a temporary
1893breakpoint at the beginning of the main procedure and then invoking
1894the @samp{run} command.
1895
f018e82f
EZ
1896@cindex elaboration phase
1897Some programs contain an @dfn{elaboration} phase where some startup code is
1898executed before the main procedure is called. This depends on the
1899languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1900constructors for static and global objects are executed before
1901@code{main} is called. It is therefore possible that the debugger stops
1902before reaching the main procedure. However, the temporary breakpoint
1903will remain to halt execution.
1904
1905Specify the arguments to give to your program as arguments to the
1906@samp{start} command. These arguments will be given verbatim to the
1907underlying @samp{run} command. Note that the same arguments will be
1908reused if no argument is provided during subsequent calls to
1909@samp{start} or @samp{run}.
1910
1911It is sometimes necessary to debug the program during elaboration. In
1912these cases, using the @code{start} command would stop the execution of
1913your program too late, as the program would have already completed the
1914elaboration phase. Under these circumstances, insert breakpoints in your
1915elaboration code before running your program.
1916@end table
1917
6d2ebf8b 1918@node Arguments
79a6e687 1919@section Your Program's Arguments
c906108c
SS
1920
1921@cindex arguments (to your program)
1922The arguments to your program can be specified by the arguments of the
5d161b24 1923@code{run} command.
c906108c
SS
1924They are passed to a shell, which expands wildcard characters and
1925performs redirection of I/O, and thence to your program. Your
1926@code{SHELL} environment variable (if it exists) specifies what shell
1927@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1928the default shell (@file{/bin/sh} on Unix).
1929
1930On non-Unix systems, the program is usually invoked directly by
1931@value{GDBN}, which emulates I/O redirection via the appropriate system
1932calls, and the wildcard characters are expanded by the startup code of
1933the program, not by the shell.
c906108c
SS
1934
1935@code{run} with no arguments uses the same arguments used by the previous
1936@code{run}, or those set by the @code{set args} command.
1937
c906108c 1938@table @code
41afff9a 1939@kindex set args
c906108c
SS
1940@item set args
1941Specify the arguments to be used the next time your program is run. If
1942@code{set args} has no arguments, @code{run} executes your program
1943with no arguments. Once you have run your program with arguments,
1944using @code{set args} before the next @code{run} is the only way to run
1945it again without arguments.
1946
1947@kindex show args
1948@item show args
1949Show the arguments to give your program when it is started.
1950@end table
1951
6d2ebf8b 1952@node Environment
79a6e687 1953@section Your Program's Environment
c906108c
SS
1954
1955@cindex environment (of your program)
1956The @dfn{environment} consists of a set of environment variables and
1957their values. Environment variables conventionally record such things as
1958your user name, your home directory, your terminal type, and your search
1959path for programs to run. Usually you set up environment variables with
1960the shell and they are inherited by all the other programs you run. When
1961debugging, it can be useful to try running your program with a modified
1962environment without having to start @value{GDBN} over again.
1963
1964@table @code
1965@kindex path
1966@item path @var{directory}
1967Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1968(the search path for executables) that will be passed to your program.
1969The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1970You may specify several directory names, separated by whitespace or by a
1971system-dependent separator character (@samp{:} on Unix, @samp{;} on
1972MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1973is moved to the front, so it is searched sooner.
c906108c
SS
1974
1975You can use the string @samp{$cwd} to refer to whatever is the current
1976working directory at the time @value{GDBN} searches the path. If you
1977use @samp{.} instead, it refers to the directory where you executed the
1978@code{path} command. @value{GDBN} replaces @samp{.} in the
1979@var{directory} argument (with the current path) before adding
1980@var{directory} to the search path.
1981@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1982@c document that, since repeating it would be a no-op.
1983
1984@kindex show paths
1985@item show paths
1986Display the list of search paths for executables (the @code{PATH}
1987environment variable).
1988
1989@kindex show environment
1990@item show environment @r{[}@var{varname}@r{]}
1991Print the value of environment variable @var{varname} to be given to
1992your program when it starts. If you do not supply @var{varname},
1993print the names and values of all environment variables to be given to
1994your program. You can abbreviate @code{environment} as @code{env}.
1995
1996@kindex set environment
53a5351d 1997@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1998Set environment variable @var{varname} to @var{value}. The value
1999changes for your program only, not for @value{GDBN} itself. @var{value} may
2000be any string; the values of environment variables are just strings, and
2001any interpretation is supplied by your program itself. The @var{value}
2002parameter is optional; if it is eliminated, the variable is set to a
2003null value.
2004@c "any string" here does not include leading, trailing
2005@c blanks. Gnu asks: does anyone care?
2006
2007For example, this command:
2008
474c8240 2009@smallexample
c906108c 2010set env USER = foo
474c8240 2011@end smallexample
c906108c
SS
2012
2013@noindent
d4f3574e 2014tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2015@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2016are not actually required.)
2017
2018@kindex unset environment
2019@item unset environment @var{varname}
2020Remove variable @var{varname} from the environment to be passed to your
2021program. This is different from @samp{set env @var{varname} =};
2022@code{unset environment} removes the variable from the environment,
2023rather than assigning it an empty value.
2024@end table
2025
d4f3574e
SS
2026@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2027the shell indicated
c906108c
SS
2028by your @code{SHELL} environment variable if it exists (or
2029@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2030that runs an initialization file---such as @file{.cshrc} for C-shell, or
2031@file{.bashrc} for BASH---any variables you set in that file affect
2032your program. You may wish to move setting of environment variables to
2033files that are only run when you sign on, such as @file{.login} or
2034@file{.profile}.
2035
6d2ebf8b 2036@node Working Directory
79a6e687 2037@section Your Program's Working Directory
c906108c
SS
2038
2039@cindex working directory (of your program)
2040Each time you start your program with @code{run}, it inherits its
2041working directory from the current working directory of @value{GDBN}.
2042The @value{GDBN} working directory is initially whatever it inherited
2043from its parent process (typically the shell), but you can specify a new
2044working directory in @value{GDBN} with the @code{cd} command.
2045
2046The @value{GDBN} working directory also serves as a default for the commands
2047that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2048Specify Files}.
c906108c
SS
2049
2050@table @code
2051@kindex cd
721c2651 2052@cindex change working directory
c906108c
SS
2053@item cd @var{directory}
2054Set the @value{GDBN} working directory to @var{directory}.
2055
2056@kindex pwd
2057@item pwd
2058Print the @value{GDBN} working directory.
2059@end table
2060
60bf7e09
EZ
2061It is generally impossible to find the current working directory of
2062the process being debugged (since a program can change its directory
2063during its run). If you work on a system where @value{GDBN} is
2064configured with the @file{/proc} support, you can use the @code{info
2065proc} command (@pxref{SVR4 Process Information}) to find out the
2066current working directory of the debuggee.
2067
6d2ebf8b 2068@node Input/Output
79a6e687 2069@section Your Program's Input and Output
c906108c
SS
2070
2071@cindex redirection
2072@cindex i/o
2073@cindex terminal
2074By default, the program you run under @value{GDBN} does input and output to
5d161b24 2075the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2076to its own terminal modes to interact with you, but it records the terminal
2077modes your program was using and switches back to them when you continue
2078running your program.
2079
2080@table @code
2081@kindex info terminal
2082@item info terminal
2083Displays information recorded by @value{GDBN} about the terminal modes your
2084program is using.
2085@end table
2086
2087You can redirect your program's input and/or output using shell
2088redirection with the @code{run} command. For example,
2089
474c8240 2090@smallexample
c906108c 2091run > outfile
474c8240 2092@end smallexample
c906108c
SS
2093
2094@noindent
2095starts your program, diverting its output to the file @file{outfile}.
2096
2097@kindex tty
2098@cindex controlling terminal
2099Another way to specify where your program should do input and output is
2100with the @code{tty} command. This command accepts a file name as
2101argument, and causes this file to be the default for future @code{run}
2102commands. It also resets the controlling terminal for the child
2103process, for future @code{run} commands. For example,
2104
474c8240 2105@smallexample
c906108c 2106tty /dev/ttyb
474c8240 2107@end smallexample
c906108c
SS
2108
2109@noindent
2110directs that processes started with subsequent @code{run} commands
2111default to do input and output on the terminal @file{/dev/ttyb} and have
2112that as their controlling terminal.
2113
2114An explicit redirection in @code{run} overrides the @code{tty} command's
2115effect on the input/output device, but not its effect on the controlling
2116terminal.
2117
2118When you use the @code{tty} command or redirect input in the @code{run}
2119command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2120for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2121for @code{set inferior-tty}.
2122
2123@cindex inferior tty
2124@cindex set inferior controlling terminal
2125You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2126display the name of the terminal that will be used for future runs of your
2127program.
2128
2129@table @code
2130@item set inferior-tty /dev/ttyb
2131@kindex set inferior-tty
2132Set the tty for the program being debugged to /dev/ttyb.
2133
2134@item show inferior-tty
2135@kindex show inferior-tty
2136Show the current tty for the program being debugged.
2137@end table
c906108c 2138
6d2ebf8b 2139@node Attach
79a6e687 2140@section Debugging an Already-running Process
c906108c
SS
2141@kindex attach
2142@cindex attach
2143
2144@table @code
2145@item attach @var{process-id}
2146This command attaches to a running process---one that was started
2147outside @value{GDBN}. (@code{info files} shows your active
2148targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2149find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2150or with the @samp{jobs -l} shell command.
2151
2152@code{attach} does not repeat if you press @key{RET} a second time after
2153executing the command.
2154@end table
2155
2156To use @code{attach}, your program must be running in an environment
2157which supports processes; for example, @code{attach} does not work for
2158programs on bare-board targets that lack an operating system. You must
2159also have permission to send the process a signal.
2160
2161When you use @code{attach}, the debugger finds the program running in
2162the process first by looking in the current working directory, then (if
2163the program is not found) by using the source file search path
79a6e687 2164(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2165the @code{file} command to load the program. @xref{Files, ,Commands to
2166Specify Files}.
2167
2168The first thing @value{GDBN} does after arranging to debug the specified
2169process is to stop it. You can examine and modify an attached process
53a5351d
JM
2170with all the @value{GDBN} commands that are ordinarily available when
2171you start processes with @code{run}. You can insert breakpoints; you
2172can step and continue; you can modify storage. If you would rather the
2173process continue running, you may use the @code{continue} command after
c906108c
SS
2174attaching @value{GDBN} to the process.
2175
2176@table @code
2177@kindex detach
2178@item detach
2179When you have finished debugging the attached process, you can use the
2180@code{detach} command to release it from @value{GDBN} control. Detaching
2181the process continues its execution. After the @code{detach} command,
2182that process and @value{GDBN} become completely independent once more, and you
2183are ready to @code{attach} another process or start one with @code{run}.
2184@code{detach} does not repeat if you press @key{RET} again after
2185executing the command.
2186@end table
2187
159fcc13
JK
2188If you exit @value{GDBN} while you have an attached process, you detach
2189that process. If you use the @code{run} command, you kill that process.
2190By default, @value{GDBN} asks for confirmation if you try to do either of these
2191things; you can control whether or not you need to confirm by using the
2192@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2193Messages}).
c906108c 2194
6d2ebf8b 2195@node Kill Process
79a6e687 2196@section Killing the Child Process
c906108c
SS
2197
2198@table @code
2199@kindex kill
2200@item kill
2201Kill the child process in which your program is running under @value{GDBN}.
2202@end table
2203
2204This command is useful if you wish to debug a core dump instead of a
2205running process. @value{GDBN} ignores any core dump file while your program
2206is running.
2207
2208On some operating systems, a program cannot be executed outside @value{GDBN}
2209while you have breakpoints set on it inside @value{GDBN}. You can use the
2210@code{kill} command in this situation to permit running your program
2211outside the debugger.
2212
2213The @code{kill} command is also useful if you wish to recompile and
2214relink your program, since on many systems it is impossible to modify an
2215executable file while it is running in a process. In this case, when you
2216next type @code{run}, @value{GDBN} notices that the file has changed, and
2217reads the symbol table again (while trying to preserve your current
2218breakpoint settings).
2219
6d2ebf8b 2220@node Threads
79a6e687 2221@section Debugging Programs with Multiple Threads
c906108c
SS
2222
2223@cindex threads of execution
2224@cindex multiple threads
2225@cindex switching threads
2226In some operating systems, such as HP-UX and Solaris, a single program
2227may have more than one @dfn{thread} of execution. The precise semantics
2228of threads differ from one operating system to another, but in general
2229the threads of a single program are akin to multiple processes---except
2230that they share one address space (that is, they can all examine and
2231modify the same variables). On the other hand, each thread has its own
2232registers and execution stack, and perhaps private memory.
2233
2234@value{GDBN} provides these facilities for debugging multi-thread
2235programs:
2236
2237@itemize @bullet
2238@item automatic notification of new threads
2239@item @samp{thread @var{threadno}}, a command to switch among threads
2240@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2241@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2242a command to apply a command to a list of threads
2243@item thread-specific breakpoints
2244@end itemize
2245
c906108c
SS
2246@quotation
2247@emph{Warning:} These facilities are not yet available on every
2248@value{GDBN} configuration where the operating system supports threads.
2249If your @value{GDBN} does not support threads, these commands have no
2250effect. For example, a system without thread support shows no output
2251from @samp{info threads}, and always rejects the @code{thread} command,
2252like this:
2253
2254@smallexample
2255(@value{GDBP}) info threads
2256(@value{GDBP}) thread 1
2257Thread ID 1 not known. Use the "info threads" command to
2258see the IDs of currently known threads.
2259@end smallexample
2260@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2261@c doesn't support threads"?
2262@end quotation
c906108c
SS
2263
2264@cindex focus of debugging
2265@cindex current thread
2266The @value{GDBN} thread debugging facility allows you to observe all
2267threads while your program runs---but whenever @value{GDBN} takes
2268control, one thread in particular is always the focus of debugging.
2269This thread is called the @dfn{current thread}. Debugging commands show
2270program information from the perspective of the current thread.
2271
41afff9a 2272@cindex @code{New} @var{systag} message
c906108c
SS
2273@cindex thread identifier (system)
2274@c FIXME-implementors!! It would be more helpful if the [New...] message
2275@c included GDB's numeric thread handle, so you could just go to that
2276@c thread without first checking `info threads'.
2277Whenever @value{GDBN} detects a new thread in your program, it displays
2278the target system's identification for the thread with a message in the
2279form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2280whose form varies depending on the particular system. For example, on
8807d78b 2281@sc{gnu}/Linux, you might see
c906108c 2282
474c8240 2283@smallexample
8807d78b 2284[New Thread 46912507313328 (LWP 25582)]
474c8240 2285@end smallexample
c906108c
SS
2286
2287@noindent
2288when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2289the @var{systag} is simply something like @samp{process 368}, with no
2290further qualifier.
2291
2292@c FIXME!! (1) Does the [New...] message appear even for the very first
2293@c thread of a program, or does it only appear for the
6ca652b0 2294@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2295@c program?
2296@c (2) *Is* there necessarily a first thread always? Or do some
2297@c multithread systems permit starting a program with multiple
5d161b24 2298@c threads ab initio?
c906108c
SS
2299
2300@cindex thread number
2301@cindex thread identifier (GDB)
2302For debugging purposes, @value{GDBN} associates its own thread
2303number---always a single integer---with each thread in your program.
2304
2305@table @code
2306@kindex info threads
2307@item info threads
2308Display a summary of all threads currently in your
2309program. @value{GDBN} displays for each thread (in this order):
2310
2311@enumerate
09d4efe1
EZ
2312@item
2313the thread number assigned by @value{GDBN}
c906108c 2314
09d4efe1
EZ
2315@item
2316the target system's thread identifier (@var{systag})
c906108c 2317
09d4efe1
EZ
2318@item
2319the current stack frame summary for that thread
c906108c
SS
2320@end enumerate
2321
2322@noindent
2323An asterisk @samp{*} to the left of the @value{GDBN} thread number
2324indicates the current thread.
2325
5d161b24 2326For example,
c906108c
SS
2327@end table
2328@c end table here to get a little more width for example
2329
2330@smallexample
2331(@value{GDBP}) info threads
2332 3 process 35 thread 27 0x34e5 in sigpause ()
2333 2 process 35 thread 23 0x34e5 in sigpause ()
2334* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2335 at threadtest.c:68
2336@end smallexample
53a5351d
JM
2337
2338On HP-UX systems:
c906108c 2339
4644b6e3
EZ
2340@cindex debugging multithreaded programs (on HP-UX)
2341@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2342For debugging purposes, @value{GDBN} associates its own thread
2343number---a small integer assigned in thread-creation order---with each
2344thread in your program.
2345
41afff9a
EZ
2346@cindex @code{New} @var{systag} message, on HP-UX
2347@cindex thread identifier (system), on HP-UX
c906108c
SS
2348@c FIXME-implementors!! It would be more helpful if the [New...] message
2349@c included GDB's numeric thread handle, so you could just go to that
2350@c thread without first checking `info threads'.
2351Whenever @value{GDBN} detects a new thread in your program, it displays
2352both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2353form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2354whose form varies depending on the particular system. For example, on
2355HP-UX, you see
2356
474c8240 2357@smallexample
c906108c 2358[New thread 2 (system thread 26594)]
474c8240 2359@end smallexample
c906108c
SS
2360
2361@noindent
5d161b24 2362when @value{GDBN} notices a new thread.
c906108c
SS
2363
2364@table @code
4644b6e3 2365@kindex info threads (HP-UX)
c906108c
SS
2366@item info threads
2367Display a summary of all threads currently in your
2368program. @value{GDBN} displays for each thread (in this order):
2369
2370@enumerate
2371@item the thread number assigned by @value{GDBN}
2372
2373@item the target system's thread identifier (@var{systag})
2374
2375@item the current stack frame summary for that thread
2376@end enumerate
2377
2378@noindent
2379An asterisk @samp{*} to the left of the @value{GDBN} thread number
2380indicates the current thread.
2381
5d161b24 2382For example,
c906108c
SS
2383@end table
2384@c end table here to get a little more width for example
2385
474c8240 2386@smallexample
c906108c 2387(@value{GDBP}) info threads
6d2ebf8b
SS
2388 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2389 at quicksort.c:137
2390 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2391 from /usr/lib/libc.2
2392 1 system thread 27905 0x7b003498 in _brk () \@*
2393 from /usr/lib/libc.2
474c8240 2394@end smallexample
c906108c 2395
c45da7e6
EZ
2396On Solaris, you can display more information about user threads with a
2397Solaris-specific command:
2398
2399@table @code
2400@item maint info sol-threads
2401@kindex maint info sol-threads
2402@cindex thread info (Solaris)
2403Display info on Solaris user threads.
2404@end table
2405
c906108c
SS
2406@table @code
2407@kindex thread @var{threadno}
2408@item thread @var{threadno}
2409Make thread number @var{threadno} the current thread. The command
2410argument @var{threadno} is the internal @value{GDBN} thread number, as
2411shown in the first field of the @samp{info threads} display.
2412@value{GDBN} responds by displaying the system identifier of the thread
2413you selected, and its current stack frame summary:
2414
2415@smallexample
2416@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2417(@value{GDBP}) thread 2
c906108c 2418[Switching to process 35 thread 23]
c906108c
SS
24190x34e5 in sigpause ()
2420@end smallexample
2421
2422@noindent
2423As with the @samp{[New @dots{}]} message, the form of the text after
2424@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2425threads.
c906108c 2426
9c16f35a 2427@kindex thread apply
638ac427 2428@cindex apply command to several threads
839c27b7
EZ
2429@item thread apply [@var{threadno}] [@var{all}] @var{command}
2430The @code{thread apply} command allows you to apply the named
2431@var{command} to one or more threads. Specify the numbers of the
2432threads that you want affected with the command argument
2433@var{threadno}. It can be a single thread number, one of the numbers
2434shown in the first field of the @samp{info threads} display; or it
2435could be a range of thread numbers, as in @code{2-4}. To apply a
2436command to all threads, type @kbd{thread apply all @var{command}}.
c906108c
SS
2437@end table
2438
2439@cindex automatic thread selection
2440@cindex switching threads automatically
2441@cindex threads, automatic switching
2442Whenever @value{GDBN} stops your program, due to a breakpoint or a
2443signal, it automatically selects the thread where that breakpoint or
2444signal happened. @value{GDBN} alerts you to the context switch with a
2445message of the form @samp{[Switching to @var{systag}]} to identify the
2446thread.
2447
79a6e687 2448@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
2449more information about how @value{GDBN} behaves when you stop and start
2450programs with multiple threads.
2451
79a6e687 2452@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 2453watchpoints in programs with multiple threads.
c906108c 2454
6d2ebf8b 2455@node Processes
79a6e687 2456@section Debugging Programs with Multiple Processes
c906108c
SS
2457
2458@cindex fork, debugging programs which call
2459@cindex multiple processes
2460@cindex processes, multiple
53a5351d
JM
2461On most systems, @value{GDBN} has no special support for debugging
2462programs which create additional processes using the @code{fork}
2463function. When a program forks, @value{GDBN} will continue to debug the
2464parent process and the child process will run unimpeded. If you have
2465set a breakpoint in any code which the child then executes, the child
2466will get a @code{SIGTRAP} signal which (unless it catches the signal)
2467will cause it to terminate.
c906108c
SS
2468
2469However, if you want to debug the child process there is a workaround
2470which isn't too painful. Put a call to @code{sleep} in the code which
2471the child process executes after the fork. It may be useful to sleep
2472only if a certain environment variable is set, or a certain file exists,
2473so that the delay need not occur when you don't want to run @value{GDBN}
2474on the child. While the child is sleeping, use the @code{ps} program to
2475get its process ID. Then tell @value{GDBN} (a new invocation of
2476@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2477the child process (@pxref{Attach}). From that point on you can debug
c906108c 2478the child process just like any other process which you attached to.
c906108c 2479
b51970ac
DJ
2480On some systems, @value{GDBN} provides support for debugging programs that
2481create additional processes using the @code{fork} or @code{vfork} functions.
2482Currently, the only platforms with this feature are HP-UX (11.x and later
a6b151f1 2483only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
c906108c
SS
2484
2485By default, when a program forks, @value{GDBN} will continue to debug
2486the parent process and the child process will run unimpeded.
2487
2488If you want to follow the child process instead of the parent process,
2489use the command @w{@code{set follow-fork-mode}}.
2490
2491@table @code
2492@kindex set follow-fork-mode
2493@item set follow-fork-mode @var{mode}
2494Set the debugger response to a program call of @code{fork} or
2495@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2496process. The @var{mode} argument can be:
c906108c
SS
2497
2498@table @code
2499@item parent
2500The original process is debugged after a fork. The child process runs
2df3850c 2501unimpeded. This is the default.
c906108c
SS
2502
2503@item child
2504The new process is debugged after a fork. The parent process runs
2505unimpeded.
2506
c906108c
SS
2507@end table
2508
9c16f35a 2509@kindex show follow-fork-mode
c906108c 2510@item show follow-fork-mode
2df3850c 2511Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2512@end table
2513
5c95884b
MS
2514@cindex debugging multiple processes
2515On Linux, if you want to debug both the parent and child processes, use the
2516command @w{@code{set detach-on-fork}}.
2517
2518@table @code
2519@kindex set detach-on-fork
2520@item set detach-on-fork @var{mode}
2521Tells gdb whether to detach one of the processes after a fork, or
2522retain debugger control over them both.
2523
2524@table @code
2525@item on
2526The child process (or parent process, depending on the value of
2527@code{follow-fork-mode}) will be detached and allowed to run
2528independently. This is the default.
2529
2530@item off
2531Both processes will be held under the control of @value{GDBN}.
2532One process (child or parent, depending on the value of
2533@code{follow-fork-mode}) is debugged as usual, while the other
2534is held suspended.
2535
2536@end table
2537
2538@kindex show detach-on-follow
2539@item show detach-on-follow
2540Show whether detach-on-follow mode is on/off.
2541@end table
2542
2543If you choose to set @var{detach-on-follow} mode off, then
2544@value{GDBN} will retain control of all forked processes (including
2545nested forks). You can list the forked processes under the control of
2546@value{GDBN} by using the @w{@code{info forks}} command, and switch
2547from one fork to another by using the @w{@code{fork}} command.
2548
2549@table @code
2550@kindex info forks
2551@item info forks
2552Print a list of all forked processes under the control of @value{GDBN}.
2553The listing will include a fork id, a process id, and the current
2554position (program counter) of the process.
2555
2556
2557@kindex fork @var{fork-id}
2558@item fork @var{fork-id}
2559Make fork number @var{fork-id} the current process. The argument
2560@var{fork-id} is the internal fork number assigned by @value{GDBN},
2561as shown in the first field of the @samp{info forks} display.
2562
2563@end table
2564
2565To quit debugging one of the forked processes, you can either detach
f73adfeb 2566from it by using the @w{@code{detach fork}} command (allowing it to
5c95884b 2567run independently), or delete (and kill) it using the
b8db102d 2568@w{@code{delete fork}} command.
5c95884b
MS
2569
2570@table @code
f73adfeb
AS
2571@kindex detach fork @var{fork-id}
2572@item detach fork @var{fork-id}
5c95884b
MS
2573Detach from the process identified by @value{GDBN} fork number
2574@var{fork-id}, and remove it from the fork list. The process will be
2575allowed to run independently.
2576
b8db102d
MS
2577@kindex delete fork @var{fork-id}
2578@item delete fork @var{fork-id}
5c95884b
MS
2579Kill the process identified by @value{GDBN} fork number @var{fork-id},
2580and remove it from the fork list.
2581
2582@end table
2583
c906108c
SS
2584If you ask to debug a child process and a @code{vfork} is followed by an
2585@code{exec}, @value{GDBN} executes the new target up to the first
2586breakpoint in the new target. If you have a breakpoint set on
2587@code{main} in your original program, the breakpoint will also be set on
2588the child process's @code{main}.
2589
2590When a child process is spawned by @code{vfork}, you cannot debug the
2591child or parent until an @code{exec} call completes.
2592
2593If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2594call executes, the new target restarts. To restart the parent process,
2595use the @code{file} command with the parent executable name as its
2596argument.
2597
2598You can use the @code{catch} command to make @value{GDBN} stop whenever
2599a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 2600Catchpoints, ,Setting Catchpoints}.
c906108c 2601
5c95884b 2602@node Checkpoint/Restart
79a6e687 2603@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
2604
2605@cindex checkpoint
2606@cindex restart
2607@cindex bookmark
2608@cindex snapshot of a process
2609@cindex rewind program state
2610
2611On certain operating systems@footnote{Currently, only
2612@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2613program's state, called a @dfn{checkpoint}, and come back to it
2614later.
2615
2616Returning to a checkpoint effectively undoes everything that has
2617happened in the program since the @code{checkpoint} was saved. This
2618includes changes in memory, registers, and even (within some limits)
2619system state. Effectively, it is like going back in time to the
2620moment when the checkpoint was saved.
2621
2622Thus, if you're stepping thru a program and you think you're
2623getting close to the point where things go wrong, you can save
2624a checkpoint. Then, if you accidentally go too far and miss
2625the critical statement, instead of having to restart your program
2626from the beginning, you can just go back to the checkpoint and
2627start again from there.
2628
2629This can be especially useful if it takes a lot of time or
2630steps to reach the point where you think the bug occurs.
2631
2632To use the @code{checkpoint}/@code{restart} method of debugging:
2633
2634@table @code
2635@kindex checkpoint
2636@item checkpoint
2637Save a snapshot of the debugged program's current execution state.
2638The @code{checkpoint} command takes no arguments, but each checkpoint
2639is assigned a small integer id, similar to a breakpoint id.
2640
2641@kindex info checkpoints
2642@item info checkpoints
2643List the checkpoints that have been saved in the current debugging
2644session. For each checkpoint, the following information will be
2645listed:
2646
2647@table @code
2648@item Checkpoint ID
2649@item Process ID
2650@item Code Address
2651@item Source line, or label
2652@end table
2653
2654@kindex restart @var{checkpoint-id}
2655@item restart @var{checkpoint-id}
2656Restore the program state that was saved as checkpoint number
2657@var{checkpoint-id}. All program variables, registers, stack frames
2658etc.@: will be returned to the values that they had when the checkpoint
2659was saved. In essence, gdb will ``wind back the clock'' to the point
2660in time when the checkpoint was saved.
2661
2662Note that breakpoints, @value{GDBN} variables, command history etc.
2663are not affected by restoring a checkpoint. In general, a checkpoint
2664only restores things that reside in the program being debugged, not in
2665the debugger.
2666
b8db102d
MS
2667@kindex delete checkpoint @var{checkpoint-id}
2668@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
2669Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2670
2671@end table
2672
2673Returning to a previously saved checkpoint will restore the user state
2674of the program being debugged, plus a significant subset of the system
2675(OS) state, including file pointers. It won't ``un-write'' data from
2676a file, but it will rewind the file pointer to the previous location,
2677so that the previously written data can be overwritten. For files
2678opened in read mode, the pointer will also be restored so that the
2679previously read data can be read again.
2680
2681Of course, characters that have been sent to a printer (or other
2682external device) cannot be ``snatched back'', and characters received
2683from eg.@: a serial device can be removed from internal program buffers,
2684but they cannot be ``pushed back'' into the serial pipeline, ready to
2685be received again. Similarly, the actual contents of files that have
2686been changed cannot be restored (at this time).
2687
2688However, within those constraints, you actually can ``rewind'' your
2689program to a previously saved point in time, and begin debugging it
2690again --- and you can change the course of events so as to debug a
2691different execution path this time.
2692
2693@cindex checkpoints and process id
2694Finally, there is one bit of internal program state that will be
2695different when you return to a checkpoint --- the program's process
2696id. Each checkpoint will have a unique process id (or @var{pid}),
2697and each will be different from the program's original @var{pid}.
2698If your program has saved a local copy of its process id, this could
2699potentially pose a problem.
2700
79a6e687 2701@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
2702
2703On some systems such as @sc{gnu}/Linux, address space randomization
2704is performed on new processes for security reasons. This makes it
2705difficult or impossible to set a breakpoint, or watchpoint, on an
2706absolute address if you have to restart the program, since the
2707absolute location of a symbol will change from one execution to the
2708next.
2709
2710A checkpoint, however, is an @emph{identical} copy of a process.
2711Therefore if you create a checkpoint at (eg.@:) the start of main,
2712and simply return to that checkpoint instead of restarting the
2713process, you can avoid the effects of address randomization and
2714your symbols will all stay in the same place.
2715
6d2ebf8b 2716@node Stopping
c906108c
SS
2717@chapter Stopping and Continuing
2718
2719The principal purposes of using a debugger are so that you can stop your
2720program before it terminates; or so that, if your program runs into
2721trouble, you can investigate and find out why.
2722
7a292a7a
SS
2723Inside @value{GDBN}, your program may stop for any of several reasons,
2724such as a signal, a breakpoint, or reaching a new line after a
2725@value{GDBN} command such as @code{step}. You may then examine and
2726change variables, set new breakpoints or remove old ones, and then
2727continue execution. Usually, the messages shown by @value{GDBN} provide
2728ample explanation of the status of your program---but you can also
2729explicitly request this information at any time.
c906108c
SS
2730
2731@table @code
2732@kindex info program
2733@item info program
2734Display information about the status of your program: whether it is
7a292a7a 2735running or not, what process it is, and why it stopped.
c906108c
SS
2736@end table
2737
2738@menu
2739* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2740* Continuing and Stepping:: Resuming execution
c906108c 2741* Signals:: Signals
c906108c 2742* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2743@end menu
2744
6d2ebf8b 2745@node Breakpoints
79a6e687 2746@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
2747
2748@cindex breakpoints
2749A @dfn{breakpoint} makes your program stop whenever a certain point in
2750the program is reached. For each breakpoint, you can add conditions to
2751control in finer detail whether your program stops. You can set
2752breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 2753Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
2754should stop by line number, function name or exact address in the
2755program.
2756
09d4efe1
EZ
2757On some systems, you can set breakpoints in shared libraries before
2758the executable is run. There is a minor limitation on HP-UX systems:
2759you must wait until the executable is run in order to set breakpoints
2760in shared library routines that are not called directly by the program
2761(for example, routines that are arguments in a @code{pthread_create}
2762call).
c906108c
SS
2763
2764@cindex watchpoints
fd60e0df 2765@cindex data breakpoints
c906108c
SS
2766@cindex memory tracing
2767@cindex breakpoint on memory address
2768@cindex breakpoint on variable modification
2769A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 2770when the value of an expression changes. The expression may be a value
0ced0c34 2771of a variable, or it could involve values of one or more variables
fd60e0df
EZ
2772combined by operators, such as @samp{a + b}. This is sometimes called
2773@dfn{data breakpoints}. You must use a different command to set
79a6e687 2774watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
2775from that, you can manage a watchpoint like any other breakpoint: you
2776enable, disable, and delete both breakpoints and watchpoints using the
2777same commands.
c906108c
SS
2778
2779You can arrange to have values from your program displayed automatically
2780whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 2781Automatic Display}.
c906108c
SS
2782
2783@cindex catchpoints
2784@cindex breakpoint on events
2785A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2786when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2787exception or the loading of a library. As with watchpoints, you use a
2788different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 2789Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 2790other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2791@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2792
2793@cindex breakpoint numbers
2794@cindex numbers for breakpoints
2795@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2796catchpoint when you create it; these numbers are successive integers
2797starting with one. In many of the commands for controlling various
2798features of breakpoints you use the breakpoint number to say which
2799breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2800@dfn{disabled}; if disabled, it has no effect on your program until you
2801enable it again.
2802
c5394b80
JM
2803@cindex breakpoint ranges
2804@cindex ranges of breakpoints
2805Some @value{GDBN} commands accept a range of breakpoints on which to
2806operate. A breakpoint range is either a single breakpoint number, like
2807@samp{5}, or two such numbers, in increasing order, separated by a
2808hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 2809all breakpoints in that range are operated on.
c5394b80 2810
c906108c
SS
2811@menu
2812* Set Breaks:: Setting breakpoints
2813* Set Watchpoints:: Setting watchpoints
2814* Set Catchpoints:: Setting catchpoints
2815* Delete Breaks:: Deleting breakpoints
2816* Disabling:: Disabling breakpoints
2817* Conditions:: Break conditions
2818* Break Commands:: Breakpoint command lists
c906108c 2819* Breakpoint Menus:: Breakpoint menus
d4f3574e 2820* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 2821* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2822@end menu
2823
6d2ebf8b 2824@node Set Breaks
79a6e687 2825@subsection Setting Breakpoints
c906108c 2826
5d161b24 2827@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2828@c consider in particular declaration with/without initialization.
2829@c
2830@c FIXME 2 is there stuff on this already? break at fun start, already init?
2831
2832@kindex break
41afff9a
EZ
2833@kindex b @r{(@code{break})}
2834@vindex $bpnum@r{, convenience variable}
c906108c
SS
2835@cindex latest breakpoint
2836Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2837@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2838number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 2839Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
2840convenience variables.
2841
2842You have several ways to say where the breakpoint should go.
2843
2844@table @code
2845@item break @var{function}
5d161b24 2846Set a breakpoint at entry to function @var{function}.
c906108c 2847When using source languages that permit overloading of symbols, such as
b37052ae 2848C@t{++}, @var{function} may refer to more than one possible place to break.
79a6e687 2849@xref{Breakpoint Menus,,Breakpoint Menus}, for a discussion of that situation.
c906108c
SS
2850
2851@item break +@var{offset}
2852@itemx break -@var{offset}
2853Set a breakpoint some number of lines forward or back from the position
d4f3574e 2854at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2855(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2856
2857@item break @var{linenum}
2858Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2859The current source file is the last file whose source text was printed.
2860The breakpoint will stop your program just before it executes any of the
c906108c
SS
2861code on that line.
2862
2863@item break @var{filename}:@var{linenum}
2864Set a breakpoint at line @var{linenum} in source file @var{filename}.
2865
2866@item break @var{filename}:@var{function}
2867Set a breakpoint at entry to function @var{function} found in file
2868@var{filename}. Specifying a file name as well as a function name is
2869superfluous except when multiple files contain similarly named
2870functions.
2871
2872@item break *@var{address}
2873Set a breakpoint at address @var{address}. You can use this to set
2874breakpoints in parts of your program which do not have debugging
2875information or source files.
2876
2877@item break
2878When called without any arguments, @code{break} sets a breakpoint at
2879the next instruction to be executed in the selected stack frame
2880(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2881innermost, this makes your program stop as soon as control
2882returns to that frame. This is similar to the effect of a
2883@code{finish} command in the frame inside the selected frame---except
2884that @code{finish} does not leave an active breakpoint. If you use
2885@code{break} without an argument in the innermost frame, @value{GDBN} stops
2886the next time it reaches the current location; this may be useful
2887inside loops.
2888
2889@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2890least one instruction has been executed. If it did not do this, you
2891would be unable to proceed past a breakpoint without first disabling the
2892breakpoint. This rule applies whether or not the breakpoint already
2893existed when your program stopped.
2894
2895@item break @dots{} if @var{cond}
2896Set a breakpoint with condition @var{cond}; evaluate the expression
2897@var{cond} each time the breakpoint is reached, and stop only if the
2898value is nonzero---that is, if @var{cond} evaluates as true.
2899@samp{@dots{}} stands for one of the possible arguments described
2900above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 2901,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
2902
2903@kindex tbreak
2904@item tbreak @var{args}
2905Set a breakpoint enabled only for one stop. @var{args} are the
2906same as for the @code{break} command, and the breakpoint is set in the same
2907way, but the breakpoint is automatically deleted after the first time your
79a6e687 2908program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 2909
c906108c 2910@kindex hbreak
ba04e063 2911@cindex hardware breakpoints
c906108c 2912@item hbreak @var{args}
d4f3574e
SS
2913Set a hardware-assisted breakpoint. @var{args} are the same as for the
2914@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2915breakpoint requires hardware support and some target hardware may not
2916have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2917debugging, so you can set a breakpoint at an instruction without
2918changing the instruction. This can be used with the new trap-generation
09d4efe1 2919provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2920will generate traps when a program accesses some data or instruction
2921address that is assigned to the debug registers. However the hardware
2922breakpoint registers can take a limited number of breakpoints. For
2923example, on the DSU, only two data breakpoints can be set at a time, and
2924@value{GDBN} will reject this command if more than two are used. Delete
2925or disable unused hardware breakpoints before setting new ones
79a6e687
BW
2926(@pxref{Disabling, ,Disabling Breakpoints}).
2927@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
2928For remote targets, you can restrict the number of hardware
2929breakpoints @value{GDBN} will use, see @ref{set remote
2930hardware-breakpoint-limit}.
501eef12 2931
c906108c
SS
2932
2933@kindex thbreak
2934@item thbreak @var{args}
2935Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2936are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2937the same way. However, like the @code{tbreak} command,
c906108c
SS
2938the breakpoint is automatically deleted after the
2939first time your program stops there. Also, like the @code{hbreak}
5d161b24 2940command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
2941may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
2942See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
2943
2944@kindex rbreak
2945@cindex regular expression
c45da7e6
EZ
2946@cindex breakpoints in functions matching a regexp
2947@cindex set breakpoints in many functions
c906108c 2948@item rbreak @var{regex}
c906108c 2949Set breakpoints on all functions matching the regular expression
11cf8741
JM
2950@var{regex}. This command sets an unconditional breakpoint on all
2951matches, printing a list of all breakpoints it set. Once these
2952breakpoints are set, they are treated just like the breakpoints set with
2953the @code{break} command. You can delete them, disable them, or make
2954them conditional the same way as any other breakpoint.
2955
2956The syntax of the regular expression is the standard one used with tools
2957like @file{grep}. Note that this is different from the syntax used by
2958shells, so for instance @code{foo*} matches all functions that include
2959an @code{fo} followed by zero or more @code{o}s. There is an implicit
2960@code{.*} leading and trailing the regular expression you supply, so to
2961match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2962
f7dc1244 2963@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2964When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2965breakpoints on overloaded functions that are not members of any special
2966classes.
c906108c 2967
f7dc1244
EZ
2968@cindex set breakpoints on all functions
2969The @code{rbreak} command can be used to set breakpoints in
2970@strong{all} the functions in a program, like this:
2971
2972@smallexample
2973(@value{GDBP}) rbreak .
2974@end smallexample
2975
c906108c
SS
2976@kindex info breakpoints
2977@cindex @code{$_} and @code{info breakpoints}
2978@item info breakpoints @r{[}@var{n}@r{]}
2979@itemx info break @r{[}@var{n}@r{]}
2980@itemx info watchpoints @r{[}@var{n}@r{]}
2981Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734
EZ
2982not deleted. Optional argument @var{n} means print information only
2983about the specified breakpoint (or watchpoint or catchpoint). For
2984each breakpoint, following columns are printed:
c906108c
SS
2985
2986@table @emph
2987@item Breakpoint Numbers
2988@item Type
2989Breakpoint, watchpoint, or catchpoint.
2990@item Disposition
2991Whether the breakpoint is marked to be disabled or deleted when hit.
2992@item Enabled or Disabled
2993Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
fe6fbf8b 2994that are not enabled. An optional @samp{(p)} suffix marks pending
3b784c4f 2995breakpoints---breakpoints for which address is either not yet
fe6fbf8b
VP
2996resolved, pending load of a shared library, or for which address was
2997in a shared library that was since unloaded. Such breakpoint won't
2998fire until a shared library that has the symbol or line referred by
2999breakpoint is loaded. See below for details.
c906108c 3000@item Address
fe6fbf8b
VP
3001Where the breakpoint is in your program, as a memory address. For a
3002pending breakpoint whose address is not yet known, this field will
3003contain @samp{<PENDING>}. A breakpoint with several locations will
3b784c4f 3004have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3005@item What
3006Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3007line number. For a pending breakpoint, the original string passed to
3008the breakpoint command will be listed as it cannot be resolved until
3009the appropriate shared library is loaded in the future.
c906108c
SS
3010@end table
3011
3012@noindent
3013If a breakpoint is conditional, @code{info break} shows the condition on
3014the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
3015are listed after that. A pending breakpoint is allowed to have a condition
3016specified for it. The condition is not parsed for validity until a shared
3017library is loaded that allows the pending breakpoint to resolve to a
3018valid location.
c906108c
SS
3019
3020@noindent
3021@code{info break} with a breakpoint
3022number @var{n} as argument lists only that breakpoint. The
3023convenience variable @code{$_} and the default examining-address for
3024the @code{x} command are set to the address of the last breakpoint
79a6e687 3025listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3026
3027@noindent
3028@code{info break} displays a count of the number of times the breakpoint
3029has been hit. This is especially useful in conjunction with the
3030@code{ignore} command. You can ignore a large number of breakpoint
3031hits, look at the breakpoint info to see how many times the breakpoint
3032was hit, and then run again, ignoring one less than that number. This
3033will get you quickly to the last hit of that breakpoint.
3034@end table
3035
3036@value{GDBN} allows you to set any number of breakpoints at the same place in
3037your program. There is nothing silly or meaningless about this. When
3038the breakpoints are conditional, this is even useful
79a6e687 3039(@pxref{Conditions, ,Break Conditions}).
c906108c 3040
fcda367b 3041It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3042in your program. Examples of this situation are:
3043
3044@itemize @bullet
3045
3046@item
3047For a C@t{++} constructor, the @value{NGCC} compiler generates several
3048instances of the function body, used in different cases.
3049
3050@item
3051For a C@t{++} template function, a given line in the function can
3052correspond to any number of instantiations.
3053
3054@item
3055For an inlined function, a given source line can correspond to
3056several places where that function is inlined.
3057
3058@end itemize
3059
3060In all those cases, @value{GDBN} will insert a breakpoint at all
3061the relevant locations.
3062
3b784c4f
EZ
3063A breakpoint with multiple locations is displayed in the breakpoint
3064table using several rows---one header row, followed by one row for
3065each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3066address column. The rows for individual locations contain the actual
3067addresses for locations, and show the functions to which those
3068locations belong. The number column for a location is of the form
fe6fbf8b
VP
3069@var{breakpoint-number}.@var{location-number}.
3070
3071For example:
3b784c4f 3072
fe6fbf8b
VP
3073@smallexample
3074Num Type Disp Enb Address What
30751 breakpoint keep y <MULTIPLE>
3076 stop only if i==1
3077 breakpoint already hit 1 time
30781.1 y 0x080486a2 in void foo<int>() at t.cc:8
30791.2 y 0x080486ca in void foo<double>() at t.cc:8
3080@end smallexample
3081
3082Each location can be individually enabled or disabled by passing
3083@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3084@code{enable} and @code{disable} commands. Note that you cannot
3085delete the individual locations from the list, you can only delete the
16bfc218 3086entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3087the @kbd{delete @var{num}} command, where @var{num} is the number of
3088the parent breakpoint, 1 in the above example). Disabling or enabling
3089the parent breakpoint (@pxref{Disabling}) affects all of the locations
3090that belong to that breakpoint.
fe6fbf8b 3091
2650777c 3092@cindex pending breakpoints
fe6fbf8b 3093It's quite common to have a breakpoint inside a shared library.
3b784c4f 3094Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3095and possibly repeatedly, as the program is executed. To support
3096this use case, @value{GDBN} updates breakpoint locations whenever
3097any shared library is loaded or unloaded. Typically, you would
fcda367b 3098set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3099debugging session, when the library is not loaded, and when the
3100symbols from the library are not available. When you try to set
3101breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3102a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3103is not yet resolved.
3104
3105After the program is run, whenever a new shared library is loaded,
3106@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3107shared library contains the symbol or line referred to by some
3108pending breakpoint, that breakpoint is resolved and becomes an
3109ordinary breakpoint. When a library is unloaded, all breakpoints
3110that refer to its symbols or source lines become pending again.
3111
3112This logic works for breakpoints with multiple locations, too. For
3113example, if you have a breakpoint in a C@t{++} template function, and
3114a newly loaded shared library has an instantiation of that template,
3115a new location is added to the list of locations for the breakpoint.
3116
3117Except for having unresolved address, pending breakpoints do not
3118differ from regular breakpoints. You can set conditions or commands,
3119enable and disable them and perform other breakpoint operations.
3120
3121@value{GDBN} provides some additional commands for controlling what
3122happens when the @samp{break} command cannot resolve breakpoint
3123address specification to an address:
dd79a6cf
JJ
3124
3125@kindex set breakpoint pending
3126@kindex show breakpoint pending
3127@table @code
3128@item set breakpoint pending auto
3129This is the default behavior. When @value{GDBN} cannot find the breakpoint
3130location, it queries you whether a pending breakpoint should be created.
3131
3132@item set breakpoint pending on
3133This indicates that an unrecognized breakpoint location should automatically
3134result in a pending breakpoint being created.
3135
3136@item set breakpoint pending off
3137This indicates that pending breakpoints are not to be created. Any
3138unrecognized breakpoint location results in an error. This setting does
3139not affect any pending breakpoints previously created.
3140
3141@item show breakpoint pending
3142Show the current behavior setting for creating pending breakpoints.
3143@end table
2650777c 3144
fe6fbf8b
VP
3145The settings above only affect the @code{break} command and its
3146variants. Once breakpoint is set, it will be automatically updated
3147as shared libraries are loaded and unloaded.
2650777c 3148
765dc015
VP
3149@cindex automatic hardware breakpoints
3150For some targets, @value{GDBN} can automatically decide if hardware or
3151software breakpoints should be used, depending on whether the
3152breakpoint address is read-only or read-write. This applies to
3153breakpoints set with the @code{break} command as well as to internal
3154breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3155breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3156breakpoints.
3157
3158You can control this automatic behaviour with the following commands::
3159
3160@kindex set breakpoint auto-hw
3161@kindex show breakpoint auto-hw
3162@table @code
3163@item set breakpoint auto-hw on
3164This is the default behavior. When @value{GDBN} sets a breakpoint, it
3165will try to use the target memory map to decide if software or hardware
3166breakpoint must be used.
3167
3168@item set breakpoint auto-hw off
3169This indicates @value{GDBN} should not automatically select breakpoint
3170type. If the target provides a memory map, @value{GDBN} will warn when
3171trying to set software breakpoint at a read-only address.
3172@end table
3173
3174
c906108c
SS
3175@cindex negative breakpoint numbers
3176@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3177@value{GDBN} itself sometimes sets breakpoints in your program for
3178special purposes, such as proper handling of @code{longjmp} (in C
3179programs). These internal breakpoints are assigned negative numbers,
3180starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3181You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3182@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3183
3184
6d2ebf8b 3185@node Set Watchpoints
79a6e687 3186@subsection Setting Watchpoints
c906108c
SS
3187
3188@cindex setting watchpoints
c906108c
SS
3189You can use a watchpoint to stop execution whenever the value of an
3190expression changes, without having to predict a particular place where
fd60e0df
EZ
3191this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3192The expression may be as simple as the value of a single variable, or
3193as complex as many variables combined by operators. Examples include:
3194
3195@itemize @bullet
3196@item
3197A reference to the value of a single variable.
3198
3199@item
3200An address cast to an appropriate data type. For example,
3201@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3202address (assuming an @code{int} occupies 4 bytes).
3203
3204@item
3205An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3206expression can use any operators valid in the program's native
3207language (@pxref{Languages}).
3208@end itemize
c906108c 3209
82f2d802
EZ
3210@cindex software watchpoints
3211@cindex hardware watchpoints
c906108c 3212Depending on your system, watchpoints may be implemented in software or
2df3850c 3213hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3214program and testing the variable's value each time, which is hundreds of
3215times slower than normal execution. (But this may still be worth it, to
3216catch errors where you have no clue what part of your program is the
3217culprit.)
3218
37e4754d 3219On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
82f2d802
EZ
3220x86-based targets, @value{GDBN} includes support for hardware
3221watchpoints, which do not slow down the running of your program.
c906108c
SS
3222
3223@table @code
3224@kindex watch
3225@item watch @var{expr}
fd60e0df
EZ
3226Set a watchpoint for an expression. @value{GDBN} will break when the
3227expression @var{expr} is written into by the program and its value
3228changes. The simplest (and the most popular) use of this command is
3229to watch the value of a single variable:
3230
3231@smallexample
3232(@value{GDBP}) watch foo
3233@end smallexample
c906108c
SS
3234
3235@kindex rwatch
3236@item rwatch @var{expr}
09d4efe1
EZ
3237Set a watchpoint that will break when the value of @var{expr} is read
3238by the program.
c906108c
SS
3239
3240@kindex awatch
3241@item awatch @var{expr}
09d4efe1
EZ
3242Set a watchpoint that will break when @var{expr} is either read from
3243or written into by the program.
c906108c 3244
45ac1734 3245@kindex info watchpoints @r{[}@var{n}@r{]}
c906108c
SS
3246@item info watchpoints
3247This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 3248it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
3249@end table
3250
3251@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3252watchpoints execute very quickly, and the debugger reports a change in
3253value at the exact instruction where the change occurs. If @value{GDBN}
3254cannot set a hardware watchpoint, it sets a software watchpoint, which
3255executes more slowly and reports the change in value at the next
82f2d802
EZ
3256@emph{statement}, not the instruction, after the change occurs.
3257
82f2d802
EZ
3258@cindex use only software watchpoints
3259You can force @value{GDBN} to use only software watchpoints with the
3260@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3261zero, @value{GDBN} will never try to use hardware watchpoints, even if
3262the underlying system supports them. (Note that hardware-assisted
3263watchpoints that were set @emph{before} setting
3264@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 3265mechanism of watching expression values.)
c906108c 3266
9c16f35a
EZ
3267@table @code
3268@item set can-use-hw-watchpoints
3269@kindex set can-use-hw-watchpoints
3270Set whether or not to use hardware watchpoints.
3271
3272@item show can-use-hw-watchpoints
3273@kindex show can-use-hw-watchpoints
3274Show the current mode of using hardware watchpoints.
3275@end table
3276
3277For remote targets, you can restrict the number of hardware
3278watchpoints @value{GDBN} will use, see @ref{set remote
3279hardware-breakpoint-limit}.
3280
c906108c
SS
3281When you issue the @code{watch} command, @value{GDBN} reports
3282
474c8240 3283@smallexample
c906108c 3284Hardware watchpoint @var{num}: @var{expr}
474c8240 3285@end smallexample
c906108c
SS
3286
3287@noindent
3288if it was able to set a hardware watchpoint.
3289
7be570e7
JM
3290Currently, the @code{awatch} and @code{rwatch} commands can only set
3291hardware watchpoints, because accesses to data that don't change the
3292value of the watched expression cannot be detected without examining
3293every instruction as it is being executed, and @value{GDBN} does not do
3294that currently. If @value{GDBN} finds that it is unable to set a
3295hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3296will print a message like this:
3297
3298@smallexample
3299Expression cannot be implemented with read/access watchpoint.
3300@end smallexample
3301
3302Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3303data type of the watched expression is wider than what a hardware
3304watchpoint on the target machine can handle. For example, some systems
3305can only watch regions that are up to 4 bytes wide; on such systems you
3306cannot set hardware watchpoints for an expression that yields a
3307double-precision floating-point number (which is typically 8 bytes
3308wide). As a work-around, it might be possible to break the large region
3309into a series of smaller ones and watch them with separate watchpoints.
3310
3311If you set too many hardware watchpoints, @value{GDBN} might be unable
3312to insert all of them when you resume the execution of your program.
3313Since the precise number of active watchpoints is unknown until such
3314time as the program is about to be resumed, @value{GDBN} might not be
3315able to warn you about this when you set the watchpoints, and the
3316warning will be printed only when the program is resumed:
3317
3318@smallexample
3319Hardware watchpoint @var{num}: Could not insert watchpoint
3320@end smallexample
3321
3322@noindent
3323If this happens, delete or disable some of the watchpoints.
3324
fd60e0df
EZ
3325Watching complex expressions that reference many variables can also
3326exhaust the resources available for hardware-assisted watchpoints.
3327That's because @value{GDBN} needs to watch every variable in the
3328expression with separately allocated resources.
3329
7be570e7
JM
3330The SPARClite DSU will generate traps when a program accesses some data
3331or instruction address that is assigned to the debug registers. For the
3332data addresses, DSU facilitates the @code{watch} command. However the
3333hardware breakpoint registers can only take two data watchpoints, and
3334both watchpoints must be the same kind. For example, you can set two
3335watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3336@strong{or} two with @code{awatch} commands, but you cannot set one
3337watchpoint with one command and the other with a different command.
c906108c
SS
3338@value{GDBN} will reject the command if you try to mix watchpoints.
3339Delete or disable unused watchpoint commands before setting new ones.
3340
3341If you call a function interactively using @code{print} or @code{call},
2df3850c 3342any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3343kind of breakpoint or the call completes.
3344
7be570e7
JM
3345@value{GDBN} automatically deletes watchpoints that watch local
3346(automatic) variables, or expressions that involve such variables, when
3347they go out of scope, that is, when the execution leaves the block in
3348which these variables were defined. In particular, when the program
3349being debugged terminates, @emph{all} local variables go out of scope,
3350and so only watchpoints that watch global variables remain set. If you
3351rerun the program, you will need to set all such watchpoints again. One
3352way of doing that would be to set a code breakpoint at the entry to the
3353@code{main} function and when it breaks, set all the watchpoints.
3354
c906108c
SS
3355@cindex watchpoints and threads
3356@cindex threads and watchpoints
d983da9c
DJ
3357In multi-threaded programs, watchpoints will detect changes to the
3358watched expression from every thread.
3359
37e4754d
LM
3360@kindex watch thread thread_num
3361@item watch @var{expr} thread @var{threadnum}
3362Set a watchpoint that will break when @var{expr} is either read from
3363or written into by the thread identified by @var{threadnum}. If @var{expr}
3364is modified by any other threads not matching @var{threadnum}, @value{GDBN}
3365will not break. Note that this will only work with Hardware Watchpoints.
3366
d983da9c
DJ
3367@quotation
3368@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
3369have only limited usefulness. If @value{GDBN} creates a software
3370watchpoint, it can only watch the value of an expression @emph{in a
3371single thread}. If you are confident that the expression can only
3372change due to the current thread's activity (and if you are also
3373confident that no other thread can become current), then you can use
3374software watchpoints as usual. However, @value{GDBN} may not notice
3375when a non-current thread's activity changes the expression. (Hardware
3376watchpoints, in contrast, watch an expression in all threads.)
c906108c 3377@end quotation
c906108c 3378
501eef12
AC
3379@xref{set remote hardware-watchpoint-limit}.
3380
6d2ebf8b 3381@node Set Catchpoints
79a6e687 3382@subsection Setting Catchpoints
d4f3574e 3383@cindex catchpoints, setting
c906108c
SS
3384@cindex exception handlers
3385@cindex event handling
3386
3387You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3388kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3389shared library. Use the @code{catch} command to set a catchpoint.
3390
3391@table @code
3392@kindex catch
3393@item catch @var{event}
3394Stop when @var{event} occurs. @var{event} can be any of the following:
3395@table @code
3396@item throw
4644b6e3 3397@cindex stop on C@t{++} exceptions
b37052ae 3398The throwing of a C@t{++} exception.
c906108c
SS
3399
3400@item catch
b37052ae 3401The catching of a C@t{++} exception.
c906108c 3402
8936fcda
JB
3403@item exception
3404@cindex Ada exception catching
3405@cindex catch Ada exceptions
3406An Ada exception being raised. If an exception name is specified
3407at the end of the command (eg @code{catch exception Program_Error}),
3408the debugger will stop only when this specific exception is raised.
3409Otherwise, the debugger stops execution when any Ada exception is raised.
3410
3411@item exception unhandled
3412An exception that was raised but is not handled by the program.
3413
3414@item assert
3415A failed Ada assertion.
3416
c906108c 3417@item exec
4644b6e3 3418@cindex break on fork/exec
c906108c
SS
3419A call to @code{exec}. This is currently only available for HP-UX.
3420
3421@item fork
c906108c
SS
3422A call to @code{fork}. This is currently only available for HP-UX.
3423
3424@item vfork
c906108c
SS
3425A call to @code{vfork}. This is currently only available for HP-UX.
3426
3427@item load
3428@itemx load @var{libname}
4644b6e3 3429@cindex break on load/unload of shared library
c906108c
SS
3430The dynamic loading of any shared library, or the loading of the library
3431@var{libname}. This is currently only available for HP-UX.
3432
3433@item unload
3434@itemx unload @var{libname}
c906108c
SS
3435The unloading of any dynamically loaded shared library, or the unloading
3436of the library @var{libname}. This is currently only available for HP-UX.
3437@end table
3438
3439@item tcatch @var{event}
3440Set a catchpoint that is enabled only for one stop. The catchpoint is
3441automatically deleted after the first time the event is caught.
3442
3443@end table
3444
3445Use the @code{info break} command to list the current catchpoints.
3446
b37052ae 3447There are currently some limitations to C@t{++} exception handling
c906108c
SS
3448(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3449
3450@itemize @bullet
3451@item
3452If you call a function interactively, @value{GDBN} normally returns
3453control to you when the function has finished executing. If the call
3454raises an exception, however, the call may bypass the mechanism that
3455returns control to you and cause your program either to abort or to
3456simply continue running until it hits a breakpoint, catches a signal
3457that @value{GDBN} is listening for, or exits. This is the case even if
3458you set a catchpoint for the exception; catchpoints on exceptions are
3459disabled within interactive calls.
3460
3461@item
3462You cannot raise an exception interactively.
3463
3464@item
3465You cannot install an exception handler interactively.
3466@end itemize
3467
3468@cindex raise exceptions
3469Sometimes @code{catch} is not the best way to debug exception handling:
3470if you need to know exactly where an exception is raised, it is better to
3471stop @emph{before} the exception handler is called, since that way you
3472can see the stack before any unwinding takes place. If you set a
3473breakpoint in an exception handler instead, it may not be easy to find
3474out where the exception was raised.
3475
3476To stop just before an exception handler is called, you need some
b37052ae 3477knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3478raised by calling a library function named @code{__raise_exception}
3479which has the following ANSI C interface:
3480
474c8240 3481@smallexample
c906108c 3482 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3483 @var{id} is the exception identifier. */
3484 void __raise_exception (void **addr, void *id);
474c8240 3485@end smallexample
c906108c
SS
3486
3487@noindent
3488To make the debugger catch all exceptions before any stack
3489unwinding takes place, set a breakpoint on @code{__raise_exception}
79a6e687 3490(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
c906108c 3491
79a6e687 3492With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
c906108c
SS
3493that depends on the value of @var{id}, you can stop your program when
3494a specific exception is raised. You can use multiple conditional
3495breakpoints to stop your program when any of a number of exceptions are
3496raised.
3497
3498
6d2ebf8b 3499@node Delete Breaks
79a6e687 3500@subsection Deleting Breakpoints
c906108c
SS
3501
3502@cindex clearing breakpoints, watchpoints, catchpoints
3503@cindex deleting breakpoints, watchpoints, catchpoints
3504It is often necessary to eliminate a breakpoint, watchpoint, or
3505catchpoint once it has done its job and you no longer want your program
3506to stop there. This is called @dfn{deleting} the breakpoint. A
3507breakpoint that has been deleted no longer exists; it is forgotten.
3508
3509With the @code{clear} command you can delete breakpoints according to
3510where they are in your program. With the @code{delete} command you can
3511delete individual breakpoints, watchpoints, or catchpoints by specifying
3512their breakpoint numbers.
3513
3514It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3515automatically ignores breakpoints on the first instruction to be executed
3516when you continue execution without changing the execution address.
3517
3518@table @code
3519@kindex clear
3520@item clear
3521Delete any breakpoints at the next instruction to be executed in the
79a6e687 3522selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
3523the innermost frame is selected, this is a good way to delete a
3524breakpoint where your program just stopped.
3525
3526@item clear @var{function}
3527@itemx clear @var{filename}:@var{function}
09d4efe1 3528Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3529
3530@item clear @var{linenum}
3531@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3532Delete any breakpoints set at or within the code of the specified
3533@var{linenum} of the specified @var{filename}.
c906108c
SS
3534
3535@cindex delete breakpoints
3536@kindex delete
41afff9a 3537@kindex d @r{(@code{delete})}
c5394b80
JM
3538@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3539Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3540ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3541breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3542confirm off}). You can abbreviate this command as @code{d}.
3543@end table
3544
6d2ebf8b 3545@node Disabling
79a6e687 3546@subsection Disabling Breakpoints
c906108c 3547
4644b6e3 3548@cindex enable/disable a breakpoint
c906108c
SS
3549Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3550prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3551it had been deleted, but remembers the information on the breakpoint so
3552that you can @dfn{enable} it again later.
3553
3554You disable and enable breakpoints, watchpoints, and catchpoints with
3555the @code{enable} and @code{disable} commands, optionally specifying one
3556or more breakpoint numbers as arguments. Use @code{info break} or
3557@code{info watch} to print a list of breakpoints, watchpoints, and
3558catchpoints if you do not know which numbers to use.
3559
3b784c4f
EZ
3560Disabling and enabling a breakpoint that has multiple locations
3561affects all of its locations.
3562
c906108c
SS
3563A breakpoint, watchpoint, or catchpoint can have any of four different
3564states of enablement:
3565
3566@itemize @bullet
3567@item
3568Enabled. The breakpoint stops your program. A breakpoint set
3569with the @code{break} command starts out in this state.
3570@item
3571Disabled. The breakpoint has no effect on your program.
3572@item
3573Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3574disabled.
c906108c
SS
3575@item
3576Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3577immediately after it does so it is deleted permanently. A breakpoint
3578set with the @code{tbreak} command starts out in this state.
c906108c
SS
3579@end itemize
3580
3581You can use the following commands to enable or disable breakpoints,
3582watchpoints, and catchpoints:
3583
3584@table @code
c906108c 3585@kindex disable
41afff9a 3586@kindex dis @r{(@code{disable})}
c5394b80 3587@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3588Disable the specified breakpoints---or all breakpoints, if none are
3589listed. A disabled breakpoint has no effect but is not forgotten. All
3590options such as ignore-counts, conditions and commands are remembered in
3591case the breakpoint is enabled again later. You may abbreviate
3592@code{disable} as @code{dis}.
3593
c906108c 3594@kindex enable
c5394b80 3595@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3596Enable the specified breakpoints (or all defined breakpoints). They
3597become effective once again in stopping your program.
3598
c5394b80 3599@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3600Enable the specified breakpoints temporarily. @value{GDBN} disables any
3601of these breakpoints immediately after stopping your program.
3602
c5394b80 3603@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3604Enable the specified breakpoints to work once, then die. @value{GDBN}
3605deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3606Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3607@end table
3608
d4f3574e
SS
3609@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3610@c confusing: tbreak is also initially enabled.
c906108c 3611Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 3612,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
3613subsequently, they become disabled or enabled only when you use one of
3614the commands above. (The command @code{until} can set and delete a
3615breakpoint of its own, but it does not change the state of your other
3616breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 3617Stepping}.)
c906108c 3618
6d2ebf8b 3619@node Conditions
79a6e687 3620@subsection Break Conditions
c906108c
SS
3621@cindex conditional breakpoints
3622@cindex breakpoint conditions
3623
3624@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3625@c in particular for a watchpoint?
c906108c
SS
3626The simplest sort of breakpoint breaks every time your program reaches a
3627specified place. You can also specify a @dfn{condition} for a
3628breakpoint. A condition is just a Boolean expression in your
3629programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3630a condition evaluates the expression each time your program reaches it,
3631and your program stops only if the condition is @emph{true}.
3632
3633This is the converse of using assertions for program validation; in that
3634situation, you want to stop when the assertion is violated---that is,
3635when the condition is false. In C, if you want to test an assertion expressed
3636by the condition @var{assert}, you should set the condition
3637@samp{! @var{assert}} on the appropriate breakpoint.
3638
3639Conditions are also accepted for watchpoints; you may not need them,
3640since a watchpoint is inspecting the value of an expression anyhow---but
3641it might be simpler, say, to just set a watchpoint on a variable name,
3642and specify a condition that tests whether the new value is an interesting
3643one.
3644
3645Break conditions can have side effects, and may even call functions in
3646your program. This can be useful, for example, to activate functions
3647that log program progress, or to use your own print functions to
3648format special data structures. The effects are completely predictable
3649unless there is another enabled breakpoint at the same address. (In
3650that case, @value{GDBN} might see the other breakpoint first and stop your
3651program without checking the condition of this one.) Note that
d4f3574e
SS
3652breakpoint commands are usually more convenient and flexible than break
3653conditions for the
c906108c 3654purpose of performing side effects when a breakpoint is reached
79a6e687 3655(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c
SS
3656
3657Break conditions can be specified when a breakpoint is set, by using
3658@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 3659Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 3660with the @code{condition} command.
53a5351d 3661
c906108c
SS
3662You can also use the @code{if} keyword with the @code{watch} command.
3663The @code{catch} command does not recognize the @code{if} keyword;
3664@code{condition} is the only way to impose a further condition on a
3665catchpoint.
c906108c
SS
3666
3667@table @code
3668@kindex condition
3669@item condition @var{bnum} @var{expression}
3670Specify @var{expression} as the break condition for breakpoint,
3671watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3672breakpoint @var{bnum} stops your program only if the value of
3673@var{expression} is true (nonzero, in C). When you use
3674@code{condition}, @value{GDBN} checks @var{expression} immediately for
3675syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3676referents in the context of your breakpoint. If @var{expression} uses
3677symbols not referenced in the context of the breakpoint, @value{GDBN}
3678prints an error message:
3679
474c8240 3680@smallexample
d4f3574e 3681No symbol "foo" in current context.
474c8240 3682@end smallexample
d4f3574e
SS
3683
3684@noindent
c906108c
SS
3685@value{GDBN} does
3686not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3687command (or a command that sets a breakpoint with a condition, like
3688@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3689
3690@item condition @var{bnum}
3691Remove the condition from breakpoint number @var{bnum}. It becomes
3692an ordinary unconditional breakpoint.
3693@end table
3694
3695@cindex ignore count (of breakpoint)
3696A special case of a breakpoint condition is to stop only when the
3697breakpoint has been reached a certain number of times. This is so
3698useful that there is a special way to do it, using the @dfn{ignore
3699count} of the breakpoint. Every breakpoint has an ignore count, which
3700is an integer. Most of the time, the ignore count is zero, and
3701therefore has no effect. But if your program reaches a breakpoint whose
3702ignore count is positive, then instead of stopping, it just decrements
3703the ignore count by one and continues. As a result, if the ignore count
3704value is @var{n}, the breakpoint does not stop the next @var{n} times
3705your program reaches it.
3706
3707@table @code
3708@kindex ignore
3709@item ignore @var{bnum} @var{count}
3710Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3711The next @var{count} times the breakpoint is reached, your program's
3712execution does not stop; other than to decrement the ignore count, @value{GDBN}
3713takes no action.
3714
3715To make the breakpoint stop the next time it is reached, specify
3716a count of zero.
3717
3718When you use @code{continue} to resume execution of your program from a
3719breakpoint, you can specify an ignore count directly as an argument to
3720@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 3721Stepping,,Continuing and Stepping}.
c906108c
SS
3722
3723If a breakpoint has a positive ignore count and a condition, the
3724condition is not checked. Once the ignore count reaches zero,
3725@value{GDBN} resumes checking the condition.
3726
3727You could achieve the effect of the ignore count with a condition such
3728as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3729is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 3730Variables}.
c906108c
SS
3731@end table
3732
3733Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3734
3735
6d2ebf8b 3736@node Break Commands
79a6e687 3737@subsection Breakpoint Command Lists
c906108c
SS
3738
3739@cindex breakpoint commands
3740You can give any breakpoint (or watchpoint or catchpoint) a series of
3741commands to execute when your program stops due to that breakpoint. For
3742example, you might want to print the values of certain expressions, or
3743enable other breakpoints.
3744
3745@table @code
3746@kindex commands
ca91424e 3747@kindex end@r{ (breakpoint commands)}
c906108c
SS
3748@item commands @r{[}@var{bnum}@r{]}
3749@itemx @dots{} @var{command-list} @dots{}
3750@itemx end
3751Specify a list of commands for breakpoint number @var{bnum}. The commands
3752themselves appear on the following lines. Type a line containing just
3753@code{end} to terminate the commands.
3754
3755To remove all commands from a breakpoint, type @code{commands} and
3756follow it immediately with @code{end}; that is, give no commands.
3757
3758With no @var{bnum} argument, @code{commands} refers to the last
3759breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3760recently encountered).
3761@end table
3762
3763Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3764disabled within a @var{command-list}.
3765
3766You can use breakpoint commands to start your program up again. Simply
3767use the @code{continue} command, or @code{step}, or any other command
3768that resumes execution.
3769
3770Any other commands in the command list, after a command that resumes
3771execution, are ignored. This is because any time you resume execution
3772(even with a simple @code{next} or @code{step}), you may encounter
3773another breakpoint---which could have its own command list, leading to
3774ambiguities about which list to execute.
3775
3776@kindex silent
3777If the first command you specify in a command list is @code{silent}, the
3778usual message about stopping at a breakpoint is not printed. This may
3779be desirable for breakpoints that are to print a specific message and
3780then continue. If none of the remaining commands print anything, you
3781see no sign that the breakpoint was reached. @code{silent} is
3782meaningful only at the beginning of a breakpoint command list.
3783
3784The commands @code{echo}, @code{output}, and @code{printf} allow you to
3785print precisely controlled output, and are often useful in silent
79a6e687 3786breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
3787
3788For example, here is how you could use breakpoint commands to print the
3789value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3790
474c8240 3791@smallexample
c906108c
SS
3792break foo if x>0
3793commands
3794silent
3795printf "x is %d\n",x
3796cont
3797end
474c8240 3798@end smallexample
c906108c
SS
3799
3800One application for breakpoint commands is to compensate for one bug so
3801you can test for another. Put a breakpoint just after the erroneous line
3802of code, give it a condition to detect the case in which something
3803erroneous has been done, and give it commands to assign correct values
3804to any variables that need them. End with the @code{continue} command
3805so that your program does not stop, and start with the @code{silent}
3806command so that no output is produced. Here is an example:
3807
474c8240 3808@smallexample
c906108c
SS
3809break 403
3810commands
3811silent
3812set x = y + 4
3813cont
3814end
474c8240 3815@end smallexample
c906108c 3816
6d2ebf8b 3817@node Breakpoint Menus
79a6e687 3818@subsection Breakpoint Menus
c906108c
SS
3819@cindex overloading
3820@cindex symbol overloading
3821
b383017d 3822Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3823single function name
c906108c
SS
3824to be defined several times, for application in different contexts.
3825This is called @dfn{overloading}. When a function name is overloaded,
3826@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3b784c4f
EZ
3827a breakpoint. You can use explicit signature of the function, as in
3828@samp{break @var{function}(@var{types})}, to specify which
c906108c
SS
3829particular version of the function you want. Otherwise, @value{GDBN} offers
3830you a menu of numbered choices for different possible breakpoints, and
3831waits for your selection with the prompt @samp{>}. The first two
3832options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3833sets a breakpoint at each definition of @var{function}, and typing
3834@kbd{0} aborts the @code{break} command without setting any new
3835breakpoints.
3836
3837For example, the following session excerpt shows an attempt to set a
3838breakpoint at the overloaded symbol @code{String::after}.
3839We choose three particular definitions of that function name:
3840
3841@c FIXME! This is likely to change to show arg type lists, at least
3842@smallexample
3843@group
3844(@value{GDBP}) b String::after
3845[0] cancel
3846[1] all
3847[2] file:String.cc; line number:867
3848[3] file:String.cc; line number:860
3849[4] file:String.cc; line number:875
3850[5] file:String.cc; line number:853
3851[6] file:String.cc; line number:846
3852[7] file:String.cc; line number:735
3853> 2 4 6
3854Breakpoint 1 at 0xb26c: file String.cc, line 867.
3855Breakpoint 2 at 0xb344: file String.cc, line 875.
3856Breakpoint 3 at 0xafcc: file String.cc, line 846.
3857Multiple breakpoints were set.
3858Use the "delete" command to delete unwanted
3859 breakpoints.
3860(@value{GDBP})
3861@end group
3862@end smallexample
c906108c
SS
3863
3864@c @ifclear BARETARGET
6d2ebf8b 3865@node Error in Breakpoints
d4f3574e 3866@subsection ``Cannot insert breakpoints''
c906108c
SS
3867@c
3868@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3869@c
d4f3574e
SS
3870Under some operating systems, breakpoints cannot be used in a program if
3871any other process is running that program. In this situation,
5d161b24 3872attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3873@value{GDBN} to print an error message:
3874
474c8240 3875@smallexample
d4f3574e
SS
3876Cannot insert breakpoints.
3877The same program may be running in another process.
474c8240 3878@end smallexample
d4f3574e
SS
3879
3880When this happens, you have three ways to proceed:
3881
3882@enumerate
3883@item
3884Remove or disable the breakpoints, then continue.
3885
3886@item
5d161b24 3887Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3888name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3889that @value{GDBN} should run your program under that name.
d4f3574e
SS
3890Then start your program again.
3891
3892@item
3893Relink your program so that the text segment is nonsharable, using the
3894linker option @samp{-N}. The operating system limitation may not apply
3895to nonsharable executables.
3896@end enumerate
c906108c
SS
3897@c @end ifclear
3898
d4f3574e
SS
3899A similar message can be printed if you request too many active
3900hardware-assisted breakpoints and watchpoints:
3901
3902@c FIXME: the precise wording of this message may change; the relevant
3903@c source change is not committed yet (Sep 3, 1999).
3904@smallexample
3905Stopped; cannot insert breakpoints.
3906You may have requested too many hardware breakpoints and watchpoints.
3907@end smallexample
3908
3909@noindent
3910This message is printed when you attempt to resume the program, since
3911only then @value{GDBN} knows exactly how many hardware breakpoints and
3912watchpoints it needs to insert.
3913
3914When this message is printed, you need to disable or remove some of the
3915hardware-assisted breakpoints and watchpoints, and then continue.
3916
79a6e687 3917@node Breakpoint-related Warnings
1485d690
KB
3918@subsection ``Breakpoint address adjusted...''
3919@cindex breakpoint address adjusted
3920
3921Some processor architectures place constraints on the addresses at
3922which breakpoints may be placed. For architectures thus constrained,
3923@value{GDBN} will attempt to adjust the breakpoint's address to comply
3924with the constraints dictated by the architecture.
3925
3926One example of such an architecture is the Fujitsu FR-V. The FR-V is
3927a VLIW architecture in which a number of RISC-like instructions may be
3928bundled together for parallel execution. The FR-V architecture
3929constrains the location of a breakpoint instruction within such a
3930bundle to the instruction with the lowest address. @value{GDBN}
3931honors this constraint by adjusting a breakpoint's address to the
3932first in the bundle.
3933
3934It is not uncommon for optimized code to have bundles which contain
3935instructions from different source statements, thus it may happen that
3936a breakpoint's address will be adjusted from one source statement to
3937another. Since this adjustment may significantly alter @value{GDBN}'s
3938breakpoint related behavior from what the user expects, a warning is
3939printed when the breakpoint is first set and also when the breakpoint
3940is hit.
3941
3942A warning like the one below is printed when setting a breakpoint
3943that's been subject to address adjustment:
3944
3945@smallexample
3946warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3947@end smallexample
3948
3949Such warnings are printed both for user settable and @value{GDBN}'s
3950internal breakpoints. If you see one of these warnings, you should
3951verify that a breakpoint set at the adjusted address will have the
3952desired affect. If not, the breakpoint in question may be removed and
b383017d 3953other breakpoints may be set which will have the desired behavior.
1485d690
KB
3954E.g., it may be sufficient to place the breakpoint at a later
3955instruction. A conditional breakpoint may also be useful in some
3956cases to prevent the breakpoint from triggering too often.
3957
3958@value{GDBN} will also issue a warning when stopping at one of these
3959adjusted breakpoints:
3960
3961@smallexample
3962warning: Breakpoint 1 address previously adjusted from 0x00010414
3963to 0x00010410.
3964@end smallexample
3965
3966When this warning is encountered, it may be too late to take remedial
3967action except in cases where the breakpoint is hit earlier or more
3968frequently than expected.
d4f3574e 3969
6d2ebf8b 3970@node Continuing and Stepping
79a6e687 3971@section Continuing and Stepping
c906108c
SS
3972
3973@cindex stepping
3974@cindex continuing
3975@cindex resuming execution
3976@dfn{Continuing} means resuming program execution until your program
3977completes normally. In contrast, @dfn{stepping} means executing just
3978one more ``step'' of your program, where ``step'' may mean either one
3979line of source code, or one machine instruction (depending on what
7a292a7a
SS
3980particular command you use). Either when continuing or when stepping,
3981your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3982it stops due to a signal, you may want to use @code{handle}, or use
3983@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3984
3985@table @code
3986@kindex continue
41afff9a
EZ
3987@kindex c @r{(@code{continue})}
3988@kindex fg @r{(resume foreground execution)}
c906108c
SS
3989@item continue @r{[}@var{ignore-count}@r{]}
3990@itemx c @r{[}@var{ignore-count}@r{]}
3991@itemx fg @r{[}@var{ignore-count}@r{]}
3992Resume program execution, at the address where your program last stopped;
3993any breakpoints set at that address are bypassed. The optional argument
3994@var{ignore-count} allows you to specify a further number of times to
3995ignore a breakpoint at this location; its effect is like that of
79a6e687 3996@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
3997
3998The argument @var{ignore-count} is meaningful only when your program
3999stopped due to a breakpoint. At other times, the argument to
4000@code{continue} is ignored.
4001
d4f3574e
SS
4002The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4003debugged program is deemed to be the foreground program) are provided
4004purely for convenience, and have exactly the same behavior as
4005@code{continue}.
c906108c
SS
4006@end table
4007
4008To resume execution at a different place, you can use @code{return}
79a6e687 4009(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 4010calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 4011Different Address}) to go to an arbitrary location in your program.
c906108c
SS
4012
4013A typical technique for using stepping is to set a breakpoint
79a6e687 4014(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
4015beginning of the function or the section of your program where a problem
4016is believed to lie, run your program until it stops at that breakpoint,
4017and then step through the suspect area, examining the variables that are
4018interesting, until you see the problem happen.
4019
4020@table @code
4021@kindex step
41afff9a 4022@kindex s @r{(@code{step})}
c906108c
SS
4023@item step
4024Continue running your program until control reaches a different source
4025line, then stop it and return control to @value{GDBN}. This command is
4026abbreviated @code{s}.
4027
4028@quotation
4029@c "without debugging information" is imprecise; actually "without line
4030@c numbers in the debugging information". (gcc -g1 has debugging info but
4031@c not line numbers). But it seems complex to try to make that
4032@c distinction here.
4033@emph{Warning:} If you use the @code{step} command while control is
4034within a function that was compiled without debugging information,
4035execution proceeds until control reaches a function that does have
4036debugging information. Likewise, it will not step into a function which
4037is compiled without debugging information. To step through functions
4038without debugging information, use the @code{stepi} command, described
4039below.
4040@end quotation
4041
4a92d011
EZ
4042The @code{step} command only stops at the first instruction of a source
4043line. This prevents the multiple stops that could otherwise occur in
4044@code{switch} statements, @code{for} loops, etc. @code{step} continues
4045to stop if a function that has debugging information is called within
4046the line. In other words, @code{step} @emph{steps inside} any functions
4047called within the line.
c906108c 4048
d4f3574e
SS
4049Also, the @code{step} command only enters a function if there is line
4050number information for the function. Otherwise it acts like the
5d161b24 4051@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 4052on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 4053was any debugging information about the routine.
c906108c
SS
4054
4055@item step @var{count}
4056Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
4057breakpoint is reached, or a signal not related to stepping occurs before
4058@var{count} steps, stepping stops right away.
c906108c
SS
4059
4060@kindex next
41afff9a 4061@kindex n @r{(@code{next})}
c906108c
SS
4062@item next @r{[}@var{count}@r{]}
4063Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
4064This is similar to @code{step}, but function calls that appear within
4065the line of code are executed without stopping. Execution stops when
4066control reaches a different line of code at the original stack level
4067that was executing when you gave the @code{next} command. This command
4068is abbreviated @code{n}.
c906108c
SS
4069
4070An argument @var{count} is a repeat count, as for @code{step}.
4071
4072
4073@c FIX ME!! Do we delete this, or is there a way it fits in with
4074@c the following paragraph? --- Vctoria
4075@c
4076@c @code{next} within a function that lacks debugging information acts like
4077@c @code{step}, but any function calls appearing within the code of the
4078@c function are executed without stopping.
4079
d4f3574e
SS
4080The @code{next} command only stops at the first instruction of a
4081source line. This prevents multiple stops that could otherwise occur in
4a92d011 4082@code{switch} statements, @code{for} loops, etc.
c906108c 4083
b90a5f51
CF
4084@kindex set step-mode
4085@item set step-mode
4086@cindex functions without line info, and stepping
4087@cindex stepping into functions with no line info
4088@itemx set step-mode on
4a92d011 4089The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
4090stop at the first instruction of a function which contains no debug line
4091information rather than stepping over it.
4092
4a92d011
EZ
4093This is useful in cases where you may be interested in inspecting the
4094machine instructions of a function which has no symbolic info and do not
4095want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
4096
4097@item set step-mode off
4a92d011 4098Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
4099debug information. This is the default.
4100
9c16f35a
EZ
4101@item show step-mode
4102Show whether @value{GDBN} will stop in or step over functions without
4103source line debug information.
4104
c906108c
SS
4105@kindex finish
4106@item finish
4107Continue running until just after function in the selected stack frame
4108returns. Print the returned value (if any).
4109
4110Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 4111,Returning from a Function}).
c906108c
SS
4112
4113@kindex until
41afff9a 4114@kindex u @r{(@code{until})}
09d4efe1 4115@cindex run until specified location
c906108c
SS
4116@item until
4117@itemx u
4118Continue running until a source line past the current line, in the
4119current stack frame, is reached. This command is used to avoid single
4120stepping through a loop more than once. It is like the @code{next}
4121command, except that when @code{until} encounters a jump, it
4122automatically continues execution until the program counter is greater
4123than the address of the jump.
4124
4125This means that when you reach the end of a loop after single stepping
4126though it, @code{until} makes your program continue execution until it
4127exits the loop. In contrast, a @code{next} command at the end of a loop
4128simply steps back to the beginning of the loop, which forces you to step
4129through the next iteration.
4130
4131@code{until} always stops your program if it attempts to exit the current
4132stack frame.
4133
4134@code{until} may produce somewhat counterintuitive results if the order
4135of machine code does not match the order of the source lines. For
4136example, in the following excerpt from a debugging session, the @code{f}
4137(@code{frame}) command shows that execution is stopped at line
4138@code{206}; yet when we use @code{until}, we get to line @code{195}:
4139
474c8240 4140@smallexample
c906108c
SS
4141(@value{GDBP}) f
4142#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4143206 expand_input();
4144(@value{GDBP}) until
4145195 for ( ; argc > 0; NEXTARG) @{
474c8240 4146@end smallexample
c906108c
SS
4147
4148This happened because, for execution efficiency, the compiler had
4149generated code for the loop closure test at the end, rather than the
4150start, of the loop---even though the test in a C @code{for}-loop is
4151written before the body of the loop. The @code{until} command appeared
4152to step back to the beginning of the loop when it advanced to this
4153expression; however, it has not really gone to an earlier
4154statement---not in terms of the actual machine code.
4155
4156@code{until} with no argument works by means of single
4157instruction stepping, and hence is slower than @code{until} with an
4158argument.
4159
4160@item until @var{location}
4161@itemx u @var{location}
4162Continue running your program until either the specified location is
4163reached, or the current stack frame returns. @var{location} is any of
4164the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
79a6e687 4165,Setting Breakpoints}). This form of the command uses breakpoints, and
c60eb6f1
EZ
4166hence is quicker than @code{until} without an argument. The specified
4167location is actually reached only if it is in the current frame. This
4168implies that @code{until} can be used to skip over recursive function
4169invocations. For instance in the code below, if the current location is
4170line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 4171line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
4172invocations have returned.
4173
4174@smallexample
417594 int factorial (int value)
417695 @{
417796 if (value > 1) @{
417897 value *= factorial (value - 1);
417998 @}
418099 return (value);
4181100 @}
4182@end smallexample
4183
4184
4185@kindex advance @var{location}
4186@itemx advance @var{location}
09d4efe1
EZ
4187Continue running the program up to the given @var{location}. An argument is
4188required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
4189command. Execution will also stop upon exit from the current stack
4190frame. This command is similar to @code{until}, but @code{advance} will
4191not skip over recursive function calls, and the target location doesn't
4192have to be in the same frame as the current one.
4193
c906108c
SS
4194
4195@kindex stepi
41afff9a 4196@kindex si @r{(@code{stepi})}
c906108c 4197@item stepi
96a2c332 4198@itemx stepi @var{arg}
c906108c
SS
4199@itemx si
4200Execute one machine instruction, then stop and return to the debugger.
4201
4202It is often useful to do @samp{display/i $pc} when stepping by machine
4203instructions. This makes @value{GDBN} automatically display the next
4204instruction to be executed, each time your program stops. @xref{Auto
79a6e687 4205Display,, Automatic Display}.
c906108c
SS
4206
4207An argument is a repeat count, as in @code{step}.
4208
4209@need 750
4210@kindex nexti
41afff9a 4211@kindex ni @r{(@code{nexti})}
c906108c 4212@item nexti
96a2c332 4213@itemx nexti @var{arg}
c906108c
SS
4214@itemx ni
4215Execute one machine instruction, but if it is a function call,
4216proceed until the function returns.
4217
4218An argument is a repeat count, as in @code{next}.
4219@end table
4220
6d2ebf8b 4221@node Signals
c906108c
SS
4222@section Signals
4223@cindex signals
4224
4225A signal is an asynchronous event that can happen in a program. The
4226operating system defines the possible kinds of signals, and gives each
4227kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 4228signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
4229@code{SIGSEGV} is the signal a program gets from referencing a place in
4230memory far away from all the areas in use; @code{SIGALRM} occurs when
4231the alarm clock timer goes off (which happens only if your program has
4232requested an alarm).
4233
4234@cindex fatal signals
4235Some signals, including @code{SIGALRM}, are a normal part of the
4236functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 4237errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
4238program has not specified in advance some other way to handle the signal.
4239@code{SIGINT} does not indicate an error in your program, but it is normally
4240fatal so it can carry out the purpose of the interrupt: to kill the program.
4241
4242@value{GDBN} has the ability to detect any occurrence of a signal in your
4243program. You can tell @value{GDBN} in advance what to do for each kind of
4244signal.
4245
4246@cindex handling signals
24f93129
EZ
4247Normally, @value{GDBN} is set up to let the non-erroneous signals like
4248@code{SIGALRM} be silently passed to your program
4249(so as not to interfere with their role in the program's functioning)
c906108c
SS
4250but to stop your program immediately whenever an error signal happens.
4251You can change these settings with the @code{handle} command.
4252
4253@table @code
4254@kindex info signals
09d4efe1 4255@kindex info handle
c906108c 4256@item info signals
96a2c332 4257@itemx info handle
c906108c
SS
4258Print a table of all the kinds of signals and how @value{GDBN} has been told to
4259handle each one. You can use this to see the signal numbers of all
4260the defined types of signals.
4261
45ac1734
EZ
4262@item info signals @var{sig}
4263Similar, but print information only about the specified signal number.
4264
d4f3574e 4265@code{info handle} is an alias for @code{info signals}.
c906108c
SS
4266
4267@kindex handle
45ac1734 4268@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
4269Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4270can be the number of a signal or its name (with or without the
24f93129 4271@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 4272@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
4273known signals. Optional arguments @var{keywords}, described below,
4274say what change to make.
c906108c
SS
4275@end table
4276
4277@c @group
4278The keywords allowed by the @code{handle} command can be abbreviated.
4279Their full names are:
4280
4281@table @code
4282@item nostop
4283@value{GDBN} should not stop your program when this signal happens. It may
4284still print a message telling you that the signal has come in.
4285
4286@item stop
4287@value{GDBN} should stop your program when this signal happens. This implies
4288the @code{print} keyword as well.
4289
4290@item print
4291@value{GDBN} should print a message when this signal happens.
4292
4293@item noprint
4294@value{GDBN} should not mention the occurrence of the signal at all. This
4295implies the @code{nostop} keyword as well.
4296
4297@item pass
5ece1a18 4298@itemx noignore
c906108c
SS
4299@value{GDBN} should allow your program to see this signal; your program
4300can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 4301and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
4302
4303@item nopass
5ece1a18 4304@itemx ignore
c906108c 4305@value{GDBN} should not allow your program to see this signal.
5ece1a18 4306@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
4307@end table
4308@c @end group
4309
d4f3574e
SS
4310When a signal stops your program, the signal is not visible to the
4311program until you
c906108c
SS
4312continue. Your program sees the signal then, if @code{pass} is in
4313effect for the signal in question @emph{at that time}. In other words,
4314after @value{GDBN} reports a signal, you can use the @code{handle}
4315command with @code{pass} or @code{nopass} to control whether your
4316program sees that signal when you continue.
4317
24f93129
EZ
4318The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4319non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4320@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4321erroneous signals.
4322
c906108c
SS
4323You can also use the @code{signal} command to prevent your program from
4324seeing a signal, or cause it to see a signal it normally would not see,
4325or to give it any signal at any time. For example, if your program stopped
4326due to some sort of memory reference error, you might store correct
4327values into the erroneous variables and continue, hoping to see more
4328execution; but your program would probably terminate immediately as
4329a result of the fatal signal once it saw the signal. To prevent this,
4330you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 4331Program a Signal}.
c906108c 4332
6d2ebf8b 4333@node Thread Stops
79a6e687 4334@section Stopping and Starting Multi-thread Programs
c906108c
SS
4335
4336When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 4337Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
4338breakpoints on all threads, or on a particular thread.
4339
4340@table @code
4341@cindex breakpoints and threads
4342@cindex thread breakpoints
4343@kindex break @dots{} thread @var{threadno}
4344@item break @var{linespec} thread @var{threadno}
4345@itemx break @var{linespec} thread @var{threadno} if @dots{}
4346@var{linespec} specifies source lines; there are several ways of
4347writing them, but the effect is always to specify some source line.
4348
4349Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4350to specify that you only want @value{GDBN} to stop the program when a
4351particular thread reaches this breakpoint. @var{threadno} is one of the
4352numeric thread identifiers assigned by @value{GDBN}, shown in the first
4353column of the @samp{info threads} display.
4354
4355If you do not specify @samp{thread @var{threadno}} when you set a
4356breakpoint, the breakpoint applies to @emph{all} threads of your
4357program.
4358
4359You can use the @code{thread} qualifier on conditional breakpoints as
4360well; in this case, place @samp{thread @var{threadno}} before the
4361breakpoint condition, like this:
4362
4363@smallexample
2df3850c 4364(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4365@end smallexample
4366
4367@end table
4368
4369@cindex stopped threads
4370@cindex threads, stopped
4371Whenever your program stops under @value{GDBN} for any reason,
4372@emph{all} threads of execution stop, not just the current thread. This
4373allows you to examine the overall state of the program, including
4374switching between threads, without worrying that things may change
4375underfoot.
4376
36d86913
MC
4377@cindex thread breakpoints and system calls
4378@cindex system calls and thread breakpoints
4379@cindex premature return from system calls
4380There is an unfortunate side effect. If one thread stops for a
4381breakpoint, or for some other reason, and another thread is blocked in a
4382system call, then the system call may return prematurely. This is a
4383consequence of the interaction between multiple threads and the signals
4384that @value{GDBN} uses to implement breakpoints and other events that
4385stop execution.
4386
4387To handle this problem, your program should check the return value of
4388each system call and react appropriately. This is good programming
4389style anyways.
4390
4391For example, do not write code like this:
4392
4393@smallexample
4394 sleep (10);
4395@end smallexample
4396
4397The call to @code{sleep} will return early if a different thread stops
4398at a breakpoint or for some other reason.
4399
4400Instead, write this:
4401
4402@smallexample
4403 int unslept = 10;
4404 while (unslept > 0)
4405 unslept = sleep (unslept);
4406@end smallexample
4407
4408A system call is allowed to return early, so the system is still
4409conforming to its specification. But @value{GDBN} does cause your
4410multi-threaded program to behave differently than it would without
4411@value{GDBN}.
4412
4413Also, @value{GDBN} uses internal breakpoints in the thread library to
4414monitor certain events such as thread creation and thread destruction.
4415When such an event happens, a system call in another thread may return
4416prematurely, even though your program does not appear to stop.
4417
c906108c
SS
4418@cindex continuing threads
4419@cindex threads, continuing
4420Conversely, whenever you restart the program, @emph{all} threads start
4421executing. @emph{This is true even when single-stepping} with commands
5d161b24 4422like @code{step} or @code{next}.
c906108c
SS
4423
4424In particular, @value{GDBN} cannot single-step all threads in lockstep.
4425Since thread scheduling is up to your debugging target's operating
4426system (not controlled by @value{GDBN}), other threads may
4427execute more than one statement while the current thread completes a
4428single step. Moreover, in general other threads stop in the middle of a
4429statement, rather than at a clean statement boundary, when the program
4430stops.
4431
4432You might even find your program stopped in another thread after
4433continuing or even single-stepping. This happens whenever some other
4434thread runs into a breakpoint, a signal, or an exception before the
4435first thread completes whatever you requested.
4436
4437On some OSes, you can lock the OS scheduler and thus allow only a single
4438thread to run.
4439
4440@table @code
4441@item set scheduler-locking @var{mode}
9c16f35a
EZ
4442@cindex scheduler locking mode
4443@cindex lock scheduler
c906108c
SS
4444Set the scheduler locking mode. If it is @code{off}, then there is no
4445locking and any thread may run at any time. If @code{on}, then only the
4446current thread may run when the inferior is resumed. The @code{step}
4447mode optimizes for single-stepping. It stops other threads from
4448``seizing the prompt'' by preempting the current thread while you are
4449stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4450when you step. They are more likely to run when you @samp{next} over a
c906108c 4451function call, and they are completely free to run when you use commands
d4f3574e 4452like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4453thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4454@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4455
4456@item show scheduler-locking
4457Display the current scheduler locking mode.
4458@end table
4459
c906108c 4460
6d2ebf8b 4461@node Stack
c906108c
SS
4462@chapter Examining the Stack
4463
4464When your program has stopped, the first thing you need to know is where it
4465stopped and how it got there.
4466
4467@cindex call stack
5d161b24
DB
4468Each time your program performs a function call, information about the call
4469is generated.
4470That information includes the location of the call in your program,
4471the arguments of the call,
c906108c 4472and the local variables of the function being called.
5d161b24 4473The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4474The stack frames are allocated in a region of memory called the @dfn{call
4475stack}.
4476
4477When your program stops, the @value{GDBN} commands for examining the
4478stack allow you to see all of this information.
4479
4480@cindex selected frame
4481One of the stack frames is @dfn{selected} by @value{GDBN} and many
4482@value{GDBN} commands refer implicitly to the selected frame. In
4483particular, whenever you ask @value{GDBN} for the value of a variable in
4484your program, the value is found in the selected frame. There are
4485special @value{GDBN} commands to select whichever frame you are
79a6e687 4486interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
4487
4488When your program stops, @value{GDBN} automatically selects the
5d161b24 4489currently executing frame and describes it briefly, similar to the
79a6e687 4490@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
4491
4492@menu
4493* Frames:: Stack frames
4494* Backtrace:: Backtraces
4495* Selection:: Selecting a frame
4496* Frame Info:: Information on a frame
c906108c
SS
4497
4498@end menu
4499
6d2ebf8b 4500@node Frames
79a6e687 4501@section Stack Frames
c906108c 4502
d4f3574e 4503@cindex frame, definition
c906108c
SS
4504@cindex stack frame
4505The call stack is divided up into contiguous pieces called @dfn{stack
4506frames}, or @dfn{frames} for short; each frame is the data associated
4507with one call to one function. The frame contains the arguments given
4508to the function, the function's local variables, and the address at
4509which the function is executing.
4510
4511@cindex initial frame
4512@cindex outermost frame
4513@cindex innermost frame
4514When your program is started, the stack has only one frame, that of the
4515function @code{main}. This is called the @dfn{initial} frame or the
4516@dfn{outermost} frame. Each time a function is called, a new frame is
4517made. Each time a function returns, the frame for that function invocation
4518is eliminated. If a function is recursive, there can be many frames for
4519the same function. The frame for the function in which execution is
4520actually occurring is called the @dfn{innermost} frame. This is the most
4521recently created of all the stack frames that still exist.
4522
4523@cindex frame pointer
4524Inside your program, stack frames are identified by their addresses. A
4525stack frame consists of many bytes, each of which has its own address; each
4526kind of computer has a convention for choosing one byte whose
4527address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4528in a register called the @dfn{frame pointer register}
4529(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4530
4531@cindex frame number
4532@value{GDBN} assigns numbers to all existing stack frames, starting with
4533zero for the innermost frame, one for the frame that called it,
4534and so on upward. These numbers do not really exist in your program;
4535they are assigned by @value{GDBN} to give you a way of designating stack
4536frames in @value{GDBN} commands.
4537
6d2ebf8b
SS
4538@c The -fomit-frame-pointer below perennially causes hbox overflow
4539@c underflow problems.
c906108c
SS
4540@cindex frameless execution
4541Some compilers provide a way to compile functions so that they operate
e22ea452 4542without stack frames. (For example, the @value{NGCC} option
474c8240 4543@smallexample
6d2ebf8b 4544@samp{-fomit-frame-pointer}
474c8240 4545@end smallexample
6d2ebf8b 4546generates functions without a frame.)
c906108c
SS
4547This is occasionally done with heavily used library functions to save
4548the frame setup time. @value{GDBN} has limited facilities for dealing
4549with these function invocations. If the innermost function invocation
4550has no stack frame, @value{GDBN} nevertheless regards it as though
4551it had a separate frame, which is numbered zero as usual, allowing
4552correct tracing of the function call chain. However, @value{GDBN} has
4553no provision for frameless functions elsewhere in the stack.
4554
4555@table @code
d4f3574e 4556@kindex frame@r{, command}
41afff9a 4557@cindex current stack frame
c906108c 4558@item frame @var{args}
5d161b24 4559The @code{frame} command allows you to move from one stack frame to another,
c906108c 4560and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4561address of the frame or the stack frame number. Without an argument,
4562@code{frame} prints the current stack frame.
c906108c
SS
4563
4564@kindex select-frame
41afff9a 4565@cindex selecting frame silently
c906108c
SS
4566@item select-frame
4567The @code{select-frame} command allows you to move from one stack frame
4568to another without printing the frame. This is the silent version of
4569@code{frame}.
4570@end table
4571
6d2ebf8b 4572@node Backtrace
c906108c
SS
4573@section Backtraces
4574
09d4efe1
EZ
4575@cindex traceback
4576@cindex call stack traces
c906108c
SS
4577A backtrace is a summary of how your program got where it is. It shows one
4578line per frame, for many frames, starting with the currently executing
4579frame (frame zero), followed by its caller (frame one), and on up the
4580stack.
4581
4582@table @code
4583@kindex backtrace
41afff9a 4584@kindex bt @r{(@code{backtrace})}
c906108c
SS
4585@item backtrace
4586@itemx bt
4587Print a backtrace of the entire stack: one line per frame for all
4588frames in the stack.
4589
4590You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 4591character, normally @kbd{Ctrl-c}.
c906108c
SS
4592
4593@item backtrace @var{n}
4594@itemx bt @var{n}
4595Similar, but print only the innermost @var{n} frames.
4596
4597@item backtrace -@var{n}
4598@itemx bt -@var{n}
4599Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4600
4601@item backtrace full
0f061b69 4602@itemx bt full
dd74f6ae
NR
4603@itemx bt full @var{n}
4604@itemx bt full -@var{n}
e7109c7e 4605Print the values of the local variables also. @var{n} specifies the
286ba84d 4606number of frames to print, as described above.
c906108c
SS
4607@end table
4608
4609@kindex where
4610@kindex info stack
c906108c
SS
4611The names @code{where} and @code{info stack} (abbreviated @code{info s})
4612are additional aliases for @code{backtrace}.
4613
839c27b7
EZ
4614@cindex multiple threads, backtrace
4615In a multi-threaded program, @value{GDBN} by default shows the
4616backtrace only for the current thread. To display the backtrace for
4617several or all of the threads, use the command @code{thread apply}
4618(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
4619apply all backtrace}, @value{GDBN} will display the backtrace for all
4620the threads; this is handy when you debug a core dump of a
4621multi-threaded program.
4622
c906108c
SS
4623Each line in the backtrace shows the frame number and the function name.
4624The program counter value is also shown---unless you use @code{set
4625print address off}. The backtrace also shows the source file name and
4626line number, as well as the arguments to the function. The program
4627counter value is omitted if it is at the beginning of the code for that
4628line number.
4629
4630Here is an example of a backtrace. It was made with the command
4631@samp{bt 3}, so it shows the innermost three frames.
4632
4633@smallexample
4634@group
5d161b24 4635#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4636 at builtin.c:993
4637#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4638#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4639 at macro.c:71
4640(More stack frames follow...)
4641@end group
4642@end smallexample
4643
4644@noindent
4645The display for frame zero does not begin with a program counter
4646value, indicating that your program has stopped at the beginning of the
4647code for line @code{993} of @code{builtin.c}.
4648
18999be5
EZ
4649@cindex value optimized out, in backtrace
4650@cindex function call arguments, optimized out
4651If your program was compiled with optimizations, some compilers will
4652optimize away arguments passed to functions if those arguments are
4653never used after the call. Such optimizations generate code that
4654passes arguments through registers, but doesn't store those arguments
4655in the stack frame. @value{GDBN} has no way of displaying such
4656arguments in stack frames other than the innermost one. Here's what
4657such a backtrace might look like:
4658
4659@smallexample
4660@group
4661#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4662 at builtin.c:993
4663#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4664#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4665 at macro.c:71
4666(More stack frames follow...)
4667@end group
4668@end smallexample
4669
4670@noindent
4671The values of arguments that were not saved in their stack frames are
4672shown as @samp{<value optimized out>}.
4673
4674If you need to display the values of such optimized-out arguments,
4675either deduce that from other variables whose values depend on the one
4676you are interested in, or recompile without optimizations.
4677
a8f24a35
EZ
4678@cindex backtrace beyond @code{main} function
4679@cindex program entry point
4680@cindex startup code, and backtrace
25d29d70
AC
4681Most programs have a standard user entry point---a place where system
4682libraries and startup code transition into user code. For C this is
d416eeec
EZ
4683@code{main}@footnote{
4684Note that embedded programs (the so-called ``free-standing''
4685environment) are not required to have a @code{main} function as the
4686entry point. They could even have multiple entry points.}.
4687When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4688it will terminate the backtrace, to avoid tracing into highly
4689system-specific (and generally uninteresting) code.
4690
4691If you need to examine the startup code, or limit the number of levels
4692in a backtrace, you can change this behavior:
95f90d25
DJ
4693
4694@table @code
25d29d70
AC
4695@item set backtrace past-main
4696@itemx set backtrace past-main on
4644b6e3 4697@kindex set backtrace
25d29d70
AC
4698Backtraces will continue past the user entry point.
4699
4700@item set backtrace past-main off
95f90d25
DJ
4701Backtraces will stop when they encounter the user entry point. This is the
4702default.
4703
25d29d70 4704@item show backtrace past-main
4644b6e3 4705@kindex show backtrace
25d29d70
AC
4706Display the current user entry point backtrace policy.
4707
2315ffec
RC
4708@item set backtrace past-entry
4709@itemx set backtrace past-entry on
a8f24a35 4710Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4711This entry point is encoded by the linker when the application is built,
4712and is likely before the user entry point @code{main} (or equivalent) is called.
4713
4714@item set backtrace past-entry off
d3e8051b 4715Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
4716application. This is the default.
4717
4718@item show backtrace past-entry
4719Display the current internal entry point backtrace policy.
4720
25d29d70
AC
4721@item set backtrace limit @var{n}
4722@itemx set backtrace limit 0
4723@cindex backtrace limit
4724Limit the backtrace to @var{n} levels. A value of zero means
4725unlimited.
95f90d25 4726
25d29d70
AC
4727@item show backtrace limit
4728Display the current limit on backtrace levels.
95f90d25
DJ
4729@end table
4730
6d2ebf8b 4731@node Selection
79a6e687 4732@section Selecting a Frame
c906108c
SS
4733
4734Most commands for examining the stack and other data in your program work on
4735whichever stack frame is selected at the moment. Here are the commands for
4736selecting a stack frame; all of them finish by printing a brief description
4737of the stack frame just selected.
4738
4739@table @code
d4f3574e 4740@kindex frame@r{, selecting}
41afff9a 4741@kindex f @r{(@code{frame})}
c906108c
SS
4742@item frame @var{n}
4743@itemx f @var{n}
4744Select frame number @var{n}. Recall that frame zero is the innermost
4745(currently executing) frame, frame one is the frame that called the
4746innermost one, and so on. The highest-numbered frame is the one for
4747@code{main}.
4748
4749@item frame @var{addr}
4750@itemx f @var{addr}
4751Select the frame at address @var{addr}. This is useful mainly if the
4752chaining of stack frames has been damaged by a bug, making it
4753impossible for @value{GDBN} to assign numbers properly to all frames. In
4754addition, this can be useful when your program has multiple stacks and
4755switches between them.
4756
c906108c
SS
4757On the SPARC architecture, @code{frame} needs two addresses to
4758select an arbitrary frame: a frame pointer and a stack pointer.
4759
4760On the MIPS and Alpha architecture, it needs two addresses: a stack
4761pointer and a program counter.
4762
4763On the 29k architecture, it needs three addresses: a register stack
4764pointer, a program counter, and a memory stack pointer.
c906108c
SS
4765
4766@kindex up
4767@item up @var{n}
4768Move @var{n} frames up the stack. For positive numbers @var{n}, this
4769advances toward the outermost frame, to higher frame numbers, to frames
4770that have existed longer. @var{n} defaults to one.
4771
4772@kindex down
41afff9a 4773@kindex do @r{(@code{down})}
c906108c
SS
4774@item down @var{n}
4775Move @var{n} frames down the stack. For positive numbers @var{n}, this
4776advances toward the innermost frame, to lower frame numbers, to frames
4777that were created more recently. @var{n} defaults to one. You may
4778abbreviate @code{down} as @code{do}.
4779@end table
4780
4781All of these commands end by printing two lines of output describing the
4782frame. The first line shows the frame number, the function name, the
4783arguments, and the source file and line number of execution in that
5d161b24 4784frame. The second line shows the text of that source line.
c906108c
SS
4785
4786@need 1000
4787For example:
4788
4789@smallexample
4790@group
4791(@value{GDBP}) up
4792#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4793 at env.c:10
479410 read_input_file (argv[i]);
4795@end group
4796@end smallexample
4797
4798After such a printout, the @code{list} command with no arguments
4799prints ten lines centered on the point of execution in the frame.
87885426
FN
4800You can also edit the program at the point of execution with your favorite
4801editing program by typing @code{edit}.
79a6e687 4802@xref{List, ,Printing Source Lines},
87885426 4803for details.
c906108c
SS
4804
4805@table @code
4806@kindex down-silently
4807@kindex up-silently
4808@item up-silently @var{n}
4809@itemx down-silently @var{n}
4810These two commands are variants of @code{up} and @code{down},
4811respectively; they differ in that they do their work silently, without
4812causing display of the new frame. They are intended primarily for use
4813in @value{GDBN} command scripts, where the output might be unnecessary and
4814distracting.
4815@end table
4816
6d2ebf8b 4817@node Frame Info
79a6e687 4818@section Information About a Frame
c906108c
SS
4819
4820There are several other commands to print information about the selected
4821stack frame.
4822
4823@table @code
4824@item frame
4825@itemx f
4826When used without any argument, this command does not change which
4827frame is selected, but prints a brief description of the currently
4828selected stack frame. It can be abbreviated @code{f}. With an
4829argument, this command is used to select a stack frame.
79a6e687 4830@xref{Selection, ,Selecting a Frame}.
c906108c
SS
4831
4832@kindex info frame
41afff9a 4833@kindex info f @r{(@code{info frame})}
c906108c
SS
4834@item info frame
4835@itemx info f
4836This command prints a verbose description of the selected stack frame,
4837including:
4838
4839@itemize @bullet
5d161b24
DB
4840@item
4841the address of the frame
c906108c
SS
4842@item
4843the address of the next frame down (called by this frame)
4844@item
4845the address of the next frame up (caller of this frame)
4846@item
4847the language in which the source code corresponding to this frame is written
4848@item
4849the address of the frame's arguments
4850@item
d4f3574e
SS
4851the address of the frame's local variables
4852@item
c906108c
SS
4853the program counter saved in it (the address of execution in the caller frame)
4854@item
4855which registers were saved in the frame
4856@end itemize
4857
4858@noindent The verbose description is useful when
4859something has gone wrong that has made the stack format fail to fit
4860the usual conventions.
4861
4862@item info frame @var{addr}
4863@itemx info f @var{addr}
4864Print a verbose description of the frame at address @var{addr}, without
4865selecting that frame. The selected frame remains unchanged by this
4866command. This requires the same kind of address (more than one for some
4867architectures) that you specify in the @code{frame} command.
79a6e687 4868@xref{Selection, ,Selecting a Frame}.
c906108c
SS
4869
4870@kindex info args
4871@item info args
4872Print the arguments of the selected frame, each on a separate line.
4873
4874@item info locals
4875@kindex info locals
4876Print the local variables of the selected frame, each on a separate
4877line. These are all variables (declared either static or automatic)
4878accessible at the point of execution of the selected frame.
4879
c906108c 4880@kindex info catch
d4f3574e
SS
4881@cindex catch exceptions, list active handlers
4882@cindex exception handlers, how to list
c906108c
SS
4883@item info catch
4884Print a list of all the exception handlers that are active in the
4885current stack frame at the current point of execution. To see other
4886exception handlers, visit the associated frame (using the @code{up},
4887@code{down}, or @code{frame} commands); then type @code{info catch}.
79a6e687 4888@xref{Set Catchpoints, , Setting Catchpoints}.
53a5351d 4889
c906108c
SS
4890@end table
4891
c906108c 4892
6d2ebf8b 4893@node Source
c906108c
SS
4894@chapter Examining Source Files
4895
4896@value{GDBN} can print parts of your program's source, since the debugging
4897information recorded in the program tells @value{GDBN} what source files were
4898used to build it. When your program stops, @value{GDBN} spontaneously prints
4899the line where it stopped. Likewise, when you select a stack frame
79a6e687 4900(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
4901execution in that frame has stopped. You can print other portions of
4902source files by explicit command.
4903
7a292a7a 4904If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4905prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4906@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4907
4908@menu
4909* List:: Printing source lines
87885426 4910* Edit:: Editing source files
c906108c 4911* Search:: Searching source files
c906108c
SS
4912* Source Path:: Specifying source directories
4913* Machine Code:: Source and machine code
4914@end menu
4915
6d2ebf8b 4916@node List
79a6e687 4917@section Printing Source Lines
c906108c
SS
4918
4919@kindex list
41afff9a 4920@kindex l @r{(@code{list})}
c906108c 4921To print lines from a source file, use the @code{list} command
5d161b24 4922(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4923There are several ways to specify what part of the file you want to print.
4924
4925Here are the forms of the @code{list} command most commonly used:
4926
4927@table @code
4928@item list @var{linenum}
4929Print lines centered around line number @var{linenum} in the
4930current source file.
4931
4932@item list @var{function}
4933Print lines centered around the beginning of function
4934@var{function}.
4935
4936@item list
4937Print more lines. If the last lines printed were printed with a
4938@code{list} command, this prints lines following the last lines
4939printed; however, if the last line printed was a solitary line printed
4940as part of displaying a stack frame (@pxref{Stack, ,Examining the
4941Stack}), this prints lines centered around that line.
4942
4943@item list -
4944Print lines just before the lines last printed.
4945@end table
4946
9c16f35a 4947@cindex @code{list}, how many lines to display
c906108c
SS
4948By default, @value{GDBN} prints ten source lines with any of these forms of
4949the @code{list} command. You can change this using @code{set listsize}:
4950
4951@table @code
4952@kindex set listsize
4953@item set listsize @var{count}
4954Make the @code{list} command display @var{count} source lines (unless
4955the @code{list} argument explicitly specifies some other number).
4956
4957@kindex show listsize
4958@item show listsize
4959Display the number of lines that @code{list} prints.
4960@end table
4961
4962Repeating a @code{list} command with @key{RET} discards the argument,
4963so it is equivalent to typing just @code{list}. This is more useful
4964than listing the same lines again. An exception is made for an
4965argument of @samp{-}; that argument is preserved in repetition so that
4966each repetition moves up in the source file.
4967
4968@cindex linespec
4969In general, the @code{list} command expects you to supply zero, one or two
4970@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4971of writing them, but the effect is always to specify some source line.
c906108c
SS
4972Here is a complete description of the possible arguments for @code{list}:
4973
4974@table @code
4975@item list @var{linespec}
4976Print lines centered around the line specified by @var{linespec}.
4977
4978@item list @var{first},@var{last}
4979Print lines from @var{first} to @var{last}. Both arguments are
4980linespecs.
4981
4982@item list ,@var{last}
4983Print lines ending with @var{last}.
4984
4985@item list @var{first},
4986Print lines starting with @var{first}.
4987
4988@item list +
4989Print lines just after the lines last printed.
4990
4991@item list -
4992Print lines just before the lines last printed.
4993
4994@item list
4995As described in the preceding table.
4996@end table
4997
4998Here are the ways of specifying a single source line---all the
4999kinds of linespec.
5000
5001@table @code
5002@item @var{number}
5003Specifies line @var{number} of the current source file.
5004When a @code{list} command has two linespecs, this refers to
5005the same source file as the first linespec.
5006
5007@item +@var{offset}
5008Specifies the line @var{offset} lines after the last line printed.
5009When used as the second linespec in a @code{list} command that has
5010two, this specifies the line @var{offset} lines down from the
5011first linespec.
5012
5013@item -@var{offset}
5014Specifies the line @var{offset} lines before the last line printed.
5015
5016@item @var{filename}:@var{number}
5017Specifies line @var{number} in the source file @var{filename}.
5018
5019@item @var{function}
5020Specifies the line that begins the body of the function @var{function}.
5021For example: in C, this is the line with the open brace.
5022
5023@item @var{filename}:@var{function}
5024Specifies the line of the open-brace that begins the body of the
5025function @var{function} in the file @var{filename}. You only need the
5026file name with a function name to avoid ambiguity when there are
5027identically named functions in different source files.
5028
5029@item *@var{address}
5030Specifies the line containing the program address @var{address}.
5031@var{address} may be any expression.
5032@end table
5033
87885426 5034@node Edit
79a6e687 5035@section Editing Source Files
87885426
FN
5036@cindex editing source files
5037
5038@kindex edit
5039@kindex e @r{(@code{edit})}
5040To edit the lines in a source file, use the @code{edit} command.
5041The editing program of your choice
5042is invoked with the current line set to
5043the active line in the program.
5044Alternatively, there are several ways to specify what part of the file you
5045want to print if you want to see other parts of the program.
5046
5047Here are the forms of the @code{edit} command most commonly used:
5048
5049@table @code
5050@item edit
5051Edit the current source file at the active line number in the program.
5052
5053@item edit @var{number}
5054Edit the current source file with @var{number} as the active line number.
5055
5056@item edit @var{function}
5057Edit the file containing @var{function} at the beginning of its definition.
5058
5059@item edit @var{filename}:@var{number}
5060Specifies line @var{number} in the source file @var{filename}.
5061
5062@item edit @var{filename}:@var{function}
5063Specifies the line that begins the body of the
5064function @var{function} in the file @var{filename}. You only need the
5065file name with a function name to avoid ambiguity when there are
5066identically named functions in different source files.
5067
5068@item edit *@var{address}
5069Specifies the line containing the program address @var{address}.
5070@var{address} may be any expression.
5071@end table
5072
79a6e687 5073@subsection Choosing your Editor
87885426
FN
5074You can customize @value{GDBN} to use any editor you want
5075@footnote{
5076The only restriction is that your editor (say @code{ex}), recognizes the
5077following command-line syntax:
10998722 5078@smallexample
87885426 5079ex +@var{number} file
10998722 5080@end smallexample
15387254
EZ
5081The optional numeric value +@var{number} specifies the number of the line in
5082the file where to start editing.}.
5083By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
5084by setting the environment variable @code{EDITOR} before using
5085@value{GDBN}. For example, to configure @value{GDBN} to use the
5086@code{vi} editor, you could use these commands with the @code{sh} shell:
5087@smallexample
87885426
FN
5088EDITOR=/usr/bin/vi
5089export EDITOR
15387254 5090gdb @dots{}
10998722 5091@end smallexample
87885426 5092or in the @code{csh} shell,
10998722 5093@smallexample
87885426 5094setenv EDITOR /usr/bin/vi
15387254 5095gdb @dots{}
10998722 5096@end smallexample
87885426 5097
6d2ebf8b 5098@node Search
79a6e687 5099@section Searching Source Files
15387254 5100@cindex searching source files
c906108c
SS
5101
5102There are two commands for searching through the current source file for a
5103regular expression.
5104
5105@table @code
5106@kindex search
5107@kindex forward-search
5108@item forward-search @var{regexp}
5109@itemx search @var{regexp}
5110The command @samp{forward-search @var{regexp}} checks each line,
5111starting with the one following the last line listed, for a match for
5d161b24 5112@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
5113synonym @samp{search @var{regexp}} or abbreviate the command name as
5114@code{fo}.
5115
09d4efe1 5116@kindex reverse-search
c906108c
SS
5117@item reverse-search @var{regexp}
5118The command @samp{reverse-search @var{regexp}} checks each line, starting
5119with the one before the last line listed and going backward, for a match
5120for @var{regexp}. It lists the line that is found. You can abbreviate
5121this command as @code{rev}.
5122@end table
c906108c 5123
6d2ebf8b 5124@node Source Path
79a6e687 5125@section Specifying Source Directories
c906108c
SS
5126
5127@cindex source path
5128@cindex directories for source files
5129Executable programs sometimes do not record the directories of the source
5130files from which they were compiled, just the names. Even when they do,
5131the directories could be moved between the compilation and your debugging
5132session. @value{GDBN} has a list of directories to search for source files;
5133this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
5134it tries all the directories in the list, in the order they are present
0b66e38c
EZ
5135in the list, until it finds a file with the desired name.
5136
5137For example, suppose an executable references the file
5138@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
5139@file{/mnt/cross}. The file is first looked up literally; if this
5140fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
5141fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
5142message is printed. @value{GDBN} does not look up the parts of the
5143source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
5144Likewise, the subdirectories of the source path are not searched: if
5145the source path is @file{/mnt/cross}, and the binary refers to
5146@file{foo.c}, @value{GDBN} would not find it under
5147@file{/mnt/cross/usr/src/foo-1.0/lib}.
5148
5149Plain file names, relative file names with leading directories, file
5150names containing dots, etc.@: are all treated as described above; for
5151instance, if the source path is @file{/mnt/cross}, and the source file
5152is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
5153@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
5154that---@file{/mnt/cross/foo.c}.
5155
5156Note that the executable search path is @emph{not} used to locate the
cd852561 5157source files.
c906108c
SS
5158
5159Whenever you reset or rearrange the source path, @value{GDBN} clears out
5160any information it has cached about where source files are found and where
5161each line is in the file.
5162
5163@kindex directory
5164@kindex dir
d4f3574e
SS
5165When you start @value{GDBN}, its source path includes only @samp{cdir}
5166and @samp{cwd}, in that order.
c906108c
SS
5167To add other directories, use the @code{directory} command.
5168
4b505b12
AS
5169The search path is used to find both program source files and @value{GDBN}
5170script files (read using the @samp{-command} option and @samp{source} command).
5171
30daae6c
JB
5172In addition to the source path, @value{GDBN} provides a set of commands
5173that manage a list of source path substitution rules. A @dfn{substitution
5174rule} specifies how to rewrite source directories stored in the program's
5175debug information in case the sources were moved to a different
5176directory between compilation and debugging. A rule is made of
5177two strings, the first specifying what needs to be rewritten in
5178the path, and the second specifying how it should be rewritten.
5179In @ref{set substitute-path}, we name these two parts @var{from} and
5180@var{to} respectively. @value{GDBN} does a simple string replacement
5181of @var{from} with @var{to} at the start of the directory part of the
5182source file name, and uses that result instead of the original file
5183name to look up the sources.
5184
5185Using the previous example, suppose the @file{foo-1.0} tree has been
5186moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 5187@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
5188@file{/mnt/cross}. The first lookup will then be
5189@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
5190of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
5191substitution rule, use the @code{set substitute-path} command
5192(@pxref{set substitute-path}).
5193
5194To avoid unexpected substitution results, a rule is applied only if the
5195@var{from} part of the directory name ends at a directory separator.
5196For instance, a rule substituting @file{/usr/source} into
5197@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
5198not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 5199is applied only at the beginning of the directory name, this rule will
30daae6c
JB
5200not be applied to @file{/root/usr/source/baz.c} either.
5201
5202In many cases, you can achieve the same result using the @code{directory}
5203command. However, @code{set substitute-path} can be more efficient in
5204the case where the sources are organized in a complex tree with multiple
5205subdirectories. With the @code{directory} command, you need to add each
5206subdirectory of your project. If you moved the entire tree while
5207preserving its internal organization, then @code{set substitute-path}
5208allows you to direct the debugger to all the sources with one single
5209command.
5210
5211@code{set substitute-path} is also more than just a shortcut command.
5212The source path is only used if the file at the original location no
5213longer exists. On the other hand, @code{set substitute-path} modifies
5214the debugger behavior to look at the rewritten location instead. So, if
5215for any reason a source file that is not relevant to your executable is
5216located at the original location, a substitution rule is the only
3f94c067 5217method available to point @value{GDBN} at the new location.
30daae6c 5218
c906108c
SS
5219@table @code
5220@item directory @var{dirname} @dots{}
5221@item dir @var{dirname} @dots{}
5222Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
5223directory names may be given to this command, separated by @samp{:}
5224(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5225part of absolute file names) or
c906108c
SS
5226whitespace. You may specify a directory that is already in the source
5227path; this moves it forward, so @value{GDBN} searches it sooner.
5228
5229@kindex cdir
5230@kindex cwd
41afff9a 5231@vindex $cdir@r{, convenience variable}
d3e8051b 5232@vindex $cwd@r{, convenience variable}
c906108c
SS
5233@cindex compilation directory
5234@cindex current directory
5235@cindex working directory
5236@cindex directory, current
5237@cindex directory, compilation
5238You can use the string @samp{$cdir} to refer to the compilation
5239directory (if one is recorded), and @samp{$cwd} to refer to the current
5240working directory. @samp{$cwd} is not the same as @samp{.}---the former
5241tracks the current working directory as it changes during your @value{GDBN}
5242session, while the latter is immediately expanded to the current
5243directory at the time you add an entry to the source path.
5244
5245@item directory
cd852561 5246Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
5247
5248@c RET-repeat for @code{directory} is explicitly disabled, but since
5249@c repeating it would be a no-op we do not say that. (thanks to RMS)
5250
5251@item show directories
5252@kindex show directories
5253Print the source path: show which directories it contains.
30daae6c
JB
5254
5255@anchor{set substitute-path}
5256@item set substitute-path @var{from} @var{to}
5257@kindex set substitute-path
5258Define a source path substitution rule, and add it at the end of the
5259current list of existing substitution rules. If a rule with the same
5260@var{from} was already defined, then the old rule is also deleted.
5261
5262For example, if the file @file{/foo/bar/baz.c} was moved to
5263@file{/mnt/cross/baz.c}, then the command
5264
5265@smallexample
5266(@value{GDBP}) set substitute-path /usr/src /mnt/cross
5267@end smallexample
5268
5269@noindent
5270will tell @value{GDBN} to replace @samp{/usr/src} with
5271@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
5272@file{baz.c} even though it was moved.
5273
5274In the case when more than one substitution rule have been defined,
5275the rules are evaluated one by one in the order where they have been
5276defined. The first one matching, if any, is selected to perform
5277the substitution.
5278
5279For instance, if we had entered the following commands:
5280
5281@smallexample
5282(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
5283(@value{GDBP}) set substitute-path /usr/src /mnt/src
5284@end smallexample
5285
5286@noindent
5287@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
5288@file{/mnt/include/defs.h} by using the first rule. However, it would
5289use the second rule to rewrite @file{/usr/src/lib/foo.c} into
5290@file{/mnt/src/lib/foo.c}.
5291
5292
5293@item unset substitute-path [path]
5294@kindex unset substitute-path
5295If a path is specified, search the current list of substitution rules
5296for a rule that would rewrite that path. Delete that rule if found.
5297A warning is emitted by the debugger if no rule could be found.
5298
5299If no path is specified, then all substitution rules are deleted.
5300
5301@item show substitute-path [path]
5302@kindex show substitute-path
5303If a path is specified, then print the source path substitution rule
5304which would rewrite that path, if any.
5305
5306If no path is specified, then print all existing source path substitution
5307rules.
5308
c906108c
SS
5309@end table
5310
5311If your source path is cluttered with directories that are no longer of
5312interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5313versions of source. You can correct the situation as follows:
5314
5315@enumerate
5316@item
cd852561 5317Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
5318
5319@item
5320Use @code{directory} with suitable arguments to reinstall the
5321directories you want in the source path. You can add all the
5322directories in one command.
5323@end enumerate
5324
6d2ebf8b 5325@node Machine Code
79a6e687 5326@section Source and Machine Code
15387254 5327@cindex source line and its code address
c906108c
SS
5328
5329You can use the command @code{info line} to map source lines to program
5330addresses (and vice versa), and the command @code{disassemble} to display
5331a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 5332mode, the @code{info line} command causes the arrow to point to the
5d161b24 5333line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
5334well as hex.
5335
5336@table @code
5337@kindex info line
5338@item info line @var{linespec}
5339Print the starting and ending addresses of the compiled code for
5340source line @var{linespec}. You can specify source lines in any of
5341the ways understood by the @code{list} command (@pxref{List, ,Printing
79a6e687 5342Source Lines}).
c906108c
SS
5343@end table
5344
5345For example, we can use @code{info line} to discover the location of
5346the object code for the first line of function
5347@code{m4_changequote}:
5348
d4f3574e
SS
5349@c FIXME: I think this example should also show the addresses in
5350@c symbolic form, as they usually would be displayed.
c906108c 5351@smallexample
96a2c332 5352(@value{GDBP}) info line m4_changequote
c906108c
SS
5353Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5354@end smallexample
5355
5356@noindent
15387254 5357@cindex code address and its source line
c906108c
SS
5358We can also inquire (using @code{*@var{addr}} as the form for
5359@var{linespec}) what source line covers a particular address:
5360@smallexample
5361(@value{GDBP}) info line *0x63ff
5362Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5363@end smallexample
5364
5365@cindex @code{$_} and @code{info line}
15387254 5366@cindex @code{x} command, default address
41afff9a 5367@kindex x@r{(examine), and} info line
c906108c
SS
5368After @code{info line}, the default address for the @code{x} command
5369is changed to the starting address of the line, so that @samp{x/i} is
5370sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 5371,Examining Memory}). Also, this address is saved as the value of the
c906108c 5372convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 5373Variables}).
c906108c
SS
5374
5375@table @code
5376@kindex disassemble
5377@cindex assembly instructions
5378@cindex instructions, assembly
5379@cindex machine instructions
5380@cindex listing machine instructions
5381@item disassemble
5382This specialized command dumps a range of memory as machine
5383instructions. The default memory range is the function surrounding the
5384program counter of the selected frame. A single argument to this
5385command is a program counter value; @value{GDBN} dumps the function
5386surrounding this value. Two arguments specify a range of addresses
5387(first inclusive, second exclusive) to dump.
5388@end table
5389
c906108c
SS
5390The following example shows the disassembly of a range of addresses of
5391HP PA-RISC 2.0 code:
5392
5393@smallexample
5394(@value{GDBP}) disas 0x32c4 0x32e4
5395Dump of assembler code from 0x32c4 to 0x32e4:
53960x32c4 <main+204>: addil 0,dp
53970x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
53980x32cc <main+212>: ldil 0x3000,r31
53990x32d0 <main+216>: ble 0x3f8(sr4,r31)
54000x32d4 <main+220>: ldo 0(r31),rp
54010x32d8 <main+224>: addil -0x800,dp
54020x32dc <main+228>: ldo 0x588(r1),r26
54030x32e0 <main+232>: ldil 0x3000,r31
5404End of assembler dump.
5405@end smallexample
c906108c
SS
5406
5407Some architectures have more than one commonly-used set of instruction
5408mnemonics or other syntax.
5409
76d17f34
EZ
5410For programs that were dynamically linked and use shared libraries,
5411instructions that call functions or branch to locations in the shared
5412libraries might show a seemingly bogus location---it's actually a
5413location of the relocation table. On some architectures, @value{GDBN}
5414might be able to resolve these to actual function names.
5415
c906108c 5416@table @code
d4f3574e 5417@kindex set disassembly-flavor
d4f3574e
SS
5418@cindex Intel disassembly flavor
5419@cindex AT&T disassembly flavor
5420@item set disassembly-flavor @var{instruction-set}
c906108c
SS
5421Select the instruction set to use when disassembling the
5422program via the @code{disassemble} or @code{x/i} commands.
5423
5424Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
5425can set @var{instruction-set} to either @code{intel} or @code{att}.
5426The default is @code{att}, the AT&T flavor used by default by Unix
5427assemblers for x86-based targets.
9c16f35a
EZ
5428
5429@kindex show disassembly-flavor
5430@item show disassembly-flavor
5431Show the current setting of the disassembly flavor.
c906108c
SS
5432@end table
5433
5434
6d2ebf8b 5435@node Data
c906108c
SS
5436@chapter Examining Data
5437
5438@cindex printing data
5439@cindex examining data
5440@kindex print
5441@kindex inspect
5442@c "inspect" is not quite a synonym if you are using Epoch, which we do not
5443@c document because it is nonstandard... Under Epoch it displays in a
5444@c different window or something like that.
5445The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
5446command (abbreviated @code{p}), or its synonym @code{inspect}. It
5447evaluates and prints the value of an expression of the language your
5448program is written in (@pxref{Languages, ,Using @value{GDBN} with
5449Different Languages}).
c906108c
SS
5450
5451@table @code
d4f3574e
SS
5452@item print @var{expr}
5453@itemx print /@var{f} @var{expr}
5454@var{expr} is an expression (in the source language). By default the
5455value of @var{expr} is printed in a format appropriate to its data type;
c906108c 5456you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 5457@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 5458Formats}.
c906108c
SS
5459
5460@item print
5461@itemx print /@var{f}
15387254 5462@cindex reprint the last value
d4f3574e 5463If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 5464@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
5465conveniently inspect the same value in an alternative format.
5466@end table
5467
5468A more low-level way of examining data is with the @code{x} command.
5469It examines data in memory at a specified address and prints it in a
79a6e687 5470specified format. @xref{Memory, ,Examining Memory}.
c906108c 5471
7a292a7a 5472If you are interested in information about types, or about how the
d4f3574e
SS
5473fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5474command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 5475Table}.
c906108c
SS
5476
5477@menu
5478* Expressions:: Expressions
5479* Variables:: Program variables
5480* Arrays:: Artificial arrays
5481* Output Formats:: Output formats
5482* Memory:: Examining memory
5483* Auto Display:: Automatic display
5484* Print Settings:: Print settings
5485* Value History:: Value history
5486* Convenience Vars:: Convenience variables
5487* Registers:: Registers
c906108c 5488* Floating Point Hardware:: Floating point hardware
53c69bd7 5489* Vector Unit:: Vector Unit
721c2651 5490* OS Information:: Auxiliary data provided by operating system
29e57380 5491* Memory Region Attributes:: Memory region attributes
16d9dec6 5492* Dump/Restore Files:: Copy between memory and a file
384ee23f 5493* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5494* Character Sets:: Debugging programs that use a different
5495 character set than GDB does
09d4efe1 5496* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5497@end menu
5498
6d2ebf8b 5499@node Expressions
c906108c
SS
5500@section Expressions
5501
5502@cindex expressions
5503@code{print} and many other @value{GDBN} commands accept an expression and
5504compute its value. Any kind of constant, variable or operator defined
5505by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5506@value{GDBN}. This includes conditional expressions, function calls,
5507casts, and string constants. It also includes preprocessor macros, if
5508you compiled your program to include this information; see
5509@ref{Compilation}.
c906108c 5510
15387254 5511@cindex arrays in expressions
d4f3574e
SS
5512@value{GDBN} supports array constants in expressions input by
5513the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5514you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5515memory that is @code{malloc}ed in the target program.
c906108c 5516
c906108c
SS
5517Because C is so widespread, most of the expressions shown in examples in
5518this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5519Languages}, for information on how to use expressions in other
5520languages.
5521
5522In this section, we discuss operators that you can use in @value{GDBN}
5523expressions regardless of your programming language.
5524
15387254 5525@cindex casts, in expressions
c906108c
SS
5526Casts are supported in all languages, not just in C, because it is so
5527useful to cast a number into a pointer in order to examine a structure
5528at that address in memory.
5529@c FIXME: casts supported---Mod2 true?
c906108c
SS
5530
5531@value{GDBN} supports these operators, in addition to those common
5532to programming languages:
5533
5534@table @code
5535@item @@
5536@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 5537@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
5538
5539@item ::
5540@samp{::} allows you to specify a variable in terms of the file or
79a6e687 5541function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
5542
5543@cindex @{@var{type}@}
5544@cindex type casting memory
5545@cindex memory, viewing as typed object
5546@cindex casts, to view memory
5547@item @{@var{type}@} @var{addr}
5548Refers to an object of type @var{type} stored at address @var{addr} in
5549memory. @var{addr} may be any expression whose value is an integer or
5550pointer (but parentheses are required around binary operators, just as in
5551a cast). This construct is allowed regardless of what kind of data is
5552normally supposed to reside at @var{addr}.
5553@end table
5554
6d2ebf8b 5555@node Variables
79a6e687 5556@section Program Variables
c906108c
SS
5557
5558The most common kind of expression to use is the name of a variable
5559in your program.
5560
5561Variables in expressions are understood in the selected stack frame
79a6e687 5562(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
5563
5564@itemize @bullet
5565@item
5566global (or file-static)
5567@end itemize
5568
5d161b24 5569@noindent or
c906108c
SS
5570
5571@itemize @bullet
5572@item
5573visible according to the scope rules of the
5574programming language from the point of execution in that frame
5d161b24 5575@end itemize
c906108c
SS
5576
5577@noindent This means that in the function
5578
474c8240 5579@smallexample
c906108c
SS
5580foo (a)
5581 int a;
5582@{
5583 bar (a);
5584 @{
5585 int b = test ();
5586 bar (b);
5587 @}
5588@}
474c8240 5589@end smallexample
c906108c
SS
5590
5591@noindent
5592you can examine and use the variable @code{a} whenever your program is
5593executing within the function @code{foo}, but you can only use or
5594examine the variable @code{b} while your program is executing inside
5595the block where @code{b} is declared.
5596
5597@cindex variable name conflict
5598There is an exception: you can refer to a variable or function whose
5599scope is a single source file even if the current execution point is not
5600in this file. But it is possible to have more than one such variable or
5601function with the same name (in different source files). If that
5602happens, referring to that name has unpredictable effects. If you wish,
5603you can specify a static variable in a particular function or file,
15387254 5604using the colon-colon (@code{::}) notation:
c906108c 5605
d4f3574e 5606@cindex colon-colon, context for variables/functions
12c27660 5607@ifnotinfo
c906108c 5608@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5609@cindex @code{::}, context for variables/functions
12c27660 5610@end ifnotinfo
474c8240 5611@smallexample
c906108c
SS
5612@var{file}::@var{variable}
5613@var{function}::@var{variable}
474c8240 5614@end smallexample
c906108c
SS
5615
5616@noindent
5617Here @var{file} or @var{function} is the name of the context for the
5618static @var{variable}. In the case of file names, you can use quotes to
5619make sure @value{GDBN} parses the file name as a single word---for example,
5620to print a global value of @code{x} defined in @file{f2.c}:
5621
474c8240 5622@smallexample
c906108c 5623(@value{GDBP}) p 'f2.c'::x
474c8240 5624@end smallexample
c906108c 5625
b37052ae 5626@cindex C@t{++} scope resolution
c906108c 5627This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5628use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5629scope resolution operator in @value{GDBN} expressions.
5630@c FIXME: Um, so what happens in one of those rare cases where it's in
5631@c conflict?? --mew
c906108c
SS
5632
5633@cindex wrong values
5634@cindex variable values, wrong
15387254
EZ
5635@cindex function entry/exit, wrong values of variables
5636@cindex optimized code, wrong values of variables
c906108c
SS
5637@quotation
5638@emph{Warning:} Occasionally, a local variable may appear to have the
5639wrong value at certain points in a function---just after entry to a new
5640scope, and just before exit.
5641@end quotation
5642You may see this problem when you are stepping by machine instructions.
5643This is because, on most machines, it takes more than one instruction to
5644set up a stack frame (including local variable definitions); if you are
5645stepping by machine instructions, variables may appear to have the wrong
5646values until the stack frame is completely built. On exit, it usually
5647also takes more than one machine instruction to destroy a stack frame;
5648after you begin stepping through that group of instructions, local
5649variable definitions may be gone.
5650
5651This may also happen when the compiler does significant optimizations.
5652To be sure of always seeing accurate values, turn off all optimization
5653when compiling.
5654
d4f3574e
SS
5655@cindex ``No symbol "foo" in current context''
5656Another possible effect of compiler optimizations is to optimize
5657unused variables out of existence, or assign variables to registers (as
5658opposed to memory addresses). Depending on the support for such cases
5659offered by the debug info format used by the compiler, @value{GDBN}
5660might not be able to display values for such local variables. If that
5661happens, @value{GDBN} will print a message like this:
5662
474c8240 5663@smallexample
d4f3574e 5664No symbol "foo" in current context.
474c8240 5665@end smallexample
d4f3574e
SS
5666
5667To solve such problems, either recompile without optimizations, or use a
5668different debug info format, if the compiler supports several such
15387254 5669formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5670usually supports the @option{-gstabs+} option. @option{-gstabs+}
5671produces debug info in a format that is superior to formats such as
5672COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5673an effective form for debug info. @xref{Debugging Options,,Options
ce9341a1
BW
5674for Debugging Your Program or GCC, gcc.info, Using the @sc{gnu}
5675Compiler Collection (GCC)}.
79a6e687 5676@xref{C, ,C and C@t{++}}, for more information about debug info formats
15387254 5677that are best suited to C@t{++} programs.
d4f3574e 5678
ab1adacd
EZ
5679If you ask to print an object whose contents are unknown to
5680@value{GDBN}, e.g., because its data type is not completely specified
5681by the debug information, @value{GDBN} will say @samp{<incomplete
5682type>}. @xref{Symbols, incomplete type}, for more about this.
5683
3a60f64e
JK
5684Strings are identified as arrays of @code{char} values without specified
5685signedness. Arrays of either @code{signed char} or @code{unsigned char} get
5686printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
5687@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
5688defines literal string type @code{"char"} as @code{char} without a sign.
5689For program code
5690
5691@smallexample
5692char var0[] = "A";
5693signed char var1[] = "A";
5694@end smallexample
5695
5696You get during debugging
5697@smallexample
5698(gdb) print var0
5699$1 = "A"
5700(gdb) print var1
5701$2 = @{65 'A', 0 '\0'@}
5702@end smallexample
5703
6d2ebf8b 5704@node Arrays
79a6e687 5705@section Artificial Arrays
c906108c
SS
5706
5707@cindex artificial array
15387254 5708@cindex arrays
41afff9a 5709@kindex @@@r{, referencing memory as an array}
c906108c
SS
5710It is often useful to print out several successive objects of the
5711same type in memory; a section of an array, or an array of
5712dynamically determined size for which only a pointer exists in the
5713program.
5714
5715You can do this by referring to a contiguous span of memory as an
5716@dfn{artificial array}, using the binary operator @samp{@@}. The left
5717operand of @samp{@@} should be the first element of the desired array
5718and be an individual object. The right operand should be the desired length
5719of the array. The result is an array value whose elements are all of
5720the type of the left argument. The first element is actually the left
5721argument; the second element comes from bytes of memory immediately
5722following those that hold the first element, and so on. Here is an
5723example. If a program says
5724
474c8240 5725@smallexample
c906108c 5726int *array = (int *) malloc (len * sizeof (int));
474c8240 5727@end smallexample
c906108c
SS
5728
5729@noindent
5730you can print the contents of @code{array} with
5731
474c8240 5732@smallexample
c906108c 5733p *array@@len
474c8240 5734@end smallexample
c906108c
SS
5735
5736The left operand of @samp{@@} must reside in memory. Array values made
5737with @samp{@@} in this way behave just like other arrays in terms of
5738subscripting, and are coerced to pointers when used in expressions.
5739Artificial arrays most often appear in expressions via the value history
79a6e687 5740(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
5741
5742Another way to create an artificial array is to use a cast.
5743This re-interprets a value as if it were an array.
5744The value need not be in memory:
474c8240 5745@smallexample
c906108c
SS
5746(@value{GDBP}) p/x (short[2])0x12345678
5747$1 = @{0x1234, 0x5678@}
474c8240 5748@end smallexample
c906108c
SS
5749
5750As a convenience, if you leave the array length out (as in
c3f6f71d 5751@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5752the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5753@smallexample
c906108c
SS
5754(@value{GDBP}) p/x (short[])0x12345678
5755$2 = @{0x1234, 0x5678@}
474c8240 5756@end smallexample
c906108c
SS
5757
5758Sometimes the artificial array mechanism is not quite enough; in
5759moderately complex data structures, the elements of interest may not
5760actually be adjacent---for example, if you are interested in the values
5761of pointers in an array. One useful work-around in this situation is
5762to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 5763Variables}) as a counter in an expression that prints the first
c906108c
SS
5764interesting value, and then repeat that expression via @key{RET}. For
5765instance, suppose you have an array @code{dtab} of pointers to
5766structures, and you are interested in the values of a field @code{fv}
5767in each structure. Here is an example of what you might type:
5768
474c8240 5769@smallexample
c906108c
SS
5770set $i = 0
5771p dtab[$i++]->fv
5772@key{RET}
5773@key{RET}
5774@dots{}
474c8240 5775@end smallexample
c906108c 5776
6d2ebf8b 5777@node Output Formats
79a6e687 5778@section Output Formats
c906108c
SS
5779
5780@cindex formatted output
5781@cindex output formats
5782By default, @value{GDBN} prints a value according to its data type. Sometimes
5783this is not what you want. For example, you might want to print a number
5784in hex, or a pointer in decimal. Or you might want to view data in memory
5785at a certain address as a character string or as an instruction. To do
5786these things, specify an @dfn{output format} when you print a value.
5787
5788The simplest use of output formats is to say how to print a value
5789already computed. This is done by starting the arguments of the
5790@code{print} command with a slash and a format letter. The format
5791letters supported are:
5792
5793@table @code
5794@item x
5795Regard the bits of the value as an integer, and print the integer in
5796hexadecimal.
5797
5798@item d
5799Print as integer in signed decimal.
5800
5801@item u
5802Print as integer in unsigned decimal.
5803
5804@item o
5805Print as integer in octal.
5806
5807@item t
5808Print as integer in binary. The letter @samp{t} stands for ``two''.
5809@footnote{@samp{b} cannot be used because these format letters are also
5810used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 5811see @ref{Memory,,Examining Memory}.}
c906108c
SS
5812
5813@item a
5814@cindex unknown address, locating
3d67e040 5815@cindex locate address
c906108c
SS
5816Print as an address, both absolute in hexadecimal and as an offset from
5817the nearest preceding symbol. You can use this format used to discover
5818where (in what function) an unknown address is located:
5819
474c8240 5820@smallexample
c906108c
SS
5821(@value{GDBP}) p/a 0x54320
5822$3 = 0x54320 <_initialize_vx+396>
474c8240 5823@end smallexample
c906108c 5824
3d67e040
EZ
5825@noindent
5826The command @code{info symbol 0x54320} yields similar results.
5827@xref{Symbols, info symbol}.
5828
c906108c 5829@item c
51274035
EZ
5830Regard as an integer and print it as a character constant. This
5831prints both the numerical value and its character representation. The
5832character representation is replaced with the octal escape @samp{\nnn}
5833for characters outside the 7-bit @sc{ascii} range.
c906108c 5834
ea37ba09
DJ
5835Without this format, @value{GDBN} displays @code{char},
5836@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
5837constants. Single-byte members of vectors are displayed as integer
5838data.
5839
c906108c
SS
5840@item f
5841Regard the bits of the value as a floating point number and print
5842using typical floating point syntax.
ea37ba09
DJ
5843
5844@item s
5845@cindex printing strings
5846@cindex printing byte arrays
5847Regard as a string, if possible. With this format, pointers to single-byte
5848data are displayed as null-terminated strings and arrays of single-byte data
5849are displayed as fixed-length strings. Other values are displayed in their
5850natural types.
5851
5852Without this format, @value{GDBN} displays pointers to and arrays of
5853@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
5854strings. Single-byte members of a vector are displayed as an integer
5855array.
c906108c
SS
5856@end table
5857
5858For example, to print the program counter in hex (@pxref{Registers}), type
5859
474c8240 5860@smallexample
c906108c 5861p/x $pc
474c8240 5862@end smallexample
c906108c
SS
5863
5864@noindent
5865Note that no space is required before the slash; this is because command
5866names in @value{GDBN} cannot contain a slash.
5867
5868To reprint the last value in the value history with a different format,
5869you can use the @code{print} command with just a format and no
5870expression. For example, @samp{p/x} reprints the last value in hex.
5871
6d2ebf8b 5872@node Memory
79a6e687 5873@section Examining Memory
c906108c
SS
5874
5875You can use the command @code{x} (for ``examine'') to examine memory in
5876any of several formats, independently of your program's data types.
5877
5878@cindex examining memory
5879@table @code
41afff9a 5880@kindex x @r{(examine memory)}
c906108c
SS
5881@item x/@var{nfu} @var{addr}
5882@itemx x @var{addr}
5883@itemx x
5884Use the @code{x} command to examine memory.
5885@end table
5886
5887@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5888much memory to display and how to format it; @var{addr} is an
5889expression giving the address where you want to start displaying memory.
5890If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5891Several commands set convenient defaults for @var{addr}.
5892
5893@table @r
5894@item @var{n}, the repeat count
5895The repeat count is a decimal integer; the default is 1. It specifies
5896how much memory (counting by units @var{u}) to display.
5897@c This really is **decimal**; unaffected by 'set radix' as of GDB
5898@c 4.1.2.
5899
5900@item @var{f}, the display format
51274035
EZ
5901The display format is one of the formats used by @code{print}
5902(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
5903@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
5904The default is @samp{x} (hexadecimal) initially. The default changes
5905each time you use either @code{x} or @code{print}.
c906108c
SS
5906
5907@item @var{u}, the unit size
5908The unit size is any of
5909
5910@table @code
5911@item b
5912Bytes.
5913@item h
5914Halfwords (two bytes).
5915@item w
5916Words (four bytes). This is the initial default.
5917@item g
5918Giant words (eight bytes).
5919@end table
5920
5921Each time you specify a unit size with @code{x}, that size becomes the
5922default unit the next time you use @code{x}. (For the @samp{s} and
5923@samp{i} formats, the unit size is ignored and is normally not written.)
5924
5925@item @var{addr}, starting display address
5926@var{addr} is the address where you want @value{GDBN} to begin displaying
5927memory. The expression need not have a pointer value (though it may);
5928it is always interpreted as an integer address of a byte of memory.
5929@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5930@var{addr} is usually just after the last address examined---but several
5931other commands also set the default address: @code{info breakpoints} (to
5932the address of the last breakpoint listed), @code{info line} (to the
5933starting address of a line), and @code{print} (if you use it to display
5934a value from memory).
5935@end table
5936
5937For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5938(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5939starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5940words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5941@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5942
5943Since the letters indicating unit sizes are all distinct from the
5944letters specifying output formats, you do not have to remember whether
5945unit size or format comes first; either order works. The output
5946specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5947(However, the count @var{n} must come first; @samp{wx4} does not work.)
5948
5949Even though the unit size @var{u} is ignored for the formats @samp{s}
5950and @samp{i}, you might still want to use a count @var{n}; for example,
5951@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
5952including any operands. For convenience, especially when used with
5953the @code{display} command, the @samp{i} format also prints branch delay
5954slot instructions, if any, beyond the count specified, which immediately
5955follow the last instruction that is within the count. The command
5956@code{disassemble} gives an alternative way of inspecting machine
5957instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
5958
5959All the defaults for the arguments to @code{x} are designed to make it
5960easy to continue scanning memory with minimal specifications each time
5961you use @code{x}. For example, after you have inspected three machine
5962instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5963with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5964the repeat count @var{n} is used again; the other arguments default as
5965for successive uses of @code{x}.
5966
5967@cindex @code{$_}, @code{$__}, and value history
5968The addresses and contents printed by the @code{x} command are not saved
5969in the value history because there is often too much of them and they
5970would get in the way. Instead, @value{GDBN} makes these values available for
5971subsequent use in expressions as values of the convenience variables
5972@code{$_} and @code{$__}. After an @code{x} command, the last address
5973examined is available for use in expressions in the convenience variable
5974@code{$_}. The contents of that address, as examined, are available in
5975the convenience variable @code{$__}.
5976
5977If the @code{x} command has a repeat count, the address and contents saved
5978are from the last memory unit printed; this is not the same as the last
5979address printed if several units were printed on the last line of output.
5980
09d4efe1
EZ
5981@cindex remote memory comparison
5982@cindex verify remote memory image
5983When you are debugging a program running on a remote target machine
ea35711c 5984(@pxref{Remote Debugging}), you may wish to verify the program's image in the
09d4efe1
EZ
5985remote machine's memory against the executable file you downloaded to
5986the target. The @code{compare-sections} command is provided for such
5987situations.
5988
5989@table @code
5990@kindex compare-sections
5991@item compare-sections @r{[}@var{section-name}@r{]}
5992Compare the data of a loadable section @var{section-name} in the
5993executable file of the program being debugged with the same section in
5994the remote machine's memory, and report any mismatches. With no
5995arguments, compares all loadable sections. This command's
5996availability depends on the target's support for the @code{"qCRC"}
5997remote request.
5998@end table
5999
6d2ebf8b 6000@node Auto Display
79a6e687 6001@section Automatic Display
c906108c
SS
6002@cindex automatic display
6003@cindex display of expressions
6004
6005If you find that you want to print the value of an expression frequently
6006(to see how it changes), you might want to add it to the @dfn{automatic
6007display list} so that @value{GDBN} prints its value each time your program stops.
6008Each expression added to the list is given a number to identify it;
6009to remove an expression from the list, you specify that number.
6010The automatic display looks like this:
6011
474c8240 6012@smallexample
c906108c
SS
60132: foo = 38
60143: bar[5] = (struct hack *) 0x3804
474c8240 6015@end smallexample
c906108c
SS
6016
6017@noindent
6018This display shows item numbers, expressions and their current values. As with
6019displays you request manually using @code{x} or @code{print}, you can
6020specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
6021whether to use @code{print} or @code{x} depending your format
6022specification---it uses @code{x} if you specify either the @samp{i}
6023or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
6024
6025@table @code
6026@kindex display
d4f3574e
SS
6027@item display @var{expr}
6028Add the expression @var{expr} to the list of expressions to display
c906108c
SS
6029each time your program stops. @xref{Expressions, ,Expressions}.
6030
6031@code{display} does not repeat if you press @key{RET} again after using it.
6032
d4f3574e 6033@item display/@var{fmt} @var{expr}
c906108c 6034For @var{fmt} specifying only a display format and not a size or
d4f3574e 6035count, add the expression @var{expr} to the auto-display list but
c906108c 6036arrange to display it each time in the specified format @var{fmt}.
79a6e687 6037@xref{Output Formats,,Output Formats}.
c906108c
SS
6038
6039@item display/@var{fmt} @var{addr}
6040For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
6041number of units, add the expression @var{addr} as a memory address to
6042be examined each time your program stops. Examining means in effect
79a6e687 6043doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
6044@end table
6045
6046For example, @samp{display/i $pc} can be helpful, to see the machine
6047instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 6048is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
6049
6050@table @code
6051@kindex delete display
6052@kindex undisplay
6053@item undisplay @var{dnums}@dots{}
6054@itemx delete display @var{dnums}@dots{}
6055Remove item numbers @var{dnums} from the list of expressions to display.
6056
6057@code{undisplay} does not repeat if you press @key{RET} after using it.
6058(Otherwise you would just get the error @samp{No display number @dots{}}.)
6059
6060@kindex disable display
6061@item disable display @var{dnums}@dots{}
6062Disable the display of item numbers @var{dnums}. A disabled display
6063item is not printed automatically, but is not forgotten. It may be
6064enabled again later.
6065
6066@kindex enable display
6067@item enable display @var{dnums}@dots{}
6068Enable display of item numbers @var{dnums}. It becomes effective once
6069again in auto display of its expression, until you specify otherwise.
6070
6071@item display
6072Display the current values of the expressions on the list, just as is
6073done when your program stops.
6074
6075@kindex info display
6076@item info display
6077Print the list of expressions previously set up to display
6078automatically, each one with its item number, but without showing the
6079values. This includes disabled expressions, which are marked as such.
6080It also includes expressions which would not be displayed right now
6081because they refer to automatic variables not currently available.
6082@end table
6083
15387254 6084@cindex display disabled out of scope
c906108c
SS
6085If a display expression refers to local variables, then it does not make
6086sense outside the lexical context for which it was set up. Such an
6087expression is disabled when execution enters a context where one of its
6088variables is not defined. For example, if you give the command
6089@code{display last_char} while inside a function with an argument
6090@code{last_char}, @value{GDBN} displays this argument while your program
6091continues to stop inside that function. When it stops elsewhere---where
6092there is no variable @code{last_char}---the display is disabled
6093automatically. The next time your program stops where @code{last_char}
6094is meaningful, you can enable the display expression once again.
6095
6d2ebf8b 6096@node Print Settings
79a6e687 6097@section Print Settings
c906108c
SS
6098
6099@cindex format options
6100@cindex print settings
6101@value{GDBN} provides the following ways to control how arrays, structures,
6102and symbols are printed.
6103
6104@noindent
6105These settings are useful for debugging programs in any language:
6106
6107@table @code
4644b6e3 6108@kindex set print
c906108c
SS
6109@item set print address
6110@itemx set print address on
4644b6e3 6111@cindex print/don't print memory addresses
c906108c
SS
6112@value{GDBN} prints memory addresses showing the location of stack
6113traces, structure values, pointer values, breakpoints, and so forth,
6114even when it also displays the contents of those addresses. The default
6115is @code{on}. For example, this is what a stack frame display looks like with
6116@code{set print address on}:
6117
6118@smallexample
6119@group
6120(@value{GDBP}) f
6121#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
6122 at input.c:530
6123530 if (lquote != def_lquote)
6124@end group
6125@end smallexample
6126
6127@item set print address off
6128Do not print addresses when displaying their contents. For example,
6129this is the same stack frame displayed with @code{set print address off}:
6130
6131@smallexample
6132@group
6133(@value{GDBP}) set print addr off
6134(@value{GDBP}) f
6135#0 set_quotes (lq="<<", rq=">>") at input.c:530
6136530 if (lquote != def_lquote)
6137@end group
6138@end smallexample
6139
6140You can use @samp{set print address off} to eliminate all machine
6141dependent displays from the @value{GDBN} interface. For example, with
6142@code{print address off}, you should get the same text for backtraces on
6143all machines---whether or not they involve pointer arguments.
6144
4644b6e3 6145@kindex show print
c906108c
SS
6146@item show print address
6147Show whether or not addresses are to be printed.
6148@end table
6149
6150When @value{GDBN} prints a symbolic address, it normally prints the
6151closest earlier symbol plus an offset. If that symbol does not uniquely
6152identify the address (for example, it is a name whose scope is a single
6153source file), you may need to clarify. One way to do this is with
6154@code{info line}, for example @samp{info line *0x4537}. Alternately,
6155you can set @value{GDBN} to print the source file and line number when
6156it prints a symbolic address:
6157
6158@table @code
c906108c 6159@item set print symbol-filename on
9c16f35a
EZ
6160@cindex source file and line of a symbol
6161@cindex symbol, source file and line
c906108c
SS
6162Tell @value{GDBN} to print the source file name and line number of a
6163symbol in the symbolic form of an address.
6164
6165@item set print symbol-filename off
6166Do not print source file name and line number of a symbol. This is the
6167default.
6168
c906108c
SS
6169@item show print symbol-filename
6170Show whether or not @value{GDBN} will print the source file name and
6171line number of a symbol in the symbolic form of an address.
6172@end table
6173
6174Another situation where it is helpful to show symbol filenames and line
6175numbers is when disassembling code; @value{GDBN} shows you the line
6176number and source file that corresponds to each instruction.
6177
6178Also, you may wish to see the symbolic form only if the address being
6179printed is reasonably close to the closest earlier symbol:
6180
6181@table @code
c906108c 6182@item set print max-symbolic-offset @var{max-offset}
4644b6e3 6183@cindex maximum value for offset of closest symbol
c906108c
SS
6184Tell @value{GDBN} to only display the symbolic form of an address if the
6185offset between the closest earlier symbol and the address is less than
5d161b24 6186@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
6187to always print the symbolic form of an address if any symbol precedes it.
6188
c906108c
SS
6189@item show print max-symbolic-offset
6190Ask how large the maximum offset is that @value{GDBN} prints in a
6191symbolic address.
6192@end table
6193
6194@cindex wild pointer, interpreting
6195@cindex pointer, finding referent
6196If you have a pointer and you are not sure where it points, try
6197@samp{set print symbol-filename on}. Then you can determine the name
6198and source file location of the variable where it points, using
6199@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
6200For example, here @value{GDBN} shows that a variable @code{ptt} points
6201at another variable @code{t}, defined in @file{hi2.c}:
6202
474c8240 6203@smallexample
c906108c
SS
6204(@value{GDBP}) set print symbol-filename on
6205(@value{GDBP}) p/a ptt
6206$4 = 0xe008 <t in hi2.c>
474c8240 6207@end smallexample
c906108c
SS
6208
6209@quotation
6210@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
6211does not show the symbol name and filename of the referent, even with
6212the appropriate @code{set print} options turned on.
6213@end quotation
6214
6215Other settings control how different kinds of objects are printed:
6216
6217@table @code
c906108c
SS
6218@item set print array
6219@itemx set print array on
4644b6e3 6220@cindex pretty print arrays
c906108c
SS
6221Pretty print arrays. This format is more convenient to read,
6222but uses more space. The default is off.
6223
6224@item set print array off
6225Return to compressed format for arrays.
6226
c906108c
SS
6227@item show print array
6228Show whether compressed or pretty format is selected for displaying
6229arrays.
6230
3c9c013a
JB
6231@cindex print array indexes
6232@item set print array-indexes
6233@itemx set print array-indexes on
6234Print the index of each element when displaying arrays. May be more
6235convenient to locate a given element in the array or quickly find the
6236index of a given element in that printed array. The default is off.
6237
6238@item set print array-indexes off
6239Stop printing element indexes when displaying arrays.
6240
6241@item show print array-indexes
6242Show whether the index of each element is printed when displaying
6243arrays.
6244
c906108c 6245@item set print elements @var{number-of-elements}
4644b6e3 6246@cindex number of array elements to print
9c16f35a 6247@cindex limit on number of printed array elements
c906108c
SS
6248Set a limit on how many elements of an array @value{GDBN} will print.
6249If @value{GDBN} is printing a large array, it stops printing after it has
6250printed the number of elements set by the @code{set print elements} command.
6251This limit also applies to the display of strings.
d4f3574e 6252When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
6253Setting @var{number-of-elements} to zero means that the printing is unlimited.
6254
c906108c
SS
6255@item show print elements
6256Display the number of elements of a large array that @value{GDBN} will print.
6257If the number is 0, then the printing is unlimited.
6258
b4740add
JB
6259@item set print frame-arguments @var{value}
6260@cindex printing frame argument values
6261@cindex print all frame argument values
6262@cindex print frame argument values for scalars only
6263@cindex do not print frame argument values
6264This command allows to control how the values of arguments are printed
6265when the debugger prints a frame (@pxref{Frames}). The possible
6266values are:
6267
6268@table @code
6269@item all
6270The values of all arguments are printed. This is the default.
6271
6272@item scalars
6273Print the value of an argument only if it is a scalar. The value of more
6274complex arguments such as arrays, structures, unions, etc, is replaced
6275by @code{@dots{}}. Here is an example where only scalar arguments are shown:
6276
6277@smallexample
6278#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
6279 at frame-args.c:23
6280@end smallexample
6281
6282@item none
6283None of the argument values are printed. Instead, the value of each argument
6284is replaced by @code{@dots{}}. In this case, the example above now becomes:
6285
6286@smallexample
6287#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
6288 at frame-args.c:23
6289@end smallexample
6290@end table
6291
6292By default, all argument values are always printed. But this command
6293can be useful in several cases. For instance, it can be used to reduce
6294the amount of information printed in each frame, making the backtrace
6295more readable. Also, this command can be used to improve performance
6296when displaying Ada frames, because the computation of large arguments
6297can sometimes be CPU-intensive, especiallly in large applications.
6298Setting @code{print frame-arguments} to @code{scalars} or @code{none}
6299avoids this computation, thus speeding up the display of each Ada frame.
6300
6301@item show print frame-arguments
6302Show how the value of arguments should be displayed when printing a frame.
6303
9c16f35a
EZ
6304@item set print repeats
6305@cindex repeated array elements
6306Set the threshold for suppressing display of repeated array
d3e8051b 6307elements. When the number of consecutive identical elements of an
9c16f35a
EZ
6308array exceeds the threshold, @value{GDBN} prints the string
6309@code{"<repeats @var{n} times>"}, where @var{n} is the number of
6310identical repetitions, instead of displaying the identical elements
6311themselves. Setting the threshold to zero will cause all elements to
6312be individually printed. The default threshold is 10.
6313
6314@item show print repeats
6315Display the current threshold for printing repeated identical
6316elements.
6317
c906108c 6318@item set print null-stop
4644b6e3 6319@cindex @sc{null} elements in arrays
c906108c 6320Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 6321@sc{null} is encountered. This is useful when large arrays actually
c906108c 6322contain only short strings.
d4f3574e 6323The default is off.
c906108c 6324
9c16f35a
EZ
6325@item show print null-stop
6326Show whether @value{GDBN} stops printing an array on the first
6327@sc{null} character.
6328
c906108c 6329@item set print pretty on
9c16f35a
EZ
6330@cindex print structures in indented form
6331@cindex indentation in structure display
5d161b24 6332Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
6333per line, like this:
6334
6335@smallexample
6336@group
6337$1 = @{
6338 next = 0x0,
6339 flags = @{
6340 sweet = 1,
6341 sour = 1
6342 @},
6343 meat = 0x54 "Pork"
6344@}
6345@end group
6346@end smallexample
6347
6348@item set print pretty off
6349Cause @value{GDBN} to print structures in a compact format, like this:
6350
6351@smallexample
6352@group
6353$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
6354meat = 0x54 "Pork"@}
6355@end group
6356@end smallexample
6357
6358@noindent
6359This is the default format.
6360
c906108c
SS
6361@item show print pretty
6362Show which format @value{GDBN} is using to print structures.
6363
c906108c 6364@item set print sevenbit-strings on
4644b6e3
EZ
6365@cindex eight-bit characters in strings
6366@cindex octal escapes in strings
c906108c
SS
6367Print using only seven-bit characters; if this option is set,
6368@value{GDBN} displays any eight-bit characters (in strings or
6369character values) using the notation @code{\}@var{nnn}. This setting is
6370best if you are working in English (@sc{ascii}) and you use the
6371high-order bit of characters as a marker or ``meta'' bit.
6372
6373@item set print sevenbit-strings off
6374Print full eight-bit characters. This allows the use of more
6375international character sets, and is the default.
6376
c906108c
SS
6377@item show print sevenbit-strings
6378Show whether or not @value{GDBN} is printing only seven-bit characters.
6379
c906108c 6380@item set print union on
4644b6e3 6381@cindex unions in structures, printing
9c16f35a
EZ
6382Tell @value{GDBN} to print unions which are contained in structures
6383and other unions. This is the default setting.
c906108c
SS
6384
6385@item set print union off
9c16f35a
EZ
6386Tell @value{GDBN} not to print unions which are contained in
6387structures and other unions. @value{GDBN} will print @code{"@{...@}"}
6388instead.
c906108c 6389
c906108c
SS
6390@item show print union
6391Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 6392structures and other unions.
c906108c
SS
6393
6394For example, given the declarations
6395
6396@smallexample
6397typedef enum @{Tree, Bug@} Species;
6398typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 6399typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
6400 Bug_forms;
6401
6402struct thing @{
6403 Species it;
6404 union @{
6405 Tree_forms tree;
6406 Bug_forms bug;
6407 @} form;
6408@};
6409
6410struct thing foo = @{Tree, @{Acorn@}@};
6411@end smallexample
6412
6413@noindent
6414with @code{set print union on} in effect @samp{p foo} would print
6415
6416@smallexample
6417$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
6418@end smallexample
6419
6420@noindent
6421and with @code{set print union off} in effect it would print
6422
6423@smallexample
6424$1 = @{it = Tree, form = @{...@}@}
6425@end smallexample
9c16f35a
EZ
6426
6427@noindent
6428@code{set print union} affects programs written in C-like languages
6429and in Pascal.
c906108c
SS
6430@end table
6431
c906108c
SS
6432@need 1000
6433@noindent
b37052ae 6434These settings are of interest when debugging C@t{++} programs:
c906108c
SS
6435
6436@table @code
4644b6e3 6437@cindex demangling C@t{++} names
c906108c
SS
6438@item set print demangle
6439@itemx set print demangle on
b37052ae 6440Print C@t{++} names in their source form rather than in the encoded
c906108c 6441(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 6442linkage. The default is on.
c906108c 6443
c906108c 6444@item show print demangle
b37052ae 6445Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 6446
c906108c
SS
6447@item set print asm-demangle
6448@itemx set print asm-demangle on
b37052ae 6449Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
6450in assembler code printouts such as instruction disassemblies.
6451The default is off.
6452
c906108c 6453@item show print asm-demangle
b37052ae 6454Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
6455or demangled form.
6456
b37052ae
EZ
6457@cindex C@t{++} symbol decoding style
6458@cindex symbol decoding style, C@t{++}
a8f24a35 6459@kindex set demangle-style
c906108c
SS
6460@item set demangle-style @var{style}
6461Choose among several encoding schemes used by different compilers to
b37052ae 6462represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
6463
6464@table @code
6465@item auto
6466Allow @value{GDBN} to choose a decoding style by inspecting your program.
6467
6468@item gnu
b37052ae 6469Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 6470This is the default.
c906108c
SS
6471
6472@item hp
b37052ae 6473Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
6474
6475@item lucid
b37052ae 6476Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
6477
6478@item arm
b37052ae 6479Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
6480@strong{Warning:} this setting alone is not sufficient to allow
6481debugging @code{cfront}-generated executables. @value{GDBN} would
6482require further enhancement to permit that.
6483
6484@end table
6485If you omit @var{style}, you will see a list of possible formats.
6486
c906108c 6487@item show demangle-style
b37052ae 6488Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 6489
c906108c
SS
6490@item set print object
6491@itemx set print object on
4644b6e3 6492@cindex derived type of an object, printing
9c16f35a 6493@cindex display derived types
c906108c
SS
6494When displaying a pointer to an object, identify the @emph{actual}
6495(derived) type of the object rather than the @emph{declared} type, using
6496the virtual function table.
6497
6498@item set print object off
6499Display only the declared type of objects, without reference to the
6500virtual function table. This is the default setting.
6501
c906108c
SS
6502@item show print object
6503Show whether actual, or declared, object types are displayed.
6504
c906108c
SS
6505@item set print static-members
6506@itemx set print static-members on
4644b6e3 6507@cindex static members of C@t{++} objects
b37052ae 6508Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
6509
6510@item set print static-members off
b37052ae 6511Do not print static members when displaying a C@t{++} object.
c906108c 6512
c906108c 6513@item show print static-members
9c16f35a
EZ
6514Show whether C@t{++} static members are printed or not.
6515
6516@item set print pascal_static-members
6517@itemx set print pascal_static-members on
d3e8051b
EZ
6518@cindex static members of Pascal objects
6519@cindex Pascal objects, static members display
9c16f35a
EZ
6520Print static members when displaying a Pascal object. The default is on.
6521
6522@item set print pascal_static-members off
6523Do not print static members when displaying a Pascal object.
6524
6525@item show print pascal_static-members
6526Show whether Pascal static members are printed or not.
c906108c
SS
6527
6528@c These don't work with HP ANSI C++ yet.
c906108c
SS
6529@item set print vtbl
6530@itemx set print vtbl on
4644b6e3 6531@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
6532@cindex virtual functions (C@t{++}) display
6533@cindex VTBL display
b37052ae 6534Pretty print C@t{++} virtual function tables. The default is off.
c906108c 6535(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 6536ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
6537
6538@item set print vtbl off
b37052ae 6539Do not pretty print C@t{++} virtual function tables.
c906108c 6540
c906108c 6541@item show print vtbl
b37052ae 6542Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 6543@end table
c906108c 6544
6d2ebf8b 6545@node Value History
79a6e687 6546@section Value History
c906108c
SS
6547
6548@cindex value history
9c16f35a 6549@cindex history of values printed by @value{GDBN}
5d161b24
DB
6550Values printed by the @code{print} command are saved in the @value{GDBN}
6551@dfn{value history}. This allows you to refer to them in other expressions.
6552Values are kept until the symbol table is re-read or discarded
6553(for example with the @code{file} or @code{symbol-file} commands).
6554When the symbol table changes, the value history is discarded,
6555since the values may contain pointers back to the types defined in the
c906108c
SS
6556symbol table.
6557
6558@cindex @code{$}
6559@cindex @code{$$}
6560@cindex history number
6561The values printed are given @dfn{history numbers} by which you can
6562refer to them. These are successive integers starting with one.
6563@code{print} shows you the history number assigned to a value by
6564printing @samp{$@var{num} = } before the value; here @var{num} is the
6565history number.
6566
6567To refer to any previous value, use @samp{$} followed by the value's
6568history number. The way @code{print} labels its output is designed to
6569remind you of this. Just @code{$} refers to the most recent value in
6570the history, and @code{$$} refers to the value before that.
6571@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6572is the value just prior to @code{$$}, @code{$$1} is equivalent to
6573@code{$$}, and @code{$$0} is equivalent to @code{$}.
6574
6575For example, suppose you have just printed a pointer to a structure and
6576want to see the contents of the structure. It suffices to type
6577
474c8240 6578@smallexample
c906108c 6579p *$
474c8240 6580@end smallexample
c906108c
SS
6581
6582If you have a chain of structures where the component @code{next} points
6583to the next one, you can print the contents of the next one with this:
6584
474c8240 6585@smallexample
c906108c 6586p *$.next
474c8240 6587@end smallexample
c906108c
SS
6588
6589@noindent
6590You can print successive links in the chain by repeating this
6591command---which you can do by just typing @key{RET}.
6592
6593Note that the history records values, not expressions. If the value of
6594@code{x} is 4 and you type these commands:
6595
474c8240 6596@smallexample
c906108c
SS
6597print x
6598set x=5
474c8240 6599@end smallexample
c906108c
SS
6600
6601@noindent
6602then the value recorded in the value history by the @code{print} command
6603remains 4 even though the value of @code{x} has changed.
6604
6605@table @code
6606@kindex show values
6607@item show values
6608Print the last ten values in the value history, with their item numbers.
6609This is like @samp{p@ $$9} repeated ten times, except that @code{show
6610values} does not change the history.
6611
6612@item show values @var{n}
6613Print ten history values centered on history item number @var{n}.
6614
6615@item show values +
6616Print ten history values just after the values last printed. If no more
6617values are available, @code{show values +} produces no display.
6618@end table
6619
6620Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6621same effect as @samp{show values +}.
6622
6d2ebf8b 6623@node Convenience Vars
79a6e687 6624@section Convenience Variables
c906108c
SS
6625
6626@cindex convenience variables
9c16f35a 6627@cindex user-defined variables
c906108c
SS
6628@value{GDBN} provides @dfn{convenience variables} that you can use within
6629@value{GDBN} to hold on to a value and refer to it later. These variables
6630exist entirely within @value{GDBN}; they are not part of your program, and
6631setting a convenience variable has no direct effect on further execution
6632of your program. That is why you can use them freely.
6633
6634Convenience variables are prefixed with @samp{$}. Any name preceded by
6635@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6636the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 6637(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 6638by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
6639
6640You can save a value in a convenience variable with an assignment
6641expression, just as you would set a variable in your program.
6642For example:
6643
474c8240 6644@smallexample
c906108c 6645set $foo = *object_ptr
474c8240 6646@end smallexample
c906108c
SS
6647
6648@noindent
6649would save in @code{$foo} the value contained in the object pointed to by
6650@code{object_ptr}.
6651
6652Using a convenience variable for the first time creates it, but its
6653value is @code{void} until you assign a new value. You can alter the
6654value with another assignment at any time.
6655
6656Convenience variables have no fixed types. You can assign a convenience
6657variable any type of value, including structures and arrays, even if
6658that variable already has a value of a different type. The convenience
6659variable, when used as an expression, has the type of its current value.
6660
6661@table @code
6662@kindex show convenience
9c16f35a 6663@cindex show all user variables
c906108c
SS
6664@item show convenience
6665Print a list of convenience variables used so far, and their values.
d4f3574e 6666Abbreviated @code{show conv}.
53e5f3cf
AS
6667
6668@kindex init-if-undefined
6669@cindex convenience variables, initializing
6670@item init-if-undefined $@var{variable} = @var{expression}
6671Set a convenience variable if it has not already been set. This is useful
6672for user-defined commands that keep some state. It is similar, in concept,
6673to using local static variables with initializers in C (except that
6674convenience variables are global). It can also be used to allow users to
6675override default values used in a command script.
6676
6677If the variable is already defined then the expression is not evaluated so
6678any side-effects do not occur.
c906108c
SS
6679@end table
6680
6681One of the ways to use a convenience variable is as a counter to be
6682incremented or a pointer to be advanced. For example, to print
6683a field from successive elements of an array of structures:
6684
474c8240 6685@smallexample
c906108c
SS
6686set $i = 0
6687print bar[$i++]->contents
474c8240 6688@end smallexample
c906108c 6689
d4f3574e
SS
6690@noindent
6691Repeat that command by typing @key{RET}.
c906108c
SS
6692
6693Some convenience variables are created automatically by @value{GDBN} and given
6694values likely to be useful.
6695
6696@table @code
41afff9a 6697@vindex $_@r{, convenience variable}
c906108c
SS
6698@item $_
6699The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 6700the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
6701commands which provide a default address for @code{x} to examine also
6702set @code{$_} to that address; these commands include @code{info line}
6703and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6704except when set by the @code{x} command, in which case it is a pointer
6705to the type of @code{$__}.
6706
41afff9a 6707@vindex $__@r{, convenience variable}
c906108c
SS
6708@item $__
6709The variable @code{$__} is automatically set by the @code{x} command
6710to the value found in the last address examined. Its type is chosen
6711to match the format in which the data was printed.
6712
6713@item $_exitcode
41afff9a 6714@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6715The variable @code{$_exitcode} is automatically set to the exit code when
6716the program being debugged terminates.
6717@end table
6718
53a5351d
JM
6719On HP-UX systems, if you refer to a function or variable name that
6720begins with a dollar sign, @value{GDBN} searches for a user or system
6721name first, before it searches for a convenience variable.
c906108c 6722
6d2ebf8b 6723@node Registers
c906108c
SS
6724@section Registers
6725
6726@cindex registers
6727You can refer to machine register contents, in expressions, as variables
6728with names starting with @samp{$}. The names of registers are different
6729for each machine; use @code{info registers} to see the names used on
6730your machine.
6731
6732@table @code
6733@kindex info registers
6734@item info registers
6735Print the names and values of all registers except floating-point
c85508ee 6736and vector registers (in the selected stack frame).
c906108c
SS
6737
6738@kindex info all-registers
6739@cindex floating point registers
6740@item info all-registers
6741Print the names and values of all registers, including floating-point
c85508ee 6742and vector registers (in the selected stack frame).
c906108c
SS
6743
6744@item info registers @var{regname} @dots{}
6745Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6746As discussed in detail below, register values are normally relative to
6747the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6748the machine you are using, with or without the initial @samp{$}.
6749@end table
6750
e09f16f9
EZ
6751@cindex stack pointer register
6752@cindex program counter register
6753@cindex process status register
6754@cindex frame pointer register
6755@cindex standard registers
c906108c
SS
6756@value{GDBN} has four ``standard'' register names that are available (in
6757expressions) on most machines---whenever they do not conflict with an
6758architecture's canonical mnemonics for registers. The register names
6759@code{$pc} and @code{$sp} are used for the program counter register and
6760the stack pointer. @code{$fp} is used for a register that contains a
6761pointer to the current stack frame, and @code{$ps} is used for a
6762register that contains the processor status. For example,
6763you could print the program counter in hex with
6764
474c8240 6765@smallexample
c906108c 6766p/x $pc
474c8240 6767@end smallexample
c906108c
SS
6768
6769@noindent
6770or print the instruction to be executed next with
6771
474c8240 6772@smallexample
c906108c 6773x/i $pc
474c8240 6774@end smallexample
c906108c
SS
6775
6776@noindent
6777or add four to the stack pointer@footnote{This is a way of removing
6778one word from the stack, on machines where stacks grow downward in
6779memory (most machines, nowadays). This assumes that the innermost
6780stack frame is selected; setting @code{$sp} is not allowed when other
6781stack frames are selected. To pop entire frames off the stack,
6782regardless of machine architecture, use @code{return};
79a6e687 6783see @ref{Returning, ,Returning from a Function}.} with
c906108c 6784
474c8240 6785@smallexample
c906108c 6786set $sp += 4
474c8240 6787@end smallexample
c906108c
SS
6788
6789Whenever possible, these four standard register names are available on
6790your machine even though the machine has different canonical mnemonics,
6791so long as there is no conflict. The @code{info registers} command
6792shows the canonical names. For example, on the SPARC, @code{info
6793registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6794can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6795is an alias for the @sc{eflags} register.
c906108c
SS
6796
6797@value{GDBN} always considers the contents of an ordinary register as an
6798integer when the register is examined in this way. Some machines have
6799special registers which can hold nothing but floating point; these
6800registers are considered to have floating point values. There is no way
6801to refer to the contents of an ordinary register as floating point value
6802(although you can @emph{print} it as a floating point value with
6803@samp{print/f $@var{regname}}).
6804
6805Some registers have distinct ``raw'' and ``virtual'' data formats. This
6806means that the data format in which the register contents are saved by
6807the operating system is not the same one that your program normally
6808sees. For example, the registers of the 68881 floating point
6809coprocessor are always saved in ``extended'' (raw) format, but all C
6810programs expect to work with ``double'' (virtual) format. In such
5d161b24 6811cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6812that makes sense for your program), but the @code{info registers} command
6813prints the data in both formats.
6814
36b80e65
EZ
6815@cindex SSE registers (x86)
6816@cindex MMX registers (x86)
6817Some machines have special registers whose contents can be interpreted
6818in several different ways. For example, modern x86-based machines
6819have SSE and MMX registers that can hold several values packed
6820together in several different formats. @value{GDBN} refers to such
6821registers in @code{struct} notation:
6822
6823@smallexample
6824(@value{GDBP}) print $xmm1
6825$1 = @{
6826 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
6827 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
6828 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6829 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
6830 v4_int32 = @{0, 20657912, 11, 13@},
6831 v2_int64 = @{88725056443645952, 55834574859@},
6832 uint128 = 0x0000000d0000000b013b36f800000000
6833@}
6834@end smallexample
6835
6836@noindent
6837To set values of such registers, you need to tell @value{GDBN} which
6838view of the register you wish to change, as if you were assigning
6839value to a @code{struct} member:
6840
6841@smallexample
6842 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6843@end smallexample
6844
c906108c 6845Normally, register values are relative to the selected stack frame
79a6e687 6846(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
6847value that the register would contain if all stack frames farther in
6848were exited and their saved registers restored. In order to see the
6849true contents of hardware registers, you must select the innermost
6850frame (with @samp{frame 0}).
6851
6852However, @value{GDBN} must deduce where registers are saved, from the machine
6853code generated by your compiler. If some registers are not saved, or if
6854@value{GDBN} is unable to locate the saved registers, the selected stack
6855frame makes no difference.
6856
6d2ebf8b 6857@node Floating Point Hardware
79a6e687 6858@section Floating Point Hardware
c906108c
SS
6859@cindex floating point
6860
6861Depending on the configuration, @value{GDBN} may be able to give
6862you more information about the status of the floating point hardware.
6863
6864@table @code
6865@kindex info float
6866@item info float
6867Display hardware-dependent information about the floating
6868point unit. The exact contents and layout vary depending on the
6869floating point chip. Currently, @samp{info float} is supported on
6870the ARM and x86 machines.
6871@end table
c906108c 6872
e76f1f2e
AC
6873@node Vector Unit
6874@section Vector Unit
6875@cindex vector unit
6876
6877Depending on the configuration, @value{GDBN} may be able to give you
6878more information about the status of the vector unit.
6879
6880@table @code
6881@kindex info vector
6882@item info vector
6883Display information about the vector unit. The exact contents and
6884layout vary depending on the hardware.
6885@end table
6886
721c2651 6887@node OS Information
79a6e687 6888@section Operating System Auxiliary Information
721c2651
EZ
6889@cindex OS information
6890
6891@value{GDBN} provides interfaces to useful OS facilities that can help
6892you debug your program.
6893
6894@cindex @code{ptrace} system call
6895@cindex @code{struct user} contents
6896When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6897machines), it interfaces with the inferior via the @code{ptrace}
6898system call. The operating system creates a special sata structure,
6899called @code{struct user}, for this interface. You can use the
6900command @code{info udot} to display the contents of this data
6901structure.
6902
6903@table @code
6904@item info udot
6905@kindex info udot
6906Display the contents of the @code{struct user} maintained by the OS
6907kernel for the program being debugged. @value{GDBN} displays the
6908contents of @code{struct user} as a list of hex numbers, similar to
6909the @code{examine} command.
6910@end table
6911
b383017d
RM
6912@cindex auxiliary vector
6913@cindex vector, auxiliary
b383017d
RM
6914Some operating systems supply an @dfn{auxiliary vector} to programs at
6915startup. This is akin to the arguments and environment that you
6916specify for a program, but contains a system-dependent variety of
6917binary values that tell system libraries important details about the
6918hardware, operating system, and process. Each value's purpose is
6919identified by an integer tag; the meanings are well-known but system-specific.
6920Depending on the configuration and operating system facilities,
9c16f35a
EZ
6921@value{GDBN} may be able to show you this information. For remote
6922targets, this functionality may further depend on the remote stub's
427c3a89
DJ
6923support of the @samp{qXfer:auxv:read} packet, see
6924@ref{qXfer auxiliary vector read}.
b383017d
RM
6925
6926@table @code
6927@kindex info auxv
6928@item info auxv
6929Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6930live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6931numerically, and also shows names and text descriptions for recognized
6932tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6933pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6934most appropriate form for a recognized tag, and in hexadecimal for
6935an unrecognized tag.
6936@end table
6937
721c2651 6938
29e57380 6939@node Memory Region Attributes
79a6e687 6940@section Memory Region Attributes
29e57380
C
6941@cindex memory region attributes
6942
b383017d 6943@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
6944required by regions of your target's memory. @value{GDBN} uses
6945attributes to determine whether to allow certain types of memory
6946accesses; whether to use specific width accesses; and whether to cache
6947target memory. By default the description of memory regions is
6948fetched from the target (if the current target supports this), but the
6949user can override the fetched regions.
29e57380
C
6950
6951Defined memory regions can be individually enabled and disabled. When a
6952memory region is disabled, @value{GDBN} uses the default attributes when
6953accessing memory in that region. Similarly, if no memory regions have
6954been defined, @value{GDBN} uses the default attributes when accessing
6955all memory.
6956
b383017d 6957When a memory region is defined, it is given a number to identify it;
29e57380
C
6958to enable, disable, or remove a memory region, you specify that number.
6959
6960@table @code
6961@kindex mem
bfac230e 6962@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6963Define a memory region bounded by @var{lower} and @var{upper} with
6964attributes @var{attributes}@dots{}, and add it to the list of regions
6965monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 6966case: it is treated as the target's maximum memory address.
bfac230e 6967(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 6968
fd79ecee
DJ
6969@item mem auto
6970Discard any user changes to the memory regions and use target-supplied
6971regions, if available, or no regions if the target does not support.
6972
29e57380
C
6973@kindex delete mem
6974@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6975Remove memory regions @var{nums}@dots{} from the list of regions
6976monitored by @value{GDBN}.
29e57380
C
6977
6978@kindex disable mem
6979@item disable mem @var{nums}@dots{}
09d4efe1 6980Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6981A disabled memory region is not forgotten.
29e57380
C
6982It may be enabled again later.
6983
6984@kindex enable mem
6985@item enable mem @var{nums}@dots{}
09d4efe1 6986Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6987
6988@kindex info mem
6989@item info mem
6990Print a table of all defined memory regions, with the following columns
09d4efe1 6991for each region:
29e57380
C
6992
6993@table @emph
6994@item Memory Region Number
6995@item Enabled or Disabled.
b383017d 6996Enabled memory regions are marked with @samp{y}.
29e57380
C
6997Disabled memory regions are marked with @samp{n}.
6998
6999@item Lo Address
7000The address defining the inclusive lower bound of the memory region.
7001
7002@item Hi Address
7003The address defining the exclusive upper bound of the memory region.
7004
7005@item Attributes
7006The list of attributes set for this memory region.
7007@end table
7008@end table
7009
7010
7011@subsection Attributes
7012
b383017d 7013@subsubsection Memory Access Mode
29e57380
C
7014The access mode attributes set whether @value{GDBN} may make read or
7015write accesses to a memory region.
7016
7017While these attributes prevent @value{GDBN} from performing invalid
7018memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 7019etc.@: from accessing memory.
29e57380
C
7020
7021@table @code
7022@item ro
7023Memory is read only.
7024@item wo
7025Memory is write only.
7026@item rw
6ca652b0 7027Memory is read/write. This is the default.
29e57380
C
7028@end table
7029
7030@subsubsection Memory Access Size
d3e8051b 7031The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
7032accesses in the memory region. Often memory mapped device registers
7033require specific sized accesses. If no access size attribute is
7034specified, @value{GDBN} may use accesses of any size.
7035
7036@table @code
7037@item 8
7038Use 8 bit memory accesses.
7039@item 16
7040Use 16 bit memory accesses.
7041@item 32
7042Use 32 bit memory accesses.
7043@item 64
7044Use 64 bit memory accesses.
7045@end table
7046
7047@c @subsubsection Hardware/Software Breakpoints
7048@c The hardware/software breakpoint attributes set whether @value{GDBN}
7049@c will use hardware or software breakpoints for the internal breakpoints
7050@c used by the step, next, finish, until, etc. commands.
7051@c
7052@c @table @code
7053@c @item hwbreak
b383017d 7054@c Always use hardware breakpoints
29e57380
C
7055@c @item swbreak (default)
7056@c @end table
7057
7058@subsubsection Data Cache
7059The data cache attributes set whether @value{GDBN} will cache target
7060memory. While this generally improves performance by reducing debug
7061protocol overhead, it can lead to incorrect results because @value{GDBN}
7062does not know about volatile variables or memory mapped device
7063registers.
7064
7065@table @code
7066@item cache
b383017d 7067Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
7068@item nocache
7069Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
7070@end table
7071
4b5752d0
VP
7072@subsection Memory Access Checking
7073@value{GDBN} can be instructed to refuse accesses to memory that is
7074not explicitly described. This can be useful if accessing such
7075regions has undesired effects for a specific target, or to provide
7076better error checking. The following commands control this behaviour.
7077
7078@table @code
7079@kindex set mem inaccessible-by-default
7080@item set mem inaccessible-by-default [on|off]
7081If @code{on} is specified, make @value{GDBN} treat memory not
7082explicitly described by the memory ranges as non-existent and refuse accesses
7083to such memory. The checks are only performed if there's at least one
7084memory range defined. If @code{off} is specified, make @value{GDBN}
7085treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 7086The default value is @code{on}.
4b5752d0
VP
7087@kindex show mem inaccessible-by-default
7088@item show mem inaccessible-by-default
7089Show the current handling of accesses to unknown memory.
7090@end table
7091
7092
29e57380 7093@c @subsubsection Memory Write Verification
b383017d 7094@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
7095@c will re-reads data after each write to verify the write was successful.
7096@c
7097@c @table @code
7098@c @item verify
7099@c @item noverify (default)
7100@c @end table
7101
16d9dec6 7102@node Dump/Restore Files
79a6e687 7103@section Copy Between Memory and a File
16d9dec6
MS
7104@cindex dump/restore files
7105@cindex append data to a file
7106@cindex dump data to a file
7107@cindex restore data from a file
16d9dec6 7108
df5215a6
JB
7109You can use the commands @code{dump}, @code{append}, and
7110@code{restore} to copy data between target memory and a file. The
7111@code{dump} and @code{append} commands write data to a file, and the
7112@code{restore} command reads data from a file back into the inferior's
7113memory. Files may be in binary, Motorola S-record, Intel hex, or
7114Tektronix Hex format; however, @value{GDBN} can only append to binary
7115files.
7116
7117@table @code
7118
7119@kindex dump
7120@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7121@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
7122Dump the contents of memory from @var{start_addr} to @var{end_addr},
7123or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 7124
df5215a6 7125The @var{format} parameter may be any one of:
16d9dec6 7126@table @code
df5215a6
JB
7127@item binary
7128Raw binary form.
7129@item ihex
7130Intel hex format.
7131@item srec
7132Motorola S-record format.
7133@item tekhex
7134Tektronix Hex format.
7135@end table
7136
7137@value{GDBN} uses the same definitions of these formats as the
7138@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
7139@var{format} is omitted, @value{GDBN} dumps the data in raw binary
7140form.
7141
7142@kindex append
7143@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7144@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
7145Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 7146or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
7147(@value{GDBN} can only append data to files in raw binary form.)
7148
7149@kindex restore
7150@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
7151Restore the contents of file @var{filename} into memory. The
7152@code{restore} command can automatically recognize any known @sc{bfd}
7153file format, except for raw binary. To restore a raw binary file you
7154must specify the optional keyword @code{binary} after the filename.
16d9dec6 7155
b383017d 7156If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
7157contained in the file. Binary files always start at address zero, so
7158they will be restored at address @var{bias}. Other bfd files have
7159a built-in location; they will be restored at offset @var{bias}
7160from that location.
7161
7162If @var{start} and/or @var{end} are non-zero, then only data between
7163file offset @var{start} and file offset @var{end} will be restored.
b383017d 7164These offsets are relative to the addresses in the file, before
16d9dec6
MS
7165the @var{bias} argument is applied.
7166
7167@end table
7168
384ee23f
EZ
7169@node Core File Generation
7170@section How to Produce a Core File from Your Program
7171@cindex dump core from inferior
7172
7173A @dfn{core file} or @dfn{core dump} is a file that records the memory
7174image of a running process and its process status (register values
7175etc.). Its primary use is post-mortem debugging of a program that
7176crashed while it ran outside a debugger. A program that crashes
7177automatically produces a core file, unless this feature is disabled by
7178the user. @xref{Files}, for information on invoking @value{GDBN} in
7179the post-mortem debugging mode.
7180
7181Occasionally, you may wish to produce a core file of the program you
7182are debugging in order to preserve a snapshot of its state.
7183@value{GDBN} has a special command for that.
7184
7185@table @code
7186@kindex gcore
7187@kindex generate-core-file
7188@item generate-core-file [@var{file}]
7189@itemx gcore [@var{file}]
7190Produce a core dump of the inferior process. The optional argument
7191@var{file} specifies the file name where to put the core dump. If not
7192specified, the file name defaults to @file{core.@var{pid}}, where
7193@var{pid} is the inferior process ID.
7194
7195Note that this command is implemented only for some systems (as of
7196this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
7197@end table
7198
a0eb71c5
KB
7199@node Character Sets
7200@section Character Sets
7201@cindex character sets
7202@cindex charset
7203@cindex translating between character sets
7204@cindex host character set
7205@cindex target character set
7206
7207If the program you are debugging uses a different character set to
7208represent characters and strings than the one @value{GDBN} uses itself,
7209@value{GDBN} can automatically translate between the character sets for
7210you. The character set @value{GDBN} uses we call the @dfn{host
7211character set}; the one the inferior program uses we call the
7212@dfn{target character set}.
7213
7214For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
7215uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 7216remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
7217running on an IBM mainframe, which uses the @sc{ebcdic} character set,
7218then the host character set is Latin-1, and the target character set is
7219@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 7220target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
7221@sc{ebcdic} and Latin 1 as you print character or string values, or use
7222character and string literals in expressions.
7223
7224@value{GDBN} has no way to automatically recognize which character set
7225the inferior program uses; you must tell it, using the @code{set
7226target-charset} command, described below.
7227
7228Here are the commands for controlling @value{GDBN}'s character set
7229support:
7230
7231@table @code
7232@item set target-charset @var{charset}
7233@kindex set target-charset
7234Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
7235character set names @value{GDBN} recognizes below, but if you type
7236@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7237list the target character sets it supports.
a0eb71c5
KB
7238@end table
7239
7240@table @code
7241@item set host-charset @var{charset}
7242@kindex set host-charset
7243Set the current host character set to @var{charset}.
7244
7245By default, @value{GDBN} uses a host character set appropriate to the
7246system it is running on; you can override that default using the
7247@code{set host-charset} command.
7248
7249@value{GDBN} can only use certain character sets as its host character
7250set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
7251indicate which can be host character sets, but if you type
7252@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7253list the host character sets it supports.
a0eb71c5
KB
7254
7255@item set charset @var{charset}
7256@kindex set charset
e33d66ec
EZ
7257Set the current host and target character sets to @var{charset}. As
7258above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
7259@value{GDBN} will list the name of the character sets that can be used
7260for both host and target.
7261
a0eb71c5
KB
7262
7263@item show charset
a0eb71c5 7264@kindex show charset
b383017d 7265Show the names of the current host and target charsets.
e33d66ec
EZ
7266
7267@itemx show host-charset
a0eb71c5 7268@kindex show host-charset
b383017d 7269Show the name of the current host charset.
e33d66ec
EZ
7270
7271@itemx show target-charset
a0eb71c5 7272@kindex show target-charset
b383017d 7273Show the name of the current target charset.
a0eb71c5
KB
7274
7275@end table
7276
7277@value{GDBN} currently includes support for the following character
7278sets:
7279
7280@table @code
7281
7282@item ASCII
7283@cindex ASCII character set
7284Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
7285character set.
7286
7287@item ISO-8859-1
7288@cindex ISO 8859-1 character set
7289@cindex ISO Latin 1 character set
e33d66ec 7290The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
7291characters needed for French, German, and Spanish. @value{GDBN} can use
7292this as its host character set.
7293
7294@item EBCDIC-US
7295@itemx IBM1047
7296@cindex EBCDIC character set
7297@cindex IBM1047 character set
7298Variants of the @sc{ebcdic} character set, used on some of IBM's
7299mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
7300@value{GDBN} cannot use these as its host character set.
7301
7302@end table
7303
7304Note that these are all single-byte character sets. More work inside
3f94c067 7305@value{GDBN} is needed to support multi-byte or variable-width character
a0eb71c5
KB
7306encodings, like the UTF-8 and UCS-2 encodings of Unicode.
7307
7308Here is an example of @value{GDBN}'s character set support in action.
7309Assume that the following source code has been placed in the file
7310@file{charset-test.c}:
7311
7312@smallexample
7313#include <stdio.h>
7314
7315char ascii_hello[]
7316 = @{72, 101, 108, 108, 111, 44, 32, 119,
7317 111, 114, 108, 100, 33, 10, 0@};
7318char ibm1047_hello[]
7319 = @{200, 133, 147, 147, 150, 107, 64, 166,
7320 150, 153, 147, 132, 90, 37, 0@};
7321
7322main ()
7323@{
7324 printf ("Hello, world!\n");
7325@}
10998722 7326@end smallexample
a0eb71c5
KB
7327
7328In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
7329containing the string @samp{Hello, world!} followed by a newline,
7330encoded in the @sc{ascii} and @sc{ibm1047} character sets.
7331
7332We compile the program, and invoke the debugger on it:
7333
7334@smallexample
7335$ gcc -g charset-test.c -o charset-test
7336$ gdb -nw charset-test
7337GNU gdb 2001-12-19-cvs
7338Copyright 2001 Free Software Foundation, Inc.
7339@dots{}
f7dc1244 7340(@value{GDBP})
10998722 7341@end smallexample
a0eb71c5
KB
7342
7343We can use the @code{show charset} command to see what character sets
7344@value{GDBN} is currently using to interpret and display characters and
7345strings:
7346
7347@smallexample
f7dc1244 7348(@value{GDBP}) show charset
e33d66ec 7349The current host and target character set is `ISO-8859-1'.
f7dc1244 7350(@value{GDBP})
10998722 7351@end smallexample
a0eb71c5
KB
7352
7353For the sake of printing this manual, let's use @sc{ascii} as our
7354initial character set:
7355@smallexample
f7dc1244
EZ
7356(@value{GDBP}) set charset ASCII
7357(@value{GDBP}) show charset
e33d66ec 7358The current host and target character set is `ASCII'.
f7dc1244 7359(@value{GDBP})
10998722 7360@end smallexample
a0eb71c5
KB
7361
7362Let's assume that @sc{ascii} is indeed the correct character set for our
7363host system --- in other words, let's assume that if @value{GDBN} prints
7364characters using the @sc{ascii} character set, our terminal will display
7365them properly. Since our current target character set is also
7366@sc{ascii}, the contents of @code{ascii_hello} print legibly:
7367
7368@smallexample
f7dc1244 7369(@value{GDBP}) print ascii_hello
a0eb71c5 7370$1 = 0x401698 "Hello, world!\n"
f7dc1244 7371(@value{GDBP}) print ascii_hello[0]
a0eb71c5 7372$2 = 72 'H'
f7dc1244 7373(@value{GDBP})
10998722 7374@end smallexample
a0eb71c5
KB
7375
7376@value{GDBN} uses the target character set for character and string
7377literals you use in expressions:
7378
7379@smallexample
f7dc1244 7380(@value{GDBP}) print '+'
a0eb71c5 7381$3 = 43 '+'
f7dc1244 7382(@value{GDBP})
10998722 7383@end smallexample
a0eb71c5
KB
7384
7385The @sc{ascii} character set uses the number 43 to encode the @samp{+}
7386character.
7387
7388@value{GDBN} relies on the user to tell it which character set the
7389target program uses. If we print @code{ibm1047_hello} while our target
7390character set is still @sc{ascii}, we get jibberish:
7391
7392@smallexample
f7dc1244 7393(@value{GDBP}) print ibm1047_hello
a0eb71c5 7394$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 7395(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7396$5 = 200 '\310'
f7dc1244 7397(@value{GDBP})
10998722 7398@end smallexample
a0eb71c5 7399
e33d66ec 7400If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
7401@value{GDBN} tells us the character sets it supports:
7402
7403@smallexample
f7dc1244 7404(@value{GDBP}) set target-charset
b383017d 7405ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 7406(@value{GDBP}) set target-charset
10998722 7407@end smallexample
a0eb71c5
KB
7408
7409We can select @sc{ibm1047} as our target character set, and examine the
7410program's strings again. Now the @sc{ascii} string is wrong, but
7411@value{GDBN} translates the contents of @code{ibm1047_hello} from the
7412target character set, @sc{ibm1047}, to the host character set,
7413@sc{ascii}, and they display correctly:
7414
7415@smallexample
f7dc1244
EZ
7416(@value{GDBP}) set target-charset IBM1047
7417(@value{GDBP}) show charset
e33d66ec
EZ
7418The current host character set is `ASCII'.
7419The current target character set is `IBM1047'.
f7dc1244 7420(@value{GDBP}) print ascii_hello
a0eb71c5 7421$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 7422(@value{GDBP}) print ascii_hello[0]
a0eb71c5 7423$7 = 72 '\110'
f7dc1244 7424(@value{GDBP}) print ibm1047_hello
a0eb71c5 7425$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 7426(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 7427$9 = 200 'H'
f7dc1244 7428(@value{GDBP})
10998722 7429@end smallexample
a0eb71c5
KB
7430
7431As above, @value{GDBN} uses the target character set for character and
7432string literals you use in expressions:
7433
7434@smallexample
f7dc1244 7435(@value{GDBP}) print '+'
a0eb71c5 7436$10 = 78 '+'
f7dc1244 7437(@value{GDBP})
10998722 7438@end smallexample
a0eb71c5 7439
e33d66ec 7440The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
7441character.
7442
09d4efe1
EZ
7443@node Caching Remote Data
7444@section Caching Data of Remote Targets
7445@cindex caching data of remote targets
7446
7447@value{GDBN} can cache data exchanged between the debugger and a
ea35711c 7448remote target (@pxref{Remote Debugging}). Such caching generally improves
09d4efe1
EZ
7449performance, because it reduces the overhead of the remote protocol by
7450bundling memory reads and writes into large chunks. Unfortunately,
7451@value{GDBN} does not currently know anything about volatile
7452registers, and thus data caching will produce incorrect results when
7453volatile registers are in use.
7454
7455@table @code
7456@kindex set remotecache
7457@item set remotecache on
7458@itemx set remotecache off
7459Set caching state for remote targets. When @code{ON}, use data
7460caching. By default, this option is @code{OFF}.
7461
7462@kindex show remotecache
7463@item show remotecache
7464Show the current state of data caching for remote targets.
7465
7466@kindex info dcache
7467@item info dcache
7468Print the information about the data cache performance. The
7469information displayed includes: the dcache width and depth; and for
7470each cache line, how many times it was referenced, and its data and
7471state (dirty, bad, ok, etc.). This command is useful for debugging
7472the data cache operation.
7473@end table
7474
a0eb71c5 7475
e2e0bcd1
JB
7476@node Macros
7477@chapter C Preprocessor Macros
7478
49efadf5 7479Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
7480``preprocessor macros'' which expand into strings of tokens.
7481@value{GDBN} can evaluate expressions containing macro invocations, show
7482the result of macro expansion, and show a macro's definition, including
7483where it was defined.
7484
7485You may need to compile your program specially to provide @value{GDBN}
7486with information about preprocessor macros. Most compilers do not
7487include macros in their debugging information, even when you compile
7488with the @option{-g} flag. @xref{Compilation}.
7489
7490A program may define a macro at one point, remove that definition later,
7491and then provide a different definition after that. Thus, at different
7492points in the program, a macro may have different definitions, or have
7493no definition at all. If there is a current stack frame, @value{GDBN}
7494uses the macros in scope at that frame's source code line. Otherwise,
7495@value{GDBN} uses the macros in scope at the current listing location;
7496see @ref{List}.
7497
7498At the moment, @value{GDBN} does not support the @code{##}
7499token-splicing operator, the @code{#} stringification operator, or
7500variable-arity macros.
7501
7502Whenever @value{GDBN} evaluates an expression, it always expands any
7503macro invocations present in the expression. @value{GDBN} also provides
7504the following commands for working with macros explicitly.
7505
7506@table @code
7507
7508@kindex macro expand
7509@cindex macro expansion, showing the results of preprocessor
7510@cindex preprocessor macro expansion, showing the results of
7511@cindex expanding preprocessor macros
7512@item macro expand @var{expression}
7513@itemx macro exp @var{expression}
7514Show the results of expanding all preprocessor macro invocations in
7515@var{expression}. Since @value{GDBN} simply expands macros, but does
7516not parse the result, @var{expression} need not be a valid expression;
7517it can be any string of tokens.
7518
09d4efe1 7519@kindex macro exp1
e2e0bcd1
JB
7520@item macro expand-once @var{expression}
7521@itemx macro exp1 @var{expression}
4644b6e3 7522@cindex expand macro once
e2e0bcd1
JB
7523@i{(This command is not yet implemented.)} Show the results of
7524expanding those preprocessor macro invocations that appear explicitly in
7525@var{expression}. Macro invocations appearing in that expansion are
7526left unchanged. This command allows you to see the effect of a
7527particular macro more clearly, without being confused by further
7528expansions. Since @value{GDBN} simply expands macros, but does not
7529parse the result, @var{expression} need not be a valid expression; it
7530can be any string of tokens.
7531
475b0867 7532@kindex info macro
e2e0bcd1
JB
7533@cindex macro definition, showing
7534@cindex definition, showing a macro's
475b0867 7535@item info macro @var{macro}
e2e0bcd1
JB
7536Show the definition of the macro named @var{macro}, and describe the
7537source location where that definition was established.
7538
7539@kindex macro define
7540@cindex user-defined macros
7541@cindex defining macros interactively
7542@cindex macros, user-defined
7543@item macro define @var{macro} @var{replacement-list}
7544@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
7545@i{(This command is not yet implemented.)} Introduce a definition for a
7546preprocessor macro named @var{macro}, invocations of which are replaced
7547by the tokens given in @var{replacement-list}. The first form of this
7548command defines an ``object-like'' macro, which takes no arguments; the
7549second form defines a ``function-like'' macro, which takes the arguments
7550given in @var{arglist}.
7551
7552A definition introduced by this command is in scope in every expression
7553evaluated in @value{GDBN}, until it is removed with the @command{macro
7554undef} command, described below. The definition overrides all
7555definitions for @var{macro} present in the program being debugged, as
7556well as any previous user-supplied definition.
7557
7558@kindex macro undef
7559@item macro undef @var{macro}
7560@i{(This command is not yet implemented.)} Remove any user-supplied
7561definition for the macro named @var{macro}. This command only affects
7562definitions provided with the @command{macro define} command, described
7563above; it cannot remove definitions present in the program being
7564debugged.
7565
09d4efe1
EZ
7566@kindex macro list
7567@item macro list
7568@i{(This command is not yet implemented.)} List all the macros
7569defined using the @code{macro define} command.
e2e0bcd1
JB
7570@end table
7571
7572@cindex macros, example of debugging with
7573Here is a transcript showing the above commands in action. First, we
7574show our source files:
7575
7576@smallexample
7577$ cat sample.c
7578#include <stdio.h>
7579#include "sample.h"
7580
7581#define M 42
7582#define ADD(x) (M + x)
7583
7584main ()
7585@{
7586#define N 28
7587 printf ("Hello, world!\n");
7588#undef N
7589 printf ("We're so creative.\n");
7590#define N 1729
7591 printf ("Goodbye, world!\n");
7592@}
7593$ cat sample.h
7594#define Q <
7595$
7596@end smallexample
7597
7598Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
7599We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
7600compiler includes information about preprocessor macros in the debugging
7601information.
7602
7603@smallexample
7604$ gcc -gdwarf-2 -g3 sample.c -o sample
7605$
7606@end smallexample
7607
7608Now, we start @value{GDBN} on our sample program:
7609
7610@smallexample
7611$ gdb -nw sample
7612GNU gdb 2002-05-06-cvs
7613Copyright 2002 Free Software Foundation, Inc.
7614GDB is free software, @dots{}
f7dc1244 7615(@value{GDBP})
e2e0bcd1
JB
7616@end smallexample
7617
7618We can expand macros and examine their definitions, even when the
7619program is not running. @value{GDBN} uses the current listing position
7620to decide which macro definitions are in scope:
7621
7622@smallexample
f7dc1244 7623(@value{GDBP}) list main
e2e0bcd1
JB
76243
76254 #define M 42
76265 #define ADD(x) (M + x)
76276
76287 main ()
76298 @{
76309 #define N 28
763110 printf ("Hello, world!\n");
763211 #undef N
763312 printf ("We're so creative.\n");
f7dc1244 7634(@value{GDBP}) info macro ADD
e2e0bcd1
JB
7635Defined at /home/jimb/gdb/macros/play/sample.c:5
7636#define ADD(x) (M + x)
f7dc1244 7637(@value{GDBP}) info macro Q
e2e0bcd1
JB
7638Defined at /home/jimb/gdb/macros/play/sample.h:1
7639 included at /home/jimb/gdb/macros/play/sample.c:2
7640#define Q <
f7dc1244 7641(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7642expands to: (42 + 1)
f7dc1244 7643(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7644expands to: once (M + 1)
f7dc1244 7645(@value{GDBP})
e2e0bcd1
JB
7646@end smallexample
7647
7648In the example above, note that @command{macro expand-once} expands only
7649the macro invocation explicit in the original text --- the invocation of
7650@code{ADD} --- but does not expand the invocation of the macro @code{M},
7651which was introduced by @code{ADD}.
7652
3f94c067
BW
7653Once the program is running, @value{GDBN} uses the macro definitions in
7654force at the source line of the current stack frame:
e2e0bcd1
JB
7655
7656@smallexample
f7dc1244 7657(@value{GDBP}) break main
e2e0bcd1 7658Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7659(@value{GDBP}) run
b383017d 7660Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7661
7662Breakpoint 1, main () at sample.c:10
766310 printf ("Hello, world!\n");
f7dc1244 7664(@value{GDBP})
e2e0bcd1
JB
7665@end smallexample
7666
7667At line 10, the definition of the macro @code{N} at line 9 is in force:
7668
7669@smallexample
f7dc1244 7670(@value{GDBP}) info macro N
e2e0bcd1
JB
7671Defined at /home/jimb/gdb/macros/play/sample.c:9
7672#define N 28
f7dc1244 7673(@value{GDBP}) macro expand N Q M
e2e0bcd1 7674expands to: 28 < 42
f7dc1244 7675(@value{GDBP}) print N Q M
e2e0bcd1 7676$1 = 1
f7dc1244 7677(@value{GDBP})
e2e0bcd1
JB
7678@end smallexample
7679
7680As we step over directives that remove @code{N}'s definition, and then
7681give it a new definition, @value{GDBN} finds the definition (or lack
7682thereof) in force at each point:
7683
7684@smallexample
f7dc1244 7685(@value{GDBP}) next
e2e0bcd1
JB
7686Hello, world!
768712 printf ("We're so creative.\n");
f7dc1244 7688(@value{GDBP}) info macro N
e2e0bcd1
JB
7689The symbol `N' has no definition as a C/C++ preprocessor macro
7690at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7691(@value{GDBP}) next
e2e0bcd1
JB
7692We're so creative.
769314 printf ("Goodbye, world!\n");
f7dc1244 7694(@value{GDBP}) info macro N
e2e0bcd1
JB
7695Defined at /home/jimb/gdb/macros/play/sample.c:13
7696#define N 1729
f7dc1244 7697(@value{GDBP}) macro expand N Q M
e2e0bcd1 7698expands to: 1729 < 42
f7dc1244 7699(@value{GDBP}) print N Q M
e2e0bcd1 7700$2 = 0
f7dc1244 7701(@value{GDBP})
e2e0bcd1
JB
7702@end smallexample
7703
7704
b37052ae
EZ
7705@node Tracepoints
7706@chapter Tracepoints
7707@c This chapter is based on the documentation written by Michael
7708@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7709
7710@cindex tracepoints
7711In some applications, it is not feasible for the debugger to interrupt
7712the program's execution long enough for the developer to learn
7713anything helpful about its behavior. If the program's correctness
7714depends on its real-time behavior, delays introduced by a debugger
7715might cause the program to change its behavior drastically, or perhaps
7716fail, even when the code itself is correct. It is useful to be able
7717to observe the program's behavior without interrupting it.
7718
7719Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7720specify locations in the program, called @dfn{tracepoints}, and
7721arbitrary expressions to evaluate when those tracepoints are reached.
7722Later, using the @code{tfind} command, you can examine the values
7723those expressions had when the program hit the tracepoints. The
7724expressions may also denote objects in memory---structures or arrays,
7725for example---whose values @value{GDBN} should record; while visiting
7726a particular tracepoint, you may inspect those objects as if they were
7727in memory at that moment. However, because @value{GDBN} records these
7728values without interacting with you, it can do so quickly and
7729unobtrusively, hopefully not disturbing the program's behavior.
7730
7731The tracepoint facility is currently available only for remote
9d29849a
JB
7732targets. @xref{Targets}. In addition, your remote target must know
7733how to collect trace data. This functionality is implemented in the
7734remote stub; however, none of the stubs distributed with @value{GDBN}
7735support tracepoints as of this writing. The format of the remote
7736packets used to implement tracepoints are described in @ref{Tracepoint
7737Packets}.
b37052ae
EZ
7738
7739This chapter describes the tracepoint commands and features.
7740
7741@menu
b383017d
RM
7742* Set Tracepoints::
7743* Analyze Collected Data::
7744* Tracepoint Variables::
b37052ae
EZ
7745@end menu
7746
7747@node Set Tracepoints
7748@section Commands to Set Tracepoints
7749
7750Before running such a @dfn{trace experiment}, an arbitrary number of
7751tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7752tracepoint has a number assigned to it by @value{GDBN}. Like with
7753breakpoints, tracepoint numbers are successive integers starting from
7754one. Many of the commands associated with tracepoints take the
7755tracepoint number as their argument, to identify which tracepoint to
7756work on.
7757
7758For each tracepoint, you can specify, in advance, some arbitrary set
7759of data that you want the target to collect in the trace buffer when
7760it hits that tracepoint. The collected data can include registers,
7761local variables, or global data. Later, you can use @value{GDBN}
7762commands to examine the values these data had at the time the
7763tracepoint was hit.
7764
7765This section describes commands to set tracepoints and associated
7766conditions and actions.
7767
7768@menu
b383017d
RM
7769* Create and Delete Tracepoints::
7770* Enable and Disable Tracepoints::
7771* Tracepoint Passcounts::
7772* Tracepoint Actions::
7773* Listing Tracepoints::
79a6e687 7774* Starting and Stopping Trace Experiments::
b37052ae
EZ
7775@end menu
7776
7777@node Create and Delete Tracepoints
7778@subsection Create and Delete Tracepoints
7779
7780@table @code
7781@cindex set tracepoint
7782@kindex trace
7783@item trace
7784The @code{trace} command is very similar to the @code{break} command.
7785Its argument can be a source line, a function name, or an address in
7786the target program. @xref{Set Breaks}. The @code{trace} command
7787defines a tracepoint, which is a point in the target program where the
7788debugger will briefly stop, collect some data, and then allow the
7789program to continue. Setting a tracepoint or changing its commands
7790doesn't take effect until the next @code{tstart} command; thus, you
7791cannot change the tracepoint attributes once a trace experiment is
7792running.
7793
7794Here are some examples of using the @code{trace} command:
7795
7796@smallexample
7797(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7798
7799(@value{GDBP}) @b{trace +2} // 2 lines forward
7800
7801(@value{GDBP}) @b{trace my_function} // first source line of function
7802
7803(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7804
7805(@value{GDBP}) @b{trace *0x2117c4} // an address
7806@end smallexample
7807
7808@noindent
7809You can abbreviate @code{trace} as @code{tr}.
7810
7811@vindex $tpnum
7812@cindex last tracepoint number
7813@cindex recent tracepoint number
7814@cindex tracepoint number
7815The convenience variable @code{$tpnum} records the tracepoint number
7816of the most recently set tracepoint.
7817
7818@kindex delete tracepoint
7819@cindex tracepoint deletion
7820@item delete tracepoint @r{[}@var{num}@r{]}
7821Permanently delete one or more tracepoints. With no argument, the
7822default is to delete all tracepoints.
7823
7824Examples:
7825
7826@smallexample
7827(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7828
7829(@value{GDBP}) @b{delete trace} // remove all tracepoints
7830@end smallexample
7831
7832@noindent
7833You can abbreviate this command as @code{del tr}.
7834@end table
7835
7836@node Enable and Disable Tracepoints
7837@subsection Enable and Disable Tracepoints
7838
7839@table @code
7840@kindex disable tracepoint
7841@item disable tracepoint @r{[}@var{num}@r{]}
7842Disable tracepoint @var{num}, or all tracepoints if no argument
7843@var{num} is given. A disabled tracepoint will have no effect during
7844the next trace experiment, but it is not forgotten. You can re-enable
7845a disabled tracepoint using the @code{enable tracepoint} command.
7846
7847@kindex enable tracepoint
7848@item enable tracepoint @r{[}@var{num}@r{]}
7849Enable tracepoint @var{num}, or all tracepoints. The enabled
7850tracepoints will become effective the next time a trace experiment is
7851run.
7852@end table
7853
7854@node Tracepoint Passcounts
7855@subsection Tracepoint Passcounts
7856
7857@table @code
7858@kindex passcount
7859@cindex tracepoint pass count
7860@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7861Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7862automatically stop a trace experiment. If a tracepoint's passcount is
7863@var{n}, then the trace experiment will be automatically stopped on
7864the @var{n}'th time that tracepoint is hit. If the tracepoint number
7865@var{num} is not specified, the @code{passcount} command sets the
7866passcount of the most recently defined tracepoint. If no passcount is
7867given, the trace experiment will run until stopped explicitly by the
7868user.
7869
7870Examples:
7871
7872@smallexample
b383017d 7873(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7874@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7875
7876(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7877@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7878(@value{GDBP}) @b{trace foo}
7879(@value{GDBP}) @b{pass 3}
7880(@value{GDBP}) @b{trace bar}
7881(@value{GDBP}) @b{pass 2}
7882(@value{GDBP}) @b{trace baz}
7883(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7884@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7885@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7886@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7887@end smallexample
7888@end table
7889
7890@node Tracepoint Actions
7891@subsection Tracepoint Action Lists
7892
7893@table @code
7894@kindex actions
7895@cindex tracepoint actions
7896@item actions @r{[}@var{num}@r{]}
7897This command will prompt for a list of actions to be taken when the
7898tracepoint is hit. If the tracepoint number @var{num} is not
7899specified, this command sets the actions for the one that was most
7900recently defined (so that you can define a tracepoint and then say
7901@code{actions} without bothering about its number). You specify the
7902actions themselves on the following lines, one action at a time, and
7903terminate the actions list with a line containing just @code{end}. So
7904far, the only defined actions are @code{collect} and
7905@code{while-stepping}.
7906
7907@cindex remove actions from a tracepoint
7908To remove all actions from a tracepoint, type @samp{actions @var{num}}
7909and follow it immediately with @samp{end}.
7910
7911@smallexample
7912(@value{GDBP}) @b{collect @var{data}} // collect some data
7913
6826cf00 7914(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7915
6826cf00 7916(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7917@end smallexample
7918
7919In the following example, the action list begins with @code{collect}
7920commands indicating the things to be collected when the tracepoint is
7921hit. Then, in order to single-step and collect additional data
7922following the tracepoint, a @code{while-stepping} command is used,
7923followed by the list of things to be collected while stepping. The
7924@code{while-stepping} command is terminated by its own separate
7925@code{end} command. Lastly, the action list is terminated by an
7926@code{end} command.
7927
7928@smallexample
7929(@value{GDBP}) @b{trace foo}
7930(@value{GDBP}) @b{actions}
7931Enter actions for tracepoint 1, one per line:
7932> collect bar,baz
7933> collect $regs
7934> while-stepping 12
7935 > collect $fp, $sp
7936 > end
7937end
7938@end smallexample
7939
7940@kindex collect @r{(tracepoints)}
7941@item collect @var{expr1}, @var{expr2}, @dots{}
7942Collect values of the given expressions when the tracepoint is hit.
7943This command accepts a comma-separated list of any valid expressions.
7944In addition to global, static, or local variables, the following
7945special arguments are supported:
7946
7947@table @code
7948@item $regs
7949collect all registers
7950
7951@item $args
7952collect all function arguments
7953
7954@item $locals
7955collect all local variables.
7956@end table
7957
7958You can give several consecutive @code{collect} commands, each one
7959with a single argument, or one @code{collect} command with several
7960arguments separated by commas: the effect is the same.
7961
f5c37c66
EZ
7962The command @code{info scope} (@pxref{Symbols, info scope}) is
7963particularly useful for figuring out what data to collect.
7964
b37052ae
EZ
7965@kindex while-stepping @r{(tracepoints)}
7966@item while-stepping @var{n}
7967Perform @var{n} single-step traces after the tracepoint, collecting
7968new data at each step. The @code{while-stepping} command is
7969followed by the list of what to collect while stepping (followed by
7970its own @code{end} command):
7971
7972@smallexample
7973> while-stepping 12
7974 > collect $regs, myglobal
7975 > end
7976>
7977@end smallexample
7978
7979@noindent
7980You may abbreviate @code{while-stepping} as @code{ws} or
7981@code{stepping}.
7982@end table
7983
7984@node Listing Tracepoints
7985@subsection Listing Tracepoints
7986
7987@table @code
7988@kindex info tracepoints
09d4efe1 7989@kindex info tp
b37052ae
EZ
7990@cindex information about tracepoints
7991@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7992Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7993a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7994defined so far. For each tracepoint, the following information is
7995shown:
7996
7997@itemize @bullet
7998@item
7999its number
8000@item
8001whether it is enabled or disabled
8002@item
8003its address
8004@item
8005its passcount as given by the @code{passcount @var{n}} command
8006@item
8007its step count as given by the @code{while-stepping @var{n}} command
8008@item
8009where in the source files is the tracepoint set
8010@item
8011its action list as given by the @code{actions} command
8012@end itemize
8013
8014@smallexample
8015(@value{GDBP}) @b{info trace}
8016Num Enb Address PassC StepC What
80171 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
80182 y 0x0020dc64 0 0 in g_test at g_test.c:1375
80193 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
8020(@value{GDBP})
8021@end smallexample
8022
8023@noindent
8024This command can be abbreviated @code{info tp}.
8025@end table
8026
79a6e687
BW
8027@node Starting and Stopping Trace Experiments
8028@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
8029
8030@table @code
8031@kindex tstart
8032@cindex start a new trace experiment
8033@cindex collected data discarded
8034@item tstart
8035This command takes no arguments. It starts the trace experiment, and
8036begins collecting data. This has the side effect of discarding all
8037the data collected in the trace buffer during the previous trace
8038experiment.
8039
8040@kindex tstop
8041@cindex stop a running trace experiment
8042@item tstop
8043This command takes no arguments. It ends the trace experiment, and
8044stops collecting data.
8045
68c71a2e 8046@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
8047automatically if any tracepoint's passcount is reached
8048(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
8049
8050@kindex tstatus
8051@cindex status of trace data collection
8052@cindex trace experiment, status of
8053@item tstatus
8054This command displays the status of the current trace data
8055collection.
8056@end table
8057
8058Here is an example of the commands we described so far:
8059
8060@smallexample
8061(@value{GDBP}) @b{trace gdb_c_test}
8062(@value{GDBP}) @b{actions}
8063Enter actions for tracepoint #1, one per line.
8064> collect $regs,$locals,$args
8065> while-stepping 11
8066 > collect $regs
8067 > end
8068> end
8069(@value{GDBP}) @b{tstart}
8070 [time passes @dots{}]
8071(@value{GDBP}) @b{tstop}
8072@end smallexample
8073
8074
8075@node Analyze Collected Data
79a6e687 8076@section Using the Collected Data
b37052ae
EZ
8077
8078After the tracepoint experiment ends, you use @value{GDBN} commands
8079for examining the trace data. The basic idea is that each tracepoint
8080collects a trace @dfn{snapshot} every time it is hit and another
8081snapshot every time it single-steps. All these snapshots are
8082consecutively numbered from zero and go into a buffer, and you can
8083examine them later. The way you examine them is to @dfn{focus} on a
8084specific trace snapshot. When the remote stub is focused on a trace
8085snapshot, it will respond to all @value{GDBN} requests for memory and
8086registers by reading from the buffer which belongs to that snapshot,
8087rather than from @emph{real} memory or registers of the program being
8088debugged. This means that @strong{all} @value{GDBN} commands
8089(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
8090behave as if we were currently debugging the program state as it was
8091when the tracepoint occurred. Any requests for data that are not in
8092the buffer will fail.
8093
8094@menu
8095* tfind:: How to select a trace snapshot
8096* tdump:: How to display all data for a snapshot
8097* save-tracepoints:: How to save tracepoints for a future run
8098@end menu
8099
8100@node tfind
8101@subsection @code{tfind @var{n}}
8102
8103@kindex tfind
8104@cindex select trace snapshot
8105@cindex find trace snapshot
8106The basic command for selecting a trace snapshot from the buffer is
8107@code{tfind @var{n}}, which finds trace snapshot number @var{n},
8108counting from zero. If no argument @var{n} is given, the next
8109snapshot is selected.
8110
8111Here are the various forms of using the @code{tfind} command.
8112
8113@table @code
8114@item tfind start
8115Find the first snapshot in the buffer. This is a synonym for
8116@code{tfind 0} (since 0 is the number of the first snapshot).
8117
8118@item tfind none
8119Stop debugging trace snapshots, resume @emph{live} debugging.
8120
8121@item tfind end
8122Same as @samp{tfind none}.
8123
8124@item tfind
8125No argument means find the next trace snapshot.
8126
8127@item tfind -
8128Find the previous trace snapshot before the current one. This permits
8129retracing earlier steps.
8130
8131@item tfind tracepoint @var{num}
8132Find the next snapshot associated with tracepoint @var{num}. Search
8133proceeds forward from the last examined trace snapshot. If no
8134argument @var{num} is given, it means find the next snapshot collected
8135for the same tracepoint as the current snapshot.
8136
8137@item tfind pc @var{addr}
8138Find the next snapshot associated with the value @var{addr} of the
8139program counter. Search proceeds forward from the last examined trace
8140snapshot. If no argument @var{addr} is given, it means find the next
8141snapshot with the same value of PC as the current snapshot.
8142
8143@item tfind outside @var{addr1}, @var{addr2}
8144Find the next snapshot whose PC is outside the given range of
8145addresses.
8146
8147@item tfind range @var{addr1}, @var{addr2}
8148Find the next snapshot whose PC is between @var{addr1} and
8149@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
8150
8151@item tfind line @r{[}@var{file}:@r{]}@var{n}
8152Find the next snapshot associated with the source line @var{n}. If
8153the optional argument @var{file} is given, refer to line @var{n} in
8154that source file. Search proceeds forward from the last examined
8155trace snapshot. If no argument @var{n} is given, it means find the
8156next line other than the one currently being examined; thus saying
8157@code{tfind line} repeatedly can appear to have the same effect as
8158stepping from line to line in a @emph{live} debugging session.
8159@end table
8160
8161The default arguments for the @code{tfind} commands are specifically
8162designed to make it easy to scan through the trace buffer. For
8163instance, @code{tfind} with no argument selects the next trace
8164snapshot, and @code{tfind -} with no argument selects the previous
8165trace snapshot. So, by giving one @code{tfind} command, and then
8166simply hitting @key{RET} repeatedly you can examine all the trace
8167snapshots in order. Or, by saying @code{tfind -} and then hitting
8168@key{RET} repeatedly you can examine the snapshots in reverse order.
8169The @code{tfind line} command with no argument selects the snapshot
8170for the next source line executed. The @code{tfind pc} command with
8171no argument selects the next snapshot with the same program counter
8172(PC) as the current frame. The @code{tfind tracepoint} command with
8173no argument selects the next trace snapshot collected by the same
8174tracepoint as the current one.
8175
8176In addition to letting you scan through the trace buffer manually,
8177these commands make it easy to construct @value{GDBN} scripts that
8178scan through the trace buffer and print out whatever collected data
8179you are interested in. Thus, if we want to examine the PC, FP, and SP
8180registers from each trace frame in the buffer, we can say this:
8181
8182@smallexample
8183(@value{GDBP}) @b{tfind start}
8184(@value{GDBP}) @b{while ($trace_frame != -1)}
8185> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
8186 $trace_frame, $pc, $sp, $fp
8187> tfind
8188> end
8189
8190Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
8191Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
8192Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
8193Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
8194Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
8195Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
8196Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
8197Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
8198Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
8199Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
8200Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
8201@end smallexample
8202
8203Or, if we want to examine the variable @code{X} at each source line in
8204the buffer:
8205
8206@smallexample
8207(@value{GDBP}) @b{tfind start}
8208(@value{GDBP}) @b{while ($trace_frame != -1)}
8209> printf "Frame %d, X == %d\n", $trace_frame, X
8210> tfind line
8211> end
8212
8213Frame 0, X = 1
8214Frame 7, X = 2
8215Frame 13, X = 255
8216@end smallexample
8217
8218@node tdump
8219@subsection @code{tdump}
8220@kindex tdump
8221@cindex dump all data collected at tracepoint
8222@cindex tracepoint data, display
8223
8224This command takes no arguments. It prints all the data collected at
8225the current trace snapshot.
8226
8227@smallexample
8228(@value{GDBP}) @b{trace 444}
8229(@value{GDBP}) @b{actions}
8230Enter actions for tracepoint #2, one per line:
8231> collect $regs, $locals, $args, gdb_long_test
8232> end
8233
8234(@value{GDBP}) @b{tstart}
8235
8236(@value{GDBP}) @b{tfind line 444}
8237#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
8238at gdb_test.c:444
8239444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
8240
8241(@value{GDBP}) @b{tdump}
8242Data collected at tracepoint 2, trace frame 1:
8243d0 0xc4aa0085 -995491707
8244d1 0x18 24
8245d2 0x80 128
8246d3 0x33 51
8247d4 0x71aea3d 119204413
8248d5 0x22 34
8249d6 0xe0 224
8250d7 0x380035 3670069
8251a0 0x19e24a 1696330
8252a1 0x3000668 50333288
8253a2 0x100 256
8254a3 0x322000 3284992
8255a4 0x3000698 50333336
8256a5 0x1ad3cc 1758156
8257fp 0x30bf3c 0x30bf3c
8258sp 0x30bf34 0x30bf34
8259ps 0x0 0
8260pc 0x20b2c8 0x20b2c8
8261fpcontrol 0x0 0
8262fpstatus 0x0 0
8263fpiaddr 0x0 0
8264p = 0x20e5b4 "gdb-test"
8265p1 = (void *) 0x11
8266p2 = (void *) 0x22
8267p3 = (void *) 0x33
8268p4 = (void *) 0x44
8269p5 = (void *) 0x55
8270p6 = (void *) 0x66
8271gdb_long_test = 17 '\021'
8272
8273(@value{GDBP})
8274@end smallexample
8275
8276@node save-tracepoints
8277@subsection @code{save-tracepoints @var{filename}}
8278@kindex save-tracepoints
8279@cindex save tracepoints for future sessions
8280
8281This command saves all current tracepoint definitions together with
8282their actions and passcounts, into a file @file{@var{filename}}
8283suitable for use in a later debugging session. To read the saved
8284tracepoint definitions, use the @code{source} command (@pxref{Command
8285Files}).
8286
8287@node Tracepoint Variables
8288@section Convenience Variables for Tracepoints
8289@cindex tracepoint variables
8290@cindex convenience variables for tracepoints
8291
8292@table @code
8293@vindex $trace_frame
8294@item (int) $trace_frame
8295The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
8296snapshot is selected.
8297
8298@vindex $tracepoint
8299@item (int) $tracepoint
8300The tracepoint for the current trace snapshot.
8301
8302@vindex $trace_line
8303@item (int) $trace_line
8304The line number for the current trace snapshot.
8305
8306@vindex $trace_file
8307@item (char []) $trace_file
8308The source file for the current trace snapshot.
8309
8310@vindex $trace_func
8311@item (char []) $trace_func
8312The name of the function containing @code{$tracepoint}.
8313@end table
8314
8315Note: @code{$trace_file} is not suitable for use in @code{printf},
8316use @code{output} instead.
8317
8318Here's a simple example of using these convenience variables for
8319stepping through all the trace snapshots and printing some of their
8320data.
8321
8322@smallexample
8323(@value{GDBP}) @b{tfind start}
8324
8325(@value{GDBP}) @b{while $trace_frame != -1}
8326> output $trace_file
8327> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
8328> tfind
8329> end
8330@end smallexample
8331
df0cd8c5
JB
8332@node Overlays
8333@chapter Debugging Programs That Use Overlays
8334@cindex overlays
8335
8336If your program is too large to fit completely in your target system's
8337memory, you can sometimes use @dfn{overlays} to work around this
8338problem. @value{GDBN} provides some support for debugging programs that
8339use overlays.
8340
8341@menu
8342* How Overlays Work:: A general explanation of overlays.
8343* Overlay Commands:: Managing overlays in @value{GDBN}.
8344* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
8345 mapped by asking the inferior.
8346* Overlay Sample Program:: A sample program using overlays.
8347@end menu
8348
8349@node How Overlays Work
8350@section How Overlays Work
8351@cindex mapped overlays
8352@cindex unmapped overlays
8353@cindex load address, overlay's
8354@cindex mapped address
8355@cindex overlay area
8356
8357Suppose you have a computer whose instruction address space is only 64
8358kilobytes long, but which has much more memory which can be accessed by
8359other means: special instructions, segment registers, or memory
8360management hardware, for example. Suppose further that you want to
8361adapt a program which is larger than 64 kilobytes to run on this system.
8362
8363One solution is to identify modules of your program which are relatively
8364independent, and need not call each other directly; call these modules
8365@dfn{overlays}. Separate the overlays from the main program, and place
8366their machine code in the larger memory. Place your main program in
8367instruction memory, but leave at least enough space there to hold the
8368largest overlay as well.
8369
8370Now, to call a function located in an overlay, you must first copy that
8371overlay's machine code from the large memory into the space set aside
8372for it in the instruction memory, and then jump to its entry point
8373there.
8374
c928edc0
AC
8375@c NB: In the below the mapped area's size is greater or equal to the
8376@c size of all overlays. This is intentional to remind the developer
8377@c that overlays don't necessarily need to be the same size.
8378
474c8240 8379@smallexample
df0cd8c5 8380@group
c928edc0
AC
8381 Data Instruction Larger
8382Address Space Address Space Address Space
8383+-----------+ +-----------+ +-----------+
8384| | | | | |
8385+-----------+ +-----------+ +-----------+<-- overlay 1
8386| program | | main | .----| overlay 1 | load address
8387| variables | | program | | +-----------+
8388| and heap | | | | | |
8389+-----------+ | | | +-----------+<-- overlay 2
8390| | +-----------+ | | | load address
8391+-----------+ | | | .-| overlay 2 |
8392 | | | | | |
8393 mapped --->+-----------+ | | +-----------+
8394 address | | | | | |
8395 | overlay | <-' | | |
8396 | area | <---' +-----------+<-- overlay 3
8397 | | <---. | | load address
8398 +-----------+ `--| overlay 3 |
8399 | | | |
8400 +-----------+ | |
8401 +-----------+
8402 | |
8403 +-----------+
8404
8405 @anchor{A code overlay}A code overlay
df0cd8c5 8406@end group
474c8240 8407@end smallexample
df0cd8c5 8408
c928edc0
AC
8409The diagram (@pxref{A code overlay}) shows a system with separate data
8410and instruction address spaces. To map an overlay, the program copies
8411its code from the larger address space to the instruction address space.
8412Since the overlays shown here all use the same mapped address, only one
8413may be mapped at a time. For a system with a single address space for
8414data and instructions, the diagram would be similar, except that the
8415program variables and heap would share an address space with the main
8416program and the overlay area.
df0cd8c5
JB
8417
8418An overlay loaded into instruction memory and ready for use is called a
8419@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
8420instruction memory. An overlay not present (or only partially present)
8421in instruction memory is called @dfn{unmapped}; its @dfn{load address}
8422is its address in the larger memory. The mapped address is also called
8423the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
8424called the @dfn{load memory address}, or @dfn{LMA}.
8425
8426Unfortunately, overlays are not a completely transparent way to adapt a
8427program to limited instruction memory. They introduce a new set of
8428global constraints you must keep in mind as you design your program:
8429
8430@itemize @bullet
8431
8432@item
8433Before calling or returning to a function in an overlay, your program
8434must make sure that overlay is actually mapped. Otherwise, the call or
8435return will transfer control to the right address, but in the wrong
8436overlay, and your program will probably crash.
8437
8438@item
8439If the process of mapping an overlay is expensive on your system, you
8440will need to choose your overlays carefully to minimize their effect on
8441your program's performance.
8442
8443@item
8444The executable file you load onto your system must contain each
8445overlay's instructions, appearing at the overlay's load address, not its
8446mapped address. However, each overlay's instructions must be relocated
8447and its symbols defined as if the overlay were at its mapped address.
8448You can use GNU linker scripts to specify different load and relocation
8449addresses for pieces of your program; see @ref{Overlay Description,,,
8450ld.info, Using ld: the GNU linker}.
8451
8452@item
8453The procedure for loading executable files onto your system must be able
8454to load their contents into the larger address space as well as the
8455instruction and data spaces.
8456
8457@end itemize
8458
8459The overlay system described above is rather simple, and could be
8460improved in many ways:
8461
8462@itemize @bullet
8463
8464@item
8465If your system has suitable bank switch registers or memory management
8466hardware, you could use those facilities to make an overlay's load area
8467contents simply appear at their mapped address in instruction space.
8468This would probably be faster than copying the overlay to its mapped
8469area in the usual way.
8470
8471@item
8472If your overlays are small enough, you could set aside more than one
8473overlay area, and have more than one overlay mapped at a time.
8474
8475@item
8476You can use overlays to manage data, as well as instructions. In
8477general, data overlays are even less transparent to your design than
8478code overlays: whereas code overlays only require care when you call or
8479return to functions, data overlays require care every time you access
8480the data. Also, if you change the contents of a data overlay, you
8481must copy its contents back out to its load address before you can copy a
8482different data overlay into the same mapped area.
8483
8484@end itemize
8485
8486
8487@node Overlay Commands
8488@section Overlay Commands
8489
8490To use @value{GDBN}'s overlay support, each overlay in your program must
8491correspond to a separate section of the executable file. The section's
8492virtual memory address and load memory address must be the overlay's
8493mapped and load addresses. Identifying overlays with sections allows
8494@value{GDBN} to determine the appropriate address of a function or
8495variable, depending on whether the overlay is mapped or not.
8496
8497@value{GDBN}'s overlay commands all start with the word @code{overlay};
8498you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
8499
8500@table @code
8501@item overlay off
4644b6e3 8502@kindex overlay
df0cd8c5
JB
8503Disable @value{GDBN}'s overlay support. When overlay support is
8504disabled, @value{GDBN} assumes that all functions and variables are
8505always present at their mapped addresses. By default, @value{GDBN}'s
8506overlay support is disabled.
8507
8508@item overlay manual
df0cd8c5
JB
8509@cindex manual overlay debugging
8510Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
8511relies on you to tell it which overlays are mapped, and which are not,
8512using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
8513commands described below.
8514
8515@item overlay map-overlay @var{overlay}
8516@itemx overlay map @var{overlay}
df0cd8c5
JB
8517@cindex map an overlay
8518Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
8519be the name of the object file section containing the overlay. When an
8520overlay is mapped, @value{GDBN} assumes it can find the overlay's
8521functions and variables at their mapped addresses. @value{GDBN} assumes
8522that any other overlays whose mapped ranges overlap that of
8523@var{overlay} are now unmapped.
8524
8525@item overlay unmap-overlay @var{overlay}
8526@itemx overlay unmap @var{overlay}
df0cd8c5
JB
8527@cindex unmap an overlay
8528Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
8529must be the name of the object file section containing the overlay.
8530When an overlay is unmapped, @value{GDBN} assumes it can find the
8531overlay's functions and variables at their load addresses.
8532
8533@item overlay auto
df0cd8c5
JB
8534Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
8535consults a data structure the overlay manager maintains in the inferior
8536to see which overlays are mapped. For details, see @ref{Automatic
8537Overlay Debugging}.
8538
8539@item overlay load-target
8540@itemx overlay load
df0cd8c5
JB
8541@cindex reloading the overlay table
8542Re-read the overlay table from the inferior. Normally, @value{GDBN}
8543re-reads the table @value{GDBN} automatically each time the inferior
8544stops, so this command should only be necessary if you have changed the
8545overlay mapping yourself using @value{GDBN}. This command is only
8546useful when using automatic overlay debugging.
8547
8548@item overlay list-overlays
8549@itemx overlay list
8550@cindex listing mapped overlays
8551Display a list of the overlays currently mapped, along with their mapped
8552addresses, load addresses, and sizes.
8553
8554@end table
8555
8556Normally, when @value{GDBN} prints a code address, it includes the name
8557of the function the address falls in:
8558
474c8240 8559@smallexample
f7dc1244 8560(@value{GDBP}) print main
df0cd8c5 8561$3 = @{int ()@} 0x11a0 <main>
474c8240 8562@end smallexample
df0cd8c5
JB
8563@noindent
8564When overlay debugging is enabled, @value{GDBN} recognizes code in
8565unmapped overlays, and prints the names of unmapped functions with
8566asterisks around them. For example, if @code{foo} is a function in an
8567unmapped overlay, @value{GDBN} prints it this way:
8568
474c8240 8569@smallexample
f7dc1244 8570(@value{GDBP}) overlay list
df0cd8c5 8571No sections are mapped.
f7dc1244 8572(@value{GDBP}) print foo
df0cd8c5 8573$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 8574@end smallexample
df0cd8c5
JB
8575@noindent
8576When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
8577name normally:
8578
474c8240 8579@smallexample
f7dc1244 8580(@value{GDBP}) overlay list
b383017d 8581Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 8582 mapped at 0x1016 - 0x104a
f7dc1244 8583(@value{GDBP}) print foo
df0cd8c5 8584$6 = @{int (int)@} 0x1016 <foo>
474c8240 8585@end smallexample
df0cd8c5
JB
8586
8587When overlay debugging is enabled, @value{GDBN} can find the correct
8588address for functions and variables in an overlay, whether or not the
8589overlay is mapped. This allows most @value{GDBN} commands, like
8590@code{break} and @code{disassemble}, to work normally, even on unmapped
8591code. However, @value{GDBN}'s breakpoint support has some limitations:
8592
8593@itemize @bullet
8594@item
8595@cindex breakpoints in overlays
8596@cindex overlays, setting breakpoints in
8597You can set breakpoints in functions in unmapped overlays, as long as
8598@value{GDBN} can write to the overlay at its load address.
8599@item
8600@value{GDBN} can not set hardware or simulator-based breakpoints in
8601unmapped overlays. However, if you set a breakpoint at the end of your
8602overlay manager (and tell @value{GDBN} which overlays are now mapped, if
8603you are using manual overlay management), @value{GDBN} will re-set its
8604breakpoints properly.
8605@end itemize
8606
8607
8608@node Automatic Overlay Debugging
8609@section Automatic Overlay Debugging
8610@cindex automatic overlay debugging
8611
8612@value{GDBN} can automatically track which overlays are mapped and which
8613are not, given some simple co-operation from the overlay manager in the
8614inferior. If you enable automatic overlay debugging with the
8615@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
8616looks in the inferior's memory for certain variables describing the
8617current state of the overlays.
8618
8619Here are the variables your overlay manager must define to support
8620@value{GDBN}'s automatic overlay debugging:
8621
8622@table @asis
8623
8624@item @code{_ovly_table}:
8625This variable must be an array of the following structures:
8626
474c8240 8627@smallexample
df0cd8c5
JB
8628struct
8629@{
8630 /* The overlay's mapped address. */
8631 unsigned long vma;
8632
8633 /* The size of the overlay, in bytes. */
8634 unsigned long size;
8635
8636 /* The overlay's load address. */
8637 unsigned long lma;
8638
8639 /* Non-zero if the overlay is currently mapped;
8640 zero otherwise. */
8641 unsigned long mapped;
8642@}
474c8240 8643@end smallexample
df0cd8c5
JB
8644
8645@item @code{_novlys}:
8646This variable must be a four-byte signed integer, holding the total
8647number of elements in @code{_ovly_table}.
8648
8649@end table
8650
8651To decide whether a particular overlay is mapped or not, @value{GDBN}
8652looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8653@code{lma} members equal the VMA and LMA of the overlay's section in the
8654executable file. When @value{GDBN} finds a matching entry, it consults
8655the entry's @code{mapped} member to determine whether the overlay is
8656currently mapped.
8657
81d46470 8658In addition, your overlay manager may define a function called
def71bfa 8659@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8660will silently set a breakpoint there. If the overlay manager then
8661calls this function whenever it has changed the overlay table, this
8662will enable @value{GDBN} to accurately keep track of which overlays
8663are in program memory, and update any breakpoints that may be set
b383017d 8664in overlays. This will allow breakpoints to work even if the
81d46470
MS
8665overlays are kept in ROM or other non-writable memory while they
8666are not being executed.
df0cd8c5
JB
8667
8668@node Overlay Sample Program
8669@section Overlay Sample Program
8670@cindex overlay example program
8671
8672When linking a program which uses overlays, you must place the overlays
8673at their load addresses, while relocating them to run at their mapped
8674addresses. To do this, you must write a linker script (@pxref{Overlay
8675Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8676since linker scripts are specific to a particular host system, target
8677architecture, and target memory layout, this manual cannot provide
8678portable sample code demonstrating @value{GDBN}'s overlay support.
8679
8680However, the @value{GDBN} source distribution does contain an overlaid
8681program, with linker scripts for a few systems, as part of its test
8682suite. The program consists of the following files from
8683@file{gdb/testsuite/gdb.base}:
8684
8685@table @file
8686@item overlays.c
8687The main program file.
8688@item ovlymgr.c
8689A simple overlay manager, used by @file{overlays.c}.
8690@item foo.c
8691@itemx bar.c
8692@itemx baz.c
8693@itemx grbx.c
8694Overlay modules, loaded and used by @file{overlays.c}.
8695@item d10v.ld
8696@itemx m32r.ld
8697Linker scripts for linking the test program on the @code{d10v-elf}
8698and @code{m32r-elf} targets.
8699@end table
8700
8701You can build the test program using the @code{d10v-elf} GCC
8702cross-compiler like this:
8703
474c8240 8704@smallexample
df0cd8c5
JB
8705$ d10v-elf-gcc -g -c overlays.c
8706$ d10v-elf-gcc -g -c ovlymgr.c
8707$ d10v-elf-gcc -g -c foo.c
8708$ d10v-elf-gcc -g -c bar.c
8709$ d10v-elf-gcc -g -c baz.c
8710$ d10v-elf-gcc -g -c grbx.c
8711$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8712 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8713@end smallexample
df0cd8c5
JB
8714
8715The build process is identical for any other architecture, except that
8716you must substitute the appropriate compiler and linker script for the
8717target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8718
8719
6d2ebf8b 8720@node Languages
c906108c
SS
8721@chapter Using @value{GDBN} with Different Languages
8722@cindex languages
8723
c906108c
SS
8724Although programming languages generally have common aspects, they are
8725rarely expressed in the same manner. For instance, in ANSI C,
8726dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8727Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8728represented (and displayed) differently. Hex numbers in C appear as
c906108c 8729@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8730
8731@cindex working language
8732Language-specific information is built into @value{GDBN} for some languages,
8733allowing you to express operations like the above in your program's
8734native language, and allowing @value{GDBN} to output values in a manner
8735consistent with the syntax of your program's native language. The
8736language you use to build expressions is called the @dfn{working
8737language}.
8738
8739@menu
8740* Setting:: Switching between source languages
8741* Show:: Displaying the language
c906108c 8742* Checks:: Type and range checks
79a6e687
BW
8743* Supported Languages:: Supported languages
8744* Unsupported Languages:: Unsupported languages
c906108c
SS
8745@end menu
8746
6d2ebf8b 8747@node Setting
79a6e687 8748@section Switching Between Source Languages
c906108c
SS
8749
8750There are two ways to control the working language---either have @value{GDBN}
8751set it automatically, or select it manually yourself. You can use the
8752@code{set language} command for either purpose. On startup, @value{GDBN}
8753defaults to setting the language automatically. The working language is
8754used to determine how expressions you type are interpreted, how values
8755are printed, etc.
8756
8757In addition to the working language, every source file that
8758@value{GDBN} knows about has its own working language. For some object
8759file formats, the compiler might indicate which language a particular
8760source file is in. However, most of the time @value{GDBN} infers the
8761language from the name of the file. The language of a source file
b37052ae 8762controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8763show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8764set the language of a source file from within @value{GDBN}, but you can
8765set the language associated with a filename extension. @xref{Show, ,
79a6e687 8766Displaying the Language}.
c906108c
SS
8767
8768This is most commonly a problem when you use a program, such
5d161b24 8769as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8770another language. In that case, make the
8771program use @code{#line} directives in its C output; that way
8772@value{GDBN} will know the correct language of the source code of the original
8773program, and will display that source code, not the generated C code.
8774
8775@menu
8776* Filenames:: Filename extensions and languages.
8777* Manually:: Setting the working language manually
8778* Automatically:: Having @value{GDBN} infer the source language
8779@end menu
8780
6d2ebf8b 8781@node Filenames
79a6e687 8782@subsection List of Filename Extensions and Languages
c906108c
SS
8783
8784If a source file name ends in one of the following extensions, then
8785@value{GDBN} infers that its language is the one indicated.
8786
8787@table @file
e07c999f
PH
8788@item .ada
8789@itemx .ads
8790@itemx .adb
8791@itemx .a
8792Ada source file.
c906108c
SS
8793
8794@item .c
8795C source file
8796
8797@item .C
8798@itemx .cc
8799@itemx .cp
8800@itemx .cpp
8801@itemx .cxx
8802@itemx .c++
b37052ae 8803C@t{++} source file
c906108c 8804
b37303ee
AF
8805@item .m
8806Objective-C source file
8807
c906108c
SS
8808@item .f
8809@itemx .F
8810Fortran source file
8811
c906108c
SS
8812@item .mod
8813Modula-2 source file
c906108c
SS
8814
8815@item .s
8816@itemx .S
8817Assembler source file. This actually behaves almost like C, but
8818@value{GDBN} does not skip over function prologues when stepping.
8819@end table
8820
8821In addition, you may set the language associated with a filename
79a6e687 8822extension. @xref{Show, , Displaying the Language}.
c906108c 8823
6d2ebf8b 8824@node Manually
79a6e687 8825@subsection Setting the Working Language
c906108c
SS
8826
8827If you allow @value{GDBN} to set the language automatically,
8828expressions are interpreted the same way in your debugging session and
8829your program.
8830
8831@kindex set language
8832If you wish, you may set the language manually. To do this, issue the
8833command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8834a language, such as
c906108c 8835@code{c} or @code{modula-2}.
c906108c
SS
8836For a list of the supported languages, type @samp{set language}.
8837
c906108c
SS
8838Setting the language manually prevents @value{GDBN} from updating the working
8839language automatically. This can lead to confusion if you try
8840to debug a program when the working language is not the same as the
8841source language, when an expression is acceptable to both
8842languages---but means different things. For instance, if the current
8843source file were written in C, and @value{GDBN} was parsing Modula-2, a
8844command such as:
8845
474c8240 8846@smallexample
c906108c 8847print a = b + c
474c8240 8848@end smallexample
c906108c
SS
8849
8850@noindent
8851might not have the effect you intended. In C, this means to add
8852@code{b} and @code{c} and place the result in @code{a}. The result
8853printed would be the value of @code{a}. In Modula-2, this means to compare
8854@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8855
6d2ebf8b 8856@node Automatically
79a6e687 8857@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
8858
8859To have @value{GDBN} set the working language automatically, use
8860@samp{set language local} or @samp{set language auto}. @value{GDBN}
8861then infers the working language. That is, when your program stops in a
8862frame (usually by encountering a breakpoint), @value{GDBN} sets the
8863working language to the language recorded for the function in that
8864frame. If the language for a frame is unknown (that is, if the function
8865or block corresponding to the frame was defined in a source file that
8866does not have a recognized extension), the current working language is
8867not changed, and @value{GDBN} issues a warning.
8868
8869This may not seem necessary for most programs, which are written
8870entirely in one source language. However, program modules and libraries
8871written in one source language can be used by a main program written in
8872a different source language. Using @samp{set language auto} in this
8873case frees you from having to set the working language manually.
8874
6d2ebf8b 8875@node Show
79a6e687 8876@section Displaying the Language
c906108c
SS
8877
8878The following commands help you find out which language is the
8879working language, and also what language source files were written in.
8880
c906108c
SS
8881@table @code
8882@item show language
9c16f35a 8883@kindex show language
c906108c
SS
8884Display the current working language. This is the
8885language you can use with commands such as @code{print} to
8886build and compute expressions that may involve variables in your program.
8887
8888@item info frame
4644b6e3 8889@kindex info frame@r{, show the source language}
5d161b24 8890Display the source language for this frame. This language becomes the
c906108c 8891working language if you use an identifier from this frame.
79a6e687 8892@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
8893information listed here.
8894
8895@item info source
4644b6e3 8896@kindex info source@r{, show the source language}
c906108c 8897Display the source language of this source file.
5d161b24 8898@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8899information listed here.
8900@end table
8901
8902In unusual circumstances, you may have source files with extensions
8903not in the standard list. You can then set the extension associated
8904with a language explicitly:
8905
c906108c 8906@table @code
09d4efe1 8907@item set extension-language @var{ext} @var{language}
9c16f35a 8908@kindex set extension-language
09d4efe1
EZ
8909Tell @value{GDBN} that source files with extension @var{ext} are to be
8910assumed as written in the source language @var{language}.
c906108c
SS
8911
8912@item info extensions
9c16f35a 8913@kindex info extensions
c906108c
SS
8914List all the filename extensions and the associated languages.
8915@end table
8916
6d2ebf8b 8917@node Checks
79a6e687 8918@section Type and Range Checking
c906108c
SS
8919
8920@quotation
8921@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8922checking are included, but they do not yet have any effect. This
8923section documents the intended facilities.
8924@end quotation
8925@c FIXME remove warning when type/range code added
8926
8927Some languages are designed to guard you against making seemingly common
8928errors through a series of compile- and run-time checks. These include
8929checking the type of arguments to functions and operators, and making
8930sure mathematical overflows are caught at run time. Checks such as
8931these help to ensure a program's correctness once it has been compiled
8932by eliminating type mismatches, and providing active checks for range
8933errors when your program is running.
8934
8935@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8936Although @value{GDBN} does not check the statements in your program,
8937it can check expressions entered directly into @value{GDBN} for
8938evaluation via the @code{print} command, for example. As with the
8939working language, @value{GDBN} can also decide whether or not to check
8940automatically based on your program's source language.
79a6e687 8941@xref{Supported Languages, ,Supported Languages}, for the default
9c16f35a 8942settings of supported languages.
c906108c
SS
8943
8944@menu
8945* Type Checking:: An overview of type checking
8946* Range Checking:: An overview of range checking
8947@end menu
8948
8949@cindex type checking
8950@cindex checks, type
6d2ebf8b 8951@node Type Checking
79a6e687 8952@subsection An Overview of Type Checking
c906108c
SS
8953
8954Some languages, such as Modula-2, are strongly typed, meaning that the
8955arguments to operators and functions have to be of the correct type,
8956otherwise an error occurs. These checks prevent type mismatch
8957errors from ever causing any run-time problems. For example,
8958
8959@smallexample
89601 + 2 @result{} 3
8961@exdent but
8962@error{} 1 + 2.3
8963@end smallexample
8964
8965The second example fails because the @code{CARDINAL} 1 is not
8966type-compatible with the @code{REAL} 2.3.
8967
5d161b24
DB
8968For the expressions you use in @value{GDBN} commands, you can tell the
8969@value{GDBN} type checker to skip checking;
8970to treat any mismatches as errors and abandon the expression;
8971or to only issue warnings when type mismatches occur,
c906108c
SS
8972but evaluate the expression anyway. When you choose the last of
8973these, @value{GDBN} evaluates expressions like the second example above, but
8974also issues a warning.
8975
5d161b24
DB
8976Even if you turn type checking off, there may be other reasons
8977related to type that prevent @value{GDBN} from evaluating an expression.
8978For instance, @value{GDBN} does not know how to add an @code{int} and
8979a @code{struct foo}. These particular type errors have nothing to do
8980with the language in use, and usually arise from expressions, such as
c906108c
SS
8981the one described above, which make little sense to evaluate anyway.
8982
8983Each language defines to what degree it is strict about type. For
8984instance, both Modula-2 and C require the arguments to arithmetical
8985operators to be numbers. In C, enumerated types and pointers can be
8986represented as numbers, so that they are valid arguments to mathematical
79a6e687 8987operators. @xref{Supported Languages, ,Supported Languages}, for further
c906108c
SS
8988details on specific languages.
8989
8990@value{GDBN} provides some additional commands for controlling the type checker:
8991
c906108c
SS
8992@kindex set check type
8993@kindex show check type
8994@table @code
8995@item set check type auto
8996Set type checking on or off based on the current working language.
79a6e687 8997@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
8998each language.
8999
9000@item set check type on
9001@itemx set check type off
9002Set type checking on or off, overriding the default setting for the
9003current working language. Issue a warning if the setting does not
9004match the language default. If any type mismatches occur in
d4f3574e 9005evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
9006message and aborts evaluation of the expression.
9007
9008@item set check type warn
9009Cause the type checker to issue warnings, but to always attempt to
9010evaluate the expression. Evaluating the expression may still
9011be impossible for other reasons. For example, @value{GDBN} cannot add
9012numbers and structures.
9013
9014@item show type
5d161b24 9015Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
9016is setting it automatically.
9017@end table
9018
9019@cindex range checking
9020@cindex checks, range
6d2ebf8b 9021@node Range Checking
79a6e687 9022@subsection An Overview of Range Checking
c906108c
SS
9023
9024In some languages (such as Modula-2), it is an error to exceed the
9025bounds of a type; this is enforced with run-time checks. Such range
9026checking is meant to ensure program correctness by making sure
9027computations do not overflow, or indices on an array element access do
9028not exceed the bounds of the array.
9029
9030For expressions you use in @value{GDBN} commands, you can tell
9031@value{GDBN} to treat range errors in one of three ways: ignore them,
9032always treat them as errors and abandon the expression, or issue
9033warnings but evaluate the expression anyway.
9034
9035A range error can result from numerical overflow, from exceeding an
9036array index bound, or when you type a constant that is not a member
9037of any type. Some languages, however, do not treat overflows as an
9038error. In many implementations of C, mathematical overflow causes the
9039result to ``wrap around'' to lower values---for example, if @var{m} is
9040the largest integer value, and @var{s} is the smallest, then
9041
474c8240 9042@smallexample
c906108c 9043@var{m} + 1 @result{} @var{s}
474c8240 9044@end smallexample
c906108c
SS
9045
9046This, too, is specific to individual languages, and in some cases
79a6e687
BW
9047specific to individual compilers or machines. @xref{Supported Languages, ,
9048Supported Languages}, for further details on specific languages.
c906108c
SS
9049
9050@value{GDBN} provides some additional commands for controlling the range checker:
9051
c906108c
SS
9052@kindex set check range
9053@kindex show check range
9054@table @code
9055@item set check range auto
9056Set range checking on or off based on the current working language.
79a6e687 9057@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
9058each language.
9059
9060@item set check range on
9061@itemx set check range off
9062Set range checking on or off, overriding the default setting for the
9063current working language. A warning is issued if the setting does not
c3f6f71d
JM
9064match the language default. If a range error occurs and range checking is on,
9065then a message is printed and evaluation of the expression is aborted.
c906108c
SS
9066
9067@item set check range warn
9068Output messages when the @value{GDBN} range checker detects a range error,
9069but attempt to evaluate the expression anyway. Evaluating the
9070expression may still be impossible for other reasons, such as accessing
9071memory that the process does not own (a typical example from many Unix
9072systems).
9073
9074@item show range
9075Show the current setting of the range checker, and whether or not it is
9076being set automatically by @value{GDBN}.
9077@end table
c906108c 9078
79a6e687
BW
9079@node Supported Languages
9080@section Supported Languages
c906108c 9081
9c16f35a
EZ
9082@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
9083assembly, Modula-2, and Ada.
cce74817 9084@c This is false ...
c906108c
SS
9085Some @value{GDBN} features may be used in expressions regardless of the
9086language you use: the @value{GDBN} @code{@@} and @code{::} operators,
9087and the @samp{@{type@}addr} construct (@pxref{Expressions,
9088,Expressions}) can be used with the constructs of any supported
9089language.
9090
9091The following sections detail to what degree each source language is
9092supported by @value{GDBN}. These sections are not meant to be language
9093tutorials or references, but serve only as a reference guide to what the
9094@value{GDBN} expression parser accepts, and what input and output
9095formats should look like for different languages. There are many good
9096books written on each of these languages; please look to these for a
9097language reference or tutorial.
9098
c906108c 9099@menu
b37303ee 9100* C:: C and C@t{++}
b383017d 9101* Objective-C:: Objective-C
09d4efe1 9102* Fortran:: Fortran
9c16f35a 9103* Pascal:: Pascal
b37303ee 9104* Modula-2:: Modula-2
e07c999f 9105* Ada:: Ada
c906108c
SS
9106@end menu
9107
6d2ebf8b 9108@node C
b37052ae 9109@subsection C and C@t{++}
7a292a7a 9110
b37052ae
EZ
9111@cindex C and C@t{++}
9112@cindex expressions in C or C@t{++}
c906108c 9113
b37052ae 9114Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
9115to both languages. Whenever this is the case, we discuss those languages
9116together.
9117
41afff9a
EZ
9118@cindex C@t{++}
9119@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
9120@cindex @sc{gnu} C@t{++}
9121The C@t{++} debugging facilities are jointly implemented by the C@t{++}
9122compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
9123effectively, you must compile your C@t{++} programs with a supported
9124C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
9125compiler (@code{aCC}).
9126
0179ffac
DC
9127For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
9128format; if it doesn't work on your system, try the stabs+ debugging
9129format. You can select those formats explicitly with the @code{g++}
9130command-line options @option{-gdwarf-2} and @option{-gstabs+}.
ce9341a1
BW
9131@xref{Debugging Options,,Options for Debugging Your Program or GCC,
9132gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}.
c906108c 9133
c906108c 9134@menu
b37052ae
EZ
9135* C Operators:: C and C@t{++} operators
9136* C Constants:: C and C@t{++} constants
79a6e687 9137* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
9138* C Defaults:: Default settings for C and C@t{++}
9139* C Checks:: C and C@t{++} type and range checks
c906108c 9140* Debugging C:: @value{GDBN} and C
79a6e687 9141* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
c906108c 9142@end menu
c906108c 9143
6d2ebf8b 9144@node C Operators
79a6e687 9145@subsubsection C and C@t{++} Operators
7a292a7a 9146
b37052ae 9147@cindex C and C@t{++} operators
c906108c
SS
9148
9149Operators must be defined on values of specific types. For instance,
9150@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 9151often defined on groups of types.
c906108c 9152
b37052ae 9153For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
9154
9155@itemize @bullet
53a5351d 9156
c906108c 9157@item
c906108c 9158@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 9159specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
9160
9161@item
d4f3574e
SS
9162@emph{Floating-point types} include @code{float}, @code{double}, and
9163@code{long double} (if supported by the target platform).
c906108c
SS
9164
9165@item
53a5351d 9166@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
9167
9168@item
9169@emph{Scalar types} include all of the above.
53a5351d 9170
c906108c
SS
9171@end itemize
9172
9173@noindent
9174The following operators are supported. They are listed here
9175in order of increasing precedence:
9176
9177@table @code
9178@item ,
9179The comma or sequencing operator. Expressions in a comma-separated list
9180are evaluated from left to right, with the result of the entire
9181expression being the last expression evaluated.
9182
9183@item =
9184Assignment. The value of an assignment expression is the value
9185assigned. Defined on scalar types.
9186
9187@item @var{op}=
9188Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
9189and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 9190@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
9191@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
9192@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
9193
9194@item ?:
9195The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
9196of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
9197integral type.
9198
9199@item ||
9200Logical @sc{or}. Defined on integral types.
9201
9202@item &&
9203Logical @sc{and}. Defined on integral types.
9204
9205@item |
9206Bitwise @sc{or}. Defined on integral types.
9207
9208@item ^
9209Bitwise exclusive-@sc{or}. Defined on integral types.
9210
9211@item &
9212Bitwise @sc{and}. Defined on integral types.
9213
9214@item ==@r{, }!=
9215Equality and inequality. Defined on scalar types. The value of these
9216expressions is 0 for false and non-zero for true.
9217
9218@item <@r{, }>@r{, }<=@r{, }>=
9219Less than, greater than, less than or equal, greater than or equal.
9220Defined on scalar types. The value of these expressions is 0 for false
9221and non-zero for true.
9222
9223@item <<@r{, }>>
9224left shift, and right shift. Defined on integral types.
9225
9226@item @@
9227The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9228
9229@item +@r{, }-
9230Addition and subtraction. Defined on integral types, floating-point types and
9231pointer types.
9232
9233@item *@r{, }/@r{, }%
9234Multiplication, division, and modulus. Multiplication and division are
9235defined on integral and floating-point types. Modulus is defined on
9236integral types.
9237
9238@item ++@r{, }--
9239Increment and decrement. When appearing before a variable, the
9240operation is performed before the variable is used in an expression;
9241when appearing after it, the variable's value is used before the
9242operation takes place.
9243
9244@item *
9245Pointer dereferencing. Defined on pointer types. Same precedence as
9246@code{++}.
9247
9248@item &
9249Address operator. Defined on variables. Same precedence as @code{++}.
9250
b37052ae
EZ
9251For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
9252allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 9253(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 9254where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 9255stored.
c906108c
SS
9256
9257@item -
9258Negative. Defined on integral and floating-point types. Same
9259precedence as @code{++}.
9260
9261@item !
9262Logical negation. Defined on integral types. Same precedence as
9263@code{++}.
9264
9265@item ~
9266Bitwise complement operator. Defined on integral types. Same precedence as
9267@code{++}.
9268
9269
9270@item .@r{, }->
9271Structure member, and pointer-to-structure member. For convenience,
9272@value{GDBN} regards the two as equivalent, choosing whether to dereference a
9273pointer based on the stored type information.
9274Defined on @code{struct} and @code{union} data.
9275
c906108c
SS
9276@item .*@r{, }->*
9277Dereferences of pointers to members.
c906108c
SS
9278
9279@item []
9280Array indexing. @code{@var{a}[@var{i}]} is defined as
9281@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
9282
9283@item ()
9284Function parameter list. Same precedence as @code{->}.
9285
c906108c 9286@item ::
b37052ae 9287C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 9288and @code{class} types.
c906108c
SS
9289
9290@item ::
7a292a7a
SS
9291Doubled colons also represent the @value{GDBN} scope operator
9292(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
9293above.
c906108c
SS
9294@end table
9295
c906108c
SS
9296If an operator is redefined in the user code, @value{GDBN} usually
9297attempts to invoke the redefined version instead of using the operator's
9298predefined meaning.
c906108c 9299
6d2ebf8b 9300@node C Constants
79a6e687 9301@subsubsection C and C@t{++} Constants
c906108c 9302
b37052ae 9303@cindex C and C@t{++} constants
c906108c 9304
b37052ae 9305@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 9306following ways:
c906108c
SS
9307
9308@itemize @bullet
9309@item
9310Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
9311specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
9312by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
9313@samp{l}, specifying that the constant should be treated as a
9314@code{long} value.
9315
9316@item
9317Floating point constants are a sequence of digits, followed by a decimal
9318point, followed by a sequence of digits, and optionally followed by an
9319exponent. An exponent is of the form:
9320@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
9321sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
9322A floating-point constant may also end with a letter @samp{f} or
9323@samp{F}, specifying that the constant should be treated as being of
9324the @code{float} (as opposed to the default @code{double}) type; or with
9325a letter @samp{l} or @samp{L}, which specifies a @code{long double}
9326constant.
c906108c
SS
9327
9328@item
9329Enumerated constants consist of enumerated identifiers, or their
9330integral equivalents.
9331
9332@item
9333Character constants are a single character surrounded by single quotes
9334(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 9335(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
9336be represented by a letter or by @dfn{escape sequences}, which are of
9337the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
9338of the character's ordinal value; or of the form @samp{\@var{x}}, where
9339@samp{@var{x}} is a predefined special character---for example,
9340@samp{\n} for newline.
9341
9342@item
96a2c332
SS
9343String constants are a sequence of character constants surrounded by
9344double quotes (@code{"}). Any valid character constant (as described
9345above) may appear. Double quotes within the string must be preceded by
9346a backslash, so for instance @samp{"a\"b'c"} is a string of five
9347characters.
c906108c
SS
9348
9349@item
9350Pointer constants are an integral value. You can also write pointers
9351to constants using the C operator @samp{&}.
9352
9353@item
9354Array constants are comma-separated lists surrounded by braces @samp{@{}
9355and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
9356integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
9357and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
9358@end itemize
9359
79a6e687
BW
9360@node C Plus Plus Expressions
9361@subsubsection C@t{++} Expressions
b37052ae
EZ
9362
9363@cindex expressions in C@t{++}
9364@value{GDBN} expression handling can interpret most C@t{++} expressions.
9365
0179ffac
DC
9366@cindex debugging C@t{++} programs
9367@cindex C@t{++} compilers
9368@cindex debug formats and C@t{++}
9369@cindex @value{NGCC} and C@t{++}
c906108c 9370@quotation
b37052ae 9371@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
9372proper compiler and the proper debug format. Currently, @value{GDBN}
9373works best when debugging C@t{++} code that is compiled with
9374@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
9375@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
9376stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
9377stabs+ as their default debug format, so you usually don't need to
9378specify a debug format explicitly. Other compilers and/or debug formats
9379are likely to work badly or not at all when using @value{GDBN} to debug
9380C@t{++} code.
c906108c 9381@end quotation
c906108c
SS
9382
9383@enumerate
9384
9385@cindex member functions
9386@item
9387Member function calls are allowed; you can use expressions like
9388
474c8240 9389@smallexample
c906108c 9390count = aml->GetOriginal(x, y)
474c8240 9391@end smallexample
c906108c 9392
41afff9a 9393@vindex this@r{, inside C@t{++} member functions}
b37052ae 9394@cindex namespace in C@t{++}
c906108c
SS
9395@item
9396While a member function is active (in the selected stack frame), your
9397expressions have the same namespace available as the member function;
9398that is, @value{GDBN} allows implicit references to the class instance
b37052ae 9399pointer @code{this} following the same rules as C@t{++}.
c906108c 9400
c906108c 9401@cindex call overloaded functions
d4f3574e 9402@cindex overloaded functions, calling
b37052ae 9403@cindex type conversions in C@t{++}
c906108c
SS
9404@item
9405You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 9406call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
9407perform overload resolution involving user-defined type conversions,
9408calls to constructors, or instantiations of templates that do not exist
9409in the program. It also cannot handle ellipsis argument lists or
9410default arguments.
9411
9412It does perform integral conversions and promotions, floating-point
9413promotions, arithmetic conversions, pointer conversions, conversions of
9414class objects to base classes, and standard conversions such as those of
9415functions or arrays to pointers; it requires an exact match on the
9416number of function arguments.
9417
9418Overload resolution is always performed, unless you have specified
79a6e687
BW
9419@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
9420,@value{GDBN} Features for C@t{++}}.
c906108c 9421
d4f3574e 9422You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
9423explicit function signature to call an overloaded function, as in
9424@smallexample
9425p 'foo(char,int)'('x', 13)
9426@end smallexample
d4f3574e 9427
c906108c 9428The @value{GDBN} command-completion facility can simplify this;
79a6e687 9429see @ref{Completion, ,Command Completion}.
c906108c 9430
c906108c
SS
9431@cindex reference declarations
9432@item
b37052ae
EZ
9433@value{GDBN} understands variables declared as C@t{++} references; you can use
9434them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
9435dereferenced.
9436
9437In the parameter list shown when @value{GDBN} displays a frame, the values of
9438reference variables are not displayed (unlike other variables); this
9439avoids clutter, since references are often used for large structures.
9440The @emph{address} of a reference variable is always shown, unless
9441you have specified @samp{set print address off}.
9442
9443@item
b37052ae 9444@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
9445expressions can use it just as expressions in your program do. Since
9446one scope may be defined in another, you can use @code{::} repeatedly if
9447necessary, for example in an expression like
9448@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 9449resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 9450debugging (@pxref{Variables, ,Program Variables}).
c906108c
SS
9451@end enumerate
9452
b37052ae 9453In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
9454calling virtual functions correctly, printing out virtual bases of
9455objects, calling functions in a base subobject, casting objects, and
9456invoking user-defined operators.
c906108c 9457
6d2ebf8b 9458@node C Defaults
79a6e687 9459@subsubsection C and C@t{++} Defaults
7a292a7a 9460
b37052ae 9461@cindex C and C@t{++} defaults
c906108c 9462
c906108c
SS
9463If you allow @value{GDBN} to set type and range checking automatically, they
9464both default to @code{off} whenever the working language changes to
b37052ae 9465C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 9466selects the working language.
c906108c
SS
9467
9468If you allow @value{GDBN} to set the language automatically, it
9469recognizes source files whose names end with @file{.c}, @file{.C}, or
9470@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 9471these files, it sets the working language to C or C@t{++}.
79a6e687 9472@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
9473for further details.
9474
c906108c
SS
9475@c Type checking is (a) primarily motivated by Modula-2, and (b)
9476@c unimplemented. If (b) changes, it might make sense to let this node
9477@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 9478
6d2ebf8b 9479@node C Checks
79a6e687 9480@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 9481
b37052ae 9482@cindex C and C@t{++} checks
c906108c 9483
b37052ae 9484By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
9485is not used. However, if you turn type checking on, @value{GDBN}
9486considers two variables type equivalent if:
9487
9488@itemize @bullet
9489@item
9490The two variables are structured and have the same structure, union, or
9491enumerated tag.
9492
9493@item
9494The two variables have the same type name, or types that have been
9495declared equivalent through @code{typedef}.
9496
9497@ignore
9498@c leaving this out because neither J Gilmore nor R Pesch understand it.
9499@c FIXME--beers?
9500@item
9501The two @code{struct}, @code{union}, or @code{enum} variables are
9502declared in the same declaration. (Note: this may not be true for all C
9503compilers.)
9504@end ignore
9505@end itemize
9506
9507Range checking, if turned on, is done on mathematical operations. Array
9508indices are not checked, since they are often used to index a pointer
9509that is not itself an array.
c906108c 9510
6d2ebf8b 9511@node Debugging C
c906108c 9512@subsubsection @value{GDBN} and C
c906108c
SS
9513
9514The @code{set print union} and @code{show print union} commands apply to
9515the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
9516inside a @code{struct} or @code{class} is also printed. Otherwise, it
9517appears as @samp{@{...@}}.
c906108c
SS
9518
9519The @code{@@} operator aids in the debugging of dynamic arrays, formed
9520with pointers and a memory allocation function. @xref{Expressions,
9521,Expressions}.
9522
79a6e687
BW
9523@node Debugging C Plus Plus
9524@subsubsection @value{GDBN} Features for C@t{++}
c906108c 9525
b37052ae 9526@cindex commands for C@t{++}
7a292a7a 9527
b37052ae
EZ
9528Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
9529designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
9530
9531@table @code
9532@cindex break in overloaded functions
9533@item @r{breakpoint menus}
9534When you want a breakpoint in a function whose name is overloaded,
9535@value{GDBN} breakpoint menus help you specify which function definition
79a6e687 9536you want. @xref{Breakpoint Menus,,Breakpoint Menus}.
c906108c 9537
b37052ae 9538@cindex overloading in C@t{++}
c906108c
SS
9539@item rbreak @var{regex}
9540Setting breakpoints using regular expressions is helpful for setting
9541breakpoints on overloaded functions that are not members of any special
9542classes.
79a6e687 9543@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 9544
b37052ae 9545@cindex C@t{++} exception handling
c906108c
SS
9546@item catch throw
9547@itemx catch catch
b37052ae 9548Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 9549Catchpoints, , Setting Catchpoints}.
c906108c
SS
9550
9551@cindex inheritance
9552@item ptype @var{typename}
9553Print inheritance relationships as well as other information for type
9554@var{typename}.
9555@xref{Symbols, ,Examining the Symbol Table}.
9556
b37052ae 9557@cindex C@t{++} symbol display
c906108c
SS
9558@item set print demangle
9559@itemx show print demangle
9560@itemx set print asm-demangle
9561@itemx show print asm-demangle
b37052ae
EZ
9562Control whether C@t{++} symbols display in their source form, both when
9563displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 9564@xref{Print Settings, ,Print Settings}.
c906108c
SS
9565
9566@item set print object
9567@itemx show print object
9568Choose whether to print derived (actual) or declared types of objects.
79a6e687 9569@xref{Print Settings, ,Print Settings}.
c906108c
SS
9570
9571@item set print vtbl
9572@itemx show print vtbl
9573Control the format for printing virtual function tables.
79a6e687 9574@xref{Print Settings, ,Print Settings}.
c906108c 9575(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 9576ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
9577
9578@kindex set overload-resolution
d4f3574e 9579@cindex overloaded functions, overload resolution
c906108c 9580@item set overload-resolution on
b37052ae 9581Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
9582is on. For overloaded functions, @value{GDBN} evaluates the arguments
9583and searches for a function whose signature matches the argument types,
79a6e687
BW
9584using the standard C@t{++} conversion rules (see @ref{C Plus Plus
9585Expressions, ,C@t{++} Expressions}, for details).
9586If it cannot find a match, it emits a message.
c906108c
SS
9587
9588@item set overload-resolution off
b37052ae 9589Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
9590overloaded functions that are not class member functions, @value{GDBN}
9591chooses the first function of the specified name that it finds in the
9592symbol table, whether or not its arguments are of the correct type. For
9593overloaded functions that are class member functions, @value{GDBN}
9594searches for a function whose signature @emph{exactly} matches the
9595argument types.
c906108c 9596
9c16f35a
EZ
9597@kindex show overload-resolution
9598@item show overload-resolution
9599Show the current setting of overload resolution.
9600
c906108c
SS
9601@item @r{Overloaded symbol names}
9602You can specify a particular definition of an overloaded symbol, using
b37052ae 9603the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
9604@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
9605also use the @value{GDBN} command-line word completion facilities to list the
9606available choices, or to finish the type list for you.
79a6e687 9607@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 9608@end table
c906108c 9609
b37303ee
AF
9610@node Objective-C
9611@subsection Objective-C
9612
9613@cindex Objective-C
9614This section provides information about some commands and command
721c2651
EZ
9615options that are useful for debugging Objective-C code. See also
9616@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9617few more commands specific to Objective-C support.
b37303ee
AF
9618
9619@menu
b383017d
RM
9620* Method Names in Commands::
9621* The Print Command with Objective-C::
b37303ee
AF
9622@end menu
9623
c8f4133a 9624@node Method Names in Commands
b37303ee
AF
9625@subsubsection Method Names in Commands
9626
9627The following commands have been extended to accept Objective-C method
9628names as line specifications:
9629
9630@kindex clear@r{, and Objective-C}
9631@kindex break@r{, and Objective-C}
9632@kindex info line@r{, and Objective-C}
9633@kindex jump@r{, and Objective-C}
9634@kindex list@r{, and Objective-C}
9635@itemize
9636@item @code{clear}
9637@item @code{break}
9638@item @code{info line}
9639@item @code{jump}
9640@item @code{list}
9641@end itemize
9642
9643A fully qualified Objective-C method name is specified as
9644
9645@smallexample
9646-[@var{Class} @var{methodName}]
9647@end smallexample
9648
c552b3bb
JM
9649where the minus sign is used to indicate an instance method and a
9650plus sign (not shown) is used to indicate a class method. The class
9651name @var{Class} and method name @var{methodName} are enclosed in
9652brackets, similar to the way messages are specified in Objective-C
9653source code. For example, to set a breakpoint at the @code{create}
9654instance method of class @code{Fruit} in the program currently being
9655debugged, enter:
b37303ee
AF
9656
9657@smallexample
9658break -[Fruit create]
9659@end smallexample
9660
9661To list ten program lines around the @code{initialize} class method,
9662enter:
9663
9664@smallexample
9665list +[NSText initialize]
9666@end smallexample
9667
c552b3bb
JM
9668In the current version of @value{GDBN}, the plus or minus sign is
9669required. In future versions of @value{GDBN}, the plus or minus
9670sign will be optional, but you can use it to narrow the search. It
9671is also possible to specify just a method name:
b37303ee
AF
9672
9673@smallexample
9674break create
9675@end smallexample
9676
9677You must specify the complete method name, including any colons. If
9678your program's source files contain more than one @code{create} method,
9679you'll be presented with a numbered list of classes that implement that
9680method. Indicate your choice by number, or type @samp{0} to exit if
9681none apply.
9682
9683As another example, to clear a breakpoint established at the
9684@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9685
9686@smallexample
9687clear -[NSWindow makeKeyAndOrderFront:]
9688@end smallexample
9689
9690@node The Print Command with Objective-C
9691@subsubsection The Print Command With Objective-C
721c2651 9692@cindex Objective-C, print objects
c552b3bb
JM
9693@kindex print-object
9694@kindex po @r{(@code{print-object})}
b37303ee 9695
c552b3bb 9696The print command has also been extended to accept methods. For example:
b37303ee
AF
9697
9698@smallexample
c552b3bb 9699print -[@var{object} hash]
b37303ee
AF
9700@end smallexample
9701
9702@cindex print an Objective-C object description
c552b3bb
JM
9703@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9704@noindent
9705will tell @value{GDBN} to send the @code{hash} message to @var{object}
9706and print the result. Also, an additional command has been added,
9707@code{print-object} or @code{po} for short, which is meant to print
9708the description of an object. However, this command may only work
9709with certain Objective-C libraries that have a particular hook
9710function, @code{_NSPrintForDebugger}, defined.
b37303ee 9711
09d4efe1
EZ
9712@node Fortran
9713@subsection Fortran
9714@cindex Fortran-specific support in @value{GDBN}
9715
814e32d7
WZ
9716@value{GDBN} can be used to debug programs written in Fortran, but it
9717currently supports only the features of Fortran 77 language.
9718
9719@cindex trailing underscore, in Fortran symbols
9720Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
9721among them) append an underscore to the names of variables and
9722functions. When you debug programs compiled by those compilers, you
9723will need to refer to variables and functions with a trailing
9724underscore.
9725
9726@menu
9727* Fortran Operators:: Fortran operators and expressions
9728* Fortran Defaults:: Default settings for Fortran
79a6e687 9729* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
9730@end menu
9731
9732@node Fortran Operators
79a6e687 9733@subsubsection Fortran Operators and Expressions
814e32d7
WZ
9734
9735@cindex Fortran operators and expressions
9736
9737Operators must be defined on values of specific types. For instance,
9738@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 9739arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
9740
9741@table @code
9742@item **
9743The exponentiation operator. It raises the first operand to the power
9744of the second one.
9745
9746@item :
9747The range operator. Normally used in the form of array(low:high) to
9748represent a section of array.
9749@end table
9750
9751@node Fortran Defaults
9752@subsubsection Fortran Defaults
9753
9754@cindex Fortran Defaults
9755
9756Fortran symbols are usually case-insensitive, so @value{GDBN} by
9757default uses case-insensitive matches for Fortran symbols. You can
9758change that with the @samp{set case-insensitive} command, see
9759@ref{Symbols}, for the details.
9760
79a6e687
BW
9761@node Special Fortran Commands
9762@subsubsection Special Fortran Commands
814e32d7
WZ
9763
9764@cindex Special Fortran commands
9765
db2e3e2e
BW
9766@value{GDBN} has some commands to support Fortran-specific features,
9767such as displaying common blocks.
814e32d7 9768
09d4efe1
EZ
9769@table @code
9770@cindex @code{COMMON} blocks, Fortran
9771@kindex info common
9772@item info common @r{[}@var{common-name}@r{]}
9773This command prints the values contained in the Fortran @code{COMMON}
9774block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 9775all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
9776printed.
9777@end table
9778
9c16f35a
EZ
9779@node Pascal
9780@subsection Pascal
9781
9782@cindex Pascal support in @value{GDBN}, limitations
9783Debugging Pascal programs which use sets, subranges, file variables, or
9784nested functions does not currently work. @value{GDBN} does not support
9785entering expressions, printing values, or similar features using Pascal
9786syntax.
9787
9788The Pascal-specific command @code{set print pascal_static-members}
9789controls whether static members of Pascal objects are displayed.
9790@xref{Print Settings, pascal_static-members}.
9791
09d4efe1 9792@node Modula-2
c906108c 9793@subsection Modula-2
7a292a7a 9794
d4f3574e 9795@cindex Modula-2, @value{GDBN} support
c906108c
SS
9796
9797The extensions made to @value{GDBN} to support Modula-2 only support
9798output from the @sc{gnu} Modula-2 compiler (which is currently being
9799developed). Other Modula-2 compilers are not currently supported, and
9800attempting to debug executables produced by them is most likely
9801to give an error as @value{GDBN} reads in the executable's symbol
9802table.
9803
9804@cindex expressions in Modula-2
9805@menu
9806* M2 Operators:: Built-in operators
9807* Built-In Func/Proc:: Built-in functions and procedures
9808* M2 Constants:: Modula-2 constants
72019c9c 9809* M2 Types:: Modula-2 types
c906108c
SS
9810* M2 Defaults:: Default settings for Modula-2
9811* Deviations:: Deviations from standard Modula-2
9812* M2 Checks:: Modula-2 type and range checks
9813* M2 Scope:: The scope operators @code{::} and @code{.}
9814* GDB/M2:: @value{GDBN} and Modula-2
9815@end menu
9816
6d2ebf8b 9817@node M2 Operators
c906108c
SS
9818@subsubsection Operators
9819@cindex Modula-2 operators
9820
9821Operators must be defined on values of specific types. For instance,
9822@code{+} is defined on numbers, but not on structures. Operators are
9823often defined on groups of types. For the purposes of Modula-2, the
9824following definitions hold:
9825
9826@itemize @bullet
9827
9828@item
9829@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9830their subranges.
9831
9832@item
9833@emph{Character types} consist of @code{CHAR} and its subranges.
9834
9835@item
9836@emph{Floating-point types} consist of @code{REAL}.
9837
9838@item
9839@emph{Pointer types} consist of anything declared as @code{POINTER TO
9840@var{type}}.
9841
9842@item
9843@emph{Scalar types} consist of all of the above.
9844
9845@item
9846@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9847
9848@item
9849@emph{Boolean types} consist of @code{BOOLEAN}.
9850@end itemize
9851
9852@noindent
9853The following operators are supported, and appear in order of
9854increasing precedence:
9855
9856@table @code
9857@item ,
9858Function argument or array index separator.
9859
9860@item :=
9861Assignment. The value of @var{var} @code{:=} @var{value} is
9862@var{value}.
9863
9864@item <@r{, }>
9865Less than, greater than on integral, floating-point, or enumerated
9866types.
9867
9868@item <=@r{, }>=
96a2c332 9869Less than or equal to, greater than or equal to
c906108c
SS
9870on integral, floating-point and enumerated types, or set inclusion on
9871set types. Same precedence as @code{<}.
9872
9873@item =@r{, }<>@r{, }#
9874Equality and two ways of expressing inequality, valid on scalar types.
9875Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9876available for inequality, since @code{#} conflicts with the script
9877comment character.
9878
9879@item IN
9880Set membership. Defined on set types and the types of their members.
9881Same precedence as @code{<}.
9882
9883@item OR
9884Boolean disjunction. Defined on boolean types.
9885
9886@item AND@r{, }&
d4f3574e 9887Boolean conjunction. Defined on boolean types.
c906108c
SS
9888
9889@item @@
9890The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9891
9892@item +@r{, }-
9893Addition and subtraction on integral and floating-point types, or union
9894and difference on set types.
9895
9896@item *
9897Multiplication on integral and floating-point types, or set intersection
9898on set types.
9899
9900@item /
9901Division on floating-point types, or symmetric set difference on set
9902types. Same precedence as @code{*}.
9903
9904@item DIV@r{, }MOD
9905Integer division and remainder. Defined on integral types. Same
9906precedence as @code{*}.
9907
9908@item -
9909Negative. Defined on @code{INTEGER} and @code{REAL} data.
9910
9911@item ^
9912Pointer dereferencing. Defined on pointer types.
9913
9914@item NOT
9915Boolean negation. Defined on boolean types. Same precedence as
9916@code{^}.
9917
9918@item .
9919@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9920precedence as @code{^}.
9921
9922@item []
9923Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9924
9925@item ()
9926Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9927as @code{^}.
9928
9929@item ::@r{, }.
9930@value{GDBN} and Modula-2 scope operators.
9931@end table
9932
9933@quotation
72019c9c 9934@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
9935treats the use of the operator @code{IN}, or the use of operators
9936@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9937@code{<=}, and @code{>=} on sets as an error.
9938@end quotation
9939
cb51c4e0 9940
6d2ebf8b 9941@node Built-In Func/Proc
79a6e687 9942@subsubsection Built-in Functions and Procedures
cb51c4e0 9943@cindex Modula-2 built-ins
c906108c
SS
9944
9945Modula-2 also makes available several built-in procedures and functions.
9946In describing these, the following metavariables are used:
9947
9948@table @var
9949
9950@item a
9951represents an @code{ARRAY} variable.
9952
9953@item c
9954represents a @code{CHAR} constant or variable.
9955
9956@item i
9957represents a variable or constant of integral type.
9958
9959@item m
9960represents an identifier that belongs to a set. Generally used in the
9961same function with the metavariable @var{s}. The type of @var{s} should
9962be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9963
9964@item n
9965represents a variable or constant of integral or floating-point type.
9966
9967@item r
9968represents a variable or constant of floating-point type.
9969
9970@item t
9971represents a type.
9972
9973@item v
9974represents a variable.
9975
9976@item x
9977represents a variable or constant of one of many types. See the
9978explanation of the function for details.
9979@end table
9980
9981All Modula-2 built-in procedures also return a result, described below.
9982
9983@table @code
9984@item ABS(@var{n})
9985Returns the absolute value of @var{n}.
9986
9987@item CAP(@var{c})
9988If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9989equivalent, otherwise it returns its argument.
c906108c
SS
9990
9991@item CHR(@var{i})
9992Returns the character whose ordinal value is @var{i}.
9993
9994@item DEC(@var{v})
c3f6f71d 9995Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9996
9997@item DEC(@var{v},@var{i})
9998Decrements the value in the variable @var{v} by @var{i}. Returns the
9999new value.
10000
10001@item EXCL(@var{m},@var{s})
10002Removes the element @var{m} from the set @var{s}. Returns the new
10003set.
10004
10005@item FLOAT(@var{i})
10006Returns the floating point equivalent of the integer @var{i}.
10007
10008@item HIGH(@var{a})
10009Returns the index of the last member of @var{a}.
10010
10011@item INC(@var{v})
c3f6f71d 10012Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
10013
10014@item INC(@var{v},@var{i})
10015Increments the value in the variable @var{v} by @var{i}. Returns the
10016new value.
10017
10018@item INCL(@var{m},@var{s})
10019Adds the element @var{m} to the set @var{s} if it is not already
10020there. Returns the new set.
10021
10022@item MAX(@var{t})
10023Returns the maximum value of the type @var{t}.
10024
10025@item MIN(@var{t})
10026Returns the minimum value of the type @var{t}.
10027
10028@item ODD(@var{i})
10029Returns boolean TRUE if @var{i} is an odd number.
10030
10031@item ORD(@var{x})
10032Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
10033value of a character is its @sc{ascii} value (on machines supporting the
10034@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
10035integral, character and enumerated types.
10036
10037@item SIZE(@var{x})
10038Returns the size of its argument. @var{x} can be a variable or a type.
10039
10040@item TRUNC(@var{r})
10041Returns the integral part of @var{r}.
10042
844781a1
GM
10043@item TSIZE(@var{x})
10044Returns the size of its argument. @var{x} can be a variable or a type.
10045
c906108c
SS
10046@item VAL(@var{t},@var{i})
10047Returns the member of the type @var{t} whose ordinal value is @var{i}.
10048@end table
10049
10050@quotation
10051@emph{Warning:} Sets and their operations are not yet supported, so
10052@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
10053an error.
10054@end quotation
10055
10056@cindex Modula-2 constants
6d2ebf8b 10057@node M2 Constants
c906108c
SS
10058@subsubsection Constants
10059
10060@value{GDBN} allows you to express the constants of Modula-2 in the following
10061ways:
10062
10063@itemize @bullet
10064
10065@item
10066Integer constants are simply a sequence of digits. When used in an
10067expression, a constant is interpreted to be type-compatible with the
10068rest of the expression. Hexadecimal integers are specified by a
10069trailing @samp{H}, and octal integers by a trailing @samp{B}.
10070
10071@item
10072Floating point constants appear as a sequence of digits, followed by a
10073decimal point and another sequence of digits. An optional exponent can
10074then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
10075@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
10076digits of the floating point constant must be valid decimal (base 10)
10077digits.
10078
10079@item
10080Character constants consist of a single character enclosed by a pair of
10081like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 10082also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
10083followed by a @samp{C}.
10084
10085@item
10086String constants consist of a sequence of characters enclosed by a
10087pair of like quotes, either single (@code{'}) or double (@code{"}).
10088Escape sequences in the style of C are also allowed. @xref{C
79a6e687 10089Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
10090sequences.
10091
10092@item
10093Enumerated constants consist of an enumerated identifier.
10094
10095@item
10096Boolean constants consist of the identifiers @code{TRUE} and
10097@code{FALSE}.
10098
10099@item
10100Pointer constants consist of integral values only.
10101
10102@item
10103Set constants are not yet supported.
10104@end itemize
10105
72019c9c
GM
10106@node M2 Types
10107@subsubsection Modula-2 Types
10108@cindex Modula-2 types
10109
10110Currently @value{GDBN} can print the following data types in Modula-2
10111syntax: array types, record types, set types, pointer types, procedure
10112types, enumerated types, subrange types and base types. You can also
10113print the contents of variables declared using these type.
10114This section gives a number of simple source code examples together with
10115sample @value{GDBN} sessions.
10116
10117The first example contains the following section of code:
10118
10119@smallexample
10120VAR
10121 s: SET OF CHAR ;
10122 r: [20..40] ;
10123@end smallexample
10124
10125@noindent
10126and you can request @value{GDBN} to interrogate the type and value of
10127@code{r} and @code{s}.
10128
10129@smallexample
10130(@value{GDBP}) print s
10131@{'A'..'C', 'Z'@}
10132(@value{GDBP}) ptype s
10133SET OF CHAR
10134(@value{GDBP}) print r
1013521
10136(@value{GDBP}) ptype r
10137[20..40]
10138@end smallexample
10139
10140@noindent
10141Likewise if your source code declares @code{s} as:
10142
10143@smallexample
10144VAR
10145 s: SET ['A'..'Z'] ;
10146@end smallexample
10147
10148@noindent
10149then you may query the type of @code{s} by:
10150
10151@smallexample
10152(@value{GDBP}) ptype s
10153type = SET ['A'..'Z']
10154@end smallexample
10155
10156@noindent
10157Note that at present you cannot interactively manipulate set
10158expressions using the debugger.
10159
10160The following example shows how you might declare an array in Modula-2
10161and how you can interact with @value{GDBN} to print its type and contents:
10162
10163@smallexample
10164VAR
10165 s: ARRAY [-10..10] OF CHAR ;
10166@end smallexample
10167
10168@smallexample
10169(@value{GDBP}) ptype s
10170ARRAY [-10..10] OF CHAR
10171@end smallexample
10172
10173Note that the array handling is not yet complete and although the type
10174is printed correctly, expression handling still assumes that all
10175arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 10176above.
72019c9c
GM
10177
10178Here are some more type related Modula-2 examples:
10179
10180@smallexample
10181TYPE
10182 colour = (blue, red, yellow, green) ;
10183 t = [blue..yellow] ;
10184VAR
10185 s: t ;
10186BEGIN
10187 s := blue ;
10188@end smallexample
10189
10190@noindent
10191The @value{GDBN} interaction shows how you can query the data type
10192and value of a variable.
10193
10194@smallexample
10195(@value{GDBP}) print s
10196$1 = blue
10197(@value{GDBP}) ptype t
10198type = [blue..yellow]
10199@end smallexample
10200
10201@noindent
10202In this example a Modula-2 array is declared and its contents
10203displayed. Observe that the contents are written in the same way as
10204their @code{C} counterparts.
10205
10206@smallexample
10207VAR
10208 s: ARRAY [1..5] OF CARDINAL ;
10209BEGIN
10210 s[1] := 1 ;
10211@end smallexample
10212
10213@smallexample
10214(@value{GDBP}) print s
10215$1 = @{1, 0, 0, 0, 0@}
10216(@value{GDBP}) ptype s
10217type = ARRAY [1..5] OF CARDINAL
10218@end smallexample
10219
10220The Modula-2 language interface to @value{GDBN} also understands
10221pointer types as shown in this example:
10222
10223@smallexample
10224VAR
10225 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
10226BEGIN
10227 NEW(s) ;
10228 s^[1] := 1 ;
10229@end smallexample
10230
10231@noindent
10232and you can request that @value{GDBN} describes the type of @code{s}.
10233
10234@smallexample
10235(@value{GDBP}) ptype s
10236type = POINTER TO ARRAY [1..5] OF CARDINAL
10237@end smallexample
10238
10239@value{GDBN} handles compound types as we can see in this example.
10240Here we combine array types, record types, pointer types and subrange
10241types:
10242
10243@smallexample
10244TYPE
10245 foo = RECORD
10246 f1: CARDINAL ;
10247 f2: CHAR ;
10248 f3: myarray ;
10249 END ;
10250
10251 myarray = ARRAY myrange OF CARDINAL ;
10252 myrange = [-2..2] ;
10253VAR
10254 s: POINTER TO ARRAY myrange OF foo ;
10255@end smallexample
10256
10257@noindent
10258and you can ask @value{GDBN} to describe the type of @code{s} as shown
10259below.
10260
10261@smallexample
10262(@value{GDBP}) ptype s
10263type = POINTER TO ARRAY [-2..2] OF foo = RECORD
10264 f1 : CARDINAL;
10265 f2 : CHAR;
10266 f3 : ARRAY [-2..2] OF CARDINAL;
10267END
10268@end smallexample
10269
6d2ebf8b 10270@node M2 Defaults
79a6e687 10271@subsubsection Modula-2 Defaults
c906108c
SS
10272@cindex Modula-2 defaults
10273
10274If type and range checking are set automatically by @value{GDBN}, they
10275both default to @code{on} whenever the working language changes to
d4f3574e 10276Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
10277selected the working language.
10278
10279If you allow @value{GDBN} to set the language automatically, then entering
10280code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
10281working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
10282Infer the Source Language}, for further details.
c906108c 10283
6d2ebf8b 10284@node Deviations
79a6e687 10285@subsubsection Deviations from Standard Modula-2
c906108c
SS
10286@cindex Modula-2, deviations from
10287
10288A few changes have been made to make Modula-2 programs easier to debug.
10289This is done primarily via loosening its type strictness:
10290
10291@itemize @bullet
10292@item
10293Unlike in standard Modula-2, pointer constants can be formed by
10294integers. This allows you to modify pointer variables during
10295debugging. (In standard Modula-2, the actual address contained in a
10296pointer variable is hidden from you; it can only be modified
10297through direct assignment to another pointer variable or expression that
10298returned a pointer.)
10299
10300@item
10301C escape sequences can be used in strings and characters to represent
10302non-printable characters. @value{GDBN} prints out strings with these
10303escape sequences embedded. Single non-printable characters are
10304printed using the @samp{CHR(@var{nnn})} format.
10305
10306@item
10307The assignment operator (@code{:=}) returns the value of its right-hand
10308argument.
10309
10310@item
10311All built-in procedures both modify @emph{and} return their argument.
10312@end itemize
10313
6d2ebf8b 10314@node M2 Checks
79a6e687 10315@subsubsection Modula-2 Type and Range Checks
c906108c
SS
10316@cindex Modula-2 checks
10317
10318@quotation
10319@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
10320range checking.
10321@end quotation
10322@c FIXME remove warning when type/range checks added
10323
10324@value{GDBN} considers two Modula-2 variables type equivalent if:
10325
10326@itemize @bullet
10327@item
10328They are of types that have been declared equivalent via a @code{TYPE
10329@var{t1} = @var{t2}} statement
10330
10331@item
10332They have been declared on the same line. (Note: This is true of the
10333@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
10334@end itemize
10335
10336As long as type checking is enabled, any attempt to combine variables
10337whose types are not equivalent is an error.
10338
10339Range checking is done on all mathematical operations, assignment, array
10340index bounds, and all built-in functions and procedures.
10341
6d2ebf8b 10342@node M2 Scope
79a6e687 10343@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 10344@cindex scope
41afff9a 10345@cindex @code{.}, Modula-2 scope operator
c906108c
SS
10346@cindex colon, doubled as scope operator
10347@ifinfo
41afff9a 10348@vindex colon-colon@r{, in Modula-2}
c906108c
SS
10349@c Info cannot handle :: but TeX can.
10350@end ifinfo
10351@iftex
41afff9a 10352@vindex ::@r{, in Modula-2}
c906108c
SS
10353@end iftex
10354
10355There are a few subtle differences between the Modula-2 scope operator
10356(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
10357similar syntax:
10358
474c8240 10359@smallexample
c906108c
SS
10360
10361@var{module} . @var{id}
10362@var{scope} :: @var{id}
474c8240 10363@end smallexample
c906108c
SS
10364
10365@noindent
10366where @var{scope} is the name of a module or a procedure,
10367@var{module} the name of a module, and @var{id} is any declared
10368identifier within your program, except another module.
10369
10370Using the @code{::} operator makes @value{GDBN} search the scope
10371specified by @var{scope} for the identifier @var{id}. If it is not
10372found in the specified scope, then @value{GDBN} searches all scopes
10373enclosing the one specified by @var{scope}.
10374
10375Using the @code{.} operator makes @value{GDBN} search the current scope for
10376the identifier specified by @var{id} that was imported from the
10377definition module specified by @var{module}. With this operator, it is
10378an error if the identifier @var{id} was not imported from definition
10379module @var{module}, or if @var{id} is not an identifier in
10380@var{module}.
10381
6d2ebf8b 10382@node GDB/M2
c906108c
SS
10383@subsubsection @value{GDBN} and Modula-2
10384
10385Some @value{GDBN} commands have little use when debugging Modula-2 programs.
10386Five subcommands of @code{set print} and @code{show print} apply
b37052ae 10387specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 10388@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 10389apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
10390analogue in Modula-2.
10391
10392The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 10393with any language, is not useful with Modula-2. Its
c906108c 10394intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 10395created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 10396address can be specified by an integral constant, the construct
d4f3574e 10397@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
10398
10399@cindex @code{#} in Modula-2
10400In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
10401interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 10402
e07c999f
PH
10403@node Ada
10404@subsection Ada
10405@cindex Ada
10406
10407The extensions made to @value{GDBN} for Ada only support
10408output from the @sc{gnu} Ada (GNAT) compiler.
10409Other Ada compilers are not currently supported, and
10410attempting to debug executables produced by them is most likely
10411to be difficult.
10412
10413
10414@cindex expressions in Ada
10415@menu
10416* Ada Mode Intro:: General remarks on the Ada syntax
10417 and semantics supported by Ada mode
10418 in @value{GDBN}.
10419* Omissions from Ada:: Restrictions on the Ada expression syntax.
10420* Additions to Ada:: Extensions of the Ada expression syntax.
10421* Stopping Before Main Program:: Debugging the program during elaboration.
10422* Ada Glitches:: Known peculiarities of Ada mode.
10423@end menu
10424
10425@node Ada Mode Intro
10426@subsubsection Introduction
10427@cindex Ada mode, general
10428
10429The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
10430syntax, with some extensions.
10431The philosophy behind the design of this subset is
10432
10433@itemize @bullet
10434@item
10435That @value{GDBN} should provide basic literals and access to operations for
10436arithmetic, dereferencing, field selection, indexing, and subprogram calls,
10437leaving more sophisticated computations to subprograms written into the
10438program (which therefore may be called from @value{GDBN}).
10439
10440@item
10441That type safety and strict adherence to Ada language restrictions
10442are not particularly important to the @value{GDBN} user.
10443
10444@item
10445That brevity is important to the @value{GDBN} user.
10446@end itemize
10447
10448Thus, for brevity, the debugger acts as if there were
10449implicit @code{with} and @code{use} clauses in effect for all user-written
10450packages, making it unnecessary to fully qualify most names with
10451their packages, regardless of context. Where this causes ambiguity,
10452@value{GDBN} asks the user's intent.
10453
10454The debugger will start in Ada mode if it detects an Ada main program.
10455As for other languages, it will enter Ada mode when stopped in a program that
10456was translated from an Ada source file.
10457
10458While in Ada mode, you may use `@t{--}' for comments. This is useful
10459mostly for documenting command files. The standard @value{GDBN} comment
10460(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
10461middle (to allow based literals).
10462
10463The debugger supports limited overloading. Given a subprogram call in which
10464the function symbol has multiple definitions, it will use the number of
10465actual parameters and some information about their types to attempt to narrow
10466the set of definitions. It also makes very limited use of context, preferring
10467procedures to functions in the context of the @code{call} command, and
10468functions to procedures elsewhere.
10469
10470@node Omissions from Ada
10471@subsubsection Omissions from Ada
10472@cindex Ada, omissions from
10473
10474Here are the notable omissions from the subset:
10475
10476@itemize @bullet
10477@item
10478Only a subset of the attributes are supported:
10479
10480@itemize @minus
10481@item
10482@t{'First}, @t{'Last}, and @t{'Length}
10483 on array objects (not on types and subtypes).
10484
10485@item
10486@t{'Min} and @t{'Max}.
10487
10488@item
10489@t{'Pos} and @t{'Val}.
10490
10491@item
10492@t{'Tag}.
10493
10494@item
10495@t{'Range} on array objects (not subtypes), but only as the right
10496operand of the membership (@code{in}) operator.
10497
10498@item
10499@t{'Access}, @t{'Unchecked_Access}, and
10500@t{'Unrestricted_Access} (a GNAT extension).
10501
10502@item
10503@t{'Address}.
10504@end itemize
10505
10506@item
10507The names in
10508@code{Characters.Latin_1} are not available and
10509concatenation is not implemented. Thus, escape characters in strings are
10510not currently available.
10511
10512@item
10513Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
10514equality of representations. They will generally work correctly
10515for strings and arrays whose elements have integer or enumeration types.
10516They may not work correctly for arrays whose element
10517types have user-defined equality, for arrays of real values
10518(in particular, IEEE-conformant floating point, because of negative
10519zeroes and NaNs), and for arrays whose elements contain unused bits with
10520indeterminate values.
10521
10522@item
10523The other component-by-component array operations (@code{and}, @code{or},
10524@code{xor}, @code{not}, and relational tests other than equality)
10525are not implemented.
10526
10527@item
860701dc
PH
10528@cindex array aggregates (Ada)
10529@cindex record aggregates (Ada)
10530@cindex aggregates (Ada)
10531There is limited support for array and record aggregates. They are
10532permitted only on the right sides of assignments, as in these examples:
10533
10534@smallexample
10535set An_Array := (1, 2, 3, 4, 5, 6)
10536set An_Array := (1, others => 0)
10537set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
10538set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
10539set A_Record := (1, "Peter", True);
10540set A_Record := (Name => "Peter", Id => 1, Alive => True)
10541@end smallexample
10542
10543Changing a
10544discriminant's value by assigning an aggregate has an
10545undefined effect if that discriminant is used within the record.
10546However, you can first modify discriminants by directly assigning to
10547them (which normally would not be allowed in Ada), and then performing an
10548aggregate assignment. For example, given a variable @code{A_Rec}
10549declared to have a type such as:
10550
10551@smallexample
10552type Rec (Len : Small_Integer := 0) is record
10553 Id : Integer;
10554 Vals : IntArray (1 .. Len);
10555end record;
10556@end smallexample
10557
10558you can assign a value with a different size of @code{Vals} with two
10559assignments:
10560
10561@smallexample
10562set A_Rec.Len := 4
10563set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
10564@end smallexample
10565
10566As this example also illustrates, @value{GDBN} is very loose about the usual
10567rules concerning aggregates. You may leave out some of the
10568components of an array or record aggregate (such as the @code{Len}
10569component in the assignment to @code{A_Rec} above); they will retain their
10570original values upon assignment. You may freely use dynamic values as
10571indices in component associations. You may even use overlapping or
10572redundant component associations, although which component values are
10573assigned in such cases is not defined.
e07c999f
PH
10574
10575@item
10576Calls to dispatching subprograms are not implemented.
10577
10578@item
10579The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
10580than that of real Ada. It makes only limited use of the context in
10581which a subexpression appears to resolve its meaning, and it is much
10582looser in its rules for allowing type matches. As a result, some
10583function calls will be ambiguous, and the user will be asked to choose
10584the proper resolution.
e07c999f
PH
10585
10586@item
10587The @code{new} operator is not implemented.
10588
10589@item
10590Entry calls are not implemented.
10591
10592@item
10593Aside from printing, arithmetic operations on the native VAX floating-point
10594formats are not supported.
10595
10596@item
10597It is not possible to slice a packed array.
10598@end itemize
10599
10600@node Additions to Ada
10601@subsubsection Additions to Ada
10602@cindex Ada, deviations from
10603
10604As it does for other languages, @value{GDBN} makes certain generic
10605extensions to Ada (@pxref{Expressions}):
10606
10607@itemize @bullet
10608@item
ae21e955
BW
10609If the expression @var{E} is a variable residing in memory (typically
10610a local variable or array element) and @var{N} is a positive integer,
10611then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
10612@var{N}-1 adjacent variables following it in memory as an array. In
10613Ada, this operator is generally not necessary, since its prime use is
10614in displaying parts of an array, and slicing will usually do this in
10615Ada. However, there are occasional uses when debugging programs in
10616which certain debugging information has been optimized away.
e07c999f
PH
10617
10618@item
ae21e955
BW
10619@code{@var{B}::@var{var}} means ``the variable named @var{var} that
10620appears in function or file @var{B}.'' When @var{B} is a file name,
10621you must typically surround it in single quotes.
e07c999f
PH
10622
10623@item
10624The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
10625@var{type} that appears at address @var{addr}.''
10626
10627@item
10628A name starting with @samp{$} is a convenience variable
10629(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
10630@end itemize
10631
ae21e955
BW
10632In addition, @value{GDBN} provides a few other shortcuts and outright
10633additions specific to Ada:
e07c999f
PH
10634
10635@itemize @bullet
10636@item
10637The assignment statement is allowed as an expression, returning
10638its right-hand operand as its value. Thus, you may enter
10639
10640@smallexample
10641set x := y + 3
10642print A(tmp := y + 1)
10643@end smallexample
10644
10645@item
10646The semicolon is allowed as an ``operator,'' returning as its value
10647the value of its right-hand operand.
10648This allows, for example,
10649complex conditional breaks:
10650
10651@smallexample
10652break f
10653condition 1 (report(i); k += 1; A(k) > 100)
10654@end smallexample
10655
10656@item
10657Rather than use catenation and symbolic character names to introduce special
10658characters into strings, one may instead use a special bracket notation,
10659which is also used to print strings. A sequence of characters of the form
10660@samp{["@var{XX}"]} within a string or character literal denotes the
10661(single) character whose numeric encoding is @var{XX} in hexadecimal. The
10662sequence of characters @samp{["""]} also denotes a single quotation mark
10663in strings. For example,
10664@smallexample
10665 "One line.["0a"]Next line.["0a"]"
10666@end smallexample
10667@noindent
ae21e955
BW
10668contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
10669after each period.
e07c999f
PH
10670
10671@item
10672The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
10673@t{'Max} is optional (and is ignored in any case). For example, it is valid
10674to write
10675
10676@smallexample
10677print 'max(x, y)
10678@end smallexample
10679
10680@item
10681When printing arrays, @value{GDBN} uses positional notation when the
10682array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
10683For example, a one-dimensional array of three integers with a lower bound
10684of 3 might print as
e07c999f
PH
10685
10686@smallexample
10687(3 => 10, 17, 1)
10688@end smallexample
10689
10690@noindent
10691That is, in contrast to valid Ada, only the first component has a @code{=>}
10692clause.
10693
10694@item
10695You may abbreviate attributes in expressions with any unique,
10696multi-character subsequence of
10697their names (an exact match gets preference).
10698For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
10699in place of @t{a'length}.
10700
10701@item
10702@cindex quoting Ada internal identifiers
10703Since Ada is case-insensitive, the debugger normally maps identifiers you type
10704to lower case. The GNAT compiler uses upper-case characters for
10705some of its internal identifiers, which are normally of no interest to users.
10706For the rare occasions when you actually have to look at them,
10707enclose them in angle brackets to avoid the lower-case mapping.
10708For example,
10709@smallexample
10710@value{GDBP} print <JMPBUF_SAVE>[0]
10711@end smallexample
10712
10713@item
10714Printing an object of class-wide type or dereferencing an
10715access-to-class-wide value will display all the components of the object's
10716specific type (as indicated by its run-time tag). Likewise, component
10717selection on such a value will operate on the specific type of the
10718object.
10719
10720@end itemize
10721
10722@node Stopping Before Main Program
10723@subsubsection Stopping at the Very Beginning
10724
10725@cindex breakpointing Ada elaboration code
10726It is sometimes necessary to debug the program during elaboration, and
10727before reaching the main procedure.
10728As defined in the Ada Reference
10729Manual, the elaboration code is invoked from a procedure called
10730@code{adainit}. To run your program up to the beginning of
10731elaboration, simply use the following two commands:
10732@code{tbreak adainit} and @code{run}.
10733
10734@node Ada Glitches
10735@subsubsection Known Peculiarities of Ada Mode
10736@cindex Ada, problems
10737
10738Besides the omissions listed previously (@pxref{Omissions from Ada}),
10739we know of several problems with and limitations of Ada mode in
10740@value{GDBN},
10741some of which will be fixed with planned future releases of the debugger
10742and the GNU Ada compiler.
10743
10744@itemize @bullet
10745@item
10746Currently, the debugger
10747has insufficient information to determine whether certain pointers represent
10748pointers to objects or the objects themselves.
10749Thus, the user may have to tack an extra @code{.all} after an expression
10750to get it printed properly.
10751
10752@item
10753Static constants that the compiler chooses not to materialize as objects in
10754storage are invisible to the debugger.
10755
10756@item
10757Named parameter associations in function argument lists are ignored (the
10758argument lists are treated as positional).
10759
10760@item
10761Many useful library packages are currently invisible to the debugger.
10762
10763@item
10764Fixed-point arithmetic, conversions, input, and output is carried out using
10765floating-point arithmetic, and may give results that only approximate those on
10766the host machine.
10767
10768@item
10769The type of the @t{'Address} attribute may not be @code{System.Address}.
10770
10771@item
10772The GNAT compiler never generates the prefix @code{Standard} for any of
10773the standard symbols defined by the Ada language. @value{GDBN} knows about
10774this: it will strip the prefix from names when you use it, and will never
10775look for a name you have so qualified among local symbols, nor match against
10776symbols in other packages or subprograms. If you have
10777defined entities anywhere in your program other than parameters and
10778local variables whose simple names match names in @code{Standard},
10779GNAT's lack of qualification here can cause confusion. When this happens,
10780you can usually resolve the confusion
10781by qualifying the problematic names with package
10782@code{Standard} explicitly.
10783@end itemize
10784
79a6e687
BW
10785@node Unsupported Languages
10786@section Unsupported Languages
4e562065
JB
10787
10788@cindex unsupported languages
10789@cindex minimal language
10790In addition to the other fully-supported programming languages,
10791@value{GDBN} also provides a pseudo-language, called @code{minimal}.
10792It does not represent a real programming language, but provides a set
10793of capabilities close to what the C or assembly languages provide.
10794This should allow most simple operations to be performed while debugging
10795an application that uses a language currently not supported by @value{GDBN}.
10796
10797If the language is set to @code{auto}, @value{GDBN} will automatically
10798select this language if the current frame corresponds to an unsupported
10799language.
10800
6d2ebf8b 10801@node Symbols
c906108c
SS
10802@chapter Examining the Symbol Table
10803
d4f3574e 10804The commands described in this chapter allow you to inquire about the
c906108c
SS
10805symbols (names of variables, functions and types) defined in your
10806program. This information is inherent in the text of your program and
10807does not change as your program executes. @value{GDBN} finds it in your
10808program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
10809(@pxref{File Options, ,Choosing Files}), or by one of the
10810file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
10811
10812@cindex symbol names
10813@cindex names of symbols
10814@cindex quoting names
10815Occasionally, you may need to refer to symbols that contain unusual
10816characters, which @value{GDBN} ordinarily treats as word delimiters. The
10817most frequent case is in referring to static variables in other
79a6e687 10818source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
10819are recorded in object files as debugging symbols, but @value{GDBN} would
10820ordinarily parse a typical file name, like @file{foo.c}, as the three words
10821@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
10822@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
10823
474c8240 10824@smallexample
c906108c 10825p 'foo.c'::x
474c8240 10826@end smallexample
c906108c
SS
10827
10828@noindent
10829looks up the value of @code{x} in the scope of the file @file{foo.c}.
10830
10831@table @code
a8f24a35
EZ
10832@cindex case-insensitive symbol names
10833@cindex case sensitivity in symbol names
10834@kindex set case-sensitive
10835@item set case-sensitive on
10836@itemx set case-sensitive off
10837@itemx set case-sensitive auto
10838Normally, when @value{GDBN} looks up symbols, it matches their names
10839with case sensitivity determined by the current source language.
10840Occasionally, you may wish to control that. The command @code{set
10841case-sensitive} lets you do that by specifying @code{on} for
10842case-sensitive matches or @code{off} for case-insensitive ones. If
10843you specify @code{auto}, case sensitivity is reset to the default
10844suitable for the source language. The default is case-sensitive
10845matches for all languages except for Fortran, for which the default is
10846case-insensitive matches.
10847
9c16f35a
EZ
10848@kindex show case-sensitive
10849@item show case-sensitive
a8f24a35
EZ
10850This command shows the current setting of case sensitivity for symbols
10851lookups.
10852
c906108c 10853@kindex info address
b37052ae 10854@cindex address of a symbol
c906108c
SS
10855@item info address @var{symbol}
10856Describe where the data for @var{symbol} is stored. For a register
10857variable, this says which register it is kept in. For a non-register
10858local variable, this prints the stack-frame offset at which the variable
10859is always stored.
10860
10861Note the contrast with @samp{print &@var{symbol}}, which does not work
10862at all for a register variable, and for a stack local variable prints
10863the exact address of the current instantiation of the variable.
10864
3d67e040 10865@kindex info symbol
b37052ae 10866@cindex symbol from address
9c16f35a 10867@cindex closest symbol and offset for an address
3d67e040
EZ
10868@item info symbol @var{addr}
10869Print the name of a symbol which is stored at the address @var{addr}.
10870If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10871nearest symbol and an offset from it:
10872
474c8240 10873@smallexample
3d67e040
EZ
10874(@value{GDBP}) info symbol 0x54320
10875_initialize_vx + 396 in section .text
474c8240 10876@end smallexample
3d67e040
EZ
10877
10878@noindent
10879This is the opposite of the @code{info address} command. You can use
10880it to find out the name of a variable or a function given its address.
10881
c906108c 10882@kindex whatis
62f3a2ba
FF
10883@item whatis [@var{arg}]
10884Print the data type of @var{arg}, which can be either an expression or
10885a data type. With no argument, print the data type of @code{$}, the
10886last value in the value history. If @var{arg} is an expression, it is
10887not actually evaluated, and any side-effecting operations (such as
10888assignments or function calls) inside it do not take place. If
10889@var{arg} is a type name, it may be the name of a type or typedef, or
10890for C code it may have the form @samp{class @var{class-name}},
10891@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
10892@samp{enum @var{enum-tag}}.
c906108c
SS
10893@xref{Expressions, ,Expressions}.
10894
c906108c 10895@kindex ptype
62f3a2ba
FF
10896@item ptype [@var{arg}]
10897@code{ptype} accepts the same arguments as @code{whatis}, but prints a
10898detailed description of the type, instead of just the name of the type.
10899@xref{Expressions, ,Expressions}.
c906108c
SS
10900
10901For example, for this variable declaration:
10902
474c8240 10903@smallexample
c906108c 10904struct complex @{double real; double imag;@} v;
474c8240 10905@end smallexample
c906108c
SS
10906
10907@noindent
10908the two commands give this output:
10909
474c8240 10910@smallexample
c906108c
SS
10911@group
10912(@value{GDBP}) whatis v
10913type = struct complex
10914(@value{GDBP}) ptype v
10915type = struct complex @{
10916 double real;
10917 double imag;
10918@}
10919@end group
474c8240 10920@end smallexample
c906108c
SS
10921
10922@noindent
10923As with @code{whatis}, using @code{ptype} without an argument refers to
10924the type of @code{$}, the last value in the value history.
10925
ab1adacd
EZ
10926@cindex incomplete type
10927Sometimes, programs use opaque data types or incomplete specifications
10928of complex data structure. If the debug information included in the
10929program does not allow @value{GDBN} to display a full declaration of
10930the data type, it will say @samp{<incomplete type>}. For example,
10931given these declarations:
10932
10933@smallexample
10934 struct foo;
10935 struct foo *fooptr;
10936@end smallexample
10937
10938@noindent
10939but no definition for @code{struct foo} itself, @value{GDBN} will say:
10940
10941@smallexample
ddb50cd7 10942 (@value{GDBP}) ptype foo
ab1adacd
EZ
10943 $1 = <incomplete type>
10944@end smallexample
10945
10946@noindent
10947``Incomplete type'' is C terminology for data types that are not
10948completely specified.
10949
c906108c
SS
10950@kindex info types
10951@item info types @var{regexp}
10952@itemx info types
09d4efe1
EZ
10953Print a brief description of all types whose names match the regular
10954expression @var{regexp} (or all types in your program, if you supply
10955no argument). Each complete typename is matched as though it were a
10956complete line; thus, @samp{i type value} gives information on all
10957types in your program whose names include the string @code{value}, but
10958@samp{i type ^value$} gives information only on types whose complete
10959name is @code{value}.
c906108c
SS
10960
10961This command differs from @code{ptype} in two ways: first, like
10962@code{whatis}, it does not print a detailed description; second, it
10963lists all source files where a type is defined.
10964
b37052ae
EZ
10965@kindex info scope
10966@cindex local variables
09d4efe1 10967@item info scope @var{location}
b37052ae 10968List all the variables local to a particular scope. This command
09d4efe1
EZ
10969accepts a @var{location} argument---a function name, a source line, or
10970an address preceded by a @samp{*}, and prints all the variables local
10971to the scope defined by that location. For example:
b37052ae
EZ
10972
10973@smallexample
10974(@value{GDBP}) @b{info scope command_line_handler}
10975Scope for command_line_handler:
10976Symbol rl is an argument at stack/frame offset 8, length 4.
10977Symbol linebuffer is in static storage at address 0x150a18, length 4.
10978Symbol linelength is in static storage at address 0x150a1c, length 4.
10979Symbol p is a local variable in register $esi, length 4.
10980Symbol p1 is a local variable in register $ebx, length 4.
10981Symbol nline is a local variable in register $edx, length 4.
10982Symbol repeat is a local variable at frame offset -8, length 4.
10983@end smallexample
10984
f5c37c66
EZ
10985@noindent
10986This command is especially useful for determining what data to collect
10987during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10988collect}.
10989
c906108c
SS
10990@kindex info source
10991@item info source
919d772c
JB
10992Show information about the current source file---that is, the source file for
10993the function containing the current point of execution:
10994@itemize @bullet
10995@item
10996the name of the source file, and the directory containing it,
10997@item
10998the directory it was compiled in,
10999@item
11000its length, in lines,
11001@item
11002which programming language it is written in,
11003@item
11004whether the executable includes debugging information for that file, and
11005if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
11006@item
11007whether the debugging information includes information about
11008preprocessor macros.
11009@end itemize
11010
c906108c
SS
11011
11012@kindex info sources
11013@item info sources
11014Print the names of all source files in your program for which there is
11015debugging information, organized into two lists: files whose symbols
11016have already been read, and files whose symbols will be read when needed.
11017
11018@kindex info functions
11019@item info functions
11020Print the names and data types of all defined functions.
11021
11022@item info functions @var{regexp}
11023Print the names and data types of all defined functions
11024whose names contain a match for regular expression @var{regexp}.
11025Thus, @samp{info fun step} finds all functions whose names
11026include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 11027start with @code{step}. If a function name contains characters
c1468174 11028that conflict with the regular expression language (e.g.@:
1c5dfdad 11029@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
11030
11031@kindex info variables
11032@item info variables
11033Print the names and data types of all variables that are declared
6ca652b0 11034outside of functions (i.e.@: excluding local variables).
c906108c
SS
11035
11036@item info variables @var{regexp}
11037Print the names and data types of all variables (except for local
11038variables) whose names contain a match for regular expression
11039@var{regexp}.
11040
b37303ee 11041@kindex info classes
721c2651 11042@cindex Objective-C, classes and selectors
b37303ee
AF
11043@item info classes
11044@itemx info classes @var{regexp}
11045Display all Objective-C classes in your program, or
11046(with the @var{regexp} argument) all those matching a particular regular
11047expression.
11048
11049@kindex info selectors
11050@item info selectors
11051@itemx info selectors @var{regexp}
11052Display all Objective-C selectors in your program, or
11053(with the @var{regexp} argument) all those matching a particular regular
11054expression.
11055
c906108c
SS
11056@ignore
11057This was never implemented.
11058@kindex info methods
11059@item info methods
11060@itemx info methods @var{regexp}
11061The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
11062methods within C@t{++} program, or (with the @var{regexp} argument) a
11063specific set of methods found in the various C@t{++} classes. Many
11064C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
11065from the @code{ptype} command can be overwhelming and hard to use. The
11066@code{info-methods} command filters the methods, printing only those
11067which match the regular-expression @var{regexp}.
11068@end ignore
11069
c906108c
SS
11070@cindex reloading symbols
11071Some systems allow individual object files that make up your program to
7a292a7a
SS
11072be replaced without stopping and restarting your program. For example,
11073in VxWorks you can simply recompile a defective object file and keep on
11074running. If you are running on one of these systems, you can allow
11075@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
11076
11077@table @code
11078@kindex set symbol-reloading
11079@item set symbol-reloading on
11080Replace symbol definitions for the corresponding source file when an
11081object file with a particular name is seen again.
11082
11083@item set symbol-reloading off
6d2ebf8b
SS
11084Do not replace symbol definitions when encountering object files of the
11085same name more than once. This is the default state; if you are not
11086running on a system that permits automatic relinking of modules, you
11087should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
11088may discard symbols when linking large programs, that may contain
11089several modules (from different directories or libraries) with the same
11090name.
c906108c
SS
11091
11092@kindex show symbol-reloading
11093@item show symbol-reloading
11094Show the current @code{on} or @code{off} setting.
11095@end table
c906108c 11096
9c16f35a 11097@cindex opaque data types
c906108c
SS
11098@kindex set opaque-type-resolution
11099@item set opaque-type-resolution on
11100Tell @value{GDBN} to resolve opaque types. An opaque type is a type
11101declared as a pointer to a @code{struct}, @code{class}, or
11102@code{union}---for example, @code{struct MyType *}---that is used in one
11103source file although the full declaration of @code{struct MyType} is in
11104another source file. The default is on.
11105
11106A change in the setting of this subcommand will not take effect until
11107the next time symbols for a file are loaded.
11108
11109@item set opaque-type-resolution off
11110Tell @value{GDBN} not to resolve opaque types. In this case, the type
11111is printed as follows:
11112@smallexample
11113@{<no data fields>@}
11114@end smallexample
11115
11116@kindex show opaque-type-resolution
11117@item show opaque-type-resolution
11118Show whether opaque types are resolved or not.
c906108c
SS
11119
11120@kindex maint print symbols
11121@cindex symbol dump
11122@kindex maint print psymbols
11123@cindex partial symbol dump
11124@item maint print symbols @var{filename}
11125@itemx maint print psymbols @var{filename}
11126@itemx maint print msymbols @var{filename}
11127Write a dump of debugging symbol data into the file @var{filename}.
11128These commands are used to debug the @value{GDBN} symbol-reading code. Only
11129symbols with debugging data are included. If you use @samp{maint print
11130symbols}, @value{GDBN} includes all the symbols for which it has already
11131collected full details: that is, @var{filename} reflects symbols for
11132only those files whose symbols @value{GDBN} has read. You can use the
11133command @code{info sources} to find out which files these are. If you
11134use @samp{maint print psymbols} instead, the dump shows information about
11135symbols that @value{GDBN} only knows partially---that is, symbols defined in
11136files that @value{GDBN} has skimmed, but not yet read completely. Finally,
11137@samp{maint print msymbols} dumps just the minimal symbol information
11138required for each object file from which @value{GDBN} has read some symbols.
79a6e687 11139@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 11140@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 11141
5e7b2f39
JB
11142@kindex maint info symtabs
11143@kindex maint info psymtabs
44ea7b70
JB
11144@cindex listing @value{GDBN}'s internal symbol tables
11145@cindex symbol tables, listing @value{GDBN}'s internal
11146@cindex full symbol tables, listing @value{GDBN}'s internal
11147@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
11148@item maint info symtabs @r{[} @var{regexp} @r{]}
11149@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
11150
11151List the @code{struct symtab} or @code{struct partial_symtab}
11152structures whose names match @var{regexp}. If @var{regexp} is not
11153given, list them all. The output includes expressions which you can
11154copy into a @value{GDBN} debugging this one to examine a particular
11155structure in more detail. For example:
11156
11157@smallexample
5e7b2f39 11158(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
11159@{ objfile /home/gnu/build/gdb/gdb
11160 ((struct objfile *) 0x82e69d0)
b383017d 11161 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
11162 ((struct partial_symtab *) 0x8474b10)
11163 readin no
11164 fullname (null)
11165 text addresses 0x814d3c8 -- 0x8158074
11166 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
11167 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
11168 dependencies (none)
11169 @}
11170@}
5e7b2f39 11171(@value{GDBP}) maint info symtabs
44ea7b70
JB
11172(@value{GDBP})
11173@end smallexample
11174@noindent
11175We see that there is one partial symbol table whose filename contains
11176the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
11177and we see that @value{GDBN} has not read in any symtabs yet at all.
11178If we set a breakpoint on a function, that will cause @value{GDBN} to
11179read the symtab for the compilation unit containing that function:
11180
11181@smallexample
11182(@value{GDBP}) break dwarf2_psymtab_to_symtab
11183Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
11184line 1574.
5e7b2f39 11185(@value{GDBP}) maint info symtabs
b383017d 11186@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 11187 ((struct objfile *) 0x82e69d0)
b383017d 11188 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
11189 ((struct symtab *) 0x86c1f38)
11190 dirname (null)
11191 fullname (null)
11192 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 11193 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
11194 debugformat DWARF 2
11195 @}
11196@}
b383017d 11197(@value{GDBP})
44ea7b70 11198@end smallexample
c906108c
SS
11199@end table
11200
44ea7b70 11201
6d2ebf8b 11202@node Altering
c906108c
SS
11203@chapter Altering Execution
11204
11205Once you think you have found an error in your program, you might want to
11206find out for certain whether correcting the apparent error would lead to
11207correct results in the rest of the run. You can find the answer by
11208experiment, using the @value{GDBN} features for altering execution of the
11209program.
11210
11211For example, you can store new values into variables or memory
7a292a7a
SS
11212locations, give your program a signal, restart it at a different
11213address, or even return prematurely from a function.
c906108c
SS
11214
11215@menu
11216* Assignment:: Assignment to variables
11217* Jumping:: Continuing at a different address
c906108c 11218* Signaling:: Giving your program a signal
c906108c
SS
11219* Returning:: Returning from a function
11220* Calling:: Calling your program's functions
11221* Patching:: Patching your program
11222@end menu
11223
6d2ebf8b 11224@node Assignment
79a6e687 11225@section Assignment to Variables
c906108c
SS
11226
11227@cindex assignment
11228@cindex setting variables
11229To alter the value of a variable, evaluate an assignment expression.
11230@xref{Expressions, ,Expressions}. For example,
11231
474c8240 11232@smallexample
c906108c 11233print x=4
474c8240 11234@end smallexample
c906108c
SS
11235
11236@noindent
11237stores the value 4 into the variable @code{x}, and then prints the
5d161b24 11238value of the assignment expression (which is 4).
c906108c
SS
11239@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
11240information on operators in supported languages.
c906108c
SS
11241
11242@kindex set variable
11243@cindex variables, setting
11244If you are not interested in seeing the value of the assignment, use the
11245@code{set} command instead of the @code{print} command. @code{set} is
11246really the same as @code{print} except that the expression's value is
11247not printed and is not put in the value history (@pxref{Value History,
79a6e687 11248,Value History}). The expression is evaluated only for its effects.
c906108c 11249
c906108c
SS
11250If the beginning of the argument string of the @code{set} command
11251appears identical to a @code{set} subcommand, use the @code{set
11252variable} command instead of just @code{set}. This command is identical
11253to @code{set} except for its lack of subcommands. For example, if your
11254program has a variable @code{width}, you get an error if you try to set
11255a new value with just @samp{set width=13}, because @value{GDBN} has the
11256command @code{set width}:
11257
474c8240 11258@smallexample
c906108c
SS
11259(@value{GDBP}) whatis width
11260type = double
11261(@value{GDBP}) p width
11262$4 = 13
11263(@value{GDBP}) set width=47
11264Invalid syntax in expression.
474c8240 11265@end smallexample
c906108c
SS
11266
11267@noindent
11268The invalid expression, of course, is @samp{=47}. In
11269order to actually set the program's variable @code{width}, use
11270
474c8240 11271@smallexample
c906108c 11272(@value{GDBP}) set var width=47
474c8240 11273@end smallexample
53a5351d 11274
c906108c
SS
11275Because the @code{set} command has many subcommands that can conflict
11276with the names of program variables, it is a good idea to use the
11277@code{set variable} command instead of just @code{set}. For example, if
11278your program has a variable @code{g}, you run into problems if you try
11279to set a new value with just @samp{set g=4}, because @value{GDBN} has
11280the command @code{set gnutarget}, abbreviated @code{set g}:
11281
474c8240 11282@smallexample
c906108c
SS
11283@group
11284(@value{GDBP}) whatis g
11285type = double
11286(@value{GDBP}) p g
11287$1 = 1
11288(@value{GDBP}) set g=4
2df3850c 11289(@value{GDBP}) p g
c906108c
SS
11290$2 = 1
11291(@value{GDBP}) r
11292The program being debugged has been started already.
11293Start it from the beginning? (y or n) y
11294Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
11295"/home/smith/cc_progs/a.out": can't open to read symbols:
11296 Invalid bfd target.
c906108c
SS
11297(@value{GDBP}) show g
11298The current BFD target is "=4".
11299@end group
474c8240 11300@end smallexample
c906108c
SS
11301
11302@noindent
11303The program variable @code{g} did not change, and you silently set the
11304@code{gnutarget} to an invalid value. In order to set the variable
11305@code{g}, use
11306
474c8240 11307@smallexample
c906108c 11308(@value{GDBP}) set var g=4
474c8240 11309@end smallexample
c906108c
SS
11310
11311@value{GDBN} allows more implicit conversions in assignments than C; you can
11312freely store an integer value into a pointer variable or vice versa,
11313and you can convert any structure to any other structure that is the
11314same length or shorter.
11315@comment FIXME: how do structs align/pad in these conversions?
11316@comment /doc@cygnus.com 18dec1990
11317
11318To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
11319construct to generate a value of specified type at a specified address
11320(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
11321to memory location @code{0x83040} as an integer (which implies a certain size
11322and representation in memory), and
11323
474c8240 11324@smallexample
c906108c 11325set @{int@}0x83040 = 4
474c8240 11326@end smallexample
c906108c
SS
11327
11328@noindent
11329stores the value 4 into that memory location.
11330
6d2ebf8b 11331@node Jumping
79a6e687 11332@section Continuing at a Different Address
c906108c
SS
11333
11334Ordinarily, when you continue your program, you do so at the place where
11335it stopped, with the @code{continue} command. You can instead continue at
11336an address of your own choosing, with the following commands:
11337
11338@table @code
11339@kindex jump
11340@item jump @var{linespec}
11341Resume execution at line @var{linespec}. Execution stops again
11342immediately if there is a breakpoint there. @xref{List, ,Printing
79a6e687 11343Source Lines}, for a description of the different forms of
c906108c
SS
11344@var{linespec}. It is common practice to use the @code{tbreak} command
11345in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
79a6e687 11346Breakpoints}.
c906108c
SS
11347
11348The @code{jump} command does not change the current stack frame, or
11349the stack pointer, or the contents of any memory location or any
11350register other than the program counter. If line @var{linespec} is in
11351a different function from the one currently executing, the results may
11352be bizarre if the two functions expect different patterns of arguments or
11353of local variables. For this reason, the @code{jump} command requests
11354confirmation if the specified line is not in the function currently
11355executing. However, even bizarre results are predictable if you are
11356well acquainted with the machine-language code of your program.
11357
11358@item jump *@var{address}
11359Resume execution at the instruction at address @var{address}.
11360@end table
11361
c906108c 11362@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
11363On many systems, you can get much the same effect as the @code{jump}
11364command by storing a new value into the register @code{$pc}. The
11365difference is that this does not start your program running; it only
11366changes the address of where it @emph{will} run when you continue. For
11367example,
c906108c 11368
474c8240 11369@smallexample
c906108c 11370set $pc = 0x485
474c8240 11371@end smallexample
c906108c
SS
11372
11373@noindent
11374makes the next @code{continue} command or stepping command execute at
11375address @code{0x485}, rather than at the address where your program stopped.
79a6e687 11376@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
11377
11378The most common occasion to use the @code{jump} command is to back
11379up---perhaps with more breakpoints set---over a portion of a program
11380that has already executed, in order to examine its execution in more
11381detail.
11382
c906108c 11383@c @group
6d2ebf8b 11384@node Signaling
79a6e687 11385@section Giving your Program a Signal
9c16f35a 11386@cindex deliver a signal to a program
c906108c
SS
11387
11388@table @code
11389@kindex signal
11390@item signal @var{signal}
11391Resume execution where your program stopped, but immediately give it the
11392signal @var{signal}. @var{signal} can be the name or the number of a
11393signal. For example, on many systems @code{signal 2} and @code{signal
11394SIGINT} are both ways of sending an interrupt signal.
11395
11396Alternatively, if @var{signal} is zero, continue execution without
11397giving a signal. This is useful when your program stopped on account of
11398a signal and would ordinary see the signal when resumed with the
11399@code{continue} command; @samp{signal 0} causes it to resume without a
11400signal.
11401
11402@code{signal} does not repeat when you press @key{RET} a second time
11403after executing the command.
11404@end table
11405@c @end group
11406
11407Invoking the @code{signal} command is not the same as invoking the
11408@code{kill} utility from the shell. Sending a signal with @code{kill}
11409causes @value{GDBN} to decide what to do with the signal depending on
11410the signal handling tables (@pxref{Signals}). The @code{signal} command
11411passes the signal directly to your program.
11412
c906108c 11413
6d2ebf8b 11414@node Returning
79a6e687 11415@section Returning from a Function
c906108c
SS
11416
11417@table @code
11418@cindex returning from a function
11419@kindex return
11420@item return
11421@itemx return @var{expression}
11422You can cancel execution of a function call with the @code{return}
11423command. If you give an
11424@var{expression} argument, its value is used as the function's return
11425value.
11426@end table
11427
11428When you use @code{return}, @value{GDBN} discards the selected stack frame
11429(and all frames within it). You can think of this as making the
11430discarded frame return prematurely. If you wish to specify a value to
11431be returned, give that value as the argument to @code{return}.
11432
11433This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 11434Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
11435innermost remaining frame. That frame becomes selected. The
11436specified value is stored in the registers used for returning values
11437of functions.
11438
11439The @code{return} command does not resume execution; it leaves the
11440program stopped in the state that would exist if the function had just
11441returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 11442and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
11443selected stack frame returns naturally.
11444
6d2ebf8b 11445@node Calling
79a6e687 11446@section Calling Program Functions
c906108c 11447
f8568604 11448@table @code
c906108c 11449@cindex calling functions
f8568604
EZ
11450@cindex inferior functions, calling
11451@item print @var{expr}
d3e8051b 11452Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
11453@var{expr} may include calls to functions in the program being
11454debugged.
11455
c906108c 11456@kindex call
c906108c
SS
11457@item call @var{expr}
11458Evaluate the expression @var{expr} without displaying @code{void}
11459returned values.
c906108c
SS
11460
11461You can use this variant of the @code{print} command if you want to
f8568604
EZ
11462execute a function from your program that does not return anything
11463(a.k.a.@: @dfn{a void function}), but without cluttering the output
11464with @code{void} returned values that @value{GDBN} will otherwise
11465print. If the result is not void, it is printed and saved in the
11466value history.
11467@end table
11468
9c16f35a
EZ
11469It is possible for the function you call via the @code{print} or
11470@code{call} command to generate a signal (e.g., if there's a bug in
11471the function, or if you passed it incorrect arguments). What happens
11472in that case is controlled by the @code{set unwindonsignal} command.
11473
11474@table @code
11475@item set unwindonsignal
11476@kindex set unwindonsignal
11477@cindex unwind stack in called functions
11478@cindex call dummy stack unwinding
11479Set unwinding of the stack if a signal is received while in a function
11480that @value{GDBN} called in the program being debugged. If set to on,
11481@value{GDBN} unwinds the stack it created for the call and restores
11482the context to what it was before the call. If set to off (the
11483default), @value{GDBN} stops in the frame where the signal was
11484received.
11485
11486@item show unwindonsignal
11487@kindex show unwindonsignal
11488Show the current setting of stack unwinding in the functions called by
11489@value{GDBN}.
11490@end table
11491
f8568604
EZ
11492@cindex weak alias functions
11493Sometimes, a function you wish to call is actually a @dfn{weak alias}
11494for another function. In such case, @value{GDBN} might not pick up
11495the type information, including the types of the function arguments,
11496which causes @value{GDBN} to call the inferior function incorrectly.
11497As a result, the called function will function erroneously and may
11498even crash. A solution to that is to use the name of the aliased
11499function instead.
c906108c 11500
6d2ebf8b 11501@node Patching
79a6e687 11502@section Patching Programs
7a292a7a 11503
c906108c
SS
11504@cindex patching binaries
11505@cindex writing into executables
c906108c 11506@cindex writing into corefiles
c906108c 11507
7a292a7a
SS
11508By default, @value{GDBN} opens the file containing your program's
11509executable code (or the corefile) read-only. This prevents accidental
11510alterations to machine code; but it also prevents you from intentionally
11511patching your program's binary.
c906108c
SS
11512
11513If you'd like to be able to patch the binary, you can specify that
11514explicitly with the @code{set write} command. For example, you might
11515want to turn on internal debugging flags, or even to make emergency
11516repairs.
11517
11518@table @code
11519@kindex set write
11520@item set write on
11521@itemx set write off
7a292a7a
SS
11522If you specify @samp{set write on}, @value{GDBN} opens executable and
11523core files for both reading and writing; if you specify @samp{set write
c906108c
SS
11524off} (the default), @value{GDBN} opens them read-only.
11525
11526If you have already loaded a file, you must load it again (using the
7a292a7a
SS
11527@code{exec-file} or @code{core-file} command) after changing @code{set
11528write}, for your new setting to take effect.
c906108c
SS
11529
11530@item show write
11531@kindex show write
7a292a7a
SS
11532Display whether executable files and core files are opened for writing
11533as well as reading.
c906108c
SS
11534@end table
11535
6d2ebf8b 11536@node GDB Files
c906108c
SS
11537@chapter @value{GDBN} Files
11538
7a292a7a
SS
11539@value{GDBN} needs to know the file name of the program to be debugged,
11540both in order to read its symbol table and in order to start your
11541program. To debug a core dump of a previous run, you must also tell
11542@value{GDBN} the name of the core dump file.
c906108c
SS
11543
11544@menu
11545* Files:: Commands to specify files
5b5d99cf 11546* Separate Debug Files:: Debugging information in separate files
c906108c
SS
11547* Symbol Errors:: Errors reading symbol files
11548@end menu
11549
6d2ebf8b 11550@node Files
79a6e687 11551@section Commands to Specify Files
c906108c 11552
7a292a7a 11553@cindex symbol table
c906108c 11554@cindex core dump file
7a292a7a
SS
11555
11556You may want to specify executable and core dump file names. The usual
11557way to do this is at start-up time, using the arguments to
11558@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
11559Out of @value{GDBN}}).
c906108c
SS
11560
11561Occasionally it is necessary to change to a different file during a
397ca115
EZ
11562@value{GDBN} session. Or you may run @value{GDBN} and forget to
11563specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
11564via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
11565Program}). In these situations the @value{GDBN} commands to specify
0869d01b 11566new files are useful.
c906108c
SS
11567
11568@table @code
11569@cindex executable file
11570@kindex file
11571@item file @var{filename}
11572Use @var{filename} as the program to be debugged. It is read for its
11573symbols and for the contents of pure memory. It is also the program
11574executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
11575directory and the file is not found in the @value{GDBN} working directory,
11576@value{GDBN} uses the environment variable @code{PATH} as a list of
11577directories to search, just as the shell does when looking for a program
11578to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
11579and your program, using the @code{path} command.
11580
fc8be69e
EZ
11581@cindex unlinked object files
11582@cindex patching object files
11583You can load unlinked object @file{.o} files into @value{GDBN} using
11584the @code{file} command. You will not be able to ``run'' an object
11585file, but you can disassemble functions and inspect variables. Also,
11586if the underlying BFD functionality supports it, you could use
11587@kbd{gdb -write} to patch object files using this technique. Note
11588that @value{GDBN} can neither interpret nor modify relocations in this
11589case, so branches and some initialized variables will appear to go to
11590the wrong place. But this feature is still handy from time to time.
11591
c906108c
SS
11592@item file
11593@code{file} with no argument makes @value{GDBN} discard any information it
11594has on both executable file and the symbol table.
11595
11596@kindex exec-file
11597@item exec-file @r{[} @var{filename} @r{]}
11598Specify that the program to be run (but not the symbol table) is found
11599in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
11600if necessary to locate your program. Omitting @var{filename} means to
11601discard information on the executable file.
11602
11603@kindex symbol-file
11604@item symbol-file @r{[} @var{filename} @r{]}
11605Read symbol table information from file @var{filename}. @code{PATH} is
11606searched when necessary. Use the @code{file} command to get both symbol
11607table and program to run from the same file.
11608
11609@code{symbol-file} with no argument clears out @value{GDBN} information on your
11610program's symbol table.
11611
ae5a43e0
DJ
11612The @code{symbol-file} command causes @value{GDBN} to forget the contents of
11613some breakpoints and auto-display expressions. This is because they may
11614contain pointers to the internal data recording symbols and data types,
11615which are part of the old symbol table data being discarded inside
11616@value{GDBN}.
c906108c
SS
11617
11618@code{symbol-file} does not repeat if you press @key{RET} again after
11619executing it once.
11620
11621When @value{GDBN} is configured for a particular environment, it
11622understands debugging information in whatever format is the standard
11623generated for that environment; you may use either a @sc{gnu} compiler, or
11624other compilers that adhere to the local conventions.
c906108c 11625Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 11626using @code{@value{NGCC}} you can generate debugging information for
c906108c 11627optimized code.
c906108c
SS
11628
11629For most kinds of object files, with the exception of old SVR3 systems
11630using COFF, the @code{symbol-file} command does not normally read the
11631symbol table in full right away. Instead, it scans the symbol table
11632quickly to find which source files and which symbols are present. The
11633details are read later, one source file at a time, as they are needed.
11634
11635The purpose of this two-stage reading strategy is to make @value{GDBN}
11636start up faster. For the most part, it is invisible except for
11637occasional pauses while the symbol table details for a particular source
11638file are being read. (The @code{set verbose} command can turn these
11639pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 11640Warnings and Messages}.)
c906108c 11641
c906108c
SS
11642We have not implemented the two-stage strategy for COFF yet. When the
11643symbol table is stored in COFF format, @code{symbol-file} reads the
11644symbol table data in full right away. Note that ``stabs-in-COFF''
11645still does the two-stage strategy, since the debug info is actually
11646in stabs format.
11647
11648@kindex readnow
11649@cindex reading symbols immediately
11650@cindex symbols, reading immediately
a94ab193
EZ
11651@item symbol-file @var{filename} @r{[} -readnow @r{]}
11652@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
11653You can override the @value{GDBN} two-stage strategy for reading symbol
11654tables by using the @samp{-readnow} option with any of the commands that
11655load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 11656entire symbol table available.
c906108c 11657
c906108c
SS
11658@c FIXME: for now no mention of directories, since this seems to be in
11659@c flux. 13mar1992 status is that in theory GDB would look either in
11660@c current dir or in same dir as myprog; but issues like competing
11661@c GDB's, or clutter in system dirs, mean that in practice right now
11662@c only current dir is used. FFish says maybe a special GDB hierarchy
11663@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
11664@c files.
11665
c906108c 11666@kindex core-file
09d4efe1 11667@item core-file @r{[}@var{filename}@r{]}
4644b6e3 11668@itemx core
c906108c
SS
11669Specify the whereabouts of a core dump file to be used as the ``contents
11670of memory''. Traditionally, core files contain only some parts of the
11671address space of the process that generated them; @value{GDBN} can access the
11672executable file itself for other parts.
11673
11674@code{core-file} with no argument specifies that no core file is
11675to be used.
11676
11677Note that the core file is ignored when your program is actually running
7a292a7a
SS
11678under @value{GDBN}. So, if you have been running your program and you
11679wish to debug a core file instead, you must kill the subprocess in which
11680the program is running. To do this, use the @code{kill} command
79a6e687 11681(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 11682
c906108c
SS
11683@kindex add-symbol-file
11684@cindex dynamic linking
11685@item add-symbol-file @var{filename} @var{address}
a94ab193 11686@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 11687@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
11688The @code{add-symbol-file} command reads additional symbol table
11689information from the file @var{filename}. You would use this command
11690when @var{filename} has been dynamically loaded (by some other means)
11691into the program that is running. @var{address} should be the memory
11692address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
11693this out for itself. You can additionally specify an arbitrary number
11694of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
11695section name and base address for that section. You can specify any
11696@var{address} as an expression.
c906108c
SS
11697
11698The symbol table of the file @var{filename} is added to the symbol table
11699originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
11700@code{add-symbol-file} command any number of times; the new symbol data
11701thus read keeps adding to the old. To discard all old symbol data
11702instead, use the @code{symbol-file} command without any arguments.
c906108c 11703
17d9d558
JB
11704@cindex relocatable object files, reading symbols from
11705@cindex object files, relocatable, reading symbols from
11706@cindex reading symbols from relocatable object files
11707@cindex symbols, reading from relocatable object files
11708@cindex @file{.o} files, reading symbols from
11709Although @var{filename} is typically a shared library file, an
11710executable file, or some other object file which has been fully
11711relocated for loading into a process, you can also load symbolic
11712information from relocatable @file{.o} files, as long as:
11713
11714@itemize @bullet
11715@item
11716the file's symbolic information refers only to linker symbols defined in
11717that file, not to symbols defined by other object files,
11718@item
11719every section the file's symbolic information refers to has actually
11720been loaded into the inferior, as it appears in the file, and
11721@item
11722you can determine the address at which every section was loaded, and
11723provide these to the @code{add-symbol-file} command.
11724@end itemize
11725
11726@noindent
11727Some embedded operating systems, like Sun Chorus and VxWorks, can load
11728relocatable files into an already running program; such systems
11729typically make the requirements above easy to meet. However, it's
11730important to recognize that many native systems use complex link
49efadf5 11731procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
11732assembly, for example) that make the requirements difficult to meet. In
11733general, one cannot assume that using @code{add-symbol-file} to read a
11734relocatable object file's symbolic information will have the same effect
11735as linking the relocatable object file into the program in the normal
11736way.
11737
c906108c
SS
11738@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
11739
c45da7e6
EZ
11740@kindex add-symbol-file-from-memory
11741@cindex @code{syscall DSO}
11742@cindex load symbols from memory
11743@item add-symbol-file-from-memory @var{address}
11744Load symbols from the given @var{address} in a dynamically loaded
11745object file whose image is mapped directly into the inferior's memory.
11746For example, the Linux kernel maps a @code{syscall DSO} into each
11747process's address space; this DSO provides kernel-specific code for
11748some system calls. The argument can be any expression whose
11749evaluation yields the address of the file's shared object file header.
11750For this command to work, you must have used @code{symbol-file} or
11751@code{exec-file} commands in advance.
11752
09d4efe1
EZ
11753@kindex add-shared-symbol-files
11754@kindex assf
11755@item add-shared-symbol-files @var{library-file}
11756@itemx assf @var{library-file}
11757The @code{add-shared-symbol-files} command can currently be used only
11758in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
11759alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
11760@value{GDBN} automatically looks for shared libraries, however if
11761@value{GDBN} does not find yours, you can invoke
11762@code{add-shared-symbol-files}. It takes one argument: the shared
11763library's file name. @code{assf} is a shorthand alias for
11764@code{add-shared-symbol-files}.
c906108c 11765
c906108c 11766@kindex section
09d4efe1
EZ
11767@item section @var{section} @var{addr}
11768The @code{section} command changes the base address of the named
11769@var{section} of the exec file to @var{addr}. This can be used if the
11770exec file does not contain section addresses, (such as in the
11771@code{a.out} format), or when the addresses specified in the file
11772itself are wrong. Each section must be changed separately. The
11773@code{info files} command, described below, lists all the sections and
11774their addresses.
c906108c
SS
11775
11776@kindex info files
11777@kindex info target
11778@item info files
11779@itemx info target
7a292a7a
SS
11780@code{info files} and @code{info target} are synonymous; both print the
11781current target (@pxref{Targets, ,Specifying a Debugging Target}),
11782including the names of the executable and core dump files currently in
11783use by @value{GDBN}, and the files from which symbols were loaded. The
11784command @code{help target} lists all possible targets rather than
11785current ones.
11786
fe95c787
MS
11787@kindex maint info sections
11788@item maint info sections
11789Another command that can give you extra information about program sections
11790is @code{maint info sections}. In addition to the section information
11791displayed by @code{info files}, this command displays the flags and file
11792offset of each section in the executable and core dump files. In addition,
11793@code{maint info sections} provides the following command options (which
11794may be arbitrarily combined):
11795
11796@table @code
11797@item ALLOBJ
11798Display sections for all loaded object files, including shared libraries.
11799@item @var{sections}
6600abed 11800Display info only for named @var{sections}.
fe95c787
MS
11801@item @var{section-flags}
11802Display info only for sections for which @var{section-flags} are true.
11803The section flags that @value{GDBN} currently knows about are:
11804@table @code
11805@item ALLOC
11806Section will have space allocated in the process when loaded.
11807Set for all sections except those containing debug information.
11808@item LOAD
11809Section will be loaded from the file into the child process memory.
11810Set for pre-initialized code and data, clear for @code{.bss} sections.
11811@item RELOC
11812Section needs to be relocated before loading.
11813@item READONLY
11814Section cannot be modified by the child process.
11815@item CODE
11816Section contains executable code only.
6600abed 11817@item DATA
fe95c787
MS
11818Section contains data only (no executable code).
11819@item ROM
11820Section will reside in ROM.
11821@item CONSTRUCTOR
11822Section contains data for constructor/destructor lists.
11823@item HAS_CONTENTS
11824Section is not empty.
11825@item NEVER_LOAD
11826An instruction to the linker to not output the section.
11827@item COFF_SHARED_LIBRARY
11828A notification to the linker that the section contains
11829COFF shared library information.
11830@item IS_COMMON
11831Section contains common symbols.
11832@end table
11833@end table
6763aef9 11834@kindex set trust-readonly-sections
9c16f35a 11835@cindex read-only sections
6763aef9
MS
11836@item set trust-readonly-sections on
11837Tell @value{GDBN} that readonly sections in your object file
6ca652b0 11838really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
11839In that case, @value{GDBN} can fetch values from these sections
11840out of the object file, rather than from the target program.
11841For some targets (notably embedded ones), this can be a significant
11842enhancement to debugging performance.
11843
11844The default is off.
11845
11846@item set trust-readonly-sections off
15110bc3 11847Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
11848the contents of the section might change while the program is running,
11849and must therefore be fetched from the target when needed.
9c16f35a
EZ
11850
11851@item show trust-readonly-sections
11852Show the current setting of trusting readonly sections.
c906108c
SS
11853@end table
11854
11855All file-specifying commands allow both absolute and relative file names
11856as arguments. @value{GDBN} always converts the file name to an absolute file
11857name and remembers it that way.
11858
c906108c 11859@cindex shared libraries
9cceb671
DJ
11860@anchor{Shared Libraries}
11861@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 11862and IBM RS/6000 AIX shared libraries.
53a5351d 11863
9cceb671
DJ
11864On MS-Windows @value{GDBN} must be linked with the Expat library to support
11865shared libraries. @xref{Expat}.
11866
c906108c
SS
11867@value{GDBN} automatically loads symbol definitions from shared libraries
11868when you use the @code{run} command, or when you examine a core file.
11869(Before you issue the @code{run} command, @value{GDBN} does not understand
11870references to a function in a shared library, however---unless you are
11871debugging a core file).
53a5351d
JM
11872
11873On HP-UX, if the program loads a library explicitly, @value{GDBN}
11874automatically loads the symbols at the time of the @code{shl_load} call.
11875
c906108c
SS
11876@c FIXME: some @value{GDBN} release may permit some refs to undef
11877@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11878@c FIXME...lib; check this from time to time when updating manual
11879
b7209cb4
FF
11880There are times, however, when you may wish to not automatically load
11881symbol definitions from shared libraries, such as when they are
11882particularly large or there are many of them.
11883
11884To control the automatic loading of shared library symbols, use the
11885commands:
11886
11887@table @code
11888@kindex set auto-solib-add
11889@item set auto-solib-add @var{mode}
11890If @var{mode} is @code{on}, symbols from all shared object libraries
11891will be loaded automatically when the inferior begins execution, you
11892attach to an independently started inferior, or when the dynamic linker
11893informs @value{GDBN} that a new library has been loaded. If @var{mode}
11894is @code{off}, symbols must be loaded manually, using the
11895@code{sharedlibrary} command. The default value is @code{on}.
11896
dcaf7c2c
EZ
11897@cindex memory used for symbol tables
11898If your program uses lots of shared libraries with debug info that
11899takes large amounts of memory, you can decrease the @value{GDBN}
11900memory footprint by preventing it from automatically loading the
11901symbols from shared libraries. To that end, type @kbd{set
11902auto-solib-add off} before running the inferior, then load each
11903library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 11904@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
11905the libraries whose symbols you want to be loaded.
11906
b7209cb4
FF
11907@kindex show auto-solib-add
11908@item show auto-solib-add
11909Display the current autoloading mode.
11910@end table
11911
c45da7e6 11912@cindex load shared library
b7209cb4
FF
11913To explicitly load shared library symbols, use the @code{sharedlibrary}
11914command:
11915
c906108c
SS
11916@table @code
11917@kindex info sharedlibrary
11918@kindex info share
11919@item info share
11920@itemx info sharedlibrary
11921Print the names of the shared libraries which are currently loaded.
11922
11923@kindex sharedlibrary
11924@kindex share
11925@item sharedlibrary @var{regex}
11926@itemx share @var{regex}
c906108c
SS
11927Load shared object library symbols for files matching a
11928Unix regular expression.
11929As with files loaded automatically, it only loads shared libraries
11930required by your program for a core file or after typing @code{run}. If
11931@var{regex} is omitted all shared libraries required by your program are
11932loaded.
c45da7e6
EZ
11933
11934@item nosharedlibrary
11935@kindex nosharedlibrary
11936@cindex unload symbols from shared libraries
11937Unload all shared object library symbols. This discards all symbols
11938that have been loaded from all shared libraries. Symbols from shared
11939libraries that were loaded by explicit user requests are not
11940discarded.
c906108c
SS
11941@end table
11942
721c2651
EZ
11943Sometimes you may wish that @value{GDBN} stops and gives you control
11944when any of shared library events happen. Use the @code{set
11945stop-on-solib-events} command for this:
11946
11947@table @code
11948@item set stop-on-solib-events
11949@kindex set stop-on-solib-events
11950This command controls whether @value{GDBN} should give you control
11951when the dynamic linker notifies it about some shared library event.
11952The most common event of interest is loading or unloading of a new
11953shared library.
11954
11955@item show stop-on-solib-events
11956@kindex show stop-on-solib-events
11957Show whether @value{GDBN} stops and gives you control when shared
11958library events happen.
11959@end table
11960
f5ebfba0
DJ
11961Shared libraries are also supported in many cross or remote debugging
11962configurations. A copy of the target's libraries need to be present on the
11963host system; they need to be the same as the target libraries, although the
11964copies on the target can be stripped as long as the copies on the host are
11965not.
11966
59b7b46f
EZ
11967@cindex where to look for shared libraries
11968For remote debugging, you need to tell @value{GDBN} where the target
11969libraries are, so that it can load the correct copies---otherwise, it
11970may try to load the host's libraries. @value{GDBN} has two variables
11971to specify the search directories for target libraries.
f5ebfba0
DJ
11972
11973@table @code
59b7b46f 11974@cindex prefix for shared library file names
f822c95b 11975@cindex system root, alternate
f5ebfba0 11976@kindex set solib-absolute-prefix
f822c95b
DJ
11977@kindex set sysroot
11978@item set sysroot @var{path}
11979Use @var{path} as the system root for the program being debugged. Any
11980absolute shared library paths will be prefixed with @var{path}; many
11981runtime loaders store the absolute paths to the shared library in the
11982target program's memory. If you use @code{set sysroot} to find shared
11983libraries, they need to be laid out in the same way that they are on
11984the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
11985under @var{path}.
11986
11987The @code{set solib-absolute-prefix} command is an alias for @code{set
11988sysroot}.
11989
11990@cindex default system root
59b7b46f 11991@cindex @samp{--with-sysroot}
f822c95b
DJ
11992You can set the default system root by using the configure-time
11993@samp{--with-sysroot} option. If the system root is inside
11994@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
11995@samp{--exec-prefix}), then the default system root will be updated
11996automatically if the installed @value{GDBN} is moved to a new
11997location.
11998
11999@kindex show sysroot
12000@item show sysroot
f5ebfba0
DJ
12001Display the current shared library prefix.
12002
12003@kindex set solib-search-path
12004@item set solib-search-path @var{path}
f822c95b
DJ
12005If this variable is set, @var{path} is a colon-separated list of
12006directories to search for shared libraries. @samp{solib-search-path}
12007is used after @samp{sysroot} fails to locate the library, or if the
12008path to the library is relative instead of absolute. If you want to
12009use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 12010@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 12011finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 12012it to a nonexistent directory may interfere with automatic loading
f822c95b 12013of shared library symbols.
f5ebfba0
DJ
12014
12015@kindex show solib-search-path
12016@item show solib-search-path
12017Display the current shared library search path.
12018@end table
12019
5b5d99cf
JB
12020
12021@node Separate Debug Files
12022@section Debugging Information in Separate Files
12023@cindex separate debugging information files
12024@cindex debugging information in separate files
12025@cindex @file{.debug} subdirectories
12026@cindex debugging information directory, global
12027@cindex global debugging information directory
c7e83d54
EZ
12028@cindex build ID, and separate debugging files
12029@cindex @file{.build-id} directory
5b5d99cf
JB
12030
12031@value{GDBN} allows you to put a program's debugging information in a
12032file separate from the executable itself, in a way that allows
12033@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
12034Since debugging information can be very large---sometimes larger
12035than the executable code itself---some systems distribute debugging
5b5d99cf
JB
12036information for their executables in separate files, which users can
12037install only when they need to debug a problem.
12038
c7e83d54
EZ
12039@value{GDBN} supports two ways of specifying the separate debug info
12040file:
5b5d99cf
JB
12041
12042@itemize @bullet
12043@item
c7e83d54
EZ
12044The executable contains a @dfn{debug link} that specifies the name of
12045the separate debug info file. The separate debug file's name is
12046usually @file{@var{executable}.debug}, where @var{executable} is the
12047name of the corresponding executable file without leading directories
12048(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
12049debug link specifies a CRC32 checksum for the debug file, which
12050@value{GDBN} uses to validate that the executable and the debug file
12051came from the same build.
12052
12053@item
7e27a47a 12054The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 12055also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
12056only on some operating systems, notably those which use the ELF format
12057for binary files and the @sc{gnu} Binutils.) For more details about
12058this feature, see the description of the @option{--build-id}
12059command-line option in @ref{Options, , Command Line Options, ld.info,
12060The GNU Linker}. The debug info file's name is not specified
12061explicitly by the build ID, but can be computed from the build ID, see
12062below.
d3750b24
JK
12063@end itemize
12064
c7e83d54
EZ
12065Depending on the way the debug info file is specified, @value{GDBN}
12066uses two different methods of looking for the debug file:
d3750b24
JK
12067
12068@itemize @bullet
12069@item
c7e83d54
EZ
12070For the ``debug link'' method, @value{GDBN} looks up the named file in
12071the directory of the executable file, then in a subdirectory of that
12072directory named @file{.debug}, and finally under the global debug
12073directory, in a subdirectory whose name is identical to the leading
12074directories of the executable's absolute file name.
12075
12076@item
83f83d7f 12077For the ``build ID'' method, @value{GDBN} looks in the
c7e83d54
EZ
12078@file{.build-id} subdirectory of the global debug directory for a file
12079named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
12080first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
12081are the rest of the bit string. (Real build ID strings are 32 or more
12082hex characters, not 10.)
c7e83d54
EZ
12083@end itemize
12084
12085So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
12086@file{/usr/bin/ls}, which has a debug link that specifies the
12087file @file{ls.debug}, and a build ID whose value in hex is
c7e83d54
EZ
12088@code{abcdef1234}. If the global debug directory is
12089@file{/usr/lib/debug}, then @value{GDBN} will look for the following
12090debug information files, in the indicated order:
12091
12092@itemize @minus
12093@item
12094@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 12095@item
c7e83d54 12096@file{/usr/bin/ls.debug}
5b5d99cf 12097@item
c7e83d54 12098@file{/usr/bin/.debug/ls.debug}
5b5d99cf 12099@item
c7e83d54 12100@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 12101@end itemize
5b5d99cf
JB
12102
12103You can set the global debugging info directory's name, and view the
12104name @value{GDBN} is currently using.
12105
12106@table @code
12107
12108@kindex set debug-file-directory
12109@item set debug-file-directory @var{directory}
12110Set the directory which @value{GDBN} searches for separate debugging
12111information files to @var{directory}.
12112
12113@kindex show debug-file-directory
12114@item show debug-file-directory
12115Show the directory @value{GDBN} searches for separate debugging
12116information files.
12117
12118@end table
12119
12120@cindex @code{.gnu_debuglink} sections
c7e83d54 12121@cindex debug link sections
5b5d99cf
JB
12122A debug link is a special section of the executable file named
12123@code{.gnu_debuglink}. The section must contain:
12124
12125@itemize
12126@item
12127A filename, with any leading directory components removed, followed by
12128a zero byte,
12129@item
12130zero to three bytes of padding, as needed to reach the next four-byte
12131boundary within the section, and
12132@item
12133a four-byte CRC checksum, stored in the same endianness used for the
12134executable file itself. The checksum is computed on the debugging
12135information file's full contents by the function given below, passing
12136zero as the @var{crc} argument.
12137@end itemize
12138
12139Any executable file format can carry a debug link, as long as it can
12140contain a section named @code{.gnu_debuglink} with the contents
12141described above.
12142
d3750b24 12143@cindex @code{.note.gnu.build-id} sections
c7e83d54 12144@cindex build ID sections
7e27a47a
EZ
12145The build ID is a special section in the executable file (and in other
12146ELF binary files that @value{GDBN} may consider). This section is
12147often named @code{.note.gnu.build-id}, but that name is not mandatory.
12148It contains unique identification for the built files---the ID remains
12149the same across multiple builds of the same build tree. The default
12150algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
12151content for the build ID string. The same section with an identical
12152value is present in the original built binary with symbols, in its
12153stripped variant, and in the separate debugging information file.
d3750b24 12154
5b5d99cf
JB
12155The debugging information file itself should be an ordinary
12156executable, containing a full set of linker symbols, sections, and
12157debugging information. The sections of the debugging information file
c7e83d54
EZ
12158should have the same names, addresses, and sizes as the original file,
12159but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
12160in an ordinary executable.
12161
7e27a47a 12162The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
12163@samp{objcopy} utility that can produce
12164the separated executable / debugging information file pairs using the
12165following commands:
12166
12167@smallexample
12168@kbd{objcopy --only-keep-debug foo foo.debug}
12169@kbd{strip -g foo}
c7e83d54
EZ
12170@end smallexample
12171
12172@noindent
12173These commands remove the debugging
83f83d7f
JK
12174information from the executable file @file{foo} and place it in the file
12175@file{foo.debug}. You can use the first, second or both methods to link the
12176two files:
12177
12178@itemize @bullet
12179@item
12180The debug link method needs the following additional command to also leave
12181behind a debug link in @file{foo}:
12182
12183@smallexample
12184@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
12185@end smallexample
12186
12187Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 12188a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
12189foo.debug} has the same functionality as the two @code{objcopy} commands and
12190the @code{ln -s} command above, together.
12191
12192@item
12193Build ID gets embedded into the main executable using @code{ld --build-id} or
12194the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
12195compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 12196utilities (Binutils) package since version 2.18.
83f83d7f
JK
12197@end itemize
12198
12199@noindent
d3750b24 12200
c7e83d54
EZ
12201Since there are many different ways to compute CRC's for the debug
12202link (different polynomials, reversals, byte ordering, etc.), the
12203simplest way to describe the CRC used in @code{.gnu_debuglink}
12204sections is to give the complete code for a function that computes it:
5b5d99cf 12205
4644b6e3 12206@kindex gnu_debuglink_crc32
5b5d99cf
JB
12207@smallexample
12208unsigned long
12209gnu_debuglink_crc32 (unsigned long crc,
12210 unsigned char *buf, size_t len)
12211@{
12212 static const unsigned long crc32_table[256] =
12213 @{
12214 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
12215 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
12216 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
12217 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
12218 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
12219 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
12220 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
12221 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
12222 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
12223 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
12224 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
12225 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
12226 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
12227 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
12228 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
12229 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
12230 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
12231 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
12232 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
12233 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
12234 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
12235 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
12236 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
12237 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
12238 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
12239 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
12240 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
12241 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
12242 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
12243 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
12244 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
12245 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
12246 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
12247 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
12248 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
12249 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
12250 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
12251 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
12252 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
12253 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
12254 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
12255 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
12256 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
12257 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
12258 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
12259 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
12260 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
12261 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
12262 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
12263 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
12264 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
12265 0x2d02ef8d
12266 @};
12267 unsigned char *end;
12268
12269 crc = ~crc & 0xffffffff;
12270 for (end = buf + len; buf < end; ++buf)
12271 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 12272 return ~crc & 0xffffffff;
5b5d99cf
JB
12273@}
12274@end smallexample
12275
c7e83d54
EZ
12276@noindent
12277This computation does not apply to the ``build ID'' method.
12278
5b5d99cf 12279
6d2ebf8b 12280@node Symbol Errors
79a6e687 12281@section Errors Reading Symbol Files
c906108c
SS
12282
12283While reading a symbol file, @value{GDBN} occasionally encounters problems,
12284such as symbol types it does not recognize, or known bugs in compiler
12285output. By default, @value{GDBN} does not notify you of such problems, since
12286they are relatively common and primarily of interest to people
12287debugging compilers. If you are interested in seeing information
12288about ill-constructed symbol tables, you can either ask @value{GDBN} to print
12289only one message about each such type of problem, no matter how many
12290times the problem occurs; or you can ask @value{GDBN} to print more messages,
12291to see how many times the problems occur, with the @code{set
79a6e687
BW
12292complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
12293Messages}).
c906108c
SS
12294
12295The messages currently printed, and their meanings, include:
12296
12297@table @code
12298@item inner block not inside outer block in @var{symbol}
12299
12300The symbol information shows where symbol scopes begin and end
12301(such as at the start of a function or a block of statements). This
12302error indicates that an inner scope block is not fully contained
12303in its outer scope blocks.
12304
12305@value{GDBN} circumvents the problem by treating the inner block as if it had
12306the same scope as the outer block. In the error message, @var{symbol}
12307may be shown as ``@code{(don't know)}'' if the outer block is not a
12308function.
12309
12310@item block at @var{address} out of order
12311
12312The symbol information for symbol scope blocks should occur in
12313order of increasing addresses. This error indicates that it does not
12314do so.
12315
12316@value{GDBN} does not circumvent this problem, and has trouble
12317locating symbols in the source file whose symbols it is reading. (You
12318can often determine what source file is affected by specifying
79a6e687
BW
12319@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
12320Messages}.)
c906108c
SS
12321
12322@item bad block start address patched
12323
12324The symbol information for a symbol scope block has a start address
12325smaller than the address of the preceding source line. This is known
12326to occur in the SunOS 4.1.1 (and earlier) C compiler.
12327
12328@value{GDBN} circumvents the problem by treating the symbol scope block as
12329starting on the previous source line.
12330
12331@item bad string table offset in symbol @var{n}
12332
12333@cindex foo
12334Symbol number @var{n} contains a pointer into the string table which is
12335larger than the size of the string table.
12336
12337@value{GDBN} circumvents the problem by considering the symbol to have the
12338name @code{foo}, which may cause other problems if many symbols end up
12339with this name.
12340
12341@item unknown symbol type @code{0x@var{nn}}
12342
7a292a7a
SS
12343The symbol information contains new data types that @value{GDBN} does
12344not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 12345uncomprehended information, in hexadecimal.
c906108c 12346
7a292a7a
SS
12347@value{GDBN} circumvents the error by ignoring this symbol information.
12348This usually allows you to debug your program, though certain symbols
c906108c 12349are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
12350debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
12351on @code{complain}, then go up to the function @code{read_dbx_symtab}
12352and examine @code{*bufp} to see the symbol.
c906108c
SS
12353
12354@item stub type has NULL name
c906108c 12355
7a292a7a 12356@value{GDBN} could not find the full definition for a struct or class.
c906108c 12357
7a292a7a 12358@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 12359The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
12360information that recent versions of the compiler should have output for
12361it.
c906108c
SS
12362
12363@item info mismatch between compiler and debugger
12364
12365@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 12366
c906108c
SS
12367@end table
12368
6d2ebf8b 12369@node Targets
c906108c 12370@chapter Specifying a Debugging Target
7a292a7a 12371
c906108c 12372@cindex debugging target
c906108c 12373A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
12374
12375Often, @value{GDBN} runs in the same host environment as your program;
12376in that case, the debugging target is specified as a side effect when
12377you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
12378flexibility---for example, running @value{GDBN} on a physically separate
12379host, or controlling a standalone system over a serial port or a
53a5351d
JM
12380realtime system over a TCP/IP connection---you can use the @code{target}
12381command to specify one of the target types configured for @value{GDBN}
79a6e687 12382(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 12383
a8f24a35
EZ
12384@cindex target architecture
12385It is possible to build @value{GDBN} for several different @dfn{target
12386architectures}. When @value{GDBN} is built like that, you can choose
12387one of the available architectures with the @kbd{set architecture}
12388command.
12389
12390@table @code
12391@kindex set architecture
12392@kindex show architecture
12393@item set architecture @var{arch}
12394This command sets the current target architecture to @var{arch}. The
12395value of @var{arch} can be @code{"auto"}, in addition to one of the
12396supported architectures.
12397
12398@item show architecture
12399Show the current target architecture.
9c16f35a
EZ
12400
12401@item set processor
12402@itemx processor
12403@kindex set processor
12404@kindex show processor
12405These are alias commands for, respectively, @code{set architecture}
12406and @code{show architecture}.
a8f24a35
EZ
12407@end table
12408
c906108c
SS
12409@menu
12410* Active Targets:: Active targets
12411* Target Commands:: Commands for managing targets
c906108c 12412* Byte Order:: Choosing target byte order
c906108c
SS
12413@end menu
12414
6d2ebf8b 12415@node Active Targets
79a6e687 12416@section Active Targets
7a292a7a 12417
c906108c
SS
12418@cindex stacking targets
12419@cindex active targets
12420@cindex multiple targets
12421
c906108c 12422There are three classes of targets: processes, core files, and
7a292a7a
SS
12423executable files. @value{GDBN} can work concurrently on up to three
12424active targets, one in each class. This allows you to (for example)
12425start a process and inspect its activity without abandoning your work on
12426a core file.
c906108c
SS
12427
12428For example, if you execute @samp{gdb a.out}, then the executable file
12429@code{a.out} is the only active target. If you designate a core file as
12430well---presumably from a prior run that crashed and coredumped---then
12431@value{GDBN} has two active targets and uses them in tandem, looking
12432first in the corefile target, then in the executable file, to satisfy
12433requests for memory addresses. (Typically, these two classes of target
12434are complementary, since core files contain only a program's
12435read-write memory---variables and so on---plus machine status, while
12436executable files contain only the program text and initialized data.)
c906108c
SS
12437
12438When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
12439target as well. When a process target is active, all @value{GDBN}
12440commands requesting memory addresses refer to that target; addresses in
12441an active core file or executable file target are obscured while the
12442process target is active.
c906108c 12443
7a292a7a 12444Use the @code{core-file} and @code{exec-file} commands to select a new
79a6e687
BW
12445core file or executable target (@pxref{Files, ,Commands to Specify
12446Files}). To specify as a target a process that is already running, use
12447the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
12448Process}).
c906108c 12449
6d2ebf8b 12450@node Target Commands
79a6e687 12451@section Commands for Managing Targets
c906108c
SS
12452
12453@table @code
12454@item target @var{type} @var{parameters}
7a292a7a
SS
12455Connects the @value{GDBN} host environment to a target machine or
12456process. A target is typically a protocol for talking to debugging
12457facilities. You use the argument @var{type} to specify the type or
12458protocol of the target machine.
c906108c
SS
12459
12460Further @var{parameters} are interpreted by the target protocol, but
12461typically include things like device names or host names to connect
12462with, process numbers, and baud rates.
c906108c
SS
12463
12464The @code{target} command does not repeat if you press @key{RET} again
12465after executing the command.
12466
12467@kindex help target
12468@item help target
12469Displays the names of all targets available. To display targets
12470currently selected, use either @code{info target} or @code{info files}
79a6e687 12471(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
12472
12473@item help target @var{name}
12474Describe a particular target, including any parameters necessary to
12475select it.
12476
12477@kindex set gnutarget
12478@item set gnutarget @var{args}
5d161b24 12479@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 12480knows whether it is reading an @dfn{executable},
5d161b24
DB
12481a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
12482with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
12483with @code{gnutarget} the @code{target} refers to a program, not a machine.
12484
d4f3574e 12485@quotation
c906108c
SS
12486@emph{Warning:} To specify a file format with @code{set gnutarget},
12487you must know the actual BFD name.
d4f3574e 12488@end quotation
c906108c 12489
d4f3574e 12490@noindent
79a6e687 12491@xref{Files, , Commands to Specify Files}.
c906108c 12492
5d161b24 12493@kindex show gnutarget
c906108c
SS
12494@item show gnutarget
12495Use the @code{show gnutarget} command to display what file format
12496@code{gnutarget} is set to read. If you have not set @code{gnutarget},
12497@value{GDBN} will determine the file format for each file automatically,
12498and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
12499@end table
12500
4644b6e3 12501@cindex common targets
c906108c
SS
12502Here are some common targets (available, or not, depending on the GDB
12503configuration):
c906108c
SS
12504
12505@table @code
4644b6e3 12506@kindex target
c906108c 12507@item target exec @var{program}
4644b6e3 12508@cindex executable file target
c906108c
SS
12509An executable file. @samp{target exec @var{program}} is the same as
12510@samp{exec-file @var{program}}.
12511
c906108c 12512@item target core @var{filename}
4644b6e3 12513@cindex core dump file target
c906108c
SS
12514A core dump file. @samp{target core @var{filename}} is the same as
12515@samp{core-file @var{filename}}.
c906108c 12516
1a10341b 12517@item target remote @var{medium}
4644b6e3 12518@cindex remote target
1a10341b
JB
12519A remote system connected to @value{GDBN} via a serial line or network
12520connection. This command tells @value{GDBN} to use its own remote
12521protocol over @var{medium} for debugging. @xref{Remote Debugging}.
12522
12523For example, if you have a board connected to @file{/dev/ttya} on the
12524machine running @value{GDBN}, you could say:
12525
12526@smallexample
12527target remote /dev/ttya
12528@end smallexample
12529
12530@code{target remote} supports the @code{load} command. This is only
12531useful if you have some other way of getting the stub to the target
12532system, and you can put it somewhere in memory where it won't get
12533clobbered by the download.
c906108c 12534
c906108c 12535@item target sim
4644b6e3 12536@cindex built-in simulator target
2df3850c 12537Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 12538In general,
474c8240 12539@smallexample
104c1213
JM
12540 target sim
12541 load
12542 run
474c8240 12543@end smallexample
d4f3574e 12544@noindent
104c1213 12545works; however, you cannot assume that a specific memory map, device
d4f3574e 12546drivers, or even basic I/O is available, although some simulators do
104c1213
JM
12547provide these. For info about any processor-specific simulator details,
12548see the appropriate section in @ref{Embedded Processors, ,Embedded
12549Processors}.
12550
c906108c
SS
12551@end table
12552
104c1213 12553Some configurations may include these targets as well:
c906108c
SS
12554
12555@table @code
12556
c906108c 12557@item target nrom @var{dev}
4644b6e3 12558@cindex NetROM ROM emulator target
c906108c
SS
12559NetROM ROM emulator. This target only supports downloading.
12560
c906108c
SS
12561@end table
12562
5d161b24 12563Different targets are available on different configurations of @value{GDBN};
c906108c 12564your configuration may have more or fewer targets.
c906108c 12565
721c2651
EZ
12566Many remote targets require you to download the executable's code once
12567you've successfully established a connection. You may wish to control
3d00d119
DJ
12568various aspects of this process.
12569
12570@table @code
721c2651
EZ
12571
12572@item set hash
12573@kindex set hash@r{, for remote monitors}
12574@cindex hash mark while downloading
12575This command controls whether a hash mark @samp{#} is displayed while
12576downloading a file to the remote monitor. If on, a hash mark is
12577displayed after each S-record is successfully downloaded to the
12578monitor.
12579
12580@item show hash
12581@kindex show hash@r{, for remote monitors}
12582Show the current status of displaying the hash mark.
12583
12584@item set debug monitor
12585@kindex set debug monitor
12586@cindex display remote monitor communications
12587Enable or disable display of communications messages between
12588@value{GDBN} and the remote monitor.
12589
12590@item show debug monitor
12591@kindex show debug monitor
12592Show the current status of displaying communications between
12593@value{GDBN} and the remote monitor.
a8f24a35 12594@end table
c906108c
SS
12595
12596@table @code
12597
12598@kindex load @var{filename}
12599@item load @var{filename}
c906108c
SS
12600Depending on what remote debugging facilities are configured into
12601@value{GDBN}, the @code{load} command may be available. Where it exists, it
12602is meant to make @var{filename} (an executable) available for debugging
12603on the remote system---by downloading, or dynamic linking, for example.
12604@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
12605the @code{add-symbol-file} command.
12606
12607If your @value{GDBN} does not have a @code{load} command, attempting to
12608execute it gets the error message ``@code{You can't do that when your
12609target is @dots{}}''
c906108c
SS
12610
12611The file is loaded at whatever address is specified in the executable.
12612For some object file formats, you can specify the load address when you
12613link the program; for other formats, like a.out, the object file format
12614specifies a fixed address.
12615@c FIXME! This would be a good place for an xref to the GNU linker doc.
12616
68437a39
DJ
12617Depending on the remote side capabilities, @value{GDBN} may be able to
12618load programs into flash memory.
12619
c906108c
SS
12620@code{load} does not repeat if you press @key{RET} again after using it.
12621@end table
12622
6d2ebf8b 12623@node Byte Order
79a6e687 12624@section Choosing Target Byte Order
7a292a7a 12625
c906108c
SS
12626@cindex choosing target byte order
12627@cindex target byte order
c906108c 12628
172c2a43 12629Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
12630offer the ability to run either big-endian or little-endian byte
12631orders. Usually the executable or symbol will include a bit to
12632designate the endian-ness, and you will not need to worry about
12633which to use. However, you may still find it useful to adjust
d4f3574e 12634@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
12635
12636@table @code
4644b6e3 12637@kindex set endian
c906108c
SS
12638@item set endian big
12639Instruct @value{GDBN} to assume the target is big-endian.
12640
c906108c
SS
12641@item set endian little
12642Instruct @value{GDBN} to assume the target is little-endian.
12643
c906108c
SS
12644@item set endian auto
12645Instruct @value{GDBN} to use the byte order associated with the
12646executable.
12647
12648@item show endian
12649Display @value{GDBN}'s current idea of the target byte order.
12650
12651@end table
12652
12653Note that these commands merely adjust interpretation of symbolic
12654data on the host, and that they have absolutely no effect on the
12655target system.
12656
ea35711c
DJ
12657
12658@node Remote Debugging
12659@chapter Debugging Remote Programs
c906108c
SS
12660@cindex remote debugging
12661
12662If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
12663@value{GDBN} in the usual way, it is often useful to use remote debugging.
12664For example, you might use remote debugging on an operating system kernel,
c906108c
SS
12665or on a small system which does not have a general purpose operating system
12666powerful enough to run a full-featured debugger.
12667
12668Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
12669to make this work with particular debugging targets. In addition,
5d161b24 12670@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
12671but not specific to any particular target system) which you can use if you
12672write the remote stubs---the code that runs on the remote system to
12673communicate with @value{GDBN}.
12674
12675Other remote targets may be available in your
12676configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 12677
6b2f586d 12678@menu
07f31aa6 12679* Connecting:: Connecting to a remote target
a6b151f1 12680* File Transfer:: Sending files to a remote system
6b2f586d 12681* Server:: Using the gdbserver program
79a6e687
BW
12682* Remote Configuration:: Remote configuration
12683* Remote Stub:: Implementing a remote stub
6b2f586d
AC
12684@end menu
12685
07f31aa6 12686@node Connecting
79a6e687 12687@section Connecting to a Remote Target
07f31aa6
DJ
12688
12689On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 12690your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
12691Start up @value{GDBN} as usual, using the name of the local copy of your
12692program as the first argument.
12693
86941c27
JB
12694@cindex @code{target remote}
12695@value{GDBN} can communicate with the target over a serial line, or
12696over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
12697each case, @value{GDBN} uses the same protocol for debugging your
12698program; only the medium carrying the debugging packets varies. The
12699@code{target remote} command establishes a connection to the target.
12700Its arguments indicate which medium to use:
12701
12702@table @code
12703
12704@item target remote @var{serial-device}
07f31aa6 12705@cindex serial line, @code{target remote}
86941c27
JB
12706Use @var{serial-device} to communicate with the target. For example,
12707to use a serial line connected to the device named @file{/dev/ttyb}:
12708
12709@smallexample
12710target remote /dev/ttyb
12711@end smallexample
12712
07f31aa6
DJ
12713If you're using a serial line, you may want to give @value{GDBN} the
12714@w{@samp{--baud}} option, or use the @code{set remotebaud} command
79a6e687 12715(@pxref{Remote Configuration, set remotebaud}) before the
9c16f35a 12716@code{target} command.
07f31aa6 12717
86941c27
JB
12718@item target remote @code{@var{host}:@var{port}}
12719@itemx target remote @code{tcp:@var{host}:@var{port}}
12720@cindex @acronym{TCP} port, @code{target remote}
12721Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
12722The @var{host} may be either a host name or a numeric @acronym{IP}
12723address; @var{port} must be a decimal number. The @var{host} could be
12724the target machine itself, if it is directly connected to the net, or
12725it might be a terminal server which in turn has a serial line to the
12726target.
07f31aa6 12727
86941c27
JB
12728For example, to connect to port 2828 on a terminal server named
12729@code{manyfarms}:
07f31aa6
DJ
12730
12731@smallexample
12732target remote manyfarms:2828
12733@end smallexample
12734
86941c27
JB
12735If your remote target is actually running on the same machine as your
12736debugger session (e.g.@: a simulator for your target running on the
12737same host), you can omit the hostname. For example, to connect to
12738port 1234 on your local machine:
07f31aa6
DJ
12739
12740@smallexample
12741target remote :1234
12742@end smallexample
12743@noindent
12744
12745Note that the colon is still required here.
12746
86941c27
JB
12747@item target remote @code{udp:@var{host}:@var{port}}
12748@cindex @acronym{UDP} port, @code{target remote}
12749Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
12750connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
12751
12752@smallexample
12753target remote udp:manyfarms:2828
12754@end smallexample
12755
86941c27
JB
12756When using a @acronym{UDP} connection for remote debugging, you should
12757keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
12758can silently drop packets on busy or unreliable networks, which will
12759cause havoc with your debugging session.
12760
66b8c7f6
JB
12761@item target remote | @var{command}
12762@cindex pipe, @code{target remote} to
12763Run @var{command} in the background and communicate with it using a
12764pipe. The @var{command} is a shell command, to be parsed and expanded
12765by the system's command shell, @code{/bin/sh}; it should expect remote
12766protocol packets on its standard input, and send replies on its
12767standard output. You could use this to run a stand-alone simulator
12768that speaks the remote debugging protocol, to make net connections
12769using programs like @code{ssh}, or for other similar tricks.
12770
12771If @var{command} closes its standard output (perhaps by exiting),
12772@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
12773program has already exited, this will have no effect.)
12774
86941c27 12775@end table
07f31aa6 12776
86941c27
JB
12777Once the connection has been established, you can use all the usual
12778commands to examine and change data and to step and continue the
12779remote program.
07f31aa6
DJ
12780
12781@cindex interrupting remote programs
12782@cindex remote programs, interrupting
12783Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 12784interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
12785program. This may or may not succeed, depending in part on the hardware
12786and the serial drivers the remote system uses. If you type the
12787interrupt character once again, @value{GDBN} displays this prompt:
12788
12789@smallexample
12790Interrupted while waiting for the program.
12791Give up (and stop debugging it)? (y or n)
12792@end smallexample
12793
12794If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
12795(If you decide you want to try again later, you can use @samp{target
12796remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
12797goes back to waiting.
12798
12799@table @code
12800@kindex detach (remote)
12801@item detach
12802When you have finished debugging the remote program, you can use the
12803@code{detach} command to release it from @value{GDBN} control.
12804Detaching from the target normally resumes its execution, but the results
12805will depend on your particular remote stub. After the @code{detach}
12806command, @value{GDBN} is free to connect to another target.
12807
12808@kindex disconnect
12809@item disconnect
12810The @code{disconnect} command behaves like @code{detach}, except that
12811the target is generally not resumed. It will wait for @value{GDBN}
12812(this instance or another one) to connect and continue debugging. After
12813the @code{disconnect} command, @value{GDBN} is again free to connect to
12814another target.
09d4efe1
EZ
12815
12816@cindex send command to remote monitor
fad38dfa
EZ
12817@cindex extend @value{GDBN} for remote targets
12818@cindex add new commands for external monitor
09d4efe1
EZ
12819@kindex monitor
12820@item monitor @var{cmd}
fad38dfa
EZ
12821This command allows you to send arbitrary commands directly to the
12822remote monitor. Since @value{GDBN} doesn't care about the commands it
12823sends like this, this command is the way to extend @value{GDBN}---you
12824can add new commands that only the external monitor will understand
12825and implement.
07f31aa6
DJ
12826@end table
12827
a6b151f1
DJ
12828@node File Transfer
12829@section Sending files to a remote system
12830@cindex remote target, file transfer
12831@cindex file transfer
12832@cindex sending files to remote systems
12833
12834Some remote targets offer the ability to transfer files over the same
12835connection used to communicate with @value{GDBN}. This is convenient
12836for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
12837running @code{gdbserver} over a network interface. For other targets,
12838e.g.@: embedded devices with only a single serial port, this may be
12839the only way to upload or download files.
12840
12841Not all remote targets support these commands.
12842
12843@table @code
12844@kindex remote put
12845@item remote put @var{hostfile} @var{targetfile}
12846Copy file @var{hostfile} from the host system (the machine running
12847@value{GDBN}) to @var{targetfile} on the target system.
12848
12849@kindex remote get
12850@item remote get @var{targetfile} @var{hostfile}
12851Copy file @var{targetfile} from the target system to @var{hostfile}
12852on the host system.
12853
12854@kindex remote delete
12855@item remote delete @var{targetfile}
12856Delete @var{targetfile} from the target system.
12857
12858@end table
12859
6f05cf9f 12860@node Server
79a6e687 12861@section Using the @code{gdbserver} Program
6f05cf9f
AC
12862
12863@kindex gdbserver
12864@cindex remote connection without stubs
12865@code{gdbserver} is a control program for Unix-like systems, which
12866allows you to connect your program with a remote @value{GDBN} via
12867@code{target remote}---but without linking in the usual debugging stub.
12868
12869@code{gdbserver} is not a complete replacement for the debugging stubs,
12870because it requires essentially the same operating-system facilities
12871that @value{GDBN} itself does. In fact, a system that can run
12872@code{gdbserver} to connect to a remote @value{GDBN} could also run
12873@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
12874because it is a much smaller program than @value{GDBN} itself. It is
12875also easier to port than all of @value{GDBN}, so you may be able to get
12876started more quickly on a new system by using @code{gdbserver}.
12877Finally, if you develop code for real-time systems, you may find that
12878the tradeoffs involved in real-time operation make it more convenient to
12879do as much development work as possible on another system, for example
12880by cross-compiling. You can use @code{gdbserver} to make a similar
12881choice for debugging.
12882
12883@value{GDBN} and @code{gdbserver} communicate via either a serial line
12884or a TCP connection, using the standard @value{GDBN} remote serial
12885protocol.
12886
12887@table @emph
12888@item On the target machine,
12889you need to have a copy of the program you want to debug.
12890@code{gdbserver} does not need your program's symbol table, so you can
12891strip the program if necessary to save space. @value{GDBN} on the host
12892system does all the symbol handling.
12893
12894To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 12895the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
12896syntax is:
12897
12898@smallexample
12899target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
12900@end smallexample
12901
12902@var{comm} is either a device name (to use a serial line) or a TCP
12903hostname and portnumber. For example, to debug Emacs with the argument
12904@samp{foo.txt} and communicate with @value{GDBN} over the serial port
12905@file{/dev/com1}:
12906
12907@smallexample
12908target> gdbserver /dev/com1 emacs foo.txt
12909@end smallexample
12910
12911@code{gdbserver} waits passively for the host @value{GDBN} to communicate
12912with it.
12913
12914To use a TCP connection instead of a serial line:
12915
12916@smallexample
12917target> gdbserver host:2345 emacs foo.txt
12918@end smallexample
12919
12920The only difference from the previous example is the first argument,
12921specifying that you are communicating with the host @value{GDBN} via
12922TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
12923expect a TCP connection from machine @samp{host} to local TCP port 2345.
12924(Currently, the @samp{host} part is ignored.) You can choose any number
12925you want for the port number as long as it does not conflict with any
12926TCP ports already in use on the target system (for example, @code{23} is
12927reserved for @code{telnet}).@footnote{If you choose a port number that
12928conflicts with another service, @code{gdbserver} prints an error message
12929and exits.} You must use the same port number with the host @value{GDBN}
12930@code{target remote} command.
12931
56460a61
DJ
12932On some targets, @code{gdbserver} can also attach to running programs.
12933This is accomplished via the @code{--attach} argument. The syntax is:
12934
12935@smallexample
12936target> gdbserver @var{comm} --attach @var{pid}
12937@end smallexample
12938
12939@var{pid} is the process ID of a currently running process. It isn't necessary
12940to point @code{gdbserver} at a binary for the running process.
12941
b1fe9455
DJ
12942@pindex pidof
12943@cindex attach to a program by name
12944You can debug processes by name instead of process ID if your target has the
12945@code{pidof} utility:
12946
12947@smallexample
f822c95b 12948target> gdbserver @var{comm} --attach `pidof @var{program}`
b1fe9455
DJ
12949@end smallexample
12950
f822c95b 12951In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
12952has multiple threads, most versions of @code{pidof} support the
12953@code{-s} option to only return the first process ID.
12954
07f31aa6 12955@item On the host machine,
f822c95b
DJ
12956first make sure you have the necessary symbol files. Load symbols for
12957your application using the @code{file} command before you connect. Use
12958@code{set sysroot} to locate target libraries (unless your @value{GDBN}
12959was compiled with the correct sysroot using @code{--with-system-root}).
12960
12961The symbol file and target libraries must exactly match the executable
12962and libraries on the target, with one exception: the files on the host
12963system should not be stripped, even if the files on the target system
12964are. Mismatched or missing files will lead to confusing results
12965during debugging. On @sc{gnu}/Linux targets, mismatched or missing
12966files may also prevent @code{gdbserver} from debugging multi-threaded
12967programs.
12968
79a6e687 12969Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
12970For TCP connections, you must start up @code{gdbserver} prior to using
12971the @code{target remote} command. Otherwise you may get an error whose
12972text depends on the host system, but which usually looks something like
07f31aa6 12973@samp{Connection refused}. You don't need to use the @code{load}
397ca115 12974command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 12975already on the target.
07f31aa6 12976
6f05cf9f
AC
12977@end table
12978
79a6e687 12979@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
12980@cindex monitor commands, for @code{gdbserver}
12981
12982During a @value{GDBN} session using @code{gdbserver}, you can use the
12983@code{monitor} command to send special requests to @code{gdbserver}.
12984Here are the available commands; they are only of interest when
12985debugging @value{GDBN} or @code{gdbserver}.
12986
12987@table @code
12988@item monitor help
12989List the available monitor commands.
12990
12991@item monitor set debug 0
12992@itemx monitor set debug 1
12993Disable or enable general debugging messages.
12994
12995@item monitor set remote-debug 0
12996@itemx monitor set remote-debug 1
12997Disable or enable specific debugging messages associated with the remote
12998protocol (@pxref{Remote Protocol}).
12999
13000@end table
13001
79a6e687
BW
13002@node Remote Configuration
13003@section Remote Configuration
501eef12 13004
9c16f35a
EZ
13005@kindex set remote
13006@kindex show remote
13007This section documents the configuration options available when
13008debugging remote programs. For the options related to the File I/O
fc320d37 13009extensions of the remote protocol, see @ref{system,
9c16f35a 13010system-call-allowed}.
501eef12
AC
13011
13012@table @code
9c16f35a 13013@item set remoteaddresssize @var{bits}
d3e8051b 13014@cindex address size for remote targets
9c16f35a
EZ
13015@cindex bits in remote address
13016Set the maximum size of address in a memory packet to the specified
13017number of bits. @value{GDBN} will mask off the address bits above
13018that number, when it passes addresses to the remote target. The
13019default value is the number of bits in the target's address.
13020
13021@item show remoteaddresssize
13022Show the current value of remote address size in bits.
13023
13024@item set remotebaud @var{n}
13025@cindex baud rate for remote targets
13026Set the baud rate for the remote serial I/O to @var{n} baud. The
13027value is used to set the speed of the serial port used for debugging
13028remote targets.
13029
13030@item show remotebaud
13031Show the current speed of the remote connection.
13032
13033@item set remotebreak
13034@cindex interrupt remote programs
13035@cindex BREAK signal instead of Ctrl-C
9a6253be 13036@anchor{set remotebreak}
9c16f35a 13037If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 13038when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 13039on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
13040character instead. The default is off, since most remote systems
13041expect to see @samp{Ctrl-C} as the interrupt signal.
13042
13043@item show remotebreak
13044Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
13045interrupt the remote program.
13046
23776285
MR
13047@item set remoteflow on
13048@itemx set remoteflow off
13049@kindex set remoteflow
13050Enable or disable hardware flow control (@code{RTS}/@code{CTS})
13051on the serial port used to communicate to the remote target.
13052
13053@item show remoteflow
13054@kindex show remoteflow
13055Show the current setting of hardware flow control.
13056
9c16f35a
EZ
13057@item set remotelogbase @var{base}
13058Set the base (a.k.a.@: radix) of logging serial protocol
13059communications to @var{base}. Supported values of @var{base} are:
13060@code{ascii}, @code{octal}, and @code{hex}. The default is
13061@code{ascii}.
13062
13063@item show remotelogbase
13064Show the current setting of the radix for logging remote serial
13065protocol.
13066
13067@item set remotelogfile @var{file}
13068@cindex record serial communications on file
13069Record remote serial communications on the named @var{file}. The
13070default is not to record at all.
13071
13072@item show remotelogfile.
13073Show the current setting of the file name on which to record the
13074serial communications.
13075
13076@item set remotetimeout @var{num}
13077@cindex timeout for serial communications
13078@cindex remote timeout
13079Set the timeout limit to wait for the remote target to respond to
13080@var{num} seconds. The default is 2 seconds.
13081
13082@item show remotetimeout
13083Show the current number of seconds to wait for the remote target
13084responses.
13085
13086@cindex limit hardware breakpoints and watchpoints
13087@cindex remote target, limit break- and watchpoints
501eef12
AC
13088@anchor{set remote hardware-watchpoint-limit}
13089@anchor{set remote hardware-breakpoint-limit}
13090@item set remote hardware-watchpoint-limit @var{limit}
13091@itemx set remote hardware-breakpoint-limit @var{limit}
13092Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
13093watchpoints. A limit of -1, the default, is treated as unlimited.
13094@end table
13095
427c3a89
DJ
13096@cindex remote packets, enabling and disabling
13097The @value{GDBN} remote protocol autodetects the packets supported by
13098your debugging stub. If you need to override the autodetection, you
13099can use these commands to enable or disable individual packets. Each
13100packet can be set to @samp{on} (the remote target supports this
13101packet), @samp{off} (the remote target does not support this packet),
13102or @samp{auto} (detect remote target support for this packet). They
13103all default to @samp{auto}. For more information about each packet,
13104see @ref{Remote Protocol}.
13105
13106During normal use, you should not have to use any of these commands.
13107If you do, that may be a bug in your remote debugging stub, or a bug
13108in @value{GDBN}. You may want to report the problem to the
13109@value{GDBN} developers.
13110
cfa9d6d9
DJ
13111For each packet @var{name}, the command to enable or disable the
13112packet is @code{set remote @var{name}-packet}. The available settings
13113are:
427c3a89 13114
cfa9d6d9 13115@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
13116@item Command Name
13117@tab Remote Packet
13118@tab Related Features
13119
cfa9d6d9 13120@item @code{fetch-register}
427c3a89
DJ
13121@tab @code{p}
13122@tab @code{info registers}
13123
cfa9d6d9 13124@item @code{set-register}
427c3a89
DJ
13125@tab @code{P}
13126@tab @code{set}
13127
cfa9d6d9 13128@item @code{binary-download}
427c3a89
DJ
13129@tab @code{X}
13130@tab @code{load}, @code{set}
13131
cfa9d6d9 13132@item @code{read-aux-vector}
427c3a89
DJ
13133@tab @code{qXfer:auxv:read}
13134@tab @code{info auxv}
13135
cfa9d6d9 13136@item @code{symbol-lookup}
427c3a89
DJ
13137@tab @code{qSymbol}
13138@tab Detecting multiple threads
13139
cfa9d6d9 13140@item @code{verbose-resume}
427c3a89
DJ
13141@tab @code{vCont}
13142@tab Stepping or resuming multiple threads
13143
cfa9d6d9 13144@item @code{software-breakpoint}
427c3a89
DJ
13145@tab @code{Z0}
13146@tab @code{break}
13147
cfa9d6d9 13148@item @code{hardware-breakpoint}
427c3a89
DJ
13149@tab @code{Z1}
13150@tab @code{hbreak}
13151
cfa9d6d9 13152@item @code{write-watchpoint}
427c3a89
DJ
13153@tab @code{Z2}
13154@tab @code{watch}
13155
cfa9d6d9 13156@item @code{read-watchpoint}
427c3a89
DJ
13157@tab @code{Z3}
13158@tab @code{rwatch}
13159
cfa9d6d9 13160@item @code{access-watchpoint}
427c3a89
DJ
13161@tab @code{Z4}
13162@tab @code{awatch}
13163
cfa9d6d9
DJ
13164@item @code{target-features}
13165@tab @code{qXfer:features:read}
13166@tab @code{set architecture}
13167
13168@item @code{library-info}
13169@tab @code{qXfer:libraries:read}
13170@tab @code{info sharedlibrary}
13171
13172@item @code{memory-map}
13173@tab @code{qXfer:memory-map:read}
13174@tab @code{info mem}
13175
13176@item @code{read-spu-object}
13177@tab @code{qXfer:spu:read}
13178@tab @code{info spu}
13179
13180@item @code{write-spu-object}
13181@tab @code{qXfer:spu:write}
13182@tab @code{info spu}
13183
13184@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
13185@tab @code{qGetTLSAddr}
13186@tab Displaying @code{__thread} variables
13187
13188@item @code{supported-packets}
13189@tab @code{qSupported}
13190@tab Remote communications parameters
13191
cfa9d6d9 13192@item @code{pass-signals}
89be2091
DJ
13193@tab @code{QPassSignals}
13194@tab @code{handle @var{signal}}
13195
a6b151f1
DJ
13196@item @code{hostio-close-packet}
13197@tab @code{vFile:close}
13198@tab @code{remote get}, @code{remote put}
13199
13200@item @code{hostio-open-packet}
13201@tab @code{vFile:open}
13202@tab @code{remote get}, @code{remote put}
13203
13204@item @code{hostio-pread-packet}
13205@tab @code{vFile:pread}
13206@tab @code{remote get}, @code{remote put}
13207
13208@item @code{hostio-pwrite-packet}
13209@tab @code{vFile:pwrite}
13210@tab @code{remote get}, @code{remote put}
13211
13212@item @code{hostio-unlink-packet}
13213@tab @code{vFile:unlink}
13214@tab @code{remote delete}
427c3a89
DJ
13215@end multitable
13216
79a6e687
BW
13217@node Remote Stub
13218@section Implementing a Remote Stub
7a292a7a 13219
8e04817f
AC
13220@cindex debugging stub, example
13221@cindex remote stub, example
13222@cindex stub example, remote debugging
13223The stub files provided with @value{GDBN} implement the target side of the
13224communication protocol, and the @value{GDBN} side is implemented in the
13225@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
13226these subroutines to communicate, and ignore the details. (If you're
13227implementing your own stub file, you can still ignore the details: start
13228with one of the existing stub files. @file{sparc-stub.c} is the best
13229organized, and therefore the easiest to read.)
13230
104c1213
JM
13231@cindex remote serial debugging, overview
13232To debug a program running on another machine (the debugging
13233@dfn{target} machine), you must first arrange for all the usual
13234prerequisites for the program to run by itself. For example, for a C
13235program, you need:
c906108c 13236
104c1213
JM
13237@enumerate
13238@item
13239A startup routine to set up the C runtime environment; these usually
13240have a name like @file{crt0}. The startup routine may be supplied by
13241your hardware supplier, or you may have to write your own.
96baa820 13242
5d161b24 13243@item
d4f3574e 13244A C subroutine library to support your program's
104c1213 13245subroutine calls, notably managing input and output.
96baa820 13246
104c1213
JM
13247@item
13248A way of getting your program to the other machine---for example, a
13249download program. These are often supplied by the hardware
13250manufacturer, but you may have to write your own from hardware
13251documentation.
13252@end enumerate
96baa820 13253
104c1213
JM
13254The next step is to arrange for your program to use a serial port to
13255communicate with the machine where @value{GDBN} is running (the @dfn{host}
13256machine). In general terms, the scheme looks like this:
96baa820 13257
104c1213
JM
13258@table @emph
13259@item On the host,
13260@value{GDBN} already understands how to use this protocol; when everything
13261else is set up, you can simply use the @samp{target remote} command
13262(@pxref{Targets,,Specifying a Debugging Target}).
13263
13264@item On the target,
13265you must link with your program a few special-purpose subroutines that
13266implement the @value{GDBN} remote serial protocol. The file containing these
13267subroutines is called a @dfn{debugging stub}.
13268
13269On certain remote targets, you can use an auxiliary program
13270@code{gdbserver} instead of linking a stub into your program.
79a6e687 13271@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 13272@end table
96baa820 13273
104c1213
JM
13274The debugging stub is specific to the architecture of the remote
13275machine; for example, use @file{sparc-stub.c} to debug programs on
13276@sc{sparc} boards.
96baa820 13277
104c1213
JM
13278@cindex remote serial stub list
13279These working remote stubs are distributed with @value{GDBN}:
96baa820 13280
104c1213
JM
13281@table @code
13282
13283@item i386-stub.c
41afff9a 13284@cindex @file{i386-stub.c}
104c1213
JM
13285@cindex Intel
13286@cindex i386
13287For Intel 386 and compatible architectures.
13288
13289@item m68k-stub.c
41afff9a 13290@cindex @file{m68k-stub.c}
104c1213
JM
13291@cindex Motorola 680x0
13292@cindex m680x0
13293For Motorola 680x0 architectures.
13294
13295@item sh-stub.c
41afff9a 13296@cindex @file{sh-stub.c}
172c2a43 13297@cindex Renesas
104c1213 13298@cindex SH
172c2a43 13299For Renesas SH architectures.
104c1213
JM
13300
13301@item sparc-stub.c
41afff9a 13302@cindex @file{sparc-stub.c}
104c1213
JM
13303@cindex Sparc
13304For @sc{sparc} architectures.
13305
13306@item sparcl-stub.c
41afff9a 13307@cindex @file{sparcl-stub.c}
104c1213
JM
13308@cindex Fujitsu
13309@cindex SparcLite
13310For Fujitsu @sc{sparclite} architectures.
13311
13312@end table
13313
13314The @file{README} file in the @value{GDBN} distribution may list other
13315recently added stubs.
13316
13317@menu
13318* Stub Contents:: What the stub can do for you
13319* Bootstrapping:: What you must do for the stub
13320* Debug Session:: Putting it all together
104c1213
JM
13321@end menu
13322
6d2ebf8b 13323@node Stub Contents
79a6e687 13324@subsection What the Stub Can Do for You
104c1213
JM
13325
13326@cindex remote serial stub
13327The debugging stub for your architecture supplies these three
13328subroutines:
13329
13330@table @code
13331@item set_debug_traps
4644b6e3 13332@findex set_debug_traps
104c1213
JM
13333@cindex remote serial stub, initialization
13334This routine arranges for @code{handle_exception} to run when your
13335program stops. You must call this subroutine explicitly near the
13336beginning of your program.
13337
13338@item handle_exception
4644b6e3 13339@findex handle_exception
104c1213
JM
13340@cindex remote serial stub, main routine
13341This is the central workhorse, but your program never calls it
13342explicitly---the setup code arranges for @code{handle_exception} to
13343run when a trap is triggered.
13344
13345@code{handle_exception} takes control when your program stops during
13346execution (for example, on a breakpoint), and mediates communications
13347with @value{GDBN} on the host machine. This is where the communications
13348protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 13349representative on the target machine. It begins by sending summary
104c1213
JM
13350information on the state of your program, then continues to execute,
13351retrieving and transmitting any information @value{GDBN} needs, until you
13352execute a @value{GDBN} command that makes your program resume; at that point,
13353@code{handle_exception} returns control to your own code on the target
5d161b24 13354machine.
104c1213
JM
13355
13356@item breakpoint
13357@cindex @code{breakpoint} subroutine, remote
13358Use this auxiliary subroutine to make your program contain a
13359breakpoint. Depending on the particular situation, this may be the only
13360way for @value{GDBN} to get control. For instance, if your target
13361machine has some sort of interrupt button, you won't need to call this;
13362pressing the interrupt button transfers control to
13363@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
13364simply receiving characters on the serial port may also trigger a trap;
13365again, in that situation, you don't need to call @code{breakpoint} from
13366your own program---simply running @samp{target remote} from the host
5d161b24 13367@value{GDBN} session gets control.
104c1213
JM
13368
13369Call @code{breakpoint} if none of these is true, or if you simply want
13370to make certain your program stops at a predetermined point for the
13371start of your debugging session.
13372@end table
13373
6d2ebf8b 13374@node Bootstrapping
79a6e687 13375@subsection What You Must Do for the Stub
104c1213
JM
13376
13377@cindex remote stub, support routines
13378The debugging stubs that come with @value{GDBN} are set up for a particular
13379chip architecture, but they have no information about the rest of your
13380debugging target machine.
13381
13382First of all you need to tell the stub how to communicate with the
13383serial port.
13384
13385@table @code
13386@item int getDebugChar()
4644b6e3 13387@findex getDebugChar
104c1213
JM
13388Write this subroutine to read a single character from the serial port.
13389It may be identical to @code{getchar} for your target system; a
13390different name is used to allow you to distinguish the two if you wish.
13391
13392@item void putDebugChar(int)
4644b6e3 13393@findex putDebugChar
104c1213 13394Write this subroutine to write a single character to the serial port.
5d161b24 13395It may be identical to @code{putchar} for your target system; a
104c1213
JM
13396different name is used to allow you to distinguish the two if you wish.
13397@end table
13398
13399@cindex control C, and remote debugging
13400@cindex interrupting remote targets
13401If you want @value{GDBN} to be able to stop your program while it is
13402running, you need to use an interrupt-driven serial driver, and arrange
13403for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
13404character). That is the character which @value{GDBN} uses to tell the
13405remote system to stop.
13406
13407Getting the debugging target to return the proper status to @value{GDBN}
13408probably requires changes to the standard stub; one quick and dirty way
13409is to just execute a breakpoint instruction (the ``dirty'' part is that
13410@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
13411
13412Other routines you need to supply are:
13413
13414@table @code
13415@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 13416@findex exceptionHandler
104c1213
JM
13417Write this function to install @var{exception_address} in the exception
13418handling tables. You need to do this because the stub does not have any
13419way of knowing what the exception handling tables on your target system
13420are like (for example, the processor's table might be in @sc{rom},
13421containing entries which point to a table in @sc{ram}).
13422@var{exception_number} is the exception number which should be changed;
13423its meaning is architecture-dependent (for example, different numbers
13424might represent divide by zero, misaligned access, etc). When this
13425exception occurs, control should be transferred directly to
13426@var{exception_address}, and the processor state (stack, registers,
13427and so on) should be just as it is when a processor exception occurs. So if
13428you want to use a jump instruction to reach @var{exception_address}, it
13429should be a simple jump, not a jump to subroutine.
13430
13431For the 386, @var{exception_address} should be installed as an interrupt
13432gate so that interrupts are masked while the handler runs. The gate
13433should be at privilege level 0 (the most privileged level). The
13434@sc{sparc} and 68k stubs are able to mask interrupts themselves without
13435help from @code{exceptionHandler}.
13436
13437@item void flush_i_cache()
4644b6e3 13438@findex flush_i_cache
d4f3574e 13439On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
13440instruction cache, if any, on your target machine. If there is no
13441instruction cache, this subroutine may be a no-op.
13442
13443On target machines that have instruction caches, @value{GDBN} requires this
13444function to make certain that the state of your program is stable.
13445@end table
13446
13447@noindent
13448You must also make sure this library routine is available:
13449
13450@table @code
13451@item void *memset(void *, int, int)
4644b6e3 13452@findex memset
104c1213
JM
13453This is the standard library function @code{memset} that sets an area of
13454memory to a known value. If you have one of the free versions of
13455@code{libc.a}, @code{memset} can be found there; otherwise, you must
13456either obtain it from your hardware manufacturer, or write your own.
13457@end table
13458
13459If you do not use the GNU C compiler, you may need other standard
13460library subroutines as well; this varies from one stub to another,
13461but in general the stubs are likely to use any of the common library
e22ea452 13462subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
13463
13464
6d2ebf8b 13465@node Debug Session
79a6e687 13466@subsection Putting it All Together
104c1213
JM
13467
13468@cindex remote serial debugging summary
13469In summary, when your program is ready to debug, you must follow these
13470steps.
13471
13472@enumerate
13473@item
6d2ebf8b 13474Make sure you have defined the supporting low-level routines
79a6e687 13475(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
13476@display
13477@code{getDebugChar}, @code{putDebugChar},
13478@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
13479@end display
13480
13481@item
13482Insert these lines near the top of your program:
13483
474c8240 13484@smallexample
104c1213
JM
13485set_debug_traps();
13486breakpoint();
474c8240 13487@end smallexample
104c1213
JM
13488
13489@item
13490For the 680x0 stub only, you need to provide a variable called
13491@code{exceptionHook}. Normally you just use:
13492
474c8240 13493@smallexample
104c1213 13494void (*exceptionHook)() = 0;
474c8240 13495@end smallexample
104c1213 13496
d4f3574e 13497@noindent
104c1213 13498but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 13499function in your program, that function is called when
104c1213
JM
13500@code{@value{GDBN}} continues after stopping on a trap (for example, bus
13501error). The function indicated by @code{exceptionHook} is called with
13502one parameter: an @code{int} which is the exception number.
13503
13504@item
13505Compile and link together: your program, the @value{GDBN} debugging stub for
13506your target architecture, and the supporting subroutines.
13507
13508@item
13509Make sure you have a serial connection between your target machine and
13510the @value{GDBN} host, and identify the serial port on the host.
13511
13512@item
13513@c The "remote" target now provides a `load' command, so we should
13514@c document that. FIXME.
13515Download your program to your target machine (or get it there by
13516whatever means the manufacturer provides), and start it.
13517
13518@item
07f31aa6 13519Start @value{GDBN} on the host, and connect to the target
79a6e687 13520(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 13521
104c1213
JM
13522@end enumerate
13523
8e04817f
AC
13524@node Configurations
13525@chapter Configuration-Specific Information
104c1213 13526
8e04817f
AC
13527While nearly all @value{GDBN} commands are available for all native and
13528cross versions of the debugger, there are some exceptions. This chapter
13529describes things that are only available in certain configurations.
104c1213 13530
8e04817f
AC
13531There are three major categories of configurations: native
13532configurations, where the host and target are the same, embedded
13533operating system configurations, which are usually the same for several
13534different processor architectures, and bare embedded processors, which
13535are quite different from each other.
104c1213 13536
8e04817f
AC
13537@menu
13538* Native::
13539* Embedded OS::
13540* Embedded Processors::
13541* Architectures::
13542@end menu
104c1213 13543
8e04817f
AC
13544@node Native
13545@section Native
104c1213 13546
8e04817f
AC
13547This section describes details specific to particular native
13548configurations.
6cf7e474 13549
8e04817f
AC
13550@menu
13551* HP-UX:: HP-UX
7561d450 13552* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
13553* SVR4 Process Information:: SVR4 process information
13554* DJGPP Native:: Features specific to the DJGPP port
78c47bea 13555* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 13556* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 13557* Neutrino:: Features specific to QNX Neutrino
8e04817f 13558@end menu
6cf7e474 13559
8e04817f
AC
13560@node HP-UX
13561@subsection HP-UX
104c1213 13562
8e04817f
AC
13563On HP-UX systems, if you refer to a function or variable name that
13564begins with a dollar sign, @value{GDBN} searches for a user or system
13565name first, before it searches for a convenience variable.
104c1213 13566
9c16f35a 13567
7561d450
MK
13568@node BSD libkvm Interface
13569@subsection BSD libkvm Interface
13570
13571@cindex libkvm
13572@cindex kernel memory image
13573@cindex kernel crash dump
13574
13575BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
13576interface that provides a uniform interface for accessing kernel virtual
13577memory images, including live systems and crash dumps. @value{GDBN}
13578uses this interface to allow you to debug live kernels and kernel crash
13579dumps on many native BSD configurations. This is implemented as a
13580special @code{kvm} debugging target. For debugging a live system, load
13581the currently running kernel into @value{GDBN} and connect to the
13582@code{kvm} target:
13583
13584@smallexample
13585(@value{GDBP}) @b{target kvm}
13586@end smallexample
13587
13588For debugging crash dumps, provide the file name of the crash dump as an
13589argument:
13590
13591@smallexample
13592(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
13593@end smallexample
13594
13595Once connected to the @code{kvm} target, the following commands are
13596available:
13597
13598@table @code
13599@kindex kvm
13600@item kvm pcb
721c2651 13601Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
13602
13603@item kvm proc
13604Set current context from proc address. This command isn't available on
13605modern FreeBSD systems.
13606@end table
13607
8e04817f 13608@node SVR4 Process Information
79a6e687 13609@subsection SVR4 Process Information
60bf7e09
EZ
13610@cindex /proc
13611@cindex examine process image
13612@cindex process info via @file{/proc}
104c1213 13613
60bf7e09
EZ
13614Many versions of SVR4 and compatible systems provide a facility called
13615@samp{/proc} that can be used to examine the image of a running
13616process using file-system subroutines. If @value{GDBN} is configured
13617for an operating system with this facility, the command @code{info
13618proc} is available to report information about the process running
13619your program, or about any process running on your system. @code{info
13620proc} works only on SVR4 systems that include the @code{procfs} code.
13621This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
13622Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 13623
8e04817f
AC
13624@table @code
13625@kindex info proc
60bf7e09 13626@cindex process ID
8e04817f 13627@item info proc
60bf7e09
EZ
13628@itemx info proc @var{process-id}
13629Summarize available information about any running process. If a
13630process ID is specified by @var{process-id}, display information about
13631that process; otherwise display information about the program being
13632debugged. The summary includes the debugged process ID, the command
13633line used to invoke it, its current working directory, and its
13634executable file's absolute file name.
13635
13636On some systems, @var{process-id} can be of the form
13637@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
13638within a process. If the optional @var{pid} part is missing, it means
13639a thread from the process being debugged (the leading @samp{/} still
13640needs to be present, or else @value{GDBN} will interpret the number as
13641a process ID rather than a thread ID).
6cf7e474 13642
8e04817f 13643@item info proc mappings
60bf7e09
EZ
13644@cindex memory address space mappings
13645Report the memory address space ranges accessible in the program, with
13646information on whether the process has read, write, or execute access
13647rights to each range. On @sc{gnu}/Linux systems, each memory range
13648includes the object file which is mapped to that range, instead of the
13649memory access rights to that range.
13650
13651@item info proc stat
13652@itemx info proc status
13653@cindex process detailed status information
13654These subcommands are specific to @sc{gnu}/Linux systems. They show
13655the process-related information, including the user ID and group ID;
13656how many threads are there in the process; its virtual memory usage;
13657the signals that are pending, blocked, and ignored; its TTY; its
13658consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 13659value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
13660(type @kbd{man 5 proc} from your shell prompt).
13661
13662@item info proc all
13663Show all the information about the process described under all of the
13664above @code{info proc} subcommands.
13665
8e04817f
AC
13666@ignore
13667@comment These sub-options of 'info proc' were not included when
13668@comment procfs.c was re-written. Keep their descriptions around
13669@comment against the day when someone finds the time to put them back in.
13670@kindex info proc times
13671@item info proc times
13672Starting time, user CPU time, and system CPU time for your program and
13673its children.
6cf7e474 13674
8e04817f
AC
13675@kindex info proc id
13676@item info proc id
13677Report on the process IDs related to your program: its own process ID,
13678the ID of its parent, the process group ID, and the session ID.
8e04817f 13679@end ignore
721c2651
EZ
13680
13681@item set procfs-trace
13682@kindex set procfs-trace
13683@cindex @code{procfs} API calls
13684This command enables and disables tracing of @code{procfs} API calls.
13685
13686@item show procfs-trace
13687@kindex show procfs-trace
13688Show the current state of @code{procfs} API call tracing.
13689
13690@item set procfs-file @var{file}
13691@kindex set procfs-file
13692Tell @value{GDBN} to write @code{procfs} API trace to the named
13693@var{file}. @value{GDBN} appends the trace info to the previous
13694contents of the file. The default is to display the trace on the
13695standard output.
13696
13697@item show procfs-file
13698@kindex show procfs-file
13699Show the file to which @code{procfs} API trace is written.
13700
13701@item proc-trace-entry
13702@itemx proc-trace-exit
13703@itemx proc-untrace-entry
13704@itemx proc-untrace-exit
13705@kindex proc-trace-entry
13706@kindex proc-trace-exit
13707@kindex proc-untrace-entry
13708@kindex proc-untrace-exit
13709These commands enable and disable tracing of entries into and exits
13710from the @code{syscall} interface.
13711
13712@item info pidlist
13713@kindex info pidlist
13714@cindex process list, QNX Neutrino
13715For QNX Neutrino only, this command displays the list of all the
13716processes and all the threads within each process.
13717
13718@item info meminfo
13719@kindex info meminfo
13720@cindex mapinfo list, QNX Neutrino
13721For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 13722@end table
104c1213 13723
8e04817f
AC
13724@node DJGPP Native
13725@subsection Features for Debugging @sc{djgpp} Programs
13726@cindex @sc{djgpp} debugging
13727@cindex native @sc{djgpp} debugging
13728@cindex MS-DOS-specific commands
104c1213 13729
514c4d71
EZ
13730@cindex DPMI
13731@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
13732MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
13733that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
13734top of real-mode DOS systems and their emulations.
104c1213 13735
8e04817f
AC
13736@value{GDBN} supports native debugging of @sc{djgpp} programs, and
13737defines a few commands specific to the @sc{djgpp} port. This
13738subsection describes those commands.
104c1213 13739
8e04817f
AC
13740@table @code
13741@kindex info dos
13742@item info dos
13743This is a prefix of @sc{djgpp}-specific commands which print
13744information about the target system and important OS structures.
f1251bdd 13745
8e04817f
AC
13746@kindex sysinfo
13747@cindex MS-DOS system info
13748@cindex free memory information (MS-DOS)
13749@item info dos sysinfo
13750This command displays assorted information about the underlying
13751platform: the CPU type and features, the OS version and flavor, the
13752DPMI version, and the available conventional and DPMI memory.
104c1213 13753
8e04817f
AC
13754@cindex GDT
13755@cindex LDT
13756@cindex IDT
13757@cindex segment descriptor tables
13758@cindex descriptor tables display
13759@item info dos gdt
13760@itemx info dos ldt
13761@itemx info dos idt
13762These 3 commands display entries from, respectively, Global, Local,
13763and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
13764tables are data structures which store a descriptor for each segment
13765that is currently in use. The segment's selector is an index into a
13766descriptor table; the table entry for that index holds the
13767descriptor's base address and limit, and its attributes and access
13768rights.
104c1213 13769
8e04817f
AC
13770A typical @sc{djgpp} program uses 3 segments: a code segment, a data
13771segment (used for both data and the stack), and a DOS segment (which
13772allows access to DOS/BIOS data structures and absolute addresses in
13773conventional memory). However, the DPMI host will usually define
13774additional segments in order to support the DPMI environment.
d4f3574e 13775
8e04817f
AC
13776@cindex garbled pointers
13777These commands allow to display entries from the descriptor tables.
13778Without an argument, all entries from the specified table are
13779displayed. An argument, which should be an integer expression, means
13780display a single entry whose index is given by the argument. For
13781example, here's a convenient way to display information about the
13782debugged program's data segment:
104c1213 13783
8e04817f
AC
13784@smallexample
13785@exdent @code{(@value{GDBP}) info dos ldt $ds}
13786@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
13787@end smallexample
104c1213 13788
8e04817f
AC
13789@noindent
13790This comes in handy when you want to see whether a pointer is outside
13791the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 13792
8e04817f
AC
13793@cindex page tables display (MS-DOS)
13794@item info dos pde
13795@itemx info dos pte
13796These two commands display entries from, respectively, the Page
13797Directory and the Page Tables. Page Directories and Page Tables are
13798data structures which control how virtual memory addresses are mapped
13799into physical addresses. A Page Table includes an entry for every
13800page of memory that is mapped into the program's address space; there
13801may be several Page Tables, each one holding up to 4096 entries. A
13802Page Directory has up to 4096 entries, one each for every Page Table
13803that is currently in use.
104c1213 13804
8e04817f
AC
13805Without an argument, @kbd{info dos pde} displays the entire Page
13806Directory, and @kbd{info dos pte} displays all the entries in all of
13807the Page Tables. An argument, an integer expression, given to the
13808@kbd{info dos pde} command means display only that entry from the Page
13809Directory table. An argument given to the @kbd{info dos pte} command
13810means display entries from a single Page Table, the one pointed to by
13811the specified entry in the Page Directory.
104c1213 13812
8e04817f
AC
13813@cindex direct memory access (DMA) on MS-DOS
13814These commands are useful when your program uses @dfn{DMA} (Direct
13815Memory Access), which needs physical addresses to program the DMA
13816controller.
104c1213 13817
8e04817f 13818These commands are supported only with some DPMI servers.
104c1213 13819
8e04817f
AC
13820@cindex physical address from linear address
13821@item info dos address-pte @var{addr}
13822This command displays the Page Table entry for a specified linear
514c4d71
EZ
13823address. The argument @var{addr} is a linear address which should
13824already have the appropriate segment's base address added to it,
13825because this command accepts addresses which may belong to @emph{any}
13826segment. For example, here's how to display the Page Table entry for
13827the page where a variable @code{i} is stored:
104c1213 13828
b383017d 13829@smallexample
8e04817f
AC
13830@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
13831@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 13832@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 13833@end smallexample
104c1213 13834
8e04817f
AC
13835@noindent
13836This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 13837whose physical base address is @code{0x02698000}, and shows all the
8e04817f 13838attributes of that page.
104c1213 13839
8e04817f
AC
13840Note that you must cast the addresses of variables to a @code{char *},
13841since otherwise the value of @code{__djgpp_base_address}, the base
13842address of all variables and functions in a @sc{djgpp} program, will
13843be added using the rules of C pointer arithmetics: if @code{i} is
13844declared an @code{int}, @value{GDBN} will add 4 times the value of
13845@code{__djgpp_base_address} to the address of @code{i}.
104c1213 13846
8e04817f
AC
13847Here's another example, it displays the Page Table entry for the
13848transfer buffer:
104c1213 13849
8e04817f
AC
13850@smallexample
13851@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
13852@exdent @code{Page Table entry for address 0x29110:}
13853@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
13854@end smallexample
104c1213 13855
8e04817f
AC
13856@noindent
13857(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
138583rd member of the @code{_go32_info_block} structure.) The output
13859clearly shows that this DPMI server maps the addresses in conventional
13860memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
13861linear (@code{0x29110}) addresses are identical.
104c1213 13862
8e04817f
AC
13863This command is supported only with some DPMI servers.
13864@end table
104c1213 13865
c45da7e6 13866@cindex DOS serial data link, remote debugging
a8f24a35
EZ
13867In addition to native debugging, the DJGPP port supports remote
13868debugging via a serial data link. The following commands are specific
13869to remote serial debugging in the DJGPP port of @value{GDBN}.
13870
13871@table @code
13872@kindex set com1base
13873@kindex set com1irq
13874@kindex set com2base
13875@kindex set com2irq
13876@kindex set com3base
13877@kindex set com3irq
13878@kindex set com4base
13879@kindex set com4irq
13880@item set com1base @var{addr}
13881This command sets the base I/O port address of the @file{COM1} serial
13882port.
13883
13884@item set com1irq @var{irq}
13885This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
13886for the @file{COM1} serial port.
13887
13888There are similar commands @samp{set com2base}, @samp{set com3irq},
13889etc.@: for setting the port address and the @code{IRQ} lines for the
13890other 3 COM ports.
13891
13892@kindex show com1base
13893@kindex show com1irq
13894@kindex show com2base
13895@kindex show com2irq
13896@kindex show com3base
13897@kindex show com3irq
13898@kindex show com4base
13899@kindex show com4irq
13900The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
13901display the current settings of the base address and the @code{IRQ}
13902lines used by the COM ports.
c45da7e6
EZ
13903
13904@item info serial
13905@kindex info serial
13906@cindex DOS serial port status
13907This command prints the status of the 4 DOS serial ports. For each
13908port, it prints whether it's active or not, its I/O base address and
13909IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
13910counts of various errors encountered so far.
a8f24a35
EZ
13911@end table
13912
13913
78c47bea 13914@node Cygwin Native
79a6e687 13915@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
13916@cindex MS Windows debugging
13917@cindex native Cygwin debugging
13918@cindex Cygwin-specific commands
13919
be448670 13920@value{GDBN} supports native debugging of MS Windows programs, including
db2e3e2e
BW
13921DLLs with and without symbolic debugging information. There are various
13922additional Cygwin-specific commands, described in this section.
13923Working with DLLs that have no debugging symbols is described in
13924@ref{Non-debug DLL Symbols}.
78c47bea
PM
13925
13926@table @code
13927@kindex info w32
13928@item info w32
db2e3e2e 13929This is a prefix of MS Windows-specific commands which print
78c47bea
PM
13930information about the target system and important OS structures.
13931
13932@item info w32 selector
13933This command displays information returned by
13934the Win32 API @code{GetThreadSelectorEntry} function.
13935It takes an optional argument that is evaluated to
13936a long value to give the information about this given selector.
13937Without argument, this command displays information
d3e8051b 13938about the six segment registers.
78c47bea
PM
13939
13940@kindex info dll
13941@item info dll
db2e3e2e 13942This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
13943
13944@kindex dll-symbols
13945@item dll-symbols
13946This command loads symbols from a dll similarly to
13947add-sym command but without the need to specify a base address.
13948
be90c084 13949@kindex set cygwin-exceptions
e16b02ee
EZ
13950@cindex debugging the Cygwin DLL
13951@cindex Cygwin DLL, debugging
be90c084 13952@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
13953If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
13954happen inside the Cygwin DLL. If @var{mode} is @code{off},
13955@value{GDBN} will delay recognition of exceptions, and may ignore some
13956exceptions which seem to be caused by internal Cygwin DLL
13957``bookkeeping''. This option is meant primarily for debugging the
13958Cygwin DLL itself; the default value is @code{off} to avoid annoying
13959@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
13960
13961@kindex show cygwin-exceptions
13962@item show cygwin-exceptions
e16b02ee
EZ
13963Displays whether @value{GDBN} will break on exceptions that happen
13964inside the Cygwin DLL itself.
be90c084 13965
b383017d 13966@kindex set new-console
78c47bea 13967@item set new-console @var{mode}
b383017d 13968If @var{mode} is @code{on} the debuggee will
78c47bea
PM
13969be started in a new console on next start.
13970If @var{mode} is @code{off}i, the debuggee will
13971be started in the same console as the debugger.
13972
13973@kindex show new-console
13974@item show new-console
13975Displays whether a new console is used
13976when the debuggee is started.
13977
13978@kindex set new-group
13979@item set new-group @var{mode}
13980This boolean value controls whether the debuggee should
13981start a new group or stay in the same group as the debugger.
13982This affects the way the Windows OS handles
c8aa23ab 13983@samp{Ctrl-C}.
78c47bea
PM
13984
13985@kindex show new-group
13986@item show new-group
13987Displays current value of new-group boolean.
13988
13989@kindex set debugevents
13990@item set debugevents
219eec71
EZ
13991This boolean value adds debug output concerning kernel events related
13992to the debuggee seen by the debugger. This includes events that
13993signal thread and process creation and exit, DLL loading and
13994unloading, console interrupts, and debugging messages produced by the
13995Windows @code{OutputDebugString} API call.
78c47bea
PM
13996
13997@kindex set debugexec
13998@item set debugexec
b383017d 13999This boolean value adds debug output concerning execute events
219eec71 14000(such as resume thread) seen by the debugger.
78c47bea
PM
14001
14002@kindex set debugexceptions
14003@item set debugexceptions
219eec71
EZ
14004This boolean value adds debug output concerning exceptions in the
14005debuggee seen by the debugger.
78c47bea
PM
14006
14007@kindex set debugmemory
14008@item set debugmemory
219eec71
EZ
14009This boolean value adds debug output concerning debuggee memory reads
14010and writes by the debugger.
78c47bea
PM
14011
14012@kindex set shell
14013@item set shell
14014This boolean values specifies whether the debuggee is called
14015via a shell or directly (default value is on).
14016
14017@kindex show shell
14018@item show shell
14019Displays if the debuggee will be started with a shell.
14020
14021@end table
14022
be448670 14023@menu
79a6e687 14024* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
14025@end menu
14026
79a6e687
BW
14027@node Non-debug DLL Symbols
14028@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
14029@cindex DLLs with no debugging symbols
14030@cindex Minimal symbols and DLLs
14031
14032Very often on windows, some of the DLLs that your program relies on do
14033not include symbolic debugging information (for example,
db2e3e2e 14034@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 14035symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 14036information contained in the DLL's export table. This section
be448670
CF
14037describes working with such symbols, known internally to @value{GDBN} as
14038``minimal symbols''.
14039
14040Note that before the debugged program has started execution, no DLLs
db2e3e2e 14041will have been loaded. The easiest way around this problem is simply to
be448670 14042start the program --- either by setting a breakpoint or letting the
db2e3e2e 14043program run once to completion. It is also possible to force
be448670 14044@value{GDBN} to load a particular DLL before starting the executable ---
12c27660 14045see the shared library information in @ref{Files}, or the
db2e3e2e 14046@code{dll-symbols} command in @ref{Cygwin Native}. Currently,
be448670
CF
14047explicitly loading symbols from a DLL with no debugging information will
14048cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
14049which may adversely affect symbol lookup performance.
14050
79a6e687 14051@subsubsection DLL Name Prefixes
be448670
CF
14052
14053In keeping with the naming conventions used by the Microsoft debugging
14054tools, DLL export symbols are made available with a prefix based on the
14055DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
14056also entered into the symbol table, so @code{CreateFileA} is often
14057sufficient. In some cases there will be name clashes within a program
14058(particularly if the executable itself includes full debugging symbols)
14059necessitating the use of the fully qualified name when referring to the
14060contents of the DLL. Use single-quotes around the name to avoid the
14061exclamation mark (``!'') being interpreted as a language operator.
14062
14063Note that the internal name of the DLL may be all upper-case, even
14064though the file name of the DLL is lower-case, or vice-versa. Since
14065symbols within @value{GDBN} are @emph{case-sensitive} this may cause
14066some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
14067@code{info variables} commands or even @code{maint print msymbols}
14068(@pxref{Symbols}). Here's an example:
be448670
CF
14069
14070@smallexample
f7dc1244 14071(@value{GDBP}) info function CreateFileA
be448670
CF
14072All functions matching regular expression "CreateFileA":
14073
14074Non-debugging symbols:
140750x77e885f4 CreateFileA
140760x77e885f4 KERNEL32!CreateFileA
14077@end smallexample
14078
14079@smallexample
f7dc1244 14080(@value{GDBP}) info function !
be448670
CF
14081All functions matching regular expression "!":
14082
14083Non-debugging symbols:
140840x6100114c cygwin1!__assert
140850x61004034 cygwin1!_dll_crt0@@0
140860x61004240 cygwin1!dll_crt0(per_process *)
14087[etc...]
14088@end smallexample
14089
79a6e687 14090@subsubsection Working with Minimal Symbols
be448670
CF
14091
14092Symbols extracted from a DLL's export table do not contain very much
14093type information. All that @value{GDBN} can do is guess whether a symbol
14094refers to a function or variable depending on the linker section that
14095contains the symbol. Also note that the actual contents of the memory
14096contained in a DLL are not available unless the program is running. This
14097means that you cannot examine the contents of a variable or disassemble
14098a function within a DLL without a running program.
14099
14100Variables are generally treated as pointers and dereferenced
14101automatically. For this reason, it is often necessary to prefix a
14102variable name with the address-of operator (``&'') and provide explicit
14103type information in the command. Here's an example of the type of
14104problem:
14105
14106@smallexample
f7dc1244 14107(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
14108$1 = 268572168
14109@end smallexample
14110
14111@smallexample
f7dc1244 14112(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
141130x10021610: "\230y\""
14114@end smallexample
14115
14116And two possible solutions:
14117
14118@smallexample
f7dc1244 14119(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
14120$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
14121@end smallexample
14122
14123@smallexample
f7dc1244 14124(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 141250x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 14126(@value{GDBP}) x/x 0x10021608
be448670 141270x10021608: 0x0022fd98
f7dc1244 14128(@value{GDBP}) x/s 0x0022fd98
be448670
CF
141290x22fd98: "/cygdrive/c/mydirectory/myprogram"
14130@end smallexample
14131
14132Setting a break point within a DLL is possible even before the program
14133starts execution. However, under these circumstances, @value{GDBN} can't
14134examine the initial instructions of the function in order to skip the
14135function's frame set-up code. You can work around this by using ``*&''
14136to set the breakpoint at a raw memory address:
14137
14138@smallexample
f7dc1244 14139(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
14140Breakpoint 1 at 0x1e04eff0
14141@end smallexample
14142
14143The author of these extensions is not entirely convinced that setting a
14144break point within a shared DLL like @file{kernel32.dll} is completely
14145safe.
14146
14d6dd68 14147@node Hurd Native
79a6e687 14148@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
14149@cindex @sc{gnu} Hurd debugging
14150
14151This subsection describes @value{GDBN} commands specific to the
14152@sc{gnu} Hurd native debugging.
14153
14154@table @code
14155@item set signals
14156@itemx set sigs
14157@kindex set signals@r{, Hurd command}
14158@kindex set sigs@r{, Hurd command}
14159This command toggles the state of inferior signal interception by
14160@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
14161affected by this command. @code{sigs} is a shorthand alias for
14162@code{signals}.
14163
14164@item show signals
14165@itemx show sigs
14166@kindex show signals@r{, Hurd command}
14167@kindex show sigs@r{, Hurd command}
14168Show the current state of intercepting inferior's signals.
14169
14170@item set signal-thread
14171@itemx set sigthread
14172@kindex set signal-thread
14173@kindex set sigthread
14174This command tells @value{GDBN} which thread is the @code{libc} signal
14175thread. That thread is run when a signal is delivered to a running
14176process. @code{set sigthread} is the shorthand alias of @code{set
14177signal-thread}.
14178
14179@item show signal-thread
14180@itemx show sigthread
14181@kindex show signal-thread
14182@kindex show sigthread
14183These two commands show which thread will run when the inferior is
14184delivered a signal.
14185
14186@item set stopped
14187@kindex set stopped@r{, Hurd command}
14188This commands tells @value{GDBN} that the inferior process is stopped,
14189as with the @code{SIGSTOP} signal. The stopped process can be
14190continued by delivering a signal to it.
14191
14192@item show stopped
14193@kindex show stopped@r{, Hurd command}
14194This command shows whether @value{GDBN} thinks the debuggee is
14195stopped.
14196
14197@item set exceptions
14198@kindex set exceptions@r{, Hurd command}
14199Use this command to turn off trapping of exceptions in the inferior.
14200When exception trapping is off, neither breakpoints nor
14201single-stepping will work. To restore the default, set exception
14202trapping on.
14203
14204@item show exceptions
14205@kindex show exceptions@r{, Hurd command}
14206Show the current state of trapping exceptions in the inferior.
14207
14208@item set task pause
14209@kindex set task@r{, Hurd commands}
14210@cindex task attributes (@sc{gnu} Hurd)
14211@cindex pause current task (@sc{gnu} Hurd)
14212This command toggles task suspension when @value{GDBN} has control.
14213Setting it to on takes effect immediately, and the task is suspended
14214whenever @value{GDBN} gets control. Setting it to off will take
14215effect the next time the inferior is continued. If this option is set
14216to off, you can use @code{set thread default pause on} or @code{set
14217thread pause on} (see below) to pause individual threads.
14218
14219@item show task pause
14220@kindex show task@r{, Hurd commands}
14221Show the current state of task suspension.
14222
14223@item set task detach-suspend-count
14224@cindex task suspend count
14225@cindex detach from task, @sc{gnu} Hurd
14226This command sets the suspend count the task will be left with when
14227@value{GDBN} detaches from it.
14228
14229@item show task detach-suspend-count
14230Show the suspend count the task will be left with when detaching.
14231
14232@item set task exception-port
14233@itemx set task excp
14234@cindex task exception port, @sc{gnu} Hurd
14235This command sets the task exception port to which @value{GDBN} will
14236forward exceptions. The argument should be the value of the @dfn{send
14237rights} of the task. @code{set task excp} is a shorthand alias.
14238
14239@item set noninvasive
14240@cindex noninvasive task options
14241This command switches @value{GDBN} to a mode that is the least
14242invasive as far as interfering with the inferior is concerned. This
14243is the same as using @code{set task pause}, @code{set exceptions}, and
14244@code{set signals} to values opposite to the defaults.
14245
14246@item info send-rights
14247@itemx info receive-rights
14248@itemx info port-rights
14249@itemx info port-sets
14250@itemx info dead-names
14251@itemx info ports
14252@itemx info psets
14253@cindex send rights, @sc{gnu} Hurd
14254@cindex receive rights, @sc{gnu} Hurd
14255@cindex port rights, @sc{gnu} Hurd
14256@cindex port sets, @sc{gnu} Hurd
14257@cindex dead names, @sc{gnu} Hurd
14258These commands display information about, respectively, send rights,
14259receive rights, port rights, port sets, and dead names of a task.
14260There are also shorthand aliases: @code{info ports} for @code{info
14261port-rights} and @code{info psets} for @code{info port-sets}.
14262
14263@item set thread pause
14264@kindex set thread@r{, Hurd command}
14265@cindex thread properties, @sc{gnu} Hurd
14266@cindex pause current thread (@sc{gnu} Hurd)
14267This command toggles current thread suspension when @value{GDBN} has
14268control. Setting it to on takes effect immediately, and the current
14269thread is suspended whenever @value{GDBN} gets control. Setting it to
14270off will take effect the next time the inferior is continued.
14271Normally, this command has no effect, since when @value{GDBN} has
14272control, the whole task is suspended. However, if you used @code{set
14273task pause off} (see above), this command comes in handy to suspend
14274only the current thread.
14275
14276@item show thread pause
14277@kindex show thread@r{, Hurd command}
14278This command shows the state of current thread suspension.
14279
14280@item set thread run
d3e8051b 14281This command sets whether the current thread is allowed to run.
14d6dd68
EZ
14282
14283@item show thread run
14284Show whether the current thread is allowed to run.
14285
14286@item set thread detach-suspend-count
14287@cindex thread suspend count, @sc{gnu} Hurd
14288@cindex detach from thread, @sc{gnu} Hurd
14289This command sets the suspend count @value{GDBN} will leave on a
14290thread when detaching. This number is relative to the suspend count
14291found by @value{GDBN} when it notices the thread; use @code{set thread
14292takeover-suspend-count} to force it to an absolute value.
14293
14294@item show thread detach-suspend-count
14295Show the suspend count @value{GDBN} will leave on the thread when
14296detaching.
14297
14298@item set thread exception-port
14299@itemx set thread excp
14300Set the thread exception port to which to forward exceptions. This
14301overrides the port set by @code{set task exception-port} (see above).
14302@code{set thread excp} is the shorthand alias.
14303
14304@item set thread takeover-suspend-count
14305Normally, @value{GDBN}'s thread suspend counts are relative to the
14306value @value{GDBN} finds when it notices each thread. This command
14307changes the suspend counts to be absolute instead.
14308
14309@item set thread default
14310@itemx show thread default
14311@cindex thread default settings, @sc{gnu} Hurd
14312Each of the above @code{set thread} commands has a @code{set thread
14313default} counterpart (e.g., @code{set thread default pause}, @code{set
14314thread default exception-port}, etc.). The @code{thread default}
14315variety of commands sets the default thread properties for all
14316threads; you can then change the properties of individual threads with
14317the non-default commands.
14318@end table
14319
14320
a64548ea
EZ
14321@node Neutrino
14322@subsection QNX Neutrino
14323@cindex QNX Neutrino
14324
14325@value{GDBN} provides the following commands specific to the QNX
14326Neutrino target:
14327
14328@table @code
14329@item set debug nto-debug
14330@kindex set debug nto-debug
14331When set to on, enables debugging messages specific to the QNX
14332Neutrino support.
14333
14334@item show debug nto-debug
14335@kindex show debug nto-debug
14336Show the current state of QNX Neutrino messages.
14337@end table
14338
14339
8e04817f
AC
14340@node Embedded OS
14341@section Embedded Operating Systems
104c1213 14342
8e04817f
AC
14343This section describes configurations involving the debugging of
14344embedded operating systems that are available for several different
14345architectures.
d4f3574e 14346
8e04817f
AC
14347@menu
14348* VxWorks:: Using @value{GDBN} with VxWorks
14349@end menu
104c1213 14350
8e04817f
AC
14351@value{GDBN} includes the ability to debug programs running on
14352various real-time operating systems.
104c1213 14353
8e04817f
AC
14354@node VxWorks
14355@subsection Using @value{GDBN} with VxWorks
104c1213 14356
8e04817f 14357@cindex VxWorks
104c1213 14358
8e04817f 14359@table @code
104c1213 14360
8e04817f
AC
14361@kindex target vxworks
14362@item target vxworks @var{machinename}
14363A VxWorks system, attached via TCP/IP. The argument @var{machinename}
14364is the target system's machine name or IP address.
104c1213 14365
8e04817f 14366@end table
104c1213 14367
8e04817f
AC
14368On VxWorks, @code{load} links @var{filename} dynamically on the
14369current target system as well as adding its symbols in @value{GDBN}.
104c1213 14370
8e04817f
AC
14371@value{GDBN} enables developers to spawn and debug tasks running on networked
14372VxWorks targets from a Unix host. Already-running tasks spawned from
14373the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
14374both the Unix host and on the VxWorks target. The program
14375@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
14376installed with the name @code{vxgdb}, to distinguish it from a
14377@value{GDBN} for debugging programs on the host itself.)
104c1213 14378
8e04817f
AC
14379@table @code
14380@item VxWorks-timeout @var{args}
14381@kindex vxworks-timeout
14382All VxWorks-based targets now support the option @code{vxworks-timeout}.
14383This option is set by the user, and @var{args} represents the number of
14384seconds @value{GDBN} waits for responses to rpc's. You might use this if
14385your VxWorks target is a slow software simulator or is on the far side
14386of a thin network line.
14387@end table
104c1213 14388
8e04817f
AC
14389The following information on connecting to VxWorks was current when
14390this manual was produced; newer releases of VxWorks may use revised
14391procedures.
104c1213 14392
4644b6e3 14393@findex INCLUDE_RDB
8e04817f
AC
14394To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
14395to include the remote debugging interface routines in the VxWorks
14396library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
14397VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
14398kernel. The resulting kernel contains @file{rdb.a}, and spawns the
14399source debugging task @code{tRdbTask} when VxWorks is booted. For more
14400information on configuring and remaking VxWorks, see the manufacturer's
14401manual.
14402@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 14403
8e04817f
AC
14404Once you have included @file{rdb.a} in your VxWorks system image and set
14405your Unix execution search path to find @value{GDBN}, you are ready to
14406run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
14407@code{vxgdb}, depending on your installation).
104c1213 14408
8e04817f 14409@value{GDBN} comes up showing the prompt:
104c1213 14410
474c8240 14411@smallexample
8e04817f 14412(vxgdb)
474c8240 14413@end smallexample
104c1213 14414
8e04817f
AC
14415@menu
14416* VxWorks Connection:: Connecting to VxWorks
14417* VxWorks Download:: VxWorks download
14418* VxWorks Attach:: Running tasks
14419@end menu
104c1213 14420
8e04817f
AC
14421@node VxWorks Connection
14422@subsubsection Connecting to VxWorks
104c1213 14423
8e04817f
AC
14424The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
14425network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 14426
474c8240 14427@smallexample
8e04817f 14428(vxgdb) target vxworks tt
474c8240 14429@end smallexample
104c1213 14430
8e04817f
AC
14431@need 750
14432@value{GDBN} displays messages like these:
104c1213 14433
8e04817f
AC
14434@smallexample
14435Attaching remote machine across net...
14436Connected to tt.
14437@end smallexample
104c1213 14438
8e04817f
AC
14439@need 1000
14440@value{GDBN} then attempts to read the symbol tables of any object modules
14441loaded into the VxWorks target since it was last booted. @value{GDBN} locates
14442these files by searching the directories listed in the command search
79a6e687 14443path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 14444to find an object file, it displays a message such as:
5d161b24 14445
474c8240 14446@smallexample
8e04817f 14447prog.o: No such file or directory.
474c8240 14448@end smallexample
104c1213 14449
8e04817f
AC
14450When this happens, add the appropriate directory to the search path with
14451the @value{GDBN} command @code{path}, and execute the @code{target}
14452command again.
104c1213 14453
8e04817f 14454@node VxWorks Download
79a6e687 14455@subsubsection VxWorks Download
104c1213 14456
8e04817f
AC
14457@cindex download to VxWorks
14458If you have connected to the VxWorks target and you want to debug an
14459object that has not yet been loaded, you can use the @value{GDBN}
14460@code{load} command to download a file from Unix to VxWorks
14461incrementally. The object file given as an argument to the @code{load}
14462command is actually opened twice: first by the VxWorks target in order
14463to download the code, then by @value{GDBN} in order to read the symbol
14464table. This can lead to problems if the current working directories on
14465the two systems differ. If both systems have NFS mounted the same
14466filesystems, you can avoid these problems by using absolute paths.
14467Otherwise, it is simplest to set the working directory on both systems
14468to the directory in which the object file resides, and then to reference
14469the file by its name, without any path. For instance, a program
14470@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
14471and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
14472program, type this on VxWorks:
104c1213 14473
474c8240 14474@smallexample
8e04817f 14475-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 14476@end smallexample
104c1213 14477
8e04817f
AC
14478@noindent
14479Then, in @value{GDBN}, type:
104c1213 14480
474c8240 14481@smallexample
8e04817f
AC
14482(vxgdb) cd @var{hostpath}/vw/demo/rdb
14483(vxgdb) load prog.o
474c8240 14484@end smallexample
104c1213 14485
8e04817f 14486@value{GDBN} displays a response similar to this:
104c1213 14487
8e04817f
AC
14488@smallexample
14489Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
14490@end smallexample
104c1213 14491
8e04817f
AC
14492You can also use the @code{load} command to reload an object module
14493after editing and recompiling the corresponding source file. Note that
14494this makes @value{GDBN} delete all currently-defined breakpoints,
14495auto-displays, and convenience variables, and to clear the value
14496history. (This is necessary in order to preserve the integrity of
14497debugger's data structures that reference the target system's symbol
14498table.)
104c1213 14499
8e04817f 14500@node VxWorks Attach
79a6e687 14501@subsubsection Running Tasks
104c1213
JM
14502
14503@cindex running VxWorks tasks
14504You can also attach to an existing task using the @code{attach} command as
14505follows:
14506
474c8240 14507@smallexample
104c1213 14508(vxgdb) attach @var{task}
474c8240 14509@end smallexample
104c1213
JM
14510
14511@noindent
14512where @var{task} is the VxWorks hexadecimal task ID. The task can be running
14513or suspended when you attach to it. Running tasks are suspended at
14514the time of attachment.
14515
6d2ebf8b 14516@node Embedded Processors
104c1213
JM
14517@section Embedded Processors
14518
14519This section goes into details specific to particular embedded
14520configurations.
14521
c45da7e6
EZ
14522@cindex send command to simulator
14523Whenever a specific embedded processor has a simulator, @value{GDBN}
14524allows to send an arbitrary command to the simulator.
14525
14526@table @code
14527@item sim @var{command}
14528@kindex sim@r{, a command}
14529Send an arbitrary @var{command} string to the simulator. Consult the
14530documentation for the specific simulator in use for information about
14531acceptable commands.
14532@end table
14533
7d86b5d5 14534
104c1213 14535@menu
c45da7e6 14536* ARM:: ARM RDI
172c2a43 14537* M32R/D:: Renesas M32R/D
104c1213 14538* M68K:: Motorola M68K
104c1213 14539* MIPS Embedded:: MIPS Embedded
a37295f9 14540* OpenRISC 1000:: OpenRisc 1000
104c1213 14541* PA:: HP PA Embedded
0869d01b 14542* PowerPC:: PowerPC
104c1213
JM
14543* Sparclet:: Tsqware Sparclet
14544* Sparclite:: Fujitsu Sparclite
104c1213 14545* Z8000:: Zilog Z8000
a64548ea
EZ
14546* AVR:: Atmel AVR
14547* CRIS:: CRIS
14548* Super-H:: Renesas Super-H
104c1213
JM
14549@end menu
14550
6d2ebf8b 14551@node ARM
104c1213 14552@subsection ARM
c45da7e6 14553@cindex ARM RDI
104c1213
JM
14554
14555@table @code
8e04817f
AC
14556@kindex target rdi
14557@item target rdi @var{dev}
14558ARM Angel monitor, via RDI library interface to ADP protocol. You may
14559use this target to communicate with both boards running the Angel
14560monitor, or with the EmbeddedICE JTAG debug device.
14561
14562@kindex target rdp
14563@item target rdp @var{dev}
14564ARM Demon monitor.
14565
14566@end table
14567
e2f4edfd
EZ
14568@value{GDBN} provides the following ARM-specific commands:
14569
14570@table @code
14571@item set arm disassembler
14572@kindex set arm
14573This commands selects from a list of disassembly styles. The
14574@code{"std"} style is the standard style.
14575
14576@item show arm disassembler
14577@kindex show arm
14578Show the current disassembly style.
14579
14580@item set arm apcs32
14581@cindex ARM 32-bit mode
14582This command toggles ARM operation mode between 32-bit and 26-bit.
14583
14584@item show arm apcs32
14585Display the current usage of the ARM 32-bit mode.
14586
14587@item set arm fpu @var{fputype}
14588This command sets the ARM floating-point unit (FPU) type. The
14589argument @var{fputype} can be one of these:
14590
14591@table @code
14592@item auto
14593Determine the FPU type by querying the OS ABI.
14594@item softfpa
14595Software FPU, with mixed-endian doubles on little-endian ARM
14596processors.
14597@item fpa
14598GCC-compiled FPA co-processor.
14599@item softvfp
14600Software FPU with pure-endian doubles.
14601@item vfp
14602VFP co-processor.
14603@end table
14604
14605@item show arm fpu
14606Show the current type of the FPU.
14607
14608@item set arm abi
14609This command forces @value{GDBN} to use the specified ABI.
14610
14611@item show arm abi
14612Show the currently used ABI.
14613
14614@item set debug arm
14615Toggle whether to display ARM-specific debugging messages from the ARM
14616target support subsystem.
14617
14618@item show debug arm
14619Show whether ARM-specific debugging messages are enabled.
14620@end table
14621
c45da7e6
EZ
14622The following commands are available when an ARM target is debugged
14623using the RDI interface:
14624
14625@table @code
14626@item rdilogfile @r{[}@var{file}@r{]}
14627@kindex rdilogfile
14628@cindex ADP (Angel Debugger Protocol) logging
14629Set the filename for the ADP (Angel Debugger Protocol) packet log.
14630With an argument, sets the log file to the specified @var{file}. With
14631no argument, show the current log file name. The default log file is
14632@file{rdi.log}.
14633
14634@item rdilogenable @r{[}@var{arg}@r{]}
14635@kindex rdilogenable
14636Control logging of ADP packets. With an argument of 1 or @code{"yes"}
14637enables logging, with an argument 0 or @code{"no"} disables it. With
14638no arguments displays the current setting. When logging is enabled,
14639ADP packets exchanged between @value{GDBN} and the RDI target device
14640are logged to a file.
14641
14642@item set rdiromatzero
14643@kindex set rdiromatzero
14644@cindex ROM at zero address, RDI
14645Tell @value{GDBN} whether the target has ROM at address 0. If on,
14646vector catching is disabled, so that zero address can be used. If off
14647(the default), vector catching is enabled. For this command to take
14648effect, it needs to be invoked prior to the @code{target rdi} command.
14649
14650@item show rdiromatzero
14651@kindex show rdiromatzero
14652Show the current setting of ROM at zero address.
14653
14654@item set rdiheartbeat
14655@kindex set rdiheartbeat
14656@cindex RDI heartbeat
14657Enable or disable RDI heartbeat packets. It is not recommended to
14658turn on this option, since it confuses ARM and EPI JTAG interface, as
14659well as the Angel monitor.
14660
14661@item show rdiheartbeat
14662@kindex show rdiheartbeat
14663Show the setting of RDI heartbeat packets.
14664@end table
14665
e2f4edfd 14666
8e04817f 14667@node M32R/D
ba04e063 14668@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
14669
14670@table @code
8e04817f
AC
14671@kindex target m32r
14672@item target m32r @var{dev}
172c2a43 14673Renesas M32R/D ROM monitor.
8e04817f 14674
fb3e19c0
KI
14675@kindex target m32rsdi
14676@item target m32rsdi @var{dev}
14677Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
14678@end table
14679
14680The following @value{GDBN} commands are specific to the M32R monitor:
14681
14682@table @code
14683@item set download-path @var{path}
14684@kindex set download-path
14685@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 14686Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
14687
14688@item show download-path
14689@kindex show download-path
14690Show the default path for downloadable @sc{srec} files.
fb3e19c0 14691
721c2651
EZ
14692@item set board-address @var{addr}
14693@kindex set board-address
14694@cindex M32-EVA target board address
14695Set the IP address for the M32R-EVA target board.
14696
14697@item show board-address
14698@kindex show board-address
14699Show the current IP address of the target board.
14700
14701@item set server-address @var{addr}
14702@kindex set server-address
14703@cindex download server address (M32R)
14704Set the IP address for the download server, which is the @value{GDBN}'s
14705host machine.
14706
14707@item show server-address
14708@kindex show server-address
14709Display the IP address of the download server.
14710
14711@item upload @r{[}@var{file}@r{]}
14712@kindex upload@r{, M32R}
14713Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14714upload capability. If no @var{file} argument is given, the current
14715executable file is uploaded.
14716
14717@item tload @r{[}@var{file}@r{]}
14718@kindex tload@r{, M32R}
14719Test the @code{upload} command.
8e04817f
AC
14720@end table
14721
ba04e063
EZ
14722The following commands are available for M32R/SDI:
14723
14724@table @code
14725@item sdireset
14726@kindex sdireset
14727@cindex reset SDI connection, M32R
14728This command resets the SDI connection.
14729
14730@item sdistatus
14731@kindex sdistatus
14732This command shows the SDI connection status.
14733
14734@item debug_chaos
14735@kindex debug_chaos
14736@cindex M32R/Chaos debugging
14737Instructs the remote that M32R/Chaos debugging is to be used.
14738
14739@item use_debug_dma
14740@kindex use_debug_dma
14741Instructs the remote to use the DEBUG_DMA method of accessing memory.
14742
14743@item use_mon_code
14744@kindex use_mon_code
14745Instructs the remote to use the MON_CODE method of accessing memory.
14746
14747@item use_ib_break
14748@kindex use_ib_break
14749Instructs the remote to set breakpoints by IB break.
14750
14751@item use_dbt_break
14752@kindex use_dbt_break
14753Instructs the remote to set breakpoints by DBT.
14754@end table
14755
8e04817f
AC
14756@node M68K
14757@subsection M68k
14758
7ce59000
DJ
14759The Motorola m68k configuration includes ColdFire support, and a
14760target command for the following ROM monitor.
8e04817f
AC
14761
14762@table @code
14763
8e04817f
AC
14764@kindex target dbug
14765@item target dbug @var{dev}
14766dBUG ROM monitor for Motorola ColdFire.
14767
8e04817f
AC
14768@end table
14769
8e04817f
AC
14770@node MIPS Embedded
14771@subsection MIPS Embedded
14772
14773@cindex MIPS boards
14774@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14775MIPS board attached to a serial line. This is available when
14776you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14777
8e04817f
AC
14778@need 1000
14779Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14780
8e04817f
AC
14781@table @code
14782@item target mips @var{port}
14783@kindex target mips @var{port}
14784To run a program on the board, start up @code{@value{GDBP}} with the
14785name of your program as the argument. To connect to the board, use the
14786command @samp{target mips @var{port}}, where @var{port} is the name of
14787the serial port connected to the board. If the program has not already
14788been downloaded to the board, you may use the @code{load} command to
14789download it. You can then use all the usual @value{GDBN} commands.
104c1213 14790
8e04817f
AC
14791For example, this sequence connects to the target board through a serial
14792port, and loads and runs a program called @var{prog} through the
14793debugger:
104c1213 14794
474c8240 14795@smallexample
8e04817f
AC
14796host$ @value{GDBP} @var{prog}
14797@value{GDBN} is free software and @dots{}
14798(@value{GDBP}) target mips /dev/ttyb
14799(@value{GDBP}) load @var{prog}
14800(@value{GDBP}) run
474c8240 14801@end smallexample
104c1213 14802
8e04817f
AC
14803@item target mips @var{hostname}:@var{portnumber}
14804On some @value{GDBN} host configurations, you can specify a TCP
14805connection (for instance, to a serial line managed by a terminal
14806concentrator) instead of a serial port, using the syntax
14807@samp{@var{hostname}:@var{portnumber}}.
104c1213 14808
8e04817f
AC
14809@item target pmon @var{port}
14810@kindex target pmon @var{port}
14811PMON ROM monitor.
104c1213 14812
8e04817f
AC
14813@item target ddb @var{port}
14814@kindex target ddb @var{port}
14815NEC's DDB variant of PMON for Vr4300.
104c1213 14816
8e04817f
AC
14817@item target lsi @var{port}
14818@kindex target lsi @var{port}
14819LSI variant of PMON.
104c1213 14820
8e04817f
AC
14821@kindex target r3900
14822@item target r3900 @var{dev}
14823Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14824
8e04817f
AC
14825@kindex target array
14826@item target array @var{dev}
14827Array Tech LSI33K RAID controller board.
104c1213 14828
8e04817f 14829@end table
104c1213 14830
104c1213 14831
8e04817f
AC
14832@noindent
14833@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14834
8e04817f 14835@table @code
8e04817f
AC
14836@item set mipsfpu double
14837@itemx set mipsfpu single
14838@itemx set mipsfpu none
a64548ea 14839@itemx set mipsfpu auto
8e04817f
AC
14840@itemx show mipsfpu
14841@kindex set mipsfpu
14842@kindex show mipsfpu
14843@cindex MIPS remote floating point
14844@cindex floating point, MIPS remote
14845If your target board does not support the MIPS floating point
14846coprocessor, you should use the command @samp{set mipsfpu none} (if you
14847need this, you may wish to put the command in your @value{GDBN} init
14848file). This tells @value{GDBN} how to find the return value of
14849functions which return floating point values. It also allows
14850@value{GDBN} to avoid saving the floating point registers when calling
14851functions on the board. If you are using a floating point coprocessor
14852with only single precision floating point support, as on the @sc{r4650}
14853processor, use the command @samp{set mipsfpu single}. The default
14854double precision floating point coprocessor may be selected using
14855@samp{set mipsfpu double}.
104c1213 14856
8e04817f
AC
14857In previous versions the only choices were double precision or no
14858floating point, so @samp{set mipsfpu on} will select double precision
14859and @samp{set mipsfpu off} will select no floating point.
104c1213 14860
8e04817f
AC
14861As usual, you can inquire about the @code{mipsfpu} variable with
14862@samp{show mipsfpu}.
104c1213 14863
8e04817f
AC
14864@item set timeout @var{seconds}
14865@itemx set retransmit-timeout @var{seconds}
14866@itemx show timeout
14867@itemx show retransmit-timeout
14868@cindex @code{timeout}, MIPS protocol
14869@cindex @code{retransmit-timeout}, MIPS protocol
14870@kindex set timeout
14871@kindex show timeout
14872@kindex set retransmit-timeout
14873@kindex show retransmit-timeout
14874You can control the timeout used while waiting for a packet, in the MIPS
14875remote protocol, with the @code{set timeout @var{seconds}} command. The
14876default is 5 seconds. Similarly, you can control the timeout used while
14877waiting for an acknowledgement of a packet with the @code{set
14878retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14879You can inspect both values with @code{show timeout} and @code{show
14880retransmit-timeout}. (These commands are @emph{only} available when
14881@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14882
8e04817f
AC
14883The timeout set by @code{set timeout} does not apply when @value{GDBN}
14884is waiting for your program to stop. In that case, @value{GDBN} waits
14885forever because it has no way of knowing how long the program is going
14886to run before stopping.
ba04e063
EZ
14887
14888@item set syn-garbage-limit @var{num}
14889@kindex set syn-garbage-limit@r{, MIPS remote}
14890@cindex synchronize with remote MIPS target
14891Limit the maximum number of characters @value{GDBN} should ignore when
14892it tries to synchronize with the remote target. The default is 10
14893characters. Setting the limit to -1 means there's no limit.
14894
14895@item show syn-garbage-limit
14896@kindex show syn-garbage-limit@r{, MIPS remote}
14897Show the current limit on the number of characters to ignore when
14898trying to synchronize with the remote system.
14899
14900@item set monitor-prompt @var{prompt}
14901@kindex set monitor-prompt@r{, MIPS remote}
14902@cindex remote monitor prompt
14903Tell @value{GDBN} to expect the specified @var{prompt} string from the
14904remote monitor. The default depends on the target:
14905@table @asis
14906@item pmon target
14907@samp{PMON}
14908@item ddb target
14909@samp{NEC010}
14910@item lsi target
14911@samp{PMON>}
14912@end table
14913
14914@item show monitor-prompt
14915@kindex show monitor-prompt@r{, MIPS remote}
14916Show the current strings @value{GDBN} expects as the prompt from the
14917remote monitor.
14918
14919@item set monitor-warnings
14920@kindex set monitor-warnings@r{, MIPS remote}
14921Enable or disable monitor warnings about hardware breakpoints. This
14922has effect only for the @code{lsi} target. When on, @value{GDBN} will
14923display warning messages whose codes are returned by the @code{lsi}
14924PMON monitor for breakpoint commands.
14925
14926@item show monitor-warnings
14927@kindex show monitor-warnings@r{, MIPS remote}
14928Show the current setting of printing monitor warnings.
14929
14930@item pmon @var{command}
14931@kindex pmon@r{, MIPS remote}
14932@cindex send PMON command
14933This command allows sending an arbitrary @var{command} string to the
14934monitor. The monitor must be in debug mode for this to work.
8e04817f 14935@end table
104c1213 14936
a37295f9
MM
14937@node OpenRISC 1000
14938@subsection OpenRISC 1000
14939@cindex OpenRISC 1000
14940
14941@cindex or1k boards
14942See OR1k Architecture document (@uref{www.opencores.org}) for more information
14943about platform and commands.
14944
14945@table @code
14946
14947@kindex target jtag
14948@item target jtag jtag://@var{host}:@var{port}
14949
14950Connects to remote JTAG server.
14951JTAG remote server can be either an or1ksim or JTAG server,
14952connected via parallel port to the board.
14953
14954Example: @code{target jtag jtag://localhost:9999}
14955
14956@kindex or1ksim
14957@item or1ksim @var{command}
14958If connected to @code{or1ksim} OpenRISC 1000 Architectural
14959Simulator, proprietary commands can be executed.
14960
14961@kindex info or1k spr
14962@item info or1k spr
14963Displays spr groups.
14964
14965@item info or1k spr @var{group}
14966@itemx info or1k spr @var{groupno}
14967Displays register names in selected group.
14968
14969@item info or1k spr @var{group} @var{register}
14970@itemx info or1k spr @var{register}
14971@itemx info or1k spr @var{groupno} @var{registerno}
14972@itemx info or1k spr @var{registerno}
14973Shows information about specified spr register.
14974
14975@kindex spr
14976@item spr @var{group} @var{register} @var{value}
14977@itemx spr @var{register @var{value}}
14978@itemx spr @var{groupno} @var{registerno @var{value}}
14979@itemx spr @var{registerno @var{value}}
14980Writes @var{value} to specified spr register.
14981@end table
14982
14983Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14984It is very similar to @value{GDBN} trace, except it does not interfere with normal
14985program execution and is thus much faster. Hardware breakpoints/watchpoint
14986triggers can be set using:
14987@table @code
14988@item $LEA/$LDATA
14989Load effective address/data
14990@item $SEA/$SDATA
14991Store effective address/data
14992@item $AEA/$ADATA
14993Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14994@item $FETCH
14995Fetch data
14996@end table
14997
14998When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14999@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
15000
15001@code{htrace} commands:
15002@cindex OpenRISC 1000 htrace
15003@table @code
15004@kindex hwatch
15005@item hwatch @var{conditional}
d3e8051b 15006Set hardware watchpoint on combination of Load/Store Effective Address(es)
a37295f9
MM
15007or Data. For example:
15008
15009@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
15010
15011@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
15012
4644b6e3 15013@kindex htrace
a37295f9
MM
15014@item htrace info
15015Display information about current HW trace configuration.
15016
a37295f9
MM
15017@item htrace trigger @var{conditional}
15018Set starting criteria for HW trace.
15019
a37295f9
MM
15020@item htrace qualifier @var{conditional}
15021Set acquisition qualifier for HW trace.
15022
a37295f9
MM
15023@item htrace stop @var{conditional}
15024Set HW trace stopping criteria.
15025
f153cc92 15026@item htrace record [@var{data}]*
a37295f9
MM
15027Selects the data to be recorded, when qualifier is met and HW trace was
15028triggered.
15029
a37295f9 15030@item htrace enable
a37295f9
MM
15031@itemx htrace disable
15032Enables/disables the HW trace.
15033
f153cc92 15034@item htrace rewind [@var{filename}]
a37295f9
MM
15035Clears currently recorded trace data.
15036
15037If filename is specified, new trace file is made and any newly collected data
15038will be written there.
15039
f153cc92 15040@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
15041Prints trace buffer, using current record configuration.
15042
a37295f9
MM
15043@item htrace mode continuous
15044Set continuous trace mode.
15045
a37295f9
MM
15046@item htrace mode suspend
15047Set suspend trace mode.
15048
15049@end table
15050
8e04817f
AC
15051@node PowerPC
15052@subsection PowerPC
104c1213 15053
55eddb0f
DJ
15054@value{GDBN} provides the following PowerPC-specific commands:
15055
104c1213 15056@table @code
55eddb0f
DJ
15057@kindex set powerpc
15058@item set powerpc soft-float
15059@itemx show powerpc soft-float
15060Force @value{GDBN} to use (or not use) a software floating point calling
15061convention. By default, @value{GDBN} selects the calling convention based
15062on the selected architecture and the provided executable file.
15063
15064@item set powerpc vector-abi
15065@itemx show powerpc vector-abi
15066Force @value{GDBN} to use the specified calling convention for vector
15067arguments and return values. The valid options are @samp{auto};
15068@samp{generic}, to avoid vector registers even if they are present;
15069@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
15070registers. By default, @value{GDBN} selects the calling convention
15071based on the selected architecture and the provided executable file.
15072
8e04817f
AC
15073@kindex target dink32
15074@item target dink32 @var{dev}
15075DINK32 ROM monitor.
104c1213 15076
8e04817f
AC
15077@kindex target ppcbug
15078@item target ppcbug @var{dev}
15079@kindex target ppcbug1
15080@item target ppcbug1 @var{dev}
15081PPCBUG ROM monitor for PowerPC.
104c1213 15082
8e04817f
AC
15083@kindex target sds
15084@item target sds @var{dev}
15085SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 15086@end table
8e04817f 15087
c45da7e6 15088@cindex SDS protocol
d52fb0e9 15089The following commands specific to the SDS protocol are supported
55eddb0f 15090by @value{GDBN}:
c45da7e6
EZ
15091
15092@table @code
15093@item set sdstimeout @var{nsec}
15094@kindex set sdstimeout
15095Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
15096default is 2 seconds.
15097
15098@item show sdstimeout
15099@kindex show sdstimeout
15100Show the current value of the SDS timeout.
15101
15102@item sds @var{command}
15103@kindex sds@r{, a command}
15104Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
15105@end table
15106
c45da7e6 15107
8e04817f
AC
15108@node PA
15109@subsection HP PA Embedded
104c1213
JM
15110
15111@table @code
15112
8e04817f
AC
15113@kindex target op50n
15114@item target op50n @var{dev}
15115OP50N monitor, running on an OKI HPPA board.
15116
15117@kindex target w89k
15118@item target w89k @var{dev}
15119W89K monitor, running on a Winbond HPPA board.
104c1213
JM
15120
15121@end table
15122
8e04817f
AC
15123@node Sparclet
15124@subsection Tsqware Sparclet
104c1213 15125
8e04817f
AC
15126@cindex Sparclet
15127
15128@value{GDBN} enables developers to debug tasks running on
15129Sparclet targets from a Unix host.
15130@value{GDBN} uses code that runs on
15131both the Unix host and on the Sparclet target. The program
15132@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 15133
8e04817f
AC
15134@table @code
15135@item remotetimeout @var{args}
15136@kindex remotetimeout
15137@value{GDBN} supports the option @code{remotetimeout}.
15138This option is set by the user, and @var{args} represents the number of
15139seconds @value{GDBN} waits for responses.
104c1213
JM
15140@end table
15141
8e04817f
AC
15142@cindex compiling, on Sparclet
15143When compiling for debugging, include the options @samp{-g} to get debug
15144information and @samp{-Ttext} to relocate the program to where you wish to
15145load it on the target. You may also want to add the options @samp{-n} or
15146@samp{-N} in order to reduce the size of the sections. Example:
104c1213 15147
474c8240 15148@smallexample
8e04817f 15149sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 15150@end smallexample
104c1213 15151
8e04817f 15152You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 15153
474c8240 15154@smallexample
8e04817f 15155sparclet-aout-objdump --headers --syms prog
474c8240 15156@end smallexample
104c1213 15157
8e04817f
AC
15158@cindex running, on Sparclet
15159Once you have set
15160your Unix execution search path to find @value{GDBN}, you are ready to
15161run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
15162(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 15163
8e04817f
AC
15164@value{GDBN} comes up showing the prompt:
15165
474c8240 15166@smallexample
8e04817f 15167(gdbslet)
474c8240 15168@end smallexample
104c1213
JM
15169
15170@menu
8e04817f
AC
15171* Sparclet File:: Setting the file to debug
15172* Sparclet Connection:: Connecting to Sparclet
15173* Sparclet Download:: Sparclet download
15174* Sparclet Execution:: Running and debugging
104c1213
JM
15175@end menu
15176
8e04817f 15177@node Sparclet File
79a6e687 15178@subsubsection Setting File to Debug
104c1213 15179
8e04817f 15180The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 15181
474c8240 15182@smallexample
8e04817f 15183(gdbslet) file prog
474c8240 15184@end smallexample
104c1213 15185
8e04817f
AC
15186@need 1000
15187@value{GDBN} then attempts to read the symbol table of @file{prog}.
15188@value{GDBN} locates
15189the file by searching the directories listed in the command search
15190path.
12c27660 15191If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
15192files will be searched as well.
15193@value{GDBN} locates
15194the source files by searching the directories listed in the directory search
79a6e687 15195path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
15196If it fails
15197to find a file, it displays a message such as:
104c1213 15198
474c8240 15199@smallexample
8e04817f 15200prog: No such file or directory.
474c8240 15201@end smallexample
104c1213 15202
8e04817f
AC
15203When this happens, add the appropriate directories to the search paths with
15204the @value{GDBN} commands @code{path} and @code{dir}, and execute the
15205@code{target} command again.
104c1213 15206
8e04817f
AC
15207@node Sparclet Connection
15208@subsubsection Connecting to Sparclet
104c1213 15209
8e04817f
AC
15210The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
15211To connect to a target on serial port ``@code{ttya}'', type:
104c1213 15212
474c8240 15213@smallexample
8e04817f
AC
15214(gdbslet) target sparclet /dev/ttya
15215Remote target sparclet connected to /dev/ttya
15216main () at ../prog.c:3
474c8240 15217@end smallexample
104c1213 15218
8e04817f
AC
15219@need 750
15220@value{GDBN} displays messages like these:
104c1213 15221
474c8240 15222@smallexample
8e04817f 15223Connected to ttya.
474c8240 15224@end smallexample
104c1213 15225
8e04817f 15226@node Sparclet Download
79a6e687 15227@subsubsection Sparclet Download
104c1213 15228
8e04817f
AC
15229@cindex download to Sparclet
15230Once connected to the Sparclet target,
15231you can use the @value{GDBN}
15232@code{load} command to download the file from the host to the target.
15233The file name and load offset should be given as arguments to the @code{load}
15234command.
15235Since the file format is aout, the program must be loaded to the starting
15236address. You can use @code{objdump} to find out what this value is. The load
15237offset is an offset which is added to the VMA (virtual memory address)
15238of each of the file's sections.
15239For instance, if the program
15240@file{prog} was linked to text address 0x1201000, with data at 0x12010160
15241and bss at 0x12010170, in @value{GDBN}, type:
104c1213 15242
474c8240 15243@smallexample
8e04817f
AC
15244(gdbslet) load prog 0x12010000
15245Loading section .text, size 0xdb0 vma 0x12010000
474c8240 15246@end smallexample
104c1213 15247
8e04817f
AC
15248If the code is loaded at a different address then what the program was linked
15249to, you may need to use the @code{section} and @code{add-symbol-file} commands
15250to tell @value{GDBN} where to map the symbol table.
15251
15252@node Sparclet Execution
79a6e687 15253@subsubsection Running and Debugging
8e04817f
AC
15254
15255@cindex running and debugging Sparclet programs
15256You can now begin debugging the task using @value{GDBN}'s execution control
15257commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
15258manual for the list of commands.
15259
474c8240 15260@smallexample
8e04817f
AC
15261(gdbslet) b main
15262Breakpoint 1 at 0x12010000: file prog.c, line 3.
15263(gdbslet) run
15264Starting program: prog
15265Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
152663 char *symarg = 0;
15267(gdbslet) step
152684 char *execarg = "hello!";
15269(gdbslet)
474c8240 15270@end smallexample
8e04817f
AC
15271
15272@node Sparclite
15273@subsection Fujitsu Sparclite
104c1213
JM
15274
15275@table @code
15276
8e04817f
AC
15277@kindex target sparclite
15278@item target sparclite @var{dev}
15279Fujitsu sparclite boards, used only for the purpose of loading.
15280You must use an additional command to debug the program.
15281For example: target remote @var{dev} using @value{GDBN} standard
15282remote protocol.
104c1213
JM
15283
15284@end table
15285
8e04817f
AC
15286@node Z8000
15287@subsection Zilog Z8000
104c1213 15288
8e04817f
AC
15289@cindex Z8000
15290@cindex simulator, Z8000
15291@cindex Zilog Z8000 simulator
104c1213 15292
8e04817f
AC
15293When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
15294a Z8000 simulator.
15295
15296For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
15297unsegmented variant of the Z8000 architecture) or the Z8001 (the
15298segmented variant). The simulator recognizes which architecture is
15299appropriate by inspecting the object code.
104c1213 15300
8e04817f
AC
15301@table @code
15302@item target sim @var{args}
15303@kindex sim
15304@kindex target sim@r{, with Z8000}
15305Debug programs on a simulated CPU. If the simulator supports setup
15306options, specify them via @var{args}.
104c1213
JM
15307@end table
15308
8e04817f
AC
15309@noindent
15310After specifying this target, you can debug programs for the simulated
15311CPU in the same style as programs for your host computer; use the
15312@code{file} command to load a new program image, the @code{run} command
15313to run your program, and so on.
15314
15315As well as making available all the usual machine registers
15316(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
15317additional items of information as specially named registers:
104c1213
JM
15318
15319@table @code
15320
8e04817f
AC
15321@item cycles
15322Counts clock-ticks in the simulator.
104c1213 15323
8e04817f
AC
15324@item insts
15325Counts instructions run in the simulator.
104c1213 15326
8e04817f
AC
15327@item time
15328Execution time in 60ths of a second.
104c1213 15329
8e04817f 15330@end table
104c1213 15331
8e04817f
AC
15332You can refer to these values in @value{GDBN} expressions with the usual
15333conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
15334conditional breakpoint that suspends only after at least 5000
15335simulated clock ticks.
104c1213 15336
a64548ea
EZ
15337@node AVR
15338@subsection Atmel AVR
15339@cindex AVR
15340
15341When configured for debugging the Atmel AVR, @value{GDBN} supports the
15342following AVR-specific commands:
15343
15344@table @code
15345@item info io_registers
15346@kindex info io_registers@r{, AVR}
15347@cindex I/O registers (Atmel AVR)
15348This command displays information about the AVR I/O registers. For
15349each register, @value{GDBN} prints its number and value.
15350@end table
15351
15352@node CRIS
15353@subsection CRIS
15354@cindex CRIS
15355
15356When configured for debugging CRIS, @value{GDBN} provides the
15357following CRIS-specific commands:
15358
15359@table @code
15360@item set cris-version @var{ver}
15361@cindex CRIS version
e22e55c9
OF
15362Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
15363The CRIS version affects register names and sizes. This command is useful in
15364case autodetection of the CRIS version fails.
a64548ea
EZ
15365
15366@item show cris-version
15367Show the current CRIS version.
15368
15369@item set cris-dwarf2-cfi
15370@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
15371Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
15372Change to @samp{off} when using @code{gcc-cris} whose version is below
15373@code{R59}.
a64548ea
EZ
15374
15375@item show cris-dwarf2-cfi
15376Show the current state of using DWARF-2 CFI.
e22e55c9
OF
15377
15378@item set cris-mode @var{mode}
15379@cindex CRIS mode
15380Set the current CRIS mode to @var{mode}. It should only be changed when
15381debugging in guru mode, in which case it should be set to
15382@samp{guru} (the default is @samp{normal}).
15383
15384@item show cris-mode
15385Show the current CRIS mode.
a64548ea
EZ
15386@end table
15387
15388@node Super-H
15389@subsection Renesas Super-H
15390@cindex Super-H
15391
15392For the Renesas Super-H processor, @value{GDBN} provides these
15393commands:
15394
15395@table @code
15396@item regs
15397@kindex regs@r{, Super-H}
15398Show the values of all Super-H registers.
15399@end table
15400
15401
8e04817f
AC
15402@node Architectures
15403@section Architectures
104c1213 15404
8e04817f
AC
15405This section describes characteristics of architectures that affect
15406all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 15407
8e04817f 15408@menu
9c16f35a 15409* i386::
8e04817f
AC
15410* A29K::
15411* Alpha::
15412* MIPS::
a64548ea 15413* HPPA:: HP PA architecture
23d964e7 15414* SPU:: Cell Broadband Engine SPU architecture
8e04817f 15415@end menu
104c1213 15416
9c16f35a 15417@node i386
db2e3e2e 15418@subsection x86 Architecture-specific Issues
9c16f35a
EZ
15419
15420@table @code
15421@item set struct-convention @var{mode}
15422@kindex set struct-convention
15423@cindex struct return convention
15424@cindex struct/union returned in registers
15425Set the convention used by the inferior to return @code{struct}s and
15426@code{union}s from functions to @var{mode}. Possible values of
15427@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
15428default). @code{"default"} or @code{"pcc"} means that @code{struct}s
15429are returned on the stack, while @code{"reg"} means that a
15430@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
15431be returned in a register.
15432
15433@item show struct-convention
15434@kindex show struct-convention
15435Show the current setting of the convention to return @code{struct}s
15436from functions.
15437@end table
15438
8e04817f
AC
15439@node A29K
15440@subsection A29K
104c1213
JM
15441
15442@table @code
104c1213 15443
8e04817f
AC
15444@kindex set rstack_high_address
15445@cindex AMD 29K register stack
15446@cindex register stack, AMD29K
15447@item set rstack_high_address @var{address}
15448On AMD 29000 family processors, registers are saved in a separate
15449@dfn{register stack}. There is no way for @value{GDBN} to determine the
15450extent of this stack. Normally, @value{GDBN} just assumes that the
15451stack is ``large enough''. This may result in @value{GDBN} referencing
15452memory locations that do not exist. If necessary, you can get around
15453this problem by specifying the ending address of the register stack with
15454the @code{set rstack_high_address} command. The argument should be an
15455address, which you probably want to precede with @samp{0x} to specify in
15456hexadecimal.
104c1213 15457
8e04817f
AC
15458@kindex show rstack_high_address
15459@item show rstack_high_address
15460Display the current limit of the register stack, on AMD 29000 family
15461processors.
104c1213 15462
8e04817f 15463@end table
104c1213 15464
8e04817f
AC
15465@node Alpha
15466@subsection Alpha
104c1213 15467
8e04817f 15468See the following section.
104c1213 15469
8e04817f
AC
15470@node MIPS
15471@subsection MIPS
104c1213 15472
8e04817f
AC
15473@cindex stack on Alpha
15474@cindex stack on MIPS
15475@cindex Alpha stack
15476@cindex MIPS stack
15477Alpha- and MIPS-based computers use an unusual stack frame, which
15478sometimes requires @value{GDBN} to search backward in the object code to
15479find the beginning of a function.
104c1213 15480
8e04817f
AC
15481@cindex response time, MIPS debugging
15482To improve response time (especially for embedded applications, where
15483@value{GDBN} may be restricted to a slow serial line for this search)
15484you may want to limit the size of this search, using one of these
15485commands:
104c1213 15486
8e04817f
AC
15487@table @code
15488@cindex @code{heuristic-fence-post} (Alpha, MIPS)
15489@item set heuristic-fence-post @var{limit}
15490Restrict @value{GDBN} to examining at most @var{limit} bytes in its
15491search for the beginning of a function. A value of @var{0} (the
15492default) means there is no limit. However, except for @var{0}, the
15493larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
15494and therefore the longer it takes to run. You should only need to use
15495this command when debugging a stripped executable.
104c1213 15496
8e04817f
AC
15497@item show heuristic-fence-post
15498Display the current limit.
15499@end table
104c1213
JM
15500
15501@noindent
8e04817f
AC
15502These commands are available @emph{only} when @value{GDBN} is configured
15503for debugging programs on Alpha or MIPS processors.
104c1213 15504
a64548ea
EZ
15505Several MIPS-specific commands are available when debugging MIPS
15506programs:
15507
15508@table @code
a64548ea
EZ
15509@item set mips abi @var{arg}
15510@kindex set mips abi
15511@cindex set ABI for MIPS
15512Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
15513values of @var{arg} are:
15514
15515@table @samp
15516@item auto
15517The default ABI associated with the current binary (this is the
15518default).
15519@item o32
15520@item o64
15521@item n32
15522@item n64
15523@item eabi32
15524@item eabi64
15525@item auto
15526@end table
15527
15528@item show mips abi
15529@kindex show mips abi
15530Show the MIPS ABI used by @value{GDBN} to debug the inferior.
15531
15532@item set mipsfpu
15533@itemx show mipsfpu
15534@xref{MIPS Embedded, set mipsfpu}.
15535
15536@item set mips mask-address @var{arg}
15537@kindex set mips mask-address
15538@cindex MIPS addresses, masking
15539This command determines whether the most-significant 32 bits of 64-bit
15540MIPS addresses are masked off. The argument @var{arg} can be
15541@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
15542setting, which lets @value{GDBN} determine the correct value.
15543
15544@item show mips mask-address
15545@kindex show mips mask-address
15546Show whether the upper 32 bits of MIPS addresses are masked off or
15547not.
15548
15549@item set remote-mips64-transfers-32bit-regs
15550@kindex set remote-mips64-transfers-32bit-regs
15551This command controls compatibility with 64-bit MIPS targets that
15552transfer data in 32-bit quantities. If you have an old MIPS 64 target
15553that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
15554and 64 bits for other registers, set this option to @samp{on}.
15555
15556@item show remote-mips64-transfers-32bit-regs
15557@kindex show remote-mips64-transfers-32bit-regs
15558Show the current setting of compatibility with older MIPS 64 targets.
15559
15560@item set debug mips
15561@kindex set debug mips
15562This command turns on and off debugging messages for the MIPS-specific
15563target code in @value{GDBN}.
15564
15565@item show debug mips
15566@kindex show debug mips
15567Show the current setting of MIPS debugging messages.
15568@end table
15569
15570
15571@node HPPA
15572@subsection HPPA
15573@cindex HPPA support
15574
d3e8051b 15575When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
15576following special commands:
15577
15578@table @code
15579@item set debug hppa
15580@kindex set debug hppa
db2e3e2e 15581This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
15582messages are to be displayed.
15583
15584@item show debug hppa
15585Show whether HPPA debugging messages are displayed.
15586
15587@item maint print unwind @var{address}
15588@kindex maint print unwind@r{, HPPA}
15589This command displays the contents of the unwind table entry at the
15590given @var{address}.
15591
15592@end table
15593
104c1213 15594
23d964e7
UW
15595@node SPU
15596@subsection Cell Broadband Engine SPU architecture
15597@cindex Cell Broadband Engine
15598@cindex SPU
15599
15600When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
15601it provides the following special commands:
15602
15603@table @code
15604@item info spu event
15605@kindex info spu
15606Display SPU event facility status. Shows current event mask
15607and pending event status.
15608
15609@item info spu signal
15610Display SPU signal notification facility status. Shows pending
15611signal-control word and signal notification mode of both signal
15612notification channels.
15613
15614@item info spu mailbox
15615Display SPU mailbox facility status. Shows all pending entries,
15616in order of processing, in each of the SPU Write Outbound,
15617SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
15618
15619@item info spu dma
15620Display MFC DMA status. Shows all pending commands in the MFC
15621DMA queue. For each entry, opcode, tag, class IDs, effective
15622and local store addresses and transfer size are shown.
15623
15624@item info spu proxydma
15625Display MFC Proxy-DMA status. Shows all pending commands in the MFC
15626Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
15627and local store addresses and transfer size are shown.
15628
15629@end table
15630
15631
8e04817f
AC
15632@node Controlling GDB
15633@chapter Controlling @value{GDBN}
15634
15635You can alter the way @value{GDBN} interacts with you by using the
15636@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 15637data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
15638described here.
15639
15640@menu
15641* Prompt:: Prompt
15642* Editing:: Command editing
d620b259 15643* Command History:: Command history
8e04817f
AC
15644* Screen Size:: Screen size
15645* Numbers:: Numbers
1e698235 15646* ABI:: Configuring the current ABI
8e04817f
AC
15647* Messages/Warnings:: Optional warnings and messages
15648* Debugging Output:: Optional messages about internal happenings
15649@end menu
15650
15651@node Prompt
15652@section Prompt
104c1213 15653
8e04817f 15654@cindex prompt
104c1213 15655
8e04817f
AC
15656@value{GDBN} indicates its readiness to read a command by printing a string
15657called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15658can change the prompt string with the @code{set prompt} command. For
15659instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15660the prompt in one of the @value{GDBN} sessions so that you can always tell
15661which one you are talking to.
104c1213 15662
8e04817f
AC
15663@emph{Note:} @code{set prompt} does not add a space for you after the
15664prompt you set. This allows you to set a prompt which ends in a space
15665or a prompt that does not.
104c1213 15666
8e04817f
AC
15667@table @code
15668@kindex set prompt
15669@item set prompt @var{newprompt}
15670Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15671
8e04817f
AC
15672@kindex show prompt
15673@item show prompt
15674Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15675@end table
15676
8e04817f 15677@node Editing
79a6e687 15678@section Command Editing
8e04817f
AC
15679@cindex readline
15680@cindex command line editing
104c1213 15681
703663ab 15682@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15683@sc{gnu} library provides consistent behavior for programs which provide a
15684command line interface to the user. Advantages are @sc{gnu} Emacs-style
15685or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15686substitution, and a storage and recall of command history across
15687debugging sessions.
104c1213 15688
8e04817f
AC
15689You may control the behavior of command line editing in @value{GDBN} with the
15690command @code{set}.
104c1213 15691
8e04817f
AC
15692@table @code
15693@kindex set editing
15694@cindex editing
15695@item set editing
15696@itemx set editing on
15697Enable command line editing (enabled by default).
104c1213 15698
8e04817f
AC
15699@item set editing off
15700Disable command line editing.
104c1213 15701
8e04817f
AC
15702@kindex show editing
15703@item show editing
15704Show whether command line editing is enabled.
104c1213
JM
15705@end table
15706
703663ab
EZ
15707@xref{Command Line Editing}, for more details about the Readline
15708interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15709encouraged to read that chapter.
15710
d620b259 15711@node Command History
79a6e687 15712@section Command History
703663ab 15713@cindex command history
8e04817f
AC
15714
15715@value{GDBN} can keep track of the commands you type during your
15716debugging sessions, so that you can be certain of precisely what
15717happened. Use these commands to manage the @value{GDBN} command
15718history facility.
104c1213 15719
703663ab
EZ
15720@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15721package, to provide the history facility. @xref{Using History
15722Interactively}, for the detailed description of the History library.
15723
d620b259 15724To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
15725the state which is seen by users, prefix it with @samp{server }
15726(@pxref{Server Prefix}). This
d620b259
NR
15727means that this command will not affect the command history, nor will it
15728affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15729pressed on a line by itself.
15730
15731@cindex @code{server}, command prefix
15732The server prefix does not affect the recording of values into the value
15733history; to print a value without recording it into the value history,
15734use the @code{output} command instead of the @code{print} command.
15735
703663ab
EZ
15736Here is the description of @value{GDBN} commands related to command
15737history.
15738
104c1213 15739@table @code
8e04817f
AC
15740@cindex history substitution
15741@cindex history file
15742@kindex set history filename
4644b6e3 15743@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15744@item set history filename @var{fname}
15745Set the name of the @value{GDBN} command history file to @var{fname}.
15746This is the file where @value{GDBN} reads an initial command history
15747list, and where it writes the command history from this session when it
15748exits. You can access this list through history expansion or through
15749the history command editing characters listed below. This file defaults
15750to the value of the environment variable @code{GDBHISTFILE}, or to
15751@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15752is not set.
104c1213 15753
9c16f35a
EZ
15754@cindex save command history
15755@kindex set history save
8e04817f
AC
15756@item set history save
15757@itemx set history save on
15758Record command history in a file, whose name may be specified with the
15759@code{set history filename} command. By default, this option is disabled.
104c1213 15760
8e04817f
AC
15761@item set history save off
15762Stop recording command history in a file.
104c1213 15763
8e04817f 15764@cindex history size
9c16f35a 15765@kindex set history size
6fc08d32 15766@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15767@item set history size @var{size}
15768Set the number of commands which @value{GDBN} keeps in its history list.
15769This defaults to the value of the environment variable
15770@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15771@end table
15772
8e04817f 15773History expansion assigns special meaning to the character @kbd{!}.
703663ab 15774@xref{Event Designators}, for more details.
8e04817f 15775
703663ab 15776@cindex history expansion, turn on/off
8e04817f
AC
15777Since @kbd{!} is also the logical not operator in C, history expansion
15778is off by default. If you decide to enable history expansion with the
15779@code{set history expansion on} command, you may sometimes need to
15780follow @kbd{!} (when it is used as logical not, in an expression) with
15781a space or a tab to prevent it from being expanded. The readline
15782history facilities do not attempt substitution on the strings
15783@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15784
15785The commands to control history expansion are:
104c1213
JM
15786
15787@table @code
8e04817f
AC
15788@item set history expansion on
15789@itemx set history expansion
703663ab 15790@kindex set history expansion
8e04817f 15791Enable history expansion. History expansion is off by default.
104c1213 15792
8e04817f
AC
15793@item set history expansion off
15794Disable history expansion.
104c1213 15795
8e04817f
AC
15796@c @group
15797@kindex show history
15798@item show history
15799@itemx show history filename
15800@itemx show history save
15801@itemx show history size
15802@itemx show history expansion
15803These commands display the state of the @value{GDBN} history parameters.
15804@code{show history} by itself displays all four states.
15805@c @end group
15806@end table
15807
15808@table @code
9c16f35a
EZ
15809@kindex show commands
15810@cindex show last commands
15811@cindex display command history
8e04817f
AC
15812@item show commands
15813Display the last ten commands in the command history.
104c1213 15814
8e04817f
AC
15815@item show commands @var{n}
15816Print ten commands centered on command number @var{n}.
15817
15818@item show commands +
15819Print ten commands just after the commands last printed.
104c1213
JM
15820@end table
15821
8e04817f 15822@node Screen Size
79a6e687 15823@section Screen Size
8e04817f
AC
15824@cindex size of screen
15825@cindex pauses in output
104c1213 15826
8e04817f
AC
15827Certain commands to @value{GDBN} may produce large amounts of
15828information output to the screen. To help you read all of it,
15829@value{GDBN} pauses and asks you for input at the end of each page of
15830output. Type @key{RET} when you want to continue the output, or @kbd{q}
15831to discard the remaining output. Also, the screen width setting
15832determines when to wrap lines of output. Depending on what is being
15833printed, @value{GDBN} tries to break the line at a readable place,
15834rather than simply letting it overflow onto the following line.
15835
15836Normally @value{GDBN} knows the size of the screen from the terminal
15837driver software. For example, on Unix @value{GDBN} uses the termcap data base
15838together with the value of the @code{TERM} environment variable and the
15839@code{stty rows} and @code{stty cols} settings. If this is not correct,
15840you can override it with the @code{set height} and @code{set
15841width} commands:
15842
15843@table @code
15844@kindex set height
15845@kindex set width
15846@kindex show width
15847@kindex show height
15848@item set height @var{lpp}
15849@itemx show height
15850@itemx set width @var{cpl}
15851@itemx show width
15852These @code{set} commands specify a screen height of @var{lpp} lines and
15853a screen width of @var{cpl} characters. The associated @code{show}
15854commands display the current settings.
104c1213 15855
8e04817f
AC
15856If you specify a height of zero lines, @value{GDBN} does not pause during
15857output no matter how long the output is. This is useful if output is to a
15858file or to an editor buffer.
104c1213 15859
8e04817f
AC
15860Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15861from wrapping its output.
9c16f35a
EZ
15862
15863@item set pagination on
15864@itemx set pagination off
15865@kindex set pagination
15866Turn the output pagination on or off; the default is on. Turning
15867pagination off is the alternative to @code{set height 0}.
15868
15869@item show pagination
15870@kindex show pagination
15871Show the current pagination mode.
104c1213
JM
15872@end table
15873
8e04817f
AC
15874@node Numbers
15875@section Numbers
15876@cindex number representation
15877@cindex entering numbers
104c1213 15878
8e04817f
AC
15879You can always enter numbers in octal, decimal, or hexadecimal in
15880@value{GDBN} by the usual conventions: octal numbers begin with
15881@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15882begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15883@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1588410; likewise, the default display for numbers---when no particular
15885format is specified---is base 10. You can change the default base for
15886both input and output with the commands described below.
104c1213 15887
8e04817f
AC
15888@table @code
15889@kindex set input-radix
15890@item set input-radix @var{base}
15891Set the default base for numeric input. Supported choices
15892for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15893specified either unambiguously or using the current input radix; for
8e04817f 15894example, any of
104c1213 15895
8e04817f 15896@smallexample
9c16f35a
EZ
15897set input-radix 012
15898set input-radix 10.
15899set input-radix 0xa
8e04817f 15900@end smallexample
104c1213 15901
8e04817f 15902@noindent
9c16f35a 15903sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15904leaves the input radix unchanged, no matter what it was, since
15905@samp{10}, being without any leading or trailing signs of its base, is
15906interpreted in the current radix. Thus, if the current radix is 16,
15907@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15908change the radix.
104c1213 15909
8e04817f
AC
15910@kindex set output-radix
15911@item set output-radix @var{base}
15912Set the default base for numeric display. Supported choices
15913for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15914specified either unambiguously or using the current input radix.
104c1213 15915
8e04817f
AC
15916@kindex show input-radix
15917@item show input-radix
15918Display the current default base for numeric input.
104c1213 15919
8e04817f
AC
15920@kindex show output-radix
15921@item show output-radix
15922Display the current default base for numeric display.
9c16f35a
EZ
15923
15924@item set radix @r{[}@var{base}@r{]}
15925@itemx show radix
15926@kindex set radix
15927@kindex show radix
15928These commands set and show the default base for both input and output
15929of numbers. @code{set radix} sets the radix of input and output to
15930the same base; without an argument, it resets the radix back to its
15931default value of 10.
15932
8e04817f 15933@end table
104c1213 15934
1e698235 15935@node ABI
79a6e687 15936@section Configuring the Current ABI
1e698235
DJ
15937
15938@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15939application automatically. However, sometimes you need to override its
15940conclusions. Use these commands to manage @value{GDBN}'s view of the
15941current ABI.
15942
98b45e30
DJ
15943@cindex OS ABI
15944@kindex set osabi
b4e9345d 15945@kindex show osabi
98b45e30
DJ
15946
15947One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15948system targets, either via remote debugging or native emulation.
98b45e30
DJ
15949@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15950but you can override its conclusion using the @code{set osabi} command.
15951One example where this is useful is in debugging of binaries which use
15952an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15953not have the same identifying marks that the standard C library for your
15954platform provides.
15955
15956@table @code
15957@item show osabi
15958Show the OS ABI currently in use.
15959
15960@item set osabi
15961With no argument, show the list of registered available OS ABI's.
15962
15963@item set osabi @var{abi}
15964Set the current OS ABI to @var{abi}.
15965@end table
15966
1e698235 15967@cindex float promotion
1e698235
DJ
15968
15969Generally, the way that an argument of type @code{float} is passed to a
15970function depends on whether the function is prototyped. For a prototyped
15971(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15972according to the architecture's convention for @code{float}. For unprototyped
15973(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15974@code{double} and then passed.
15975
15976Unfortunately, some forms of debug information do not reliably indicate whether
15977a function is prototyped. If @value{GDBN} calls a function that is not marked
15978as prototyped, it consults @kbd{set coerce-float-to-double}.
15979
15980@table @code
a8f24a35 15981@kindex set coerce-float-to-double
1e698235
DJ
15982@item set coerce-float-to-double
15983@itemx set coerce-float-to-double on
15984Arguments of type @code{float} will be promoted to @code{double} when passed
15985to an unprototyped function. This is the default setting.
15986
15987@item set coerce-float-to-double off
15988Arguments of type @code{float} will be passed directly to unprototyped
15989functions.
9c16f35a
EZ
15990
15991@kindex show coerce-float-to-double
15992@item show coerce-float-to-double
15993Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15994@end table
15995
f1212245
DJ
15996@kindex set cp-abi
15997@kindex show cp-abi
15998@value{GDBN} needs to know the ABI used for your program's C@t{++}
15999objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
16000used to build your application. @value{GDBN} only fully supports
16001programs with a single C@t{++} ABI; if your program contains code using
16002multiple C@t{++} ABI's or if @value{GDBN} can not identify your
16003program's ABI correctly, you can tell @value{GDBN} which ABI to use.
16004Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
16005before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
16006``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
16007use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
16008``auto''.
16009
16010@table @code
16011@item show cp-abi
16012Show the C@t{++} ABI currently in use.
16013
16014@item set cp-abi
16015With no argument, show the list of supported C@t{++} ABI's.
16016
16017@item set cp-abi @var{abi}
16018@itemx set cp-abi auto
16019Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
16020@end table
16021
8e04817f 16022@node Messages/Warnings
79a6e687 16023@section Optional Warnings and Messages
104c1213 16024
9c16f35a
EZ
16025@cindex verbose operation
16026@cindex optional warnings
8e04817f
AC
16027By default, @value{GDBN} is silent about its inner workings. If you are
16028running on a slow machine, you may want to use the @code{set verbose}
16029command. This makes @value{GDBN} tell you when it does a lengthy
16030internal operation, so you will not think it has crashed.
104c1213 16031
8e04817f
AC
16032Currently, the messages controlled by @code{set verbose} are those
16033which announce that the symbol table for a source file is being read;
79a6e687 16034see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 16035
8e04817f
AC
16036@table @code
16037@kindex set verbose
16038@item set verbose on
16039Enables @value{GDBN} output of certain informational messages.
104c1213 16040
8e04817f
AC
16041@item set verbose off
16042Disables @value{GDBN} output of certain informational messages.
104c1213 16043
8e04817f
AC
16044@kindex show verbose
16045@item show verbose
16046Displays whether @code{set verbose} is on or off.
16047@end table
104c1213 16048
8e04817f
AC
16049By default, if @value{GDBN} encounters bugs in the symbol table of an
16050object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
16051find this information useful (@pxref{Symbol Errors, ,Errors Reading
16052Symbol Files}).
104c1213 16053
8e04817f 16054@table @code
104c1213 16055
8e04817f
AC
16056@kindex set complaints
16057@item set complaints @var{limit}
16058Permits @value{GDBN} to output @var{limit} complaints about each type of
16059unusual symbols before becoming silent about the problem. Set
16060@var{limit} to zero to suppress all complaints; set it to a large number
16061to prevent complaints from being suppressed.
104c1213 16062
8e04817f
AC
16063@kindex show complaints
16064@item show complaints
16065Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 16066
8e04817f 16067@end table
104c1213 16068
8e04817f
AC
16069By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
16070lot of stupid questions to confirm certain commands. For example, if
16071you try to run a program which is already running:
104c1213 16072
474c8240 16073@smallexample
8e04817f
AC
16074(@value{GDBP}) run
16075The program being debugged has been started already.
16076Start it from the beginning? (y or n)
474c8240 16077@end smallexample
104c1213 16078
8e04817f
AC
16079If you are willing to unflinchingly face the consequences of your own
16080commands, you can disable this ``feature'':
104c1213 16081
8e04817f 16082@table @code
104c1213 16083
8e04817f
AC
16084@kindex set confirm
16085@cindex flinching
16086@cindex confirmation
16087@cindex stupid questions
16088@item set confirm off
16089Disables confirmation requests.
104c1213 16090
8e04817f
AC
16091@item set confirm on
16092Enables confirmation requests (the default).
104c1213 16093
8e04817f
AC
16094@kindex show confirm
16095@item show confirm
16096Displays state of confirmation requests.
16097
16098@end table
104c1213 16099
16026cd7
AS
16100@cindex command tracing
16101If you need to debug user-defined commands or sourced files you may find it
16102useful to enable @dfn{command tracing}. In this mode each command will be
16103printed as it is executed, prefixed with one or more @samp{+} symbols, the
16104quantity denoting the call depth of each command.
16105
16106@table @code
16107@kindex set trace-commands
16108@cindex command scripts, debugging
16109@item set trace-commands on
16110Enable command tracing.
16111@item set trace-commands off
16112Disable command tracing.
16113@item show trace-commands
16114Display the current state of command tracing.
16115@end table
16116
8e04817f 16117@node Debugging Output
79a6e687 16118@section Optional Messages about Internal Happenings
4644b6e3
EZ
16119@cindex optional debugging messages
16120
da316a69
EZ
16121@value{GDBN} has commands that enable optional debugging messages from
16122various @value{GDBN} subsystems; normally these commands are of
16123interest to @value{GDBN} maintainers, or when reporting a bug. This
16124section documents those commands.
16125
104c1213 16126@table @code
a8f24a35
EZ
16127@kindex set exec-done-display
16128@item set exec-done-display
16129Turns on or off the notification of asynchronous commands'
16130completion. When on, @value{GDBN} will print a message when an
16131asynchronous command finishes its execution. The default is off.
16132@kindex show exec-done-display
16133@item show exec-done-display
16134Displays the current setting of asynchronous command completion
16135notification.
4644b6e3
EZ
16136@kindex set debug
16137@cindex gdbarch debugging info
a8f24a35 16138@cindex architecture debugging info
8e04817f 16139@item set debug arch
a8f24a35 16140Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 16141@kindex show debug
8e04817f
AC
16142@item show debug arch
16143Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
16144@item set debug aix-thread
16145@cindex AIX threads
16146Display debugging messages about inner workings of the AIX thread
16147module.
16148@item show debug aix-thread
16149Show the current state of AIX thread debugging info display.
8e04817f 16150@item set debug event
4644b6e3 16151@cindex event debugging info
a8f24a35 16152Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 16153default is off.
8e04817f
AC
16154@item show debug event
16155Displays the current state of displaying @value{GDBN} event debugging
16156info.
8e04817f 16157@item set debug expression
4644b6e3 16158@cindex expression debugging info
721c2651
EZ
16159Turns on or off display of debugging info about @value{GDBN}
16160expression parsing. The default is off.
8e04817f 16161@item show debug expression
721c2651
EZ
16162Displays the current state of displaying debugging info about
16163@value{GDBN} expression parsing.
7453dc06 16164@item set debug frame
4644b6e3 16165@cindex frame debugging info
7453dc06
AC
16166Turns on or off display of @value{GDBN} frame debugging info. The
16167default is off.
7453dc06
AC
16168@item show debug frame
16169Displays the current state of displaying @value{GDBN} frame debugging
16170info.
30e91e0b
RC
16171@item set debug infrun
16172@cindex inferior debugging info
16173Turns on or off display of @value{GDBN} debugging info for running the inferior.
16174The default is off. @file{infrun.c} contains GDB's runtime state machine used
16175for implementing operations such as single-stepping the inferior.
16176@item show debug infrun
16177Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
16178@item set debug lin-lwp
16179@cindex @sc{gnu}/Linux LWP debug messages
16180@cindex Linux lightweight processes
721c2651 16181Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
16182@item show debug lin-lwp
16183Show the current state of Linux LWP debugging messages.
2b4855ab 16184@item set debug observer
4644b6e3 16185@cindex observer debugging info
2b4855ab
AC
16186Turns on or off display of @value{GDBN} observer debugging. This
16187includes info such as the notification of observable events.
2b4855ab
AC
16188@item show debug observer
16189Displays the current state of observer debugging.
8e04817f 16190@item set debug overload
4644b6e3 16191@cindex C@t{++} overload debugging info
8e04817f 16192Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 16193info. This includes info such as ranking of functions, etc. The default
8e04817f 16194is off.
8e04817f
AC
16195@item show debug overload
16196Displays the current state of displaying @value{GDBN} C@t{++} overload
16197debugging info.
8e04817f
AC
16198@cindex packets, reporting on stdout
16199@cindex serial connections, debugging
605a56cb
DJ
16200@cindex debug remote protocol
16201@cindex remote protocol debugging
16202@cindex display remote packets
8e04817f
AC
16203@item set debug remote
16204Turns on or off display of reports on all packets sent back and forth across
16205the serial line to the remote machine. The info is printed on the
16206@value{GDBN} standard output stream. The default is off.
8e04817f
AC
16207@item show debug remote
16208Displays the state of display of remote packets.
8e04817f
AC
16209@item set debug serial
16210Turns on or off display of @value{GDBN} serial debugging info. The
16211default is off.
8e04817f
AC
16212@item show debug serial
16213Displays the current state of displaying @value{GDBN} serial debugging
16214info.
c45da7e6
EZ
16215@item set debug solib-frv
16216@cindex FR-V shared-library debugging
16217Turns on or off debugging messages for FR-V shared-library code.
16218@item show debug solib-frv
16219Display the current state of FR-V shared-library code debugging
16220messages.
8e04817f 16221@item set debug target
4644b6e3 16222@cindex target debugging info
8e04817f
AC
16223Turns on or off display of @value{GDBN} target debugging info. This info
16224includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
16225default is 0. Set it to 1 to track events, and to 2 to also track the
16226value of large memory transfers. Changes to this flag do not take effect
16227until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
16228@item show debug target
16229Displays the current state of displaying @value{GDBN} target debugging
16230info.
c45da7e6 16231@item set debugvarobj
4644b6e3 16232@cindex variable object debugging info
8e04817f
AC
16233Turns on or off display of @value{GDBN} variable object debugging
16234info. The default is off.
c45da7e6 16235@item show debugvarobj
8e04817f
AC
16236Displays the current state of displaying @value{GDBN} variable object
16237debugging info.
e776119f
DJ
16238@item set debug xml
16239@cindex XML parser debugging
16240Turns on or off debugging messages for built-in XML parsers.
16241@item show debug xml
16242Displays the current state of XML debugging messages.
8e04817f 16243@end table
104c1213 16244
8e04817f
AC
16245@node Sequences
16246@chapter Canned Sequences of Commands
104c1213 16247
8e04817f 16248Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 16249Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
16250commands for execution as a unit: user-defined commands and command
16251files.
104c1213 16252
8e04817f 16253@menu
fcc73fe3
EZ
16254* Define:: How to define your own commands
16255* Hooks:: Hooks for user-defined commands
16256* Command Files:: How to write scripts of commands to be stored in a file
16257* Output:: Commands for controlled output
8e04817f 16258@end menu
104c1213 16259
8e04817f 16260@node Define
79a6e687 16261@section User-defined Commands
104c1213 16262
8e04817f 16263@cindex user-defined command
fcc73fe3 16264@cindex arguments, to user-defined commands
8e04817f
AC
16265A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
16266which you assign a new name as a command. This is done with the
16267@code{define} command. User commands may accept up to 10 arguments
16268separated by whitespace. Arguments are accessed within the user command
c03c782f 16269via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 16270
8e04817f
AC
16271@smallexample
16272define adder
16273 print $arg0 + $arg1 + $arg2
c03c782f 16274end
8e04817f 16275@end smallexample
104c1213
JM
16276
16277@noindent
8e04817f 16278To execute the command use:
104c1213 16279
8e04817f
AC
16280@smallexample
16281adder 1 2 3
16282@end smallexample
104c1213 16283
8e04817f
AC
16284@noindent
16285This defines the command @code{adder}, which prints the sum of
16286its three arguments. Note the arguments are text substitutions, so they may
16287reference variables, use complex expressions, or even perform inferior
16288functions calls.
104c1213 16289
fcc73fe3
EZ
16290@cindex argument count in user-defined commands
16291@cindex how many arguments (user-defined commands)
c03c782f
AS
16292In addition, @code{$argc} may be used to find out how many arguments have
16293been passed. This expands to a number in the range 0@dots{}10.
16294
16295@smallexample
16296define adder
16297 if $argc == 2
16298 print $arg0 + $arg1
16299 end
16300 if $argc == 3
16301 print $arg0 + $arg1 + $arg2
16302 end
16303end
16304@end smallexample
16305
104c1213 16306@table @code
104c1213 16307
8e04817f
AC
16308@kindex define
16309@item define @var{commandname}
16310Define a command named @var{commandname}. If there is already a command
16311by that name, you are asked to confirm that you want to redefine it.
104c1213 16312
8e04817f
AC
16313The definition of the command is made up of other @value{GDBN} command lines,
16314which are given following the @code{define} command. The end of these
16315commands is marked by a line containing @code{end}.
104c1213 16316
8e04817f 16317@kindex document
ca91424e 16318@kindex end@r{ (user-defined commands)}
8e04817f
AC
16319@item document @var{commandname}
16320Document the user-defined command @var{commandname}, so that it can be
16321accessed by @code{help}. The command @var{commandname} must already be
16322defined. This command reads lines of documentation just as @code{define}
16323reads the lines of the command definition, ending with @code{end}.
16324After the @code{document} command is finished, @code{help} on command
16325@var{commandname} displays the documentation you have written.
104c1213 16326
8e04817f
AC
16327You may use the @code{document} command again to change the
16328documentation of a command. Redefining the command with @code{define}
16329does not change the documentation.
104c1213 16330
c45da7e6
EZ
16331@kindex dont-repeat
16332@cindex don't repeat command
16333@item dont-repeat
16334Used inside a user-defined command, this tells @value{GDBN} that this
16335command should not be repeated when the user hits @key{RET}
16336(@pxref{Command Syntax, repeat last command}).
16337
8e04817f
AC
16338@kindex help user-defined
16339@item help user-defined
16340List all user-defined commands, with the first line of the documentation
16341(if any) for each.
104c1213 16342
8e04817f
AC
16343@kindex show user
16344@item show user
16345@itemx show user @var{commandname}
16346Display the @value{GDBN} commands used to define @var{commandname} (but
16347not its documentation). If no @var{commandname} is given, display the
16348definitions for all user-defined commands.
104c1213 16349
fcc73fe3 16350@cindex infinite recursion in user-defined commands
20f01a46
DH
16351@kindex show max-user-call-depth
16352@kindex set max-user-call-depth
16353@item show max-user-call-depth
5ca0cb28
DH
16354@itemx set max-user-call-depth
16355The value of @code{max-user-call-depth} controls how many recursion
3f94c067 16356levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 16357infinite recursion and aborts the command.
104c1213
JM
16358@end table
16359
fcc73fe3
EZ
16360In addition to the above commands, user-defined commands frequently
16361use control flow commands, described in @ref{Command Files}.
16362
8e04817f
AC
16363When user-defined commands are executed, the
16364commands of the definition are not printed. An error in any command
16365stops execution of the user-defined command.
104c1213 16366
8e04817f
AC
16367If used interactively, commands that would ask for confirmation proceed
16368without asking when used inside a user-defined command. Many @value{GDBN}
16369commands that normally print messages to say what they are doing omit the
16370messages when used in a user-defined command.
104c1213 16371
8e04817f 16372@node Hooks
79a6e687 16373@section User-defined Command Hooks
8e04817f
AC
16374@cindex command hooks
16375@cindex hooks, for commands
16376@cindex hooks, pre-command
104c1213 16377
8e04817f 16378@kindex hook
8e04817f
AC
16379You may define @dfn{hooks}, which are a special kind of user-defined
16380command. Whenever you run the command @samp{foo}, if the user-defined
16381command @samp{hook-foo} exists, it is executed (with no arguments)
16382before that command.
104c1213 16383
8e04817f
AC
16384@cindex hooks, post-command
16385@kindex hookpost
8e04817f
AC
16386A hook may also be defined which is run after the command you executed.
16387Whenever you run the command @samp{foo}, if the user-defined command
16388@samp{hookpost-foo} exists, it is executed (with no arguments) after
16389that command. Post-execution hooks may exist simultaneously with
16390pre-execution hooks, for the same command.
104c1213 16391
8e04817f 16392It is valid for a hook to call the command which it hooks. If this
9f1c6395 16393occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 16394
8e04817f
AC
16395@c It would be nice if hookpost could be passed a parameter indicating
16396@c if the command it hooks executed properly or not. FIXME!
104c1213 16397
8e04817f
AC
16398@kindex stop@r{, a pseudo-command}
16399In addition, a pseudo-command, @samp{stop} exists. Defining
16400(@samp{hook-stop}) makes the associated commands execute every time
16401execution stops in your program: before breakpoint commands are run,
16402displays are printed, or the stack frame is printed.
104c1213 16403
8e04817f
AC
16404For example, to ignore @code{SIGALRM} signals while
16405single-stepping, but treat them normally during normal execution,
16406you could define:
104c1213 16407
474c8240 16408@smallexample
8e04817f
AC
16409define hook-stop
16410handle SIGALRM nopass
16411end
104c1213 16412
8e04817f
AC
16413define hook-run
16414handle SIGALRM pass
16415end
104c1213 16416
8e04817f 16417define hook-continue
d3e8051b 16418handle SIGALRM pass
8e04817f 16419end
474c8240 16420@end smallexample
104c1213 16421
d3e8051b 16422As a further example, to hook at the beginning and end of the @code{echo}
b383017d 16423command, and to add extra text to the beginning and end of the message,
8e04817f 16424you could define:
104c1213 16425
474c8240 16426@smallexample
8e04817f
AC
16427define hook-echo
16428echo <<<---
16429end
104c1213 16430
8e04817f
AC
16431define hookpost-echo
16432echo --->>>\n
16433end
104c1213 16434
8e04817f
AC
16435(@value{GDBP}) echo Hello World
16436<<<---Hello World--->>>
16437(@value{GDBP})
104c1213 16438
474c8240 16439@end smallexample
104c1213 16440
8e04817f
AC
16441You can define a hook for any single-word command in @value{GDBN}, but
16442not for command aliases; you should define a hook for the basic command
c1468174 16443name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
16444@c FIXME! So how does Joe User discover whether a command is an alias
16445@c or not?
16446If an error occurs during the execution of your hook, execution of
16447@value{GDBN} commands stops and @value{GDBN} issues a prompt
16448(before the command that you actually typed had a chance to run).
104c1213 16449
8e04817f
AC
16450If you try to define a hook which does not match any known command, you
16451get a warning from the @code{define} command.
c906108c 16452
8e04817f 16453@node Command Files
79a6e687 16454@section Command Files
c906108c 16455
8e04817f 16456@cindex command files
fcc73fe3 16457@cindex scripting commands
6fc08d32
EZ
16458A command file for @value{GDBN} is a text file made of lines that are
16459@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
16460also be included. An empty line in a command file does nothing; it
16461does not mean to repeat the last command, as it would from the
16462terminal.
c906108c 16463
6fc08d32
EZ
16464You can request the execution of a command file with the @code{source}
16465command:
c906108c 16466
8e04817f
AC
16467@table @code
16468@kindex source
ca91424e 16469@cindex execute commands from a file
16026cd7 16470@item source [@code{-v}] @var{filename}
8e04817f 16471Execute the command file @var{filename}.
c906108c
SS
16472@end table
16473
fcc73fe3
EZ
16474The lines in a command file are generally executed sequentially,
16475unless the order of execution is changed by one of the
16476@emph{flow-control commands} described below. The commands are not
a71ec265
DH
16477printed as they are executed. An error in any command terminates
16478execution of the command file and control is returned to the console.
c906108c 16479
4b505b12
AS
16480@value{GDBN} searches for @var{filename} in the current directory and then
16481on the search path (specified with the @samp{directory} command).
16482
16026cd7
AS
16483If @code{-v}, for verbose mode, is given then @value{GDBN} displays
16484each command as it is executed. The option must be given before
16485@var{filename}, and is interpreted as part of the filename anywhere else.
16486
8e04817f
AC
16487Commands that would ask for confirmation if used interactively proceed
16488without asking when used in a command file. Many @value{GDBN} commands that
16489normally print messages to say what they are doing omit the messages
16490when called from command files.
c906108c 16491
8e04817f
AC
16492@value{GDBN} also accepts command input from standard input. In this
16493mode, normal output goes to standard output and error output goes to
16494standard error. Errors in a command file supplied on standard input do
6fc08d32 16495not terminate execution of the command file---execution continues with
8e04817f 16496the next command.
c906108c 16497
474c8240 16498@smallexample
8e04817f 16499gdb < cmds > log 2>&1
474c8240 16500@end smallexample
c906108c 16501
8e04817f
AC
16502(The syntax above will vary depending on the shell used.) This example
16503will execute commands from the file @file{cmds}. All output and errors
16504would be directed to @file{log}.
c906108c 16505
fcc73fe3
EZ
16506Since commands stored on command files tend to be more general than
16507commands typed interactively, they frequently need to deal with
16508complicated situations, such as different or unexpected values of
16509variables and symbols, changes in how the program being debugged is
16510built, etc. @value{GDBN} provides a set of flow-control commands to
16511deal with these complexities. Using these commands, you can write
16512complex scripts that loop over data structures, execute commands
16513conditionally, etc.
16514
16515@table @code
16516@kindex if
16517@kindex else
16518@item if
16519@itemx else
16520This command allows to include in your script conditionally executed
16521commands. The @code{if} command takes a single argument, which is an
16522expression to evaluate. It is followed by a series of commands that
16523are executed only if the expression is true (its value is nonzero).
16524There can then optionally be an @code{else} line, followed by a series
16525of commands that are only executed if the expression was false. The
16526end of the list is marked by a line containing @code{end}.
16527
16528@kindex while
16529@item while
16530This command allows to write loops. Its syntax is similar to
16531@code{if}: the command takes a single argument, which is an expression
16532to evaluate, and must be followed by the commands to execute, one per
16533line, terminated by an @code{end}. These commands are called the
16534@dfn{body} of the loop. The commands in the body of @code{while} are
16535executed repeatedly as long as the expression evaluates to true.
16536
16537@kindex loop_break
16538@item loop_break
16539This command exits the @code{while} loop in whose body it is included.
16540Execution of the script continues after that @code{while}s @code{end}
16541line.
16542
16543@kindex loop_continue
16544@item loop_continue
16545This command skips the execution of the rest of the body of commands
16546in the @code{while} loop in whose body it is included. Execution
16547branches to the beginning of the @code{while} loop, where it evaluates
16548the controlling expression.
ca91424e
EZ
16549
16550@kindex end@r{ (if/else/while commands)}
16551@item end
16552Terminate the block of commands that are the body of @code{if},
16553@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
16554@end table
16555
16556
8e04817f 16557@node Output
79a6e687 16558@section Commands for Controlled Output
c906108c 16559
8e04817f
AC
16560During the execution of a command file or a user-defined command, normal
16561@value{GDBN} output is suppressed; the only output that appears is what is
16562explicitly printed by the commands in the definition. This section
16563describes three commands useful for generating exactly the output you
16564want.
c906108c
SS
16565
16566@table @code
8e04817f
AC
16567@kindex echo
16568@item echo @var{text}
16569@c I do not consider backslash-space a standard C escape sequence
16570@c because it is not in ANSI.
16571Print @var{text}. Nonprinting characters can be included in
16572@var{text} using C escape sequences, such as @samp{\n} to print a
16573newline. @strong{No newline is printed unless you specify one.}
16574In addition to the standard C escape sequences, a backslash followed
16575by a space stands for a space. This is useful for displaying a
16576string with spaces at the beginning or the end, since leading and
16577trailing spaces are otherwise trimmed from all arguments.
16578To print @samp{@w{ }and foo =@w{ }}, use the command
16579@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 16580
8e04817f
AC
16581A backslash at the end of @var{text} can be used, as in C, to continue
16582the command onto subsequent lines. For example,
c906108c 16583
474c8240 16584@smallexample
8e04817f
AC
16585echo This is some text\n\
16586which is continued\n\
16587onto several lines.\n
474c8240 16588@end smallexample
c906108c 16589
8e04817f 16590produces the same output as
c906108c 16591
474c8240 16592@smallexample
8e04817f
AC
16593echo This is some text\n
16594echo which is continued\n
16595echo onto several lines.\n
474c8240 16596@end smallexample
c906108c 16597
8e04817f
AC
16598@kindex output
16599@item output @var{expression}
16600Print the value of @var{expression} and nothing but that value: no
16601newlines, no @samp{$@var{nn} = }. The value is not entered in the
16602value history either. @xref{Expressions, ,Expressions}, for more information
16603on expressions.
c906108c 16604
8e04817f
AC
16605@item output/@var{fmt} @var{expression}
16606Print the value of @var{expression} in format @var{fmt}. You can use
16607the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 16608Formats}, for more information.
c906108c 16609
8e04817f 16610@kindex printf
82160952
EZ
16611@item printf @var{template}, @var{expressions}@dots{}
16612Print the values of one or more @var{expressions} under the control of
16613the string @var{template}. To print several values, make
16614@var{expressions} be a comma-separated list of individual expressions,
16615which may be either numbers or pointers. Their values are printed as
16616specified by @var{template}, exactly as a C program would do by
16617executing the code below:
c906108c 16618
474c8240 16619@smallexample
82160952 16620printf (@var{template}, @var{expressions}@dots{});
474c8240 16621@end smallexample
c906108c 16622
82160952
EZ
16623As in @code{C} @code{printf}, ordinary characters in @var{template}
16624are printed verbatim, while @dfn{conversion specification} introduced
16625by the @samp{%} character cause subsequent @var{expressions} to be
16626evaluated, their values converted and formatted according to type and
16627style information encoded in the conversion specifications, and then
16628printed.
16629
8e04817f 16630For example, you can print two values in hex like this:
c906108c 16631
8e04817f
AC
16632@smallexample
16633printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
16634@end smallexample
c906108c 16635
82160952
EZ
16636@code{printf} supports all the standard @code{C} conversion
16637specifications, including the flags and modifiers between the @samp{%}
16638character and the conversion letter, with the following exceptions:
16639
16640@itemize @bullet
16641@item
16642The argument-ordering modifiers, such as @samp{2$}, are not supported.
16643
16644@item
16645The modifier @samp{*} is not supported for specifying precision or
16646width.
16647
16648@item
16649The @samp{'} flag (for separation of digits into groups according to
16650@code{LC_NUMERIC'}) is not supported.
16651
16652@item
16653The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
16654supported.
16655
16656@item
16657The conversion letter @samp{n} (as in @samp{%n}) is not supported.
16658
16659@item
16660The conversion letters @samp{a} and @samp{A} are not supported.
16661@end itemize
16662
16663@noindent
16664Note that the @samp{ll} type modifier is supported only if the
16665underlying @code{C} implementation used to build @value{GDBN} supports
16666the @code{long long int} type, and the @samp{L} type modifier is
16667supported only if @code{long double} type is available.
16668
16669As in @code{C}, @code{printf} supports simple backslash-escape
16670sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
16671@samp{\a}, and @samp{\f}, that consist of backslash followed by a
16672single character. Octal and hexadecimal escape sequences are not
16673supported.
1a619819
LM
16674
16675Additionally, @code{printf} supports conversion specifications for DFP
16676(@dfn{Decimal Floating Point}) types using the following conversion
16677letters:
16678
16679@itemize @bullet
16680@item
16681@samp{H} for printing @code{Decimal32} types.
16682
16683@item
16684@samp{D} for printing @code{Decimal64} types.
16685
16686@item
16687@samp{DD} for printing @code{Decimal128} types.
16688@end itemize
16689
16690If the underlying @code{C} implementation used to build @value{GDBN} has
16691support for the three conversion letters for DFP types, other modifiers
3b784c4f 16692such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
16693
16694In case there is no such @code{C} support, no additional modifiers will be
16695available and the value will be printed in the standard way.
16696
16697Here's an example of printing DFP types using the above conversion letters:
16698@smallexample
16699printf "D32: %H - D64: %D - D128: %DD\n",1.2345df,1.2E10dd,1.2E1dl
16700@end smallexample
16701
c906108c
SS
16702@end table
16703
21c294e6
AC
16704@node Interpreters
16705@chapter Command Interpreters
16706@cindex command interpreters
16707
16708@value{GDBN} supports multiple command interpreters, and some command
16709infrastructure to allow users or user interface writers to switch
16710between interpreters or run commands in other interpreters.
16711
16712@value{GDBN} currently supports two command interpreters, the console
16713interpreter (sometimes called the command-line interpreter or @sc{cli})
16714and the machine interface interpreter (or @sc{gdb/mi}). This manual
16715describes both of these interfaces in great detail.
16716
16717By default, @value{GDBN} will start with the console interpreter.
16718However, the user may choose to start @value{GDBN} with another
16719interpreter by specifying the @option{-i} or @option{--interpreter}
16720startup options. Defined interpreters include:
16721
16722@table @code
16723@item console
16724@cindex console interpreter
16725The traditional console or command-line interpreter. This is the most often
16726used interpreter with @value{GDBN}. With no interpreter specified at runtime,
16727@value{GDBN} will use this interpreter.
16728
16729@item mi
16730@cindex mi interpreter
16731The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
16732by programs wishing to use @value{GDBN} as a backend for a debugger GUI
16733or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
16734Interface}.
16735
16736@item mi2
16737@cindex mi2 interpreter
16738The current @sc{gdb/mi} interface.
16739
16740@item mi1
16741@cindex mi1 interpreter
16742The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
16743
16744@end table
16745
16746@cindex invoke another interpreter
16747The interpreter being used by @value{GDBN} may not be dynamically
16748switched at runtime. Although possible, this could lead to a very
16749precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
16750enters the command "interpreter-set console" in a console view,
16751@value{GDBN} would switch to using the console interpreter, rendering
16752the IDE inoperable!
16753
16754@kindex interpreter-exec
16755Although you may only choose a single interpreter at startup, you may execute
16756commands in any interpreter from the current interpreter using the appropriate
16757command. If you are running the console interpreter, simply use the
16758@code{interpreter-exec} command:
16759
16760@smallexample
16761interpreter-exec mi "-data-list-register-names"
16762@end smallexample
16763
16764@sc{gdb/mi} has a similar command, although it is only available in versions of
16765@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16766
8e04817f
AC
16767@node TUI
16768@chapter @value{GDBN} Text User Interface
16769@cindex TUI
d0d5df6f 16770@cindex Text User Interface
c906108c 16771
8e04817f
AC
16772@menu
16773* TUI Overview:: TUI overview
16774* TUI Keys:: TUI key bindings
7cf36c78 16775* TUI Single Key Mode:: TUI single key mode
db2e3e2e 16776* TUI Commands:: TUI-specific commands
8e04817f
AC
16777* TUI Configuration:: TUI configuration variables
16778@end menu
c906108c 16779
46ba6afa 16780The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
16781interface which uses the @code{curses} library to show the source
16782file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
16783commands in separate text windows. The TUI mode is supported only
16784on platforms where a suitable version of the @code{curses} library
16785is available.
d0d5df6f 16786
46ba6afa
BW
16787@pindex @value{GDBTUI}
16788The TUI mode is enabled by default when you invoke @value{GDBN} as
16789either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
16790You can also switch in and out of TUI mode while @value{GDBN} runs by
16791using various TUI commands and key bindings, such as @kbd{C-x C-a}.
16792@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 16793
8e04817f 16794@node TUI Overview
79a6e687 16795@section TUI Overview
c906108c 16796
46ba6afa 16797In TUI mode, @value{GDBN} can display several text windows:
c906108c 16798
8e04817f
AC
16799@table @emph
16800@item command
16801This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
16802prompt and the @value{GDBN} output. The @value{GDBN} input is still
16803managed using readline.
c906108c 16804
8e04817f
AC
16805@item source
16806The source window shows the source file of the program. The current
46ba6afa 16807line and active breakpoints are displayed in this window.
c906108c 16808
8e04817f
AC
16809@item assembly
16810The assembly window shows the disassembly output of the program.
c906108c 16811
8e04817f 16812@item register
46ba6afa
BW
16813This window shows the processor registers. Registers are highlighted
16814when their values change.
c906108c
SS
16815@end table
16816
269c21fe 16817The source and assembly windows show the current program position
46ba6afa
BW
16818by highlighting the current line and marking it with a @samp{>} marker.
16819Breakpoints are indicated with two markers. The first marker
269c21fe
SC
16820indicates the breakpoint type:
16821
16822@table @code
16823@item B
16824Breakpoint which was hit at least once.
16825
16826@item b
16827Breakpoint which was never hit.
16828
16829@item H
16830Hardware breakpoint which was hit at least once.
16831
16832@item h
16833Hardware breakpoint which was never hit.
269c21fe
SC
16834@end table
16835
16836The second marker indicates whether the breakpoint is enabled or not:
16837
16838@table @code
16839@item +
16840Breakpoint is enabled.
16841
16842@item -
16843Breakpoint is disabled.
269c21fe
SC
16844@end table
16845
46ba6afa
BW
16846The source, assembly and register windows are updated when the current
16847thread changes, when the frame changes, or when the program counter
16848changes.
16849
16850These windows are not all visible at the same time. The command
16851window is always visible. The others can be arranged in several
16852layouts:
c906108c 16853
8e04817f
AC
16854@itemize @bullet
16855@item
46ba6afa 16856source only,
2df3850c 16857
8e04817f 16858@item
46ba6afa 16859assembly only,
8e04817f
AC
16860
16861@item
46ba6afa 16862source and assembly,
8e04817f
AC
16863
16864@item
46ba6afa 16865source and registers, or
c906108c 16866
8e04817f 16867@item
46ba6afa 16868assembly and registers.
8e04817f 16869@end itemize
c906108c 16870
46ba6afa 16871A status line above the command window shows the following information:
b7bb15bc
SC
16872
16873@table @emph
16874@item target
46ba6afa 16875Indicates the current @value{GDBN} target.
b7bb15bc
SC
16876(@pxref{Targets, ,Specifying a Debugging Target}).
16877
16878@item process
46ba6afa 16879Gives the current process or thread number.
b7bb15bc
SC
16880When no process is being debugged, this field is set to @code{No process}.
16881
16882@item function
16883Gives the current function name for the selected frame.
16884The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 16885When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
16886the string @code{??} is displayed.
16887
16888@item line
16889Indicates the current line number for the selected frame.
46ba6afa 16890When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
16891
16892@item pc
16893Indicates the current program counter address.
b7bb15bc
SC
16894@end table
16895
8e04817f
AC
16896@node TUI Keys
16897@section TUI Key Bindings
16898@cindex TUI key bindings
c906108c 16899
8e04817f 16900The TUI installs several key bindings in the readline keymaps
46ba6afa 16901(@pxref{Command Line Editing}). The following key bindings
8e04817f 16902are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16903
8e04817f
AC
16904@table @kbd
16905@kindex C-x C-a
16906@item C-x C-a
16907@kindex C-x a
16908@itemx C-x a
16909@kindex C-x A
16910@itemx C-x A
46ba6afa
BW
16911Enter or leave the TUI mode. When leaving the TUI mode,
16912the curses window management stops and @value{GDBN} operates using
16913its standard mode, writing on the terminal directly. When reentering
16914the TUI mode, control is given back to the curses windows.
8e04817f 16915The screen is then refreshed.
c906108c 16916
8e04817f
AC
16917@kindex C-x 1
16918@item C-x 1
16919Use a TUI layout with only one window. The layout will
16920either be @samp{source} or @samp{assembly}. When the TUI mode
16921is not active, it will switch to the TUI mode.
2df3850c 16922
8e04817f 16923Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16924
8e04817f
AC
16925@kindex C-x 2
16926@item C-x 2
16927Use a TUI layout with at least two windows. When the current
46ba6afa 16928layout already has two windows, the next layout with two windows is used.
8e04817f
AC
16929When a new layout is chosen, one window will always be common to the
16930previous layout and the new one.
c906108c 16931
8e04817f 16932Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16933
72ffddc9
SC
16934@kindex C-x o
16935@item C-x o
16936Change the active window. The TUI associates several key bindings
46ba6afa 16937(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
16938gives the focus to the next TUI window.
16939
16940Think of it as the Emacs @kbd{C-x o} binding.
16941
7cf36c78
SC
16942@kindex C-x s
16943@item C-x s
46ba6afa
BW
16944Switch in and out of the TUI SingleKey mode that binds single
16945keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
16946@end table
16947
46ba6afa 16948The following key bindings only work in the TUI mode:
5d161b24 16949
46ba6afa 16950@table @asis
8e04817f 16951@kindex PgUp
46ba6afa 16952@item @key{PgUp}
8e04817f 16953Scroll the active window one page up.
c906108c 16954
8e04817f 16955@kindex PgDn
46ba6afa 16956@item @key{PgDn}
8e04817f 16957Scroll the active window one page down.
c906108c 16958
8e04817f 16959@kindex Up
46ba6afa 16960@item @key{Up}
8e04817f 16961Scroll the active window one line up.
c906108c 16962
8e04817f 16963@kindex Down
46ba6afa 16964@item @key{Down}
8e04817f 16965Scroll the active window one line down.
c906108c 16966
8e04817f 16967@kindex Left
46ba6afa 16968@item @key{Left}
8e04817f 16969Scroll the active window one column left.
c906108c 16970
8e04817f 16971@kindex Right
46ba6afa 16972@item @key{Right}
8e04817f 16973Scroll the active window one column right.
c906108c 16974
8e04817f 16975@kindex C-L
46ba6afa 16976@item @kbd{C-L}
8e04817f 16977Refresh the screen.
8e04817f 16978@end table
c906108c 16979
46ba6afa
BW
16980Because the arrow keys scroll the active window in the TUI mode, they
16981are not available for their normal use by readline unless the command
16982window has the focus. When another window is active, you must use
16983other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
16984and @kbd{C-f} to control the command window.
8e04817f 16985
7cf36c78
SC
16986@node TUI Single Key Mode
16987@section TUI Single Key Mode
16988@cindex TUI single key mode
16989
46ba6afa
BW
16990The TUI also provides a @dfn{SingleKey} mode, which binds several
16991frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
16992switch into this mode, where the following key bindings are used:
7cf36c78
SC
16993
16994@table @kbd
16995@kindex c @r{(SingleKey TUI key)}
16996@item c
16997continue
16998
16999@kindex d @r{(SingleKey TUI key)}
17000@item d
17001down
17002
17003@kindex f @r{(SingleKey TUI key)}
17004@item f
17005finish
17006
17007@kindex n @r{(SingleKey TUI key)}
17008@item n
17009next
17010
17011@kindex q @r{(SingleKey TUI key)}
17012@item q
46ba6afa 17013exit the SingleKey mode.
7cf36c78
SC
17014
17015@kindex r @r{(SingleKey TUI key)}
17016@item r
17017run
17018
17019@kindex s @r{(SingleKey TUI key)}
17020@item s
17021step
17022
17023@kindex u @r{(SingleKey TUI key)}
17024@item u
17025up
17026
17027@kindex v @r{(SingleKey TUI key)}
17028@item v
17029info locals
17030
17031@kindex w @r{(SingleKey TUI key)}
17032@item w
17033where
7cf36c78
SC
17034@end table
17035
17036Other keys temporarily switch to the @value{GDBN} command prompt.
17037The key that was pressed is inserted in the editing buffer so that
17038it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
17039with the TUI SingleKey mode. Once the command is entered the TUI
17040SingleKey mode is restored. The only way to permanently leave
7f9087cb 17041this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
17042
17043
8e04817f 17044@node TUI Commands
db2e3e2e 17045@section TUI-specific Commands
8e04817f
AC
17046@cindex TUI commands
17047
17048The TUI has specific commands to control the text windows.
46ba6afa
BW
17049These commands are always available, even when @value{GDBN} is not in
17050the TUI mode. When @value{GDBN} is in the standard mode, most
17051of these commands will automatically switch to the TUI mode.
c906108c
SS
17052
17053@table @code
3d757584
SC
17054@item info win
17055@kindex info win
17056List and give the size of all displayed windows.
17057
8e04817f 17058@item layout next
4644b6e3 17059@kindex layout
8e04817f 17060Display the next layout.
2df3850c 17061
8e04817f 17062@item layout prev
8e04817f 17063Display the previous layout.
c906108c 17064
8e04817f 17065@item layout src
8e04817f 17066Display the source window only.
c906108c 17067
8e04817f 17068@item layout asm
8e04817f 17069Display the assembly window only.
c906108c 17070
8e04817f 17071@item layout split
8e04817f 17072Display the source and assembly window.
c906108c 17073
8e04817f 17074@item layout regs
8e04817f
AC
17075Display the register window together with the source or assembly window.
17076
46ba6afa 17077@item focus next
8e04817f 17078@kindex focus
46ba6afa
BW
17079Make the next window active for scrolling.
17080
17081@item focus prev
17082Make the previous window active for scrolling.
17083
17084@item focus src
17085Make the source window active for scrolling.
17086
17087@item focus asm
17088Make the assembly window active for scrolling.
17089
17090@item focus regs
17091Make the register window active for scrolling.
17092
17093@item focus cmd
17094Make the command window active for scrolling.
c906108c 17095
8e04817f
AC
17096@item refresh
17097@kindex refresh
7f9087cb 17098Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 17099
6a1b180d
SC
17100@item tui reg float
17101@kindex tui reg
17102Show the floating point registers in the register window.
17103
17104@item tui reg general
17105Show the general registers in the register window.
17106
17107@item tui reg next
17108Show the next register group. The list of register groups as well as
17109their order is target specific. The predefined register groups are the
17110following: @code{general}, @code{float}, @code{system}, @code{vector},
17111@code{all}, @code{save}, @code{restore}.
17112
17113@item tui reg system
17114Show the system registers in the register window.
17115
8e04817f
AC
17116@item update
17117@kindex update
17118Update the source window and the current execution point.
c906108c 17119
8e04817f
AC
17120@item winheight @var{name} +@var{count}
17121@itemx winheight @var{name} -@var{count}
17122@kindex winheight
17123Change the height of the window @var{name} by @var{count}
17124lines. Positive counts increase the height, while negative counts
17125decrease it.
2df3850c 17126
46ba6afa
BW
17127@item tabset @var{nchars}
17128@kindex tabset
c45da7e6 17129Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
17130@end table
17131
8e04817f 17132@node TUI Configuration
79a6e687 17133@section TUI Configuration Variables
8e04817f 17134@cindex TUI configuration variables
c906108c 17135
46ba6afa 17136Several configuration variables control the appearance of TUI windows.
c906108c 17137
8e04817f
AC
17138@table @code
17139@item set tui border-kind @var{kind}
17140@kindex set tui border-kind
17141Select the border appearance for the source, assembly and register windows.
17142The possible values are the following:
17143@table @code
17144@item space
17145Use a space character to draw the border.
c906108c 17146
8e04817f 17147@item ascii
46ba6afa 17148Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 17149
8e04817f
AC
17150@item acs
17151Use the Alternate Character Set to draw the border. The border is
17152drawn using character line graphics if the terminal supports them.
8e04817f 17153@end table
c78b4128 17154
8e04817f
AC
17155@item set tui border-mode @var{mode}
17156@kindex set tui border-mode
46ba6afa
BW
17157@itemx set tui active-border-mode @var{mode}
17158@kindex set tui active-border-mode
17159Select the display attributes for the borders of the inactive windows
17160or the active window. The @var{mode} can be one of the following:
8e04817f
AC
17161@table @code
17162@item normal
17163Use normal attributes to display the border.
c906108c 17164
8e04817f
AC
17165@item standout
17166Use standout mode.
c906108c 17167
8e04817f
AC
17168@item reverse
17169Use reverse video mode.
c906108c 17170
8e04817f
AC
17171@item half
17172Use half bright mode.
c906108c 17173
8e04817f
AC
17174@item half-standout
17175Use half bright and standout mode.
c906108c 17176
8e04817f
AC
17177@item bold
17178Use extra bright or bold mode.
c78b4128 17179
8e04817f
AC
17180@item bold-standout
17181Use extra bright or bold and standout mode.
8e04817f 17182@end table
8e04817f 17183@end table
c78b4128 17184
8e04817f
AC
17185@node Emacs
17186@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 17187
8e04817f
AC
17188@cindex Emacs
17189@cindex @sc{gnu} Emacs
17190A special interface allows you to use @sc{gnu} Emacs to view (and
17191edit) the source files for the program you are debugging with
17192@value{GDBN}.
c906108c 17193
8e04817f
AC
17194To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
17195executable file you want to debug as an argument. This command starts
17196@value{GDBN} as a subprocess of Emacs, with input and output through a newly
17197created Emacs buffer.
17198@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 17199
5e252a2e 17200Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 17201things:
c906108c 17202
8e04817f
AC
17203@itemize @bullet
17204@item
5e252a2e
NR
17205All ``terminal'' input and output goes through an Emacs buffer, called
17206the GUD buffer.
c906108c 17207
8e04817f
AC
17208This applies both to @value{GDBN} commands and their output, and to the input
17209and output done by the program you are debugging.
bf0184be 17210
8e04817f
AC
17211This is useful because it means that you can copy the text of previous
17212commands and input them again; you can even use parts of the output
17213in this way.
bf0184be 17214
8e04817f
AC
17215All the facilities of Emacs' Shell mode are available for interacting
17216with your program. In particular, you can send signals the usual
17217way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
17218stop.
bf0184be
ND
17219
17220@item
8e04817f 17221@value{GDBN} displays source code through Emacs.
bf0184be 17222
8e04817f
AC
17223Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
17224source file for that frame and puts an arrow (@samp{=>}) at the
17225left margin of the current line. Emacs uses a separate buffer for
17226source display, and splits the screen to show both your @value{GDBN} session
17227and the source.
bf0184be 17228
8e04817f
AC
17229Explicit @value{GDBN} @code{list} or search commands still produce output as
17230usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
17231@end itemize
17232
17233We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
17234a graphical mode, enabled by default, which provides further buffers
17235that can control the execution and describe the state of your program.
17236@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 17237
64fabec2
AC
17238If you specify an absolute file name when prompted for the @kbd{M-x
17239gdb} argument, then Emacs sets your current working directory to where
17240your program resides. If you only specify the file name, then Emacs
17241sets your current working directory to to the directory associated
17242with the previous buffer. In this case, @value{GDBN} may find your
17243program by searching your environment's @code{PATH} variable, but on
17244some operating systems it might not find the source. So, although the
17245@value{GDBN} input and output session proceeds normally, the auxiliary
17246buffer does not display the current source and line of execution.
17247
17248The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
17249line of the GUD buffer and this serves as a default for the commands
17250that specify files for @value{GDBN} to operate on. @xref{Files,
17251,Commands to Specify Files}.
64fabec2
AC
17252
17253By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
17254need to call @value{GDBN} by a different name (for example, if you
17255keep several configurations around, with different names) you can
17256customize the Emacs variable @code{gud-gdb-command-name} to run the
17257one you want.
8e04817f 17258
5e252a2e 17259In the GUD buffer, you can use these special Emacs commands in
8e04817f 17260addition to the standard Shell mode commands:
c906108c 17261
8e04817f
AC
17262@table @kbd
17263@item C-h m
5e252a2e 17264Describe the features of Emacs' GUD Mode.
c906108c 17265
64fabec2 17266@item C-c C-s
8e04817f
AC
17267Execute to another source line, like the @value{GDBN} @code{step} command; also
17268update the display window to show the current file and location.
c906108c 17269
64fabec2 17270@item C-c C-n
8e04817f
AC
17271Execute to next source line in this function, skipping all function
17272calls, like the @value{GDBN} @code{next} command. Then update the display window
17273to show the current file and location.
c906108c 17274
64fabec2 17275@item C-c C-i
8e04817f
AC
17276Execute one instruction, like the @value{GDBN} @code{stepi} command; update
17277display window accordingly.
c906108c 17278
8e04817f
AC
17279@item C-c C-f
17280Execute until exit from the selected stack frame, like the @value{GDBN}
17281@code{finish} command.
c906108c 17282
64fabec2 17283@item C-c C-r
8e04817f
AC
17284Continue execution of your program, like the @value{GDBN} @code{continue}
17285command.
b433d00b 17286
64fabec2 17287@item C-c <
8e04817f
AC
17288Go up the number of frames indicated by the numeric argument
17289(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
17290like the @value{GDBN} @code{up} command.
b433d00b 17291
64fabec2 17292@item C-c >
8e04817f
AC
17293Go down the number of frames indicated by the numeric argument, like the
17294@value{GDBN} @code{down} command.
8e04817f 17295@end table
c906108c 17296
7f9087cb 17297In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 17298tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 17299
5e252a2e
NR
17300In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
17301separate frame which shows a backtrace when the GUD buffer is current.
17302Move point to any frame in the stack and type @key{RET} to make it
17303become the current frame and display the associated source in the
17304source buffer. Alternatively, click @kbd{Mouse-2} to make the
17305selected frame become the current one. In graphical mode, the
17306speedbar displays watch expressions.
64fabec2 17307
8e04817f
AC
17308If you accidentally delete the source-display buffer, an easy way to get
17309it back is to type the command @code{f} in the @value{GDBN} buffer, to
17310request a frame display; when you run under Emacs, this recreates
17311the source buffer if necessary to show you the context of the current
17312frame.
c906108c 17313
8e04817f
AC
17314The source files displayed in Emacs are in ordinary Emacs buffers
17315which are visiting the source files in the usual way. You can edit
17316the files with these buffers if you wish; but keep in mind that @value{GDBN}
17317communicates with Emacs in terms of line numbers. If you add or
17318delete lines from the text, the line numbers that @value{GDBN} knows cease
17319to correspond properly with the code.
b383017d 17320
5e252a2e
NR
17321A more detailed description of Emacs' interaction with @value{GDBN} is
17322given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
17323Emacs Manual}).
c906108c 17324
8e04817f
AC
17325@c The following dropped because Epoch is nonstandard. Reactivate
17326@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
17327@ignore
17328@kindex Emacs Epoch environment
17329@kindex Epoch
17330@kindex inspect
c906108c 17331
8e04817f
AC
17332Version 18 of @sc{gnu} Emacs has a built-in window system
17333called the @code{epoch}
17334environment. Users of this environment can use a new command,
17335@code{inspect} which performs identically to @code{print} except that
17336each value is printed in its own window.
17337@end ignore
c906108c 17338
922fbb7b
AC
17339
17340@node GDB/MI
17341@chapter The @sc{gdb/mi} Interface
17342
17343@unnumberedsec Function and Purpose
17344
17345@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
17346@sc{gdb/mi} is a line based machine oriented text interface to
17347@value{GDBN} and is activated by specifying using the
17348@option{--interpreter} command line option (@pxref{Mode Options}). It
17349is specifically intended to support the development of systems which
17350use the debugger as just one small component of a larger system.
922fbb7b
AC
17351
17352This chapter is a specification of the @sc{gdb/mi} interface. It is written
17353in the form of a reference manual.
17354
17355Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
17356features described below are incomplete and subject to change
17357(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
17358
17359@unnumberedsec Notation and Terminology
17360
17361@cindex notational conventions, for @sc{gdb/mi}
17362This chapter uses the following notation:
17363
17364@itemize @bullet
17365@item
17366@code{|} separates two alternatives.
17367
17368@item
17369@code{[ @var{something} ]} indicates that @var{something} is optional:
17370it may or may not be given.
17371
17372@item
17373@code{( @var{group} )*} means that @var{group} inside the parentheses
17374may repeat zero or more times.
17375
17376@item
17377@code{( @var{group} )+} means that @var{group} inside the parentheses
17378may repeat one or more times.
17379
17380@item
17381@code{"@var{string}"} means a literal @var{string}.
17382@end itemize
17383
17384@ignore
17385@heading Dependencies
17386@end ignore
17387
922fbb7b
AC
17388@menu
17389* GDB/MI Command Syntax::
17390* GDB/MI Compatibility with CLI::
af6eff6f 17391* GDB/MI Development and Front Ends::
922fbb7b 17392* GDB/MI Output Records::
ef21caaf 17393* GDB/MI Simple Examples::
922fbb7b 17394* GDB/MI Command Description Format::
ef21caaf 17395* GDB/MI Breakpoint Commands::
a2c02241
NR
17396* GDB/MI Program Context::
17397* GDB/MI Thread Commands::
17398* GDB/MI Program Execution::
17399* GDB/MI Stack Manipulation::
17400* GDB/MI Variable Objects::
922fbb7b 17401* GDB/MI Data Manipulation::
a2c02241
NR
17402* GDB/MI Tracepoint Commands::
17403* GDB/MI Symbol Query::
351ff01a 17404* GDB/MI File Commands::
922fbb7b
AC
17405@ignore
17406* GDB/MI Kod Commands::
17407* GDB/MI Memory Overlay Commands::
17408* GDB/MI Signal Handling Commands::
17409@end ignore
922fbb7b 17410* GDB/MI Target Manipulation::
a6b151f1 17411* GDB/MI File Transfer Commands::
ef21caaf 17412* GDB/MI Miscellaneous Commands::
922fbb7b
AC
17413@end menu
17414
17415@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17416@node GDB/MI Command Syntax
17417@section @sc{gdb/mi} Command Syntax
17418
17419@menu
17420* GDB/MI Input Syntax::
17421* GDB/MI Output Syntax::
922fbb7b
AC
17422@end menu
17423
17424@node GDB/MI Input Syntax
17425@subsection @sc{gdb/mi} Input Syntax
17426
17427@cindex input syntax for @sc{gdb/mi}
17428@cindex @sc{gdb/mi}, input syntax
17429@table @code
17430@item @var{command} @expansion{}
17431@code{@var{cli-command} | @var{mi-command}}
17432
17433@item @var{cli-command} @expansion{}
17434@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
17435@var{cli-command} is any existing @value{GDBN} CLI command.
17436
17437@item @var{mi-command} @expansion{}
17438@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
17439@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
17440
17441@item @var{token} @expansion{}
17442"any sequence of digits"
17443
17444@item @var{option} @expansion{}
17445@code{"-" @var{parameter} [ " " @var{parameter} ]}
17446
17447@item @var{parameter} @expansion{}
17448@code{@var{non-blank-sequence} | @var{c-string}}
17449
17450@item @var{operation} @expansion{}
17451@emph{any of the operations described in this chapter}
17452
17453@item @var{non-blank-sequence} @expansion{}
17454@emph{anything, provided it doesn't contain special characters such as
17455"-", @var{nl}, """ and of course " "}
17456
17457@item @var{c-string} @expansion{}
17458@code{""" @var{seven-bit-iso-c-string-content} """}
17459
17460@item @var{nl} @expansion{}
17461@code{CR | CR-LF}
17462@end table
17463
17464@noindent
17465Notes:
17466
17467@itemize @bullet
17468@item
17469The CLI commands are still handled by the @sc{mi} interpreter; their
17470output is described below.
17471
17472@item
17473The @code{@var{token}}, when present, is passed back when the command
17474finishes.
17475
17476@item
17477Some @sc{mi} commands accept optional arguments as part of the parameter
17478list. Each option is identified by a leading @samp{-} (dash) and may be
17479followed by an optional argument parameter. Options occur first in the
17480parameter list and can be delimited from normal parameters using
17481@samp{--} (this is useful when some parameters begin with a dash).
17482@end itemize
17483
17484Pragmatics:
17485
17486@itemize @bullet
17487@item
17488We want easy access to the existing CLI syntax (for debugging).
17489
17490@item
17491We want it to be easy to spot a @sc{mi} operation.
17492@end itemize
17493
17494@node GDB/MI Output Syntax
17495@subsection @sc{gdb/mi} Output Syntax
17496
17497@cindex output syntax of @sc{gdb/mi}
17498@cindex @sc{gdb/mi}, output syntax
17499The output from @sc{gdb/mi} consists of zero or more out-of-band records
17500followed, optionally, by a single result record. This result record
17501is for the most recent command. The sequence of output records is
594fe323 17502terminated by @samp{(gdb)}.
922fbb7b
AC
17503
17504If an input command was prefixed with a @code{@var{token}} then the
17505corresponding output for that command will also be prefixed by that same
17506@var{token}.
17507
17508@table @code
17509@item @var{output} @expansion{}
594fe323 17510@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
17511
17512@item @var{result-record} @expansion{}
17513@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
17514
17515@item @var{out-of-band-record} @expansion{}
17516@code{@var{async-record} | @var{stream-record}}
17517
17518@item @var{async-record} @expansion{}
17519@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
17520
17521@item @var{exec-async-output} @expansion{}
17522@code{[ @var{token} ] "*" @var{async-output}}
17523
17524@item @var{status-async-output} @expansion{}
17525@code{[ @var{token} ] "+" @var{async-output}}
17526
17527@item @var{notify-async-output} @expansion{}
17528@code{[ @var{token} ] "=" @var{async-output}}
17529
17530@item @var{async-output} @expansion{}
17531@code{@var{async-class} ( "," @var{result} )* @var{nl}}
17532
17533@item @var{result-class} @expansion{}
17534@code{"done" | "running" | "connected" | "error" | "exit"}
17535
17536@item @var{async-class} @expansion{}
17537@code{"stopped" | @var{others}} (where @var{others} will be added
17538depending on the needs---this is still in development).
17539
17540@item @var{result} @expansion{}
17541@code{ @var{variable} "=" @var{value}}
17542
17543@item @var{variable} @expansion{}
17544@code{ @var{string} }
17545
17546@item @var{value} @expansion{}
17547@code{ @var{const} | @var{tuple} | @var{list} }
17548
17549@item @var{const} @expansion{}
17550@code{@var{c-string}}
17551
17552@item @var{tuple} @expansion{}
17553@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
17554
17555@item @var{list} @expansion{}
17556@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
17557@var{result} ( "," @var{result} )* "]" }
17558
17559@item @var{stream-record} @expansion{}
17560@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
17561
17562@item @var{console-stream-output} @expansion{}
17563@code{"~" @var{c-string}}
17564
17565@item @var{target-stream-output} @expansion{}
17566@code{"@@" @var{c-string}}
17567
17568@item @var{log-stream-output} @expansion{}
17569@code{"&" @var{c-string}}
17570
17571@item @var{nl} @expansion{}
17572@code{CR | CR-LF}
17573
17574@item @var{token} @expansion{}
17575@emph{any sequence of digits}.
17576@end table
17577
17578@noindent
17579Notes:
17580
17581@itemize @bullet
17582@item
17583All output sequences end in a single line containing a period.
17584
17585@item
17586The @code{@var{token}} is from the corresponding request. If an execution
17587command is interrupted by the @samp{-exec-interrupt} command, the
17588@var{token} associated with the @samp{*stopped} message is the one of the
17589original execution command, not the one of the interrupt command.
17590
17591@item
17592@cindex status output in @sc{gdb/mi}
17593@var{status-async-output} contains on-going status information about the
17594progress of a slow operation. It can be discarded. All status output is
17595prefixed by @samp{+}.
17596
17597@item
17598@cindex async output in @sc{gdb/mi}
17599@var{exec-async-output} contains asynchronous state change on the target
17600(stopped, started, disappeared). All async output is prefixed by
17601@samp{*}.
17602
17603@item
17604@cindex notify output in @sc{gdb/mi}
17605@var{notify-async-output} contains supplementary information that the
17606client should handle (e.g., a new breakpoint information). All notify
17607output is prefixed by @samp{=}.
17608
17609@item
17610@cindex console output in @sc{gdb/mi}
17611@var{console-stream-output} is output that should be displayed as is in the
17612console. It is the textual response to a CLI command. All the console
17613output is prefixed by @samp{~}.
17614
17615@item
17616@cindex target output in @sc{gdb/mi}
17617@var{target-stream-output} is the output produced by the target program.
17618All the target output is prefixed by @samp{@@}.
17619
17620@item
17621@cindex log output in @sc{gdb/mi}
17622@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
17623instance messages that should be displayed as part of an error log. All
17624the log output is prefixed by @samp{&}.
17625
17626@item
17627@cindex list output in @sc{gdb/mi}
17628New @sc{gdb/mi} commands should only output @var{lists} containing
17629@var{values}.
17630
17631
17632@end itemize
17633
17634@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
17635details about the various output records.
17636
922fbb7b
AC
17637@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17638@node GDB/MI Compatibility with CLI
17639@section @sc{gdb/mi} Compatibility with CLI
17640
17641@cindex compatibility, @sc{gdb/mi} and CLI
17642@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 17643
a2c02241
NR
17644For the developers convenience CLI commands can be entered directly,
17645but there may be some unexpected behaviour. For example, commands
17646that query the user will behave as if the user replied yes, breakpoint
17647command lists are not executed and some CLI commands, such as
17648@code{if}, @code{when} and @code{define}, prompt for further input with
17649@samp{>}, which is not valid MI output.
ef21caaf
NR
17650
17651This feature may be removed at some stage in the future and it is
a2c02241
NR
17652recommended that front ends use the @code{-interpreter-exec} command
17653(@pxref{-interpreter-exec}).
922fbb7b 17654
af6eff6f
NR
17655@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17656@node GDB/MI Development and Front Ends
17657@section @sc{gdb/mi} Development and Front Ends
17658@cindex @sc{gdb/mi} development
17659
17660The application which takes the MI output and presents the state of the
17661program being debugged to the user is called a @dfn{front end}.
17662
17663Although @sc{gdb/mi} is still incomplete, it is currently being used
17664by a variety of front ends to @value{GDBN}. This makes it difficult
17665to introduce new functionality without breaking existing usage. This
17666section tries to minimize the problems by describing how the protocol
17667might change.
17668
17669Some changes in MI need not break a carefully designed front end, and
17670for these the MI version will remain unchanged. The following is a
17671list of changes that may occur within one level, so front ends should
17672parse MI output in a way that can handle them:
17673
17674@itemize @bullet
17675@item
17676New MI commands may be added.
17677
17678@item
17679New fields may be added to the output of any MI command.
17680
36ece8b3
NR
17681@item
17682The range of values for fields with specified values, e.g.,
9f708cb2 17683@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 17684
af6eff6f
NR
17685@c The format of field's content e.g type prefix, may change so parse it
17686@c at your own risk. Yes, in general?
17687
17688@c The order of fields may change? Shouldn't really matter but it might
17689@c resolve inconsistencies.
17690@end itemize
17691
17692If the changes are likely to break front ends, the MI version level
17693will be increased by one. This will allow the front end to parse the
17694output according to the MI version. Apart from mi0, new versions of
17695@value{GDBN} will not support old versions of MI and it will be the
17696responsibility of the front end to work with the new one.
17697
17698@c Starting with mi3, add a new command -mi-version that prints the MI
17699@c version?
17700
17701The best way to avoid unexpected changes in MI that might break your front
17702end is to make your project known to @value{GDBN} developers and
7a9a6b69
NR
17703follow development on @email{gdb@@sourceware.org} and
17704@email{gdb-patches@@sourceware.org}. There is also the mailing list
af6eff6f 17705@email{dmi-discuss@@lists.freestandards.org}, hosted by the Free Standards
d3e8051b 17706Group, which has the aim of creating a more general MI protocol
af6eff6f
NR
17707called Debugger Machine Interface (DMI) that will become a standard
17708for all debuggers, not just @value{GDBN}.
17709@cindex mailing lists
17710
922fbb7b
AC
17711@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17712@node GDB/MI Output Records
17713@section @sc{gdb/mi} Output Records
17714
17715@menu
17716* GDB/MI Result Records::
17717* GDB/MI Stream Records::
17718* GDB/MI Out-of-band Records::
17719@end menu
17720
17721@node GDB/MI Result Records
17722@subsection @sc{gdb/mi} Result Records
17723
17724@cindex result records in @sc{gdb/mi}
17725@cindex @sc{gdb/mi}, result records
17726In addition to a number of out-of-band notifications, the response to a
17727@sc{gdb/mi} command includes one of the following result indications:
17728
17729@table @code
17730@findex ^done
17731@item "^done" [ "," @var{results} ]
17732The synchronous operation was successful, @code{@var{results}} are the return
17733values.
17734
17735@item "^running"
17736@findex ^running
17737@c Is this one correct? Should it be an out-of-band notification?
17738The asynchronous operation was successfully started. The target is
17739running.
17740
ef21caaf
NR
17741@item "^connected"
17742@findex ^connected
3f94c067 17743@value{GDBN} has connected to a remote target.
ef21caaf 17744
922fbb7b
AC
17745@item "^error" "," @var{c-string}
17746@findex ^error
17747The operation failed. The @code{@var{c-string}} contains the corresponding
17748error message.
ef21caaf
NR
17749
17750@item "^exit"
17751@findex ^exit
3f94c067 17752@value{GDBN} has terminated.
ef21caaf 17753
922fbb7b
AC
17754@end table
17755
17756@node GDB/MI Stream Records
17757@subsection @sc{gdb/mi} Stream Records
17758
17759@cindex @sc{gdb/mi}, stream records
17760@cindex stream records in @sc{gdb/mi}
17761@value{GDBN} internally maintains a number of output streams: the console, the
17762target, and the log. The output intended for each of these streams is
17763funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17764
17765Each stream record begins with a unique @dfn{prefix character} which
17766identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17767Syntax}). In addition to the prefix, each stream record contains a
17768@code{@var{string-output}}. This is either raw text (with an implicit new
17769line) or a quoted C string (which does not contain an implicit newline).
17770
17771@table @code
17772@item "~" @var{string-output}
17773The console output stream contains text that should be displayed in the
17774CLI console window. It contains the textual responses to CLI commands.
17775
17776@item "@@" @var{string-output}
17777The target output stream contains any textual output from the running
ef21caaf
NR
17778target. This is only present when GDB's event loop is truly
17779asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
17780
17781@item "&" @var{string-output}
17782The log stream contains debugging messages being produced by @value{GDBN}'s
17783internals.
17784@end table
17785
17786@node GDB/MI Out-of-band Records
17787@subsection @sc{gdb/mi} Out-of-band Records
17788
17789@cindex out-of-band records in @sc{gdb/mi}
17790@cindex @sc{gdb/mi}, out-of-band records
17791@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17792additional changes that have occurred. Those changes can either be a
17793consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17794target activity (e.g., target stopped).
17795
17796The following is a preliminary list of possible out-of-band records.
034dad6f 17797In particular, the @var{exec-async-output} records.
922fbb7b
AC
17798
17799@table @code
034dad6f
BR
17800@item *stopped,reason="@var{reason}"
17801@end table
17802
17803@var{reason} can be one of the following:
17804
17805@table @code
17806@item breakpoint-hit
17807A breakpoint was reached.
17808@item watchpoint-trigger
17809A watchpoint was triggered.
17810@item read-watchpoint-trigger
17811A read watchpoint was triggered.
17812@item access-watchpoint-trigger
17813An access watchpoint was triggered.
17814@item function-finished
17815An -exec-finish or similar CLI command was accomplished.
17816@item location-reached
17817An -exec-until or similar CLI command was accomplished.
17818@item watchpoint-scope
17819A watchpoint has gone out of scope.
17820@item end-stepping-range
17821An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17822similar CLI command was accomplished.
17823@item exited-signalled
17824The inferior exited because of a signal.
17825@item exited
17826The inferior exited.
17827@item exited-normally
17828The inferior exited normally.
17829@item signal-received
17830A signal was received by the inferior.
922fbb7b
AC
17831@end table
17832
17833
ef21caaf
NR
17834@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17835@node GDB/MI Simple Examples
17836@section Simple Examples of @sc{gdb/mi} Interaction
17837@cindex @sc{gdb/mi}, simple examples
17838
17839This subsection presents several simple examples of interaction using
17840the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
17841following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
17842the output received from @sc{gdb/mi}.
17843
d3e8051b 17844Note the line breaks shown in the examples are here only for
ef21caaf
NR
17845readability, they don't appear in the real output.
17846
79a6e687 17847@subheading Setting a Breakpoint
ef21caaf
NR
17848
17849Setting a breakpoint generates synchronous output which contains detailed
17850information of the breakpoint.
17851
17852@smallexample
17853-> -break-insert main
17854<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
17855 enabled="y",addr="0x08048564",func="main",file="myprog.c",
17856 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
17857<- (gdb)
17858@end smallexample
17859
17860@subheading Program Execution
17861
17862Program execution generates asynchronous records and MI gives the
17863reason that execution stopped.
17864
17865@smallexample
17866-> -exec-run
17867<- ^running
17868<- (gdb)
17869<- *stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",
17870 frame=@{addr="0x08048564",func="main",
17871 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
17872 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
17873<- (gdb)
17874-> -exec-continue
17875<- ^running
17876<- (gdb)
17877<- *stopped,reason="exited-normally"
17878<- (gdb)
17879@end smallexample
17880
3f94c067 17881@subheading Quitting @value{GDBN}
ef21caaf 17882
3f94c067 17883Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
17884
17885@smallexample
17886-> (gdb)
17887<- -gdb-exit
17888<- ^exit
17889@end smallexample
17890
a2c02241 17891@subheading A Bad Command
ef21caaf
NR
17892
17893Here's what happens if you pass a non-existent command:
17894
17895@smallexample
17896-> -rubbish
17897<- ^error,msg="Undefined MI command: rubbish"
594fe323 17898<- (gdb)
ef21caaf
NR
17899@end smallexample
17900
17901
922fbb7b
AC
17902@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17903@node GDB/MI Command Description Format
17904@section @sc{gdb/mi} Command Description Format
17905
17906The remaining sections describe blocks of commands. Each block of
17907commands is laid out in a fashion similar to this section.
17908
922fbb7b
AC
17909@subheading Motivation
17910
17911The motivation for this collection of commands.
17912
17913@subheading Introduction
17914
17915A brief introduction to this collection of commands as a whole.
17916
17917@subheading Commands
17918
17919For each command in the block, the following is described:
17920
17921@subsubheading Synopsis
17922
17923@smallexample
17924 -command @var{args}@dots{}
17925@end smallexample
17926
922fbb7b
AC
17927@subsubheading Result
17928
265eeb58 17929@subsubheading @value{GDBN} Command
922fbb7b 17930
265eeb58 17931The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17932
17933@subsubheading Example
17934
ef21caaf
NR
17935Example(s) formatted for readability. Some of the described commands have
17936not been implemented yet and these are labeled N.A.@: (not available).
17937
17938
922fbb7b 17939@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
17940@node GDB/MI Breakpoint Commands
17941@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
17942
17943@cindex breakpoint commands for @sc{gdb/mi}
17944@cindex @sc{gdb/mi}, breakpoint commands
17945This section documents @sc{gdb/mi} commands for manipulating
17946breakpoints.
17947
17948@subheading The @code{-break-after} Command
17949@findex -break-after
17950
17951@subsubheading Synopsis
17952
17953@smallexample
17954 -break-after @var{number} @var{count}
17955@end smallexample
17956
17957The breakpoint number @var{number} is not in effect until it has been
17958hit @var{count} times. To see how this is reflected in the output of
17959the @samp{-break-list} command, see the description of the
17960@samp{-break-list} command below.
17961
17962@subsubheading @value{GDBN} Command
17963
17964The corresponding @value{GDBN} command is @samp{ignore}.
17965
17966@subsubheading Example
17967
17968@smallexample
594fe323 17969(gdb)
922fbb7b 17970-break-insert main
948d5102
NR
17971^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",
17972fullname="/home/foo/hello.c",line="5",times="0"@}
594fe323 17973(gdb)
922fbb7b
AC
17974-break-after 1 3
17975~
17976^done
594fe323 17977(gdb)
922fbb7b
AC
17978-break-list
17979^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17980hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17981@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17982@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17983@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17984@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17985@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17986body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
17987addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
17988line="5",times="0",ignore="3"@}]@}
594fe323 17989(gdb)
922fbb7b
AC
17990@end smallexample
17991
17992@ignore
17993@subheading The @code{-break-catch} Command
17994@findex -break-catch
17995
17996@subheading The @code{-break-commands} Command
17997@findex -break-commands
17998@end ignore
17999
18000
18001@subheading The @code{-break-condition} Command
18002@findex -break-condition
18003
18004@subsubheading Synopsis
18005
18006@smallexample
18007 -break-condition @var{number} @var{expr}
18008@end smallexample
18009
18010Breakpoint @var{number} will stop the program only if the condition in
18011@var{expr} is true. The condition becomes part of the
18012@samp{-break-list} output (see the description of the @samp{-break-list}
18013command below).
18014
18015@subsubheading @value{GDBN} Command
18016
18017The corresponding @value{GDBN} command is @samp{condition}.
18018
18019@subsubheading Example
18020
18021@smallexample
594fe323 18022(gdb)
922fbb7b
AC
18023-break-condition 1 1
18024^done
594fe323 18025(gdb)
922fbb7b
AC
18026-break-list
18027^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18028hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18029@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18030@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18031@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18032@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18033@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18034body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18035addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18036line="5",cond="1",times="0",ignore="3"@}]@}
594fe323 18037(gdb)
922fbb7b
AC
18038@end smallexample
18039
18040@subheading The @code{-break-delete} Command
18041@findex -break-delete
18042
18043@subsubheading Synopsis
18044
18045@smallexample
18046 -break-delete ( @var{breakpoint} )+
18047@end smallexample
18048
18049Delete the breakpoint(s) whose number(s) are specified in the argument
18050list. This is obviously reflected in the breakpoint list.
18051
79a6e687 18052@subsubheading @value{GDBN} Command
922fbb7b
AC
18053
18054The corresponding @value{GDBN} command is @samp{delete}.
18055
18056@subsubheading Example
18057
18058@smallexample
594fe323 18059(gdb)
922fbb7b
AC
18060-break-delete 1
18061^done
594fe323 18062(gdb)
922fbb7b
AC
18063-break-list
18064^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18065hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18066@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18067@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18068@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18069@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18070@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18071body=[]@}
594fe323 18072(gdb)
922fbb7b
AC
18073@end smallexample
18074
18075@subheading The @code{-break-disable} Command
18076@findex -break-disable
18077
18078@subsubheading Synopsis
18079
18080@smallexample
18081 -break-disable ( @var{breakpoint} )+
18082@end smallexample
18083
18084Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
18085break list is now set to @samp{n} for the named @var{breakpoint}(s).
18086
18087@subsubheading @value{GDBN} Command
18088
18089The corresponding @value{GDBN} command is @samp{disable}.
18090
18091@subsubheading Example
18092
18093@smallexample
594fe323 18094(gdb)
922fbb7b
AC
18095-break-disable 2
18096^done
594fe323 18097(gdb)
922fbb7b
AC
18098-break-list
18099^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18100hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18101@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18102@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18103@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18104@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18105@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18106body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102
NR
18107addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18108line="5",times="0"@}]@}
594fe323 18109(gdb)
922fbb7b
AC
18110@end smallexample
18111
18112@subheading The @code{-break-enable} Command
18113@findex -break-enable
18114
18115@subsubheading Synopsis
18116
18117@smallexample
18118 -break-enable ( @var{breakpoint} )+
18119@end smallexample
18120
18121Enable (previously disabled) @var{breakpoint}(s).
18122
18123@subsubheading @value{GDBN} Command
18124
18125The corresponding @value{GDBN} command is @samp{enable}.
18126
18127@subsubheading Example
18128
18129@smallexample
594fe323 18130(gdb)
922fbb7b
AC
18131-break-enable 2
18132^done
594fe323 18133(gdb)
922fbb7b
AC
18134-break-list
18135^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18136hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18137@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18138@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18139@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18140@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18141@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18142body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18143addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18144line="5",times="0"@}]@}
594fe323 18145(gdb)
922fbb7b
AC
18146@end smallexample
18147
18148@subheading The @code{-break-info} Command
18149@findex -break-info
18150
18151@subsubheading Synopsis
18152
18153@smallexample
18154 -break-info @var{breakpoint}
18155@end smallexample
18156
18157@c REDUNDANT???
18158Get information about a single breakpoint.
18159
79a6e687 18160@subsubheading @value{GDBN} Command
922fbb7b
AC
18161
18162The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
18163
18164@subsubheading Example
18165N.A.
18166
18167@subheading The @code{-break-insert} Command
18168@findex -break-insert
18169
18170@subsubheading Synopsis
18171
18172@smallexample
afe8ab22 18173 -break-insert [ -t ] [ -h ] [ -f ]
922fbb7b 18174 [ -c @var{condition} ] [ -i @var{ignore-count} ]
afe8ab22 18175 [ -p @var{thread} ] [ @var{location} ]
922fbb7b
AC
18176@end smallexample
18177
18178@noindent
afe8ab22 18179If specified, @var{location}, can be one of:
922fbb7b
AC
18180
18181@itemize @bullet
18182@item function
18183@c @item +offset
18184@c @item -offset
18185@c @item linenum
18186@item filename:linenum
18187@item filename:function
18188@item *address
18189@end itemize
18190
18191The possible optional parameters of this command are:
18192
18193@table @samp
18194@item -t
948d5102 18195Insert a temporary breakpoint.
922fbb7b
AC
18196@item -h
18197Insert a hardware breakpoint.
18198@item -c @var{condition}
18199Make the breakpoint conditional on @var{condition}.
18200@item -i @var{ignore-count}
18201Initialize the @var{ignore-count}.
afe8ab22
VP
18202@item -f
18203If @var{location} cannot be parsed (for example if it
18204refers to unknown files or functions), create a pending
18205breakpoint. Without this flag, @value{GDBN} will report
18206an error, and won't create a breakpoint, if @var{location}
18207cannot be parsed.
922fbb7b
AC
18208@end table
18209
18210@subsubheading Result
18211
18212The result is in the form:
18213
18214@smallexample
948d5102
NR
18215^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
18216enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
ef21caaf
NR
18217fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
18218times="@var{times}"@}
922fbb7b
AC
18219@end smallexample
18220
18221@noindent
948d5102
NR
18222where @var{number} is the @value{GDBN} number for this breakpoint,
18223@var{funcname} is the name of the function where the breakpoint was
18224inserted, @var{filename} is the name of the source file which contains
18225this function, @var{lineno} is the source line number within that file
18226and @var{times} the number of times that the breakpoint has been hit
18227(always 0 for -break-insert but may be greater for -break-info or -break-list
18228which use the same output).
922fbb7b
AC
18229
18230Note: this format is open to change.
18231@c An out-of-band breakpoint instead of part of the result?
18232
18233@subsubheading @value{GDBN} Command
18234
18235The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
18236@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
18237
18238@subsubheading Example
18239
18240@smallexample
594fe323 18241(gdb)
922fbb7b 18242-break-insert main
948d5102
NR
18243^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
18244fullname="/home/foo/recursive2.c,line="4",times="0"@}
594fe323 18245(gdb)
922fbb7b 18246-break-insert -t foo
948d5102
NR
18247^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
18248fullname="/home/foo/recursive2.c,line="11",times="0"@}
594fe323 18249(gdb)
922fbb7b
AC
18250-break-list
18251^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18252hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18253@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18254@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18255@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18256@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18257@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18258body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18259addr="0x0001072c", func="main",file="recursive2.c",
18260fullname="/home/foo/recursive2.c,"line="4",times="0"@},
922fbb7b 18261bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102
NR
18262addr="0x00010774",func="foo",file="recursive2.c",
18263fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
594fe323 18264(gdb)
922fbb7b
AC
18265-break-insert -r foo.*
18266~int foo(int, int);
948d5102
NR
18267^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
18268"fullname="/home/foo/recursive2.c",line="11",times="0"@}
594fe323 18269(gdb)
922fbb7b
AC
18270@end smallexample
18271
18272@subheading The @code{-break-list} Command
18273@findex -break-list
18274
18275@subsubheading Synopsis
18276
18277@smallexample
18278 -break-list
18279@end smallexample
18280
18281Displays the list of inserted breakpoints, showing the following fields:
18282
18283@table @samp
18284@item Number
18285number of the breakpoint
18286@item Type
18287type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
18288@item Disposition
18289should the breakpoint be deleted or disabled when it is hit: @samp{keep}
18290or @samp{nokeep}
18291@item Enabled
18292is the breakpoint enabled or no: @samp{y} or @samp{n}
18293@item Address
18294memory location at which the breakpoint is set
18295@item What
18296logical location of the breakpoint, expressed by function name, file
18297name, line number
18298@item Times
18299number of times the breakpoint has been hit
18300@end table
18301
18302If there are no breakpoints or watchpoints, the @code{BreakpointTable}
18303@code{body} field is an empty list.
18304
18305@subsubheading @value{GDBN} Command
18306
18307The corresponding @value{GDBN} command is @samp{info break}.
18308
18309@subsubheading Example
18310
18311@smallexample
594fe323 18312(gdb)
922fbb7b
AC
18313-break-list
18314^done,BreakpointTable=@{nr_rows="2",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=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18322addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
18323bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
18324addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
18325line="13",times="0"@}]@}
594fe323 18326(gdb)
922fbb7b
AC
18327@end smallexample
18328
18329Here's an example of the result when there are no breakpoints:
18330
18331@smallexample
594fe323 18332(gdb)
922fbb7b
AC
18333-break-list
18334^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18335hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18336@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18337@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18338@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18339@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18340@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18341body=[]@}
594fe323 18342(gdb)
922fbb7b
AC
18343@end smallexample
18344
18345@subheading The @code{-break-watch} Command
18346@findex -break-watch
18347
18348@subsubheading Synopsis
18349
18350@smallexample
18351 -break-watch [ -a | -r ]
18352@end smallexample
18353
18354Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 18355@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 18356read from or on a write to the memory location. With the @samp{-r}
d3e8051b 18357option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
18358trigger only when the memory location is accessed for reading. Without
18359either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 18360i.e., it will trigger when the memory location is accessed for writing.
79a6e687 18361@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
18362
18363Note that @samp{-break-list} will report a single list of watchpoints and
18364breakpoints inserted.
18365
18366@subsubheading @value{GDBN} Command
18367
18368The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
18369@samp{rwatch}.
18370
18371@subsubheading Example
18372
18373Setting a watchpoint on a variable in the @code{main} function:
18374
18375@smallexample
594fe323 18376(gdb)
922fbb7b
AC
18377-break-watch x
18378^done,wpt=@{number="2",exp="x"@}
594fe323 18379(gdb)
922fbb7b
AC
18380-exec-continue
18381^running
0869d01b
NR
18382(gdb)
18383*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 18384value=@{old="-268439212",new="55"@},
76ff342d 18385frame=@{func="main",args=[],file="recursive2.c",
948d5102 18386fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 18387(gdb)
922fbb7b
AC
18388@end smallexample
18389
18390Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
18391the program execution twice: first for the variable changing value, then
18392for the watchpoint going out of scope.
18393
18394@smallexample
594fe323 18395(gdb)
922fbb7b
AC
18396-break-watch C
18397^done,wpt=@{number="5",exp="C"@}
594fe323 18398(gdb)
922fbb7b
AC
18399-exec-continue
18400^running
0869d01b
NR
18401(gdb)
18402*stopped,reason="watchpoint-trigger",
922fbb7b
AC
18403wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
18404frame=@{func="callee4",args=[],
76ff342d
DJ
18405file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18406fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 18407(gdb)
922fbb7b
AC
18408-exec-continue
18409^running
0869d01b
NR
18410(gdb)
18411*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
18412frame=@{func="callee3",args=[@{name="strarg",
18413value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18414file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18415fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 18416(gdb)
922fbb7b
AC
18417@end smallexample
18418
18419Listing breakpoints and watchpoints, at different points in the program
18420execution. Note that once the watchpoint goes out of scope, it is
18421deleted.
18422
18423@smallexample
594fe323 18424(gdb)
922fbb7b
AC
18425-break-watch C
18426^done,wpt=@{number="2",exp="C"@}
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="0"@}]@}
594fe323 18442(gdb)
922fbb7b
AC
18443-exec-continue
18444^running
0869d01b
NR
18445(gdb)
18446*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
18447value=@{old="-276895068",new="3"@},
18448frame=@{func="callee4",args=[],
76ff342d
DJ
18449file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18450fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 18451(gdb)
922fbb7b
AC
18452-break-list
18453^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18454hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18455@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18456@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18457@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18458@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18459@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18460body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18461addr="0x00010734",func="callee4",
948d5102
NR
18462file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18463fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
922fbb7b
AC
18464bkpt=@{number="2",type="watchpoint",disp="keep",
18465enabled="y",addr="",what="C",times="-5"@}]@}
594fe323 18466(gdb)
922fbb7b
AC
18467-exec-continue
18468^running
18469^done,reason="watchpoint-scope",wpnum="2",
18470frame=@{func="callee3",args=[@{name="strarg",
18471value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18472file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18473fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 18474(gdb)
922fbb7b
AC
18475-break-list
18476^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18477hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18478@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18479@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18480@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18481@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18482@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18483body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18484addr="0x00010734",func="callee4",
948d5102
NR
18485file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18486fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
18487times="1"@}]@}
594fe323 18488(gdb)
922fbb7b
AC
18489@end smallexample
18490
18491@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
18492@node GDB/MI Program Context
18493@section @sc{gdb/mi} Program Context
922fbb7b 18494
a2c02241
NR
18495@subheading The @code{-exec-arguments} Command
18496@findex -exec-arguments
922fbb7b 18497
922fbb7b
AC
18498
18499@subsubheading Synopsis
18500
18501@smallexample
a2c02241 18502 -exec-arguments @var{args}
922fbb7b
AC
18503@end smallexample
18504
a2c02241
NR
18505Set the inferior program arguments, to be used in the next
18506@samp{-exec-run}.
922fbb7b 18507
a2c02241 18508@subsubheading @value{GDBN} Command
922fbb7b 18509
a2c02241 18510The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 18511
a2c02241 18512@subsubheading Example
922fbb7b 18513
a2c02241
NR
18514@c FIXME!
18515Don't have one around.
922fbb7b 18516
a2c02241
NR
18517
18518@subheading The @code{-exec-show-arguments} Command
18519@findex -exec-show-arguments
18520
18521@subsubheading Synopsis
18522
18523@smallexample
18524 -exec-show-arguments
18525@end smallexample
18526
18527Print the arguments of the program.
922fbb7b
AC
18528
18529@subsubheading @value{GDBN} Command
18530
a2c02241 18531The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
18532
18533@subsubheading Example
a2c02241 18534N.A.
922fbb7b 18535
922fbb7b 18536
a2c02241
NR
18537@subheading The @code{-environment-cd} Command
18538@findex -environment-cd
922fbb7b 18539
a2c02241 18540@subsubheading Synopsis
922fbb7b
AC
18541
18542@smallexample
a2c02241 18543 -environment-cd @var{pathdir}
922fbb7b
AC
18544@end smallexample
18545
a2c02241 18546Set @value{GDBN}'s working directory.
922fbb7b 18547
a2c02241 18548@subsubheading @value{GDBN} Command
922fbb7b 18549
a2c02241
NR
18550The corresponding @value{GDBN} command is @samp{cd}.
18551
18552@subsubheading Example
922fbb7b
AC
18553
18554@smallexample
594fe323 18555(gdb)
a2c02241
NR
18556-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18557^done
594fe323 18558(gdb)
922fbb7b
AC
18559@end smallexample
18560
18561
a2c02241
NR
18562@subheading The @code{-environment-directory} Command
18563@findex -environment-directory
922fbb7b
AC
18564
18565@subsubheading Synopsis
18566
18567@smallexample
a2c02241 18568 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
18569@end smallexample
18570
a2c02241
NR
18571Add directories @var{pathdir} to beginning of search path for source files.
18572If the @samp{-r} option is used, the search path is reset to the default
18573search path. If directories @var{pathdir} are supplied in addition to the
18574@samp{-r} option, the search path is first reset and then addition
18575occurs as normal.
18576Multiple directories may be specified, separated by blanks. Specifying
18577multiple directories in a single command
18578results in the directories added to the beginning of the
18579search path in the same order they were presented in the command.
18580If blanks are needed as
18581part of a directory name, double-quotes should be used around
18582the name. In the command output, the path will show up separated
d3e8051b 18583by the system directory-separator character. The directory-separator
a2c02241
NR
18584character must not be used
18585in any directory name.
18586If no directories are specified, the current search path is displayed.
922fbb7b
AC
18587
18588@subsubheading @value{GDBN} Command
18589
a2c02241 18590The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
18591
18592@subsubheading Example
18593
922fbb7b 18594@smallexample
594fe323 18595(gdb)
a2c02241
NR
18596-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18597^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 18598(gdb)
a2c02241
NR
18599-environment-directory ""
18600^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 18601(gdb)
a2c02241
NR
18602-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18603^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 18604(gdb)
a2c02241
NR
18605-environment-directory -r
18606^done,source-path="$cdir:$cwd"
594fe323 18607(gdb)
922fbb7b
AC
18608@end smallexample
18609
18610
a2c02241
NR
18611@subheading The @code{-environment-path} Command
18612@findex -environment-path
922fbb7b
AC
18613
18614@subsubheading Synopsis
18615
18616@smallexample
a2c02241 18617 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
18618@end smallexample
18619
a2c02241
NR
18620Add directories @var{pathdir} to beginning of search path for object files.
18621If the @samp{-r} option is used, the search path is reset to the original
18622search path that existed at gdb start-up. If directories @var{pathdir} are
18623supplied in addition to the
18624@samp{-r} option, the search path is first reset and then addition
18625occurs as normal.
18626Multiple directories may be specified, separated by blanks. Specifying
18627multiple directories in a single command
18628results in the directories added to the beginning of the
18629search path in the same order they were presented in the command.
18630If blanks are needed as
18631part of a directory name, double-quotes should be used around
18632the name. In the command output, the path will show up separated
d3e8051b 18633by the system directory-separator character. The directory-separator
a2c02241
NR
18634character must not be used
18635in any directory name.
18636If no directories are specified, the current path is displayed.
18637
922fbb7b
AC
18638
18639@subsubheading @value{GDBN} Command
18640
a2c02241 18641The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
18642
18643@subsubheading Example
18644
922fbb7b 18645@smallexample
594fe323 18646(gdb)
a2c02241
NR
18647-environment-path
18648^done,path="/usr/bin"
594fe323 18649(gdb)
a2c02241
NR
18650-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18651^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 18652(gdb)
a2c02241
NR
18653-environment-path -r /usr/local/bin
18654^done,path="/usr/local/bin:/usr/bin"
594fe323 18655(gdb)
922fbb7b
AC
18656@end smallexample
18657
18658
a2c02241
NR
18659@subheading The @code{-environment-pwd} Command
18660@findex -environment-pwd
922fbb7b
AC
18661
18662@subsubheading Synopsis
18663
18664@smallexample
a2c02241 18665 -environment-pwd
922fbb7b
AC
18666@end smallexample
18667
a2c02241 18668Show the current working directory.
922fbb7b 18669
79a6e687 18670@subsubheading @value{GDBN} Command
922fbb7b 18671
a2c02241 18672The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
18673
18674@subsubheading Example
18675
922fbb7b 18676@smallexample
594fe323 18677(gdb)
a2c02241
NR
18678-environment-pwd
18679^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 18680(gdb)
922fbb7b
AC
18681@end smallexample
18682
a2c02241
NR
18683@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18684@node GDB/MI Thread Commands
18685@section @sc{gdb/mi} Thread Commands
18686
18687
18688@subheading The @code{-thread-info} Command
18689@findex -thread-info
922fbb7b
AC
18690
18691@subsubheading Synopsis
18692
18693@smallexample
a2c02241 18694 -thread-info
922fbb7b
AC
18695@end smallexample
18696
79a6e687 18697@subsubheading @value{GDBN} Command
922fbb7b 18698
a2c02241 18699No equivalent.
922fbb7b
AC
18700
18701@subsubheading Example
a2c02241 18702N.A.
922fbb7b
AC
18703
18704
a2c02241
NR
18705@subheading The @code{-thread-list-all-threads} Command
18706@findex -thread-list-all-threads
922fbb7b
AC
18707
18708@subsubheading Synopsis
18709
18710@smallexample
a2c02241 18711 -thread-list-all-threads
922fbb7b
AC
18712@end smallexample
18713
a2c02241 18714@subsubheading @value{GDBN} Command
922fbb7b 18715
a2c02241 18716The equivalent @value{GDBN} command is @samp{info threads}.
922fbb7b 18717
a2c02241
NR
18718@subsubheading Example
18719N.A.
922fbb7b 18720
922fbb7b 18721
a2c02241
NR
18722@subheading The @code{-thread-list-ids} Command
18723@findex -thread-list-ids
922fbb7b 18724
a2c02241 18725@subsubheading Synopsis
922fbb7b 18726
a2c02241
NR
18727@smallexample
18728 -thread-list-ids
18729@end smallexample
922fbb7b 18730
a2c02241
NR
18731Produces a list of the currently known @value{GDBN} thread ids. At the
18732end of the list it also prints the total number of such threads.
922fbb7b
AC
18733
18734@subsubheading @value{GDBN} Command
18735
a2c02241 18736Part of @samp{info threads} supplies the same information.
922fbb7b
AC
18737
18738@subsubheading Example
18739
a2c02241 18740No threads present, besides the main process:
922fbb7b
AC
18741
18742@smallexample
594fe323 18743(gdb)
a2c02241
NR
18744-thread-list-ids
18745^done,thread-ids=@{@},number-of-threads="0"
594fe323 18746(gdb)
922fbb7b
AC
18747@end smallexample
18748
922fbb7b 18749
a2c02241 18750Several threads:
922fbb7b
AC
18751
18752@smallexample
594fe323 18753(gdb)
a2c02241
NR
18754-thread-list-ids
18755^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18756number-of-threads="3"
594fe323 18757(gdb)
922fbb7b
AC
18758@end smallexample
18759
a2c02241
NR
18760
18761@subheading The @code{-thread-select} Command
18762@findex -thread-select
922fbb7b
AC
18763
18764@subsubheading Synopsis
18765
18766@smallexample
a2c02241 18767 -thread-select @var{threadnum}
922fbb7b
AC
18768@end smallexample
18769
a2c02241
NR
18770Make @var{threadnum} the current thread. It prints the number of the new
18771current thread, and the topmost frame for that thread.
922fbb7b
AC
18772
18773@subsubheading @value{GDBN} Command
18774
a2c02241 18775The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
18776
18777@subsubheading Example
922fbb7b
AC
18778
18779@smallexample
594fe323 18780(gdb)
a2c02241
NR
18781-exec-next
18782^running
594fe323 18783(gdb)
a2c02241
NR
18784*stopped,reason="end-stepping-range",thread-id="2",line="187",
18785file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 18786(gdb)
a2c02241
NR
18787-thread-list-ids
18788^done,
18789thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18790number-of-threads="3"
594fe323 18791(gdb)
a2c02241
NR
18792-thread-select 3
18793^done,new-thread-id="3",
18794frame=@{level="0",func="vprintf",
18795args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18796@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 18797(gdb)
922fbb7b
AC
18798@end smallexample
18799
a2c02241
NR
18800@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18801@node GDB/MI Program Execution
18802@section @sc{gdb/mi} Program Execution
922fbb7b 18803
ef21caaf 18804These are the asynchronous commands which generate the out-of-band
3f94c067 18805record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
18806asynchronously with remote targets and this interaction is mimicked in
18807other cases.
922fbb7b 18808
922fbb7b
AC
18809@subheading The @code{-exec-continue} Command
18810@findex -exec-continue
18811
18812@subsubheading Synopsis
18813
18814@smallexample
18815 -exec-continue
18816@end smallexample
18817
ef21caaf
NR
18818Resumes the execution of the inferior program until a breakpoint is
18819encountered, or until the inferior exits.
922fbb7b
AC
18820
18821@subsubheading @value{GDBN} Command
18822
18823The corresponding @value{GDBN} corresponding is @samp{continue}.
18824
18825@subsubheading Example
18826
18827@smallexample
18828-exec-continue
18829^running
594fe323 18830(gdb)
922fbb7b
AC
18831@@Hello world
18832*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
948d5102 18833file="hello.c",fullname="/home/foo/bar/hello.c",line="13"@}
594fe323 18834(gdb)
922fbb7b
AC
18835@end smallexample
18836
18837
18838@subheading The @code{-exec-finish} Command
18839@findex -exec-finish
18840
18841@subsubheading Synopsis
18842
18843@smallexample
18844 -exec-finish
18845@end smallexample
18846
ef21caaf
NR
18847Resumes the execution of the inferior program until the current
18848function is exited. Displays the results returned by the function.
922fbb7b
AC
18849
18850@subsubheading @value{GDBN} Command
18851
18852The corresponding @value{GDBN} command is @samp{finish}.
18853
18854@subsubheading Example
18855
18856Function returning @code{void}.
18857
18858@smallexample
18859-exec-finish
18860^running
594fe323 18861(gdb)
922fbb7b
AC
18862@@hello from foo
18863*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 18864file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 18865(gdb)
922fbb7b
AC
18866@end smallexample
18867
18868Function returning other than @code{void}. The name of the internal
18869@value{GDBN} variable storing the result is printed, together with the
18870value itself.
18871
18872@smallexample
18873-exec-finish
18874^running
594fe323 18875(gdb)
922fbb7b
AC
18876*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18877args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 18878file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 18879gdb-result-var="$1",return-value="0"
594fe323 18880(gdb)
922fbb7b
AC
18881@end smallexample
18882
18883
18884@subheading The @code{-exec-interrupt} Command
18885@findex -exec-interrupt
18886
18887@subsubheading Synopsis
18888
18889@smallexample
18890 -exec-interrupt
18891@end smallexample
18892
ef21caaf
NR
18893Interrupts the background execution of the target. Note how the token
18894associated with the stop message is the one for the execution command
18895that has been interrupted. The token for the interrupt itself only
18896appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
18897interrupt a non-running program, an error message will be printed.
18898
18899@subsubheading @value{GDBN} Command
18900
18901The corresponding @value{GDBN} command is @samp{interrupt}.
18902
18903@subsubheading Example
18904
18905@smallexample
594fe323 18906(gdb)
922fbb7b
AC
18907111-exec-continue
18908111^running
18909
594fe323 18910(gdb)
922fbb7b
AC
18911222-exec-interrupt
18912222^done
594fe323 18913(gdb)
922fbb7b 18914111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 18915frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 18916fullname="/home/foo/bar/try.c",line="13"@}
594fe323 18917(gdb)
922fbb7b 18918
594fe323 18919(gdb)
922fbb7b
AC
18920-exec-interrupt
18921^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 18922(gdb)
922fbb7b
AC
18923@end smallexample
18924
18925
18926@subheading The @code{-exec-next} Command
18927@findex -exec-next
18928
18929@subsubheading Synopsis
18930
18931@smallexample
18932 -exec-next
18933@end smallexample
18934
ef21caaf
NR
18935Resumes execution of the inferior program, stopping when the beginning
18936of the next source line is reached.
922fbb7b
AC
18937
18938@subsubheading @value{GDBN} Command
18939
18940The corresponding @value{GDBN} command is @samp{next}.
18941
18942@subsubheading Example
18943
18944@smallexample
18945-exec-next
18946^running
594fe323 18947(gdb)
922fbb7b 18948*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 18949(gdb)
922fbb7b
AC
18950@end smallexample
18951
18952
18953@subheading The @code{-exec-next-instruction} Command
18954@findex -exec-next-instruction
18955
18956@subsubheading Synopsis
18957
18958@smallexample
18959 -exec-next-instruction
18960@end smallexample
18961
ef21caaf
NR
18962Executes one machine instruction. If the instruction is a function
18963call, continues until the function returns. If the program stops at an
18964instruction in the middle of a source line, the address will be
18965printed as well.
922fbb7b
AC
18966
18967@subsubheading @value{GDBN} Command
18968
18969The corresponding @value{GDBN} command is @samp{nexti}.
18970
18971@subsubheading Example
18972
18973@smallexample
594fe323 18974(gdb)
922fbb7b
AC
18975-exec-next-instruction
18976^running
18977
594fe323 18978(gdb)
922fbb7b
AC
18979*stopped,reason="end-stepping-range",
18980addr="0x000100d4",line="5",file="hello.c"
594fe323 18981(gdb)
922fbb7b
AC
18982@end smallexample
18983
18984
18985@subheading The @code{-exec-return} Command
18986@findex -exec-return
18987
18988@subsubheading Synopsis
18989
18990@smallexample
18991 -exec-return
18992@end smallexample
18993
18994Makes current function return immediately. Doesn't execute the inferior.
18995Displays the new current frame.
18996
18997@subsubheading @value{GDBN} Command
18998
18999The corresponding @value{GDBN} command is @samp{return}.
19000
19001@subsubheading Example
19002
19003@smallexample
594fe323 19004(gdb)
922fbb7b
AC
19005200-break-insert callee4
19006200^done,bkpt=@{number="1",addr="0x00010734",
19007file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 19008(gdb)
922fbb7b
AC
19009000-exec-run
19010000^running
594fe323 19011(gdb)
922fbb7b
AC
19012000*stopped,reason="breakpoint-hit",bkptno="1",
19013frame=@{func="callee4",args=[],
76ff342d
DJ
19014file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19015fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 19016(gdb)
922fbb7b
AC
19017205-break-delete
19018205^done
594fe323 19019(gdb)
922fbb7b
AC
19020111-exec-return
19021111^done,frame=@{level="0",func="callee3",
19022args=[@{name="strarg",
19023value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
19024file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19025fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 19026(gdb)
922fbb7b
AC
19027@end smallexample
19028
19029
19030@subheading The @code{-exec-run} Command
19031@findex -exec-run
19032
19033@subsubheading Synopsis
19034
19035@smallexample
19036 -exec-run
19037@end smallexample
19038
ef21caaf
NR
19039Starts execution of the inferior from the beginning. The inferior
19040executes until either a breakpoint is encountered or the program
19041exits. In the latter case the output will include an exit code, if
19042the program has exited exceptionally.
922fbb7b
AC
19043
19044@subsubheading @value{GDBN} Command
19045
19046The corresponding @value{GDBN} command is @samp{run}.
19047
ef21caaf 19048@subsubheading Examples
922fbb7b
AC
19049
19050@smallexample
594fe323 19051(gdb)
922fbb7b
AC
19052-break-insert main
19053^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 19054(gdb)
922fbb7b
AC
19055-exec-run
19056^running
594fe323 19057(gdb)
922fbb7b 19058*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d 19059frame=@{func="main",args=[],file="recursive2.c",
948d5102 19060fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 19061(gdb)
922fbb7b
AC
19062@end smallexample
19063
ef21caaf
NR
19064@noindent
19065Program exited normally:
19066
19067@smallexample
594fe323 19068(gdb)
ef21caaf
NR
19069-exec-run
19070^running
594fe323 19071(gdb)
ef21caaf
NR
19072x = 55
19073*stopped,reason="exited-normally"
594fe323 19074(gdb)
ef21caaf
NR
19075@end smallexample
19076
19077@noindent
19078Program exited exceptionally:
19079
19080@smallexample
594fe323 19081(gdb)
ef21caaf
NR
19082-exec-run
19083^running
594fe323 19084(gdb)
ef21caaf
NR
19085x = 55
19086*stopped,reason="exited",exit-code="01"
594fe323 19087(gdb)
ef21caaf
NR
19088@end smallexample
19089
19090Another way the program can terminate is if it receives a signal such as
19091@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
19092
19093@smallexample
594fe323 19094(gdb)
ef21caaf
NR
19095*stopped,reason="exited-signalled",signal-name="SIGINT",
19096signal-meaning="Interrupt"
19097@end smallexample
19098
922fbb7b 19099
a2c02241
NR
19100@c @subheading -exec-signal
19101
19102
19103@subheading The @code{-exec-step} Command
19104@findex -exec-step
922fbb7b
AC
19105
19106@subsubheading Synopsis
19107
19108@smallexample
a2c02241 19109 -exec-step
922fbb7b
AC
19110@end smallexample
19111
a2c02241
NR
19112Resumes execution of the inferior program, stopping when the beginning
19113of the next source line is reached, if the next source line is not a
19114function call. If it is, stop at the first instruction of the called
19115function.
922fbb7b
AC
19116
19117@subsubheading @value{GDBN} Command
19118
a2c02241 19119The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
19120
19121@subsubheading Example
19122
19123Stepping into a function:
19124
19125@smallexample
19126-exec-step
19127^running
594fe323 19128(gdb)
922fbb7b
AC
19129*stopped,reason="end-stepping-range",
19130frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 19131@{name="b",value="0"@}],file="recursive2.c",
948d5102 19132fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 19133(gdb)
922fbb7b
AC
19134@end smallexample
19135
19136Regular stepping:
19137
19138@smallexample
19139-exec-step
19140^running
594fe323 19141(gdb)
922fbb7b 19142*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 19143(gdb)
922fbb7b
AC
19144@end smallexample
19145
19146
19147@subheading The @code{-exec-step-instruction} Command
19148@findex -exec-step-instruction
19149
19150@subsubheading Synopsis
19151
19152@smallexample
19153 -exec-step-instruction
19154@end smallexample
19155
ef21caaf
NR
19156Resumes the inferior which executes one machine instruction. The
19157output, once @value{GDBN} has stopped, will vary depending on whether
19158we have stopped in the middle of a source line or not. In the former
19159case, the address at which the program stopped will be printed as
922fbb7b
AC
19160well.
19161
19162@subsubheading @value{GDBN} Command
19163
19164The corresponding @value{GDBN} command is @samp{stepi}.
19165
19166@subsubheading Example
19167
19168@smallexample
594fe323 19169(gdb)
922fbb7b
AC
19170-exec-step-instruction
19171^running
19172
594fe323 19173(gdb)
922fbb7b 19174*stopped,reason="end-stepping-range",
76ff342d 19175frame=@{func="foo",args=[],file="try.c",
948d5102 19176fullname="/home/foo/bar/try.c",line="10"@}
594fe323 19177(gdb)
922fbb7b
AC
19178-exec-step-instruction
19179^running
19180
594fe323 19181(gdb)
922fbb7b 19182*stopped,reason="end-stepping-range",
76ff342d 19183frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 19184fullname="/home/foo/bar/try.c",line="10"@}
594fe323 19185(gdb)
922fbb7b
AC
19186@end smallexample
19187
19188
19189@subheading The @code{-exec-until} Command
19190@findex -exec-until
19191
19192@subsubheading Synopsis
19193
19194@smallexample
19195 -exec-until [ @var{location} ]
19196@end smallexample
19197
ef21caaf
NR
19198Executes the inferior until the @var{location} specified in the
19199argument is reached. If there is no argument, the inferior executes
19200until a source line greater than the current one is reached. The
19201reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
19202
19203@subsubheading @value{GDBN} Command
19204
19205The corresponding @value{GDBN} command is @samp{until}.
19206
19207@subsubheading Example
19208
19209@smallexample
594fe323 19210(gdb)
922fbb7b
AC
19211-exec-until recursive2.c:6
19212^running
594fe323 19213(gdb)
922fbb7b
AC
19214x = 55
19215*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 19216file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 19217(gdb)
922fbb7b
AC
19218@end smallexample
19219
19220@ignore
19221@subheading -file-clear
19222Is this going away????
19223@end ignore
19224
351ff01a 19225@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
19226@node GDB/MI Stack Manipulation
19227@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 19228
922fbb7b 19229
a2c02241
NR
19230@subheading The @code{-stack-info-frame} Command
19231@findex -stack-info-frame
922fbb7b
AC
19232
19233@subsubheading Synopsis
19234
19235@smallexample
a2c02241 19236 -stack-info-frame
922fbb7b
AC
19237@end smallexample
19238
a2c02241 19239Get info on the selected frame.
922fbb7b
AC
19240
19241@subsubheading @value{GDBN} Command
19242
a2c02241
NR
19243The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19244(without arguments).
922fbb7b
AC
19245
19246@subsubheading Example
19247
19248@smallexample
594fe323 19249(gdb)
a2c02241
NR
19250-stack-info-frame
19251^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19252file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19253fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 19254(gdb)
922fbb7b
AC
19255@end smallexample
19256
a2c02241
NR
19257@subheading The @code{-stack-info-depth} Command
19258@findex -stack-info-depth
922fbb7b
AC
19259
19260@subsubheading Synopsis
19261
19262@smallexample
a2c02241 19263 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
19264@end smallexample
19265
a2c02241
NR
19266Return the depth of the stack. If the integer argument @var{max-depth}
19267is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
19268
19269@subsubheading @value{GDBN} Command
19270
a2c02241 19271There's no equivalent @value{GDBN} command.
922fbb7b
AC
19272
19273@subsubheading Example
19274
a2c02241
NR
19275For a stack with frame levels 0 through 11:
19276
922fbb7b 19277@smallexample
594fe323 19278(gdb)
a2c02241
NR
19279-stack-info-depth
19280^done,depth="12"
594fe323 19281(gdb)
a2c02241
NR
19282-stack-info-depth 4
19283^done,depth="4"
594fe323 19284(gdb)
a2c02241
NR
19285-stack-info-depth 12
19286^done,depth="12"
594fe323 19287(gdb)
a2c02241
NR
19288-stack-info-depth 11
19289^done,depth="11"
594fe323 19290(gdb)
a2c02241
NR
19291-stack-info-depth 13
19292^done,depth="12"
594fe323 19293(gdb)
922fbb7b
AC
19294@end smallexample
19295
a2c02241
NR
19296@subheading The @code{-stack-list-arguments} Command
19297@findex -stack-list-arguments
922fbb7b
AC
19298
19299@subsubheading Synopsis
19300
19301@smallexample
a2c02241
NR
19302 -stack-list-arguments @var{show-values}
19303 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
19304@end smallexample
19305
a2c02241
NR
19306Display a list of the arguments for the frames between @var{low-frame}
19307and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
19308@var{high-frame} are not provided, list the arguments for the whole
19309call stack. If the two arguments are equal, show the single frame
19310at the corresponding level. It is an error if @var{low-frame} is
19311larger than the actual number of frames. On the other hand,
19312@var{high-frame} may be larger than the actual number of frames, in
19313which case only existing frames will be returned.
a2c02241
NR
19314
19315The @var{show-values} argument must have a value of 0 or 1. A value of
193160 means that only the names of the arguments are listed, a value of 1
19317means that both names and values of the arguments are printed.
922fbb7b
AC
19318
19319@subsubheading @value{GDBN} Command
19320
a2c02241
NR
19321@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19322@samp{gdb_get_args} command which partially overlaps with the
19323functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
19324
19325@subsubheading Example
922fbb7b 19326
a2c02241 19327@smallexample
594fe323 19328(gdb)
a2c02241
NR
19329-stack-list-frames
19330^done,
19331stack=[
19332frame=@{level="0",addr="0x00010734",func="callee4",
19333file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19334fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
19335frame=@{level="1",addr="0x0001076c",func="callee3",
19336file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19337fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
19338frame=@{level="2",addr="0x0001078c",func="callee2",
19339file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19340fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
19341frame=@{level="3",addr="0x000107b4",func="callee1",
19342file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19343fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
19344frame=@{level="4",addr="0x000107e0",func="main",
19345file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19346fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 19347(gdb)
a2c02241
NR
19348-stack-list-arguments 0
19349^done,
19350stack-args=[
19351frame=@{level="0",args=[]@},
19352frame=@{level="1",args=[name="strarg"]@},
19353frame=@{level="2",args=[name="intarg",name="strarg"]@},
19354frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19355frame=@{level="4",args=[]@}]
594fe323 19356(gdb)
a2c02241
NR
19357-stack-list-arguments 1
19358^done,
19359stack-args=[
19360frame=@{level="0",args=[]@},
19361frame=@{level="1",
19362 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19363frame=@{level="2",args=[
19364@{name="intarg",value="2"@},
19365@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19366@{frame=@{level="3",args=[
19367@{name="intarg",value="2"@},
19368@{name="strarg",value="0x11940 \"A string argument.\""@},
19369@{name="fltarg",value="3.5"@}]@},
19370frame=@{level="4",args=[]@}]
594fe323 19371(gdb)
a2c02241
NR
19372-stack-list-arguments 0 2 2
19373^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 19374(gdb)
a2c02241
NR
19375-stack-list-arguments 1 2 2
19376^done,stack-args=[frame=@{level="2",
19377args=[@{name="intarg",value="2"@},
19378@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 19379(gdb)
a2c02241
NR
19380@end smallexample
19381
19382@c @subheading -stack-list-exception-handlers
922fbb7b 19383
a2c02241
NR
19384
19385@subheading The @code{-stack-list-frames} Command
19386@findex -stack-list-frames
1abaf70c
BR
19387
19388@subsubheading Synopsis
19389
19390@smallexample
a2c02241 19391 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
19392@end smallexample
19393
a2c02241
NR
19394List the frames currently on the stack. For each frame it displays the
19395following info:
19396
19397@table @samp
19398@item @var{level}
d3e8051b 19399The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
19400@item @var{addr}
19401The @code{$pc} value for that frame.
19402@item @var{func}
19403Function name.
19404@item @var{file}
19405File name of the source file where the function lives.
19406@item @var{line}
19407Line number corresponding to the @code{$pc}.
19408@end table
19409
19410If invoked without arguments, this command prints a backtrace for the
19411whole stack. If given two integer arguments, it shows the frames whose
19412levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
19413are equal, it shows the single frame at the corresponding level. It is
19414an error if @var{low-frame} is larger than the actual number of
a5451f4e 19415frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 19416actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
19417
19418@subsubheading @value{GDBN} Command
19419
a2c02241 19420The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
19421
19422@subsubheading Example
19423
a2c02241
NR
19424Full stack backtrace:
19425
1abaf70c 19426@smallexample
594fe323 19427(gdb)
a2c02241
NR
19428-stack-list-frames
19429^done,stack=
19430[frame=@{level="0",addr="0x0001076c",func="foo",
19431 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
19432frame=@{level="1",addr="0x000107a4",func="foo",
19433 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19434frame=@{level="2",addr="0x000107a4",func="foo",
19435 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19436frame=@{level="3",addr="0x000107a4",func="foo",
19437 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19438frame=@{level="4",addr="0x000107a4",func="foo",
19439 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19440frame=@{level="5",addr="0x000107a4",func="foo",
19441 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19442frame=@{level="6",addr="0x000107a4",func="foo",
19443 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19444frame=@{level="7",addr="0x000107a4",func="foo",
19445 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19446frame=@{level="8",addr="0x000107a4",func="foo",
19447 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19448frame=@{level="9",addr="0x000107a4",func="foo",
19449 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19450frame=@{level="10",addr="0x000107a4",func="foo",
19451 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19452frame=@{level="11",addr="0x00010738",func="main",
19453 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 19454(gdb)
1abaf70c
BR
19455@end smallexample
19456
a2c02241 19457Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 19458
a2c02241 19459@smallexample
594fe323 19460(gdb)
a2c02241
NR
19461-stack-list-frames 3 5
19462^done,stack=
19463[frame=@{level="3",addr="0x000107a4",func="foo",
19464 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19465frame=@{level="4",addr="0x000107a4",func="foo",
19466 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19467frame=@{level="5",addr="0x000107a4",func="foo",
19468 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 19469(gdb)
a2c02241 19470@end smallexample
922fbb7b 19471
a2c02241 19472Show a single frame:
922fbb7b
AC
19473
19474@smallexample
594fe323 19475(gdb)
a2c02241
NR
19476-stack-list-frames 3 3
19477^done,stack=
19478[frame=@{level="3",addr="0x000107a4",func="foo",
19479 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 19480(gdb)
922fbb7b
AC
19481@end smallexample
19482
922fbb7b 19483
a2c02241
NR
19484@subheading The @code{-stack-list-locals} Command
19485@findex -stack-list-locals
57c22c6c 19486
a2c02241 19487@subsubheading Synopsis
922fbb7b
AC
19488
19489@smallexample
a2c02241 19490 -stack-list-locals @var{print-values}
922fbb7b
AC
19491@end smallexample
19492
a2c02241
NR
19493Display the local variable names for the selected frame. If
19494@var{print-values} is 0 or @code{--no-values}, print only the names of
19495the variables; if it is 1 or @code{--all-values}, print also their
19496values; and if it is 2 or @code{--simple-values}, print the name,
19497type and value for simple data types and the name and type for arrays,
19498structures and unions. In this last case, a frontend can immediately
19499display the value of simple data types and create variable objects for
d3e8051b 19500other data types when the user wishes to explore their values in
a2c02241 19501more detail.
922fbb7b
AC
19502
19503@subsubheading @value{GDBN} Command
19504
a2c02241 19505@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
19506
19507@subsubheading Example
922fbb7b
AC
19508
19509@smallexample
594fe323 19510(gdb)
a2c02241
NR
19511-stack-list-locals 0
19512^done,locals=[name="A",name="B",name="C"]
594fe323 19513(gdb)
a2c02241
NR
19514-stack-list-locals --all-values
19515^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
19516 @{name="C",value="@{1, 2, 3@}"@}]
19517-stack-list-locals --simple-values
19518^done,locals=[@{name="A",type="int",value="1"@},
19519 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 19520(gdb)
922fbb7b
AC
19521@end smallexample
19522
922fbb7b 19523
a2c02241
NR
19524@subheading The @code{-stack-select-frame} Command
19525@findex -stack-select-frame
922fbb7b
AC
19526
19527@subsubheading Synopsis
19528
19529@smallexample
a2c02241 19530 -stack-select-frame @var{framenum}
922fbb7b
AC
19531@end smallexample
19532
a2c02241
NR
19533Change the selected frame. Select a different frame @var{framenum} on
19534the stack.
922fbb7b
AC
19535
19536@subsubheading @value{GDBN} Command
19537
a2c02241
NR
19538The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19539@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
19540
19541@subsubheading Example
19542
19543@smallexample
594fe323 19544(gdb)
a2c02241 19545-stack-select-frame 2
922fbb7b 19546^done
594fe323 19547(gdb)
922fbb7b
AC
19548@end smallexample
19549
19550@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
19551@node GDB/MI Variable Objects
19552@section @sc{gdb/mi} Variable Objects
922fbb7b 19553
a1b5960f 19554@ignore
922fbb7b 19555
a2c02241 19556@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 19557
a2c02241
NR
19558For the implementation of a variable debugger window (locals, watched
19559expressions, etc.), we are proposing the adaptation of the existing code
19560used by @code{Insight}.
922fbb7b 19561
a2c02241 19562The two main reasons for that are:
922fbb7b 19563
a2c02241
NR
19564@enumerate 1
19565@item
19566It has been proven in practice (it is already on its second generation).
922fbb7b 19567
a2c02241
NR
19568@item
19569It will shorten development time (needless to say how important it is
19570now).
19571@end enumerate
922fbb7b 19572
a2c02241
NR
19573The original interface was designed to be used by Tcl code, so it was
19574slightly changed so it could be used through @sc{gdb/mi}. This section
19575describes the @sc{gdb/mi} operations that will be available and gives some
19576hints about their use.
922fbb7b 19577
a2c02241
NR
19578@emph{Note}: In addition to the set of operations described here, we
19579expect the @sc{gui} implementation of a variable window to require, at
19580least, the following operations:
922fbb7b 19581
a2c02241
NR
19582@itemize @bullet
19583@item @code{-gdb-show} @code{output-radix}
19584@item @code{-stack-list-arguments}
19585@item @code{-stack-list-locals}
19586@item @code{-stack-select-frame}
19587@end itemize
922fbb7b 19588
a1b5960f
VP
19589@end ignore
19590
c8b2f53c 19591@subheading Introduction to Variable Objects
922fbb7b 19592
a2c02241 19593@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
19594
19595Variable objects are "object-oriented" MI interface for examining and
19596changing values of expressions. Unlike some other MI interfaces that
19597work with expressions, variable objects are specifically designed for
19598simple and efficient presentation in the frontend. A variable object
19599is identified by string name. When a variable object is created, the
19600frontend specifies the expression for that variable object. The
19601expression can be a simple variable, or it can be an arbitrary complex
19602expression, and can even involve CPU registers. After creating a
19603variable object, the frontend can invoke other variable object
19604operations---for example to obtain or change the value of a variable
19605object, or to change display format.
19606
19607Variable objects have hierarchical tree structure. Any variable object
19608that corresponds to a composite type, such as structure in C, has
19609a number of child variable objects, for example corresponding to each
19610element of a structure. A child variable object can itself have
19611children, recursively. Recursion ends when we reach
25d5ea92
VP
19612leaf variable objects, which always have built-in types. Child variable
19613objects are created only by explicit request, so if a frontend
19614is not interested in the children of a particular variable object, no
19615child will be created.
c8b2f53c
VP
19616
19617For a leaf variable object it is possible to obtain its value as a
19618string, or set the value from a string. String value can be also
19619obtained for a non-leaf variable object, but it's generally a string
19620that only indicates the type of the object, and does not list its
19621contents. Assignment to a non-leaf variable object is not allowed.
19622
19623A frontend does not need to read the values of all variable objects each time
19624the program stops. Instead, MI provides an update command that lists all
19625variable objects whose values has changed since the last update
19626operation. This considerably reduces the amount of data that must
25d5ea92
VP
19627be transferred to the frontend. As noted above, children variable
19628objects are created on demand, and only leaf variable objects have a
19629real value. As result, gdb will read target memory only for leaf
19630variables that frontend has created.
19631
19632The automatic update is not always desirable. For example, a frontend
19633might want to keep a value of some expression for future reference,
19634and never update it. For another example, fetching memory is
19635relatively slow for embedded targets, so a frontend might want
19636to disable automatic update for the variables that are either not
19637visible on the screen, or ``closed''. This is possible using so
19638called ``frozen variable objects''. Such variable objects are never
19639implicitly updated.
922fbb7b 19640
a2c02241
NR
19641The following is the complete set of @sc{gdb/mi} operations defined to
19642access this functionality:
922fbb7b 19643
a2c02241
NR
19644@multitable @columnfractions .4 .6
19645@item @strong{Operation}
19646@tab @strong{Description}
922fbb7b 19647
a2c02241
NR
19648@item @code{-var-create}
19649@tab create a variable object
19650@item @code{-var-delete}
22d8a470 19651@tab delete the variable object and/or its children
a2c02241
NR
19652@item @code{-var-set-format}
19653@tab set the display format of this variable
19654@item @code{-var-show-format}
19655@tab show the display format of this variable
19656@item @code{-var-info-num-children}
19657@tab tells how many children this object has
19658@item @code{-var-list-children}
19659@tab return a list of the object's children
19660@item @code{-var-info-type}
19661@tab show the type of this variable object
19662@item @code{-var-info-expression}
02142340
VP
19663@tab print parent-relative expression that this variable object represents
19664@item @code{-var-info-path-expression}
19665@tab print full expression that this variable object represents
a2c02241
NR
19666@item @code{-var-show-attributes}
19667@tab is this variable editable? does it exist here?
19668@item @code{-var-evaluate-expression}
19669@tab get the value of this variable
19670@item @code{-var-assign}
19671@tab set the value of this variable
19672@item @code{-var-update}
19673@tab update the variable and its children
25d5ea92
VP
19674@item @code{-var-set-frozen}
19675@tab set frozeness attribute
a2c02241 19676@end multitable
922fbb7b 19677
a2c02241
NR
19678In the next subsection we describe each operation in detail and suggest
19679how it can be used.
922fbb7b 19680
a2c02241 19681@subheading Description And Use of Operations on Variable Objects
922fbb7b 19682
a2c02241
NR
19683@subheading The @code{-var-create} Command
19684@findex -var-create
ef21caaf 19685
a2c02241 19686@subsubheading Synopsis
ef21caaf 19687
a2c02241
NR
19688@smallexample
19689 -var-create @{@var{name} | "-"@}
19690 @{@var{frame-addr} | "*"@} @var{expression}
19691@end smallexample
19692
19693This operation creates a variable object, which allows the monitoring of
19694a variable, the result of an expression, a memory cell or a CPU
19695register.
ef21caaf 19696
a2c02241
NR
19697The @var{name} parameter is the string by which the object can be
19698referenced. It must be unique. If @samp{-} is specified, the varobj
19699system will generate a string ``varNNNNNN'' automatically. It will be
19700unique provided that one does not specify @var{name} on that format.
19701The command fails if a duplicate name is found.
ef21caaf 19702
a2c02241
NR
19703The frame under which the expression should be evaluated can be
19704specified by @var{frame-addr}. A @samp{*} indicates that the current
19705frame should be used.
922fbb7b 19706
a2c02241
NR
19707@var{expression} is any expression valid on the current language set (must not
19708begin with a @samp{*}), or one of the following:
922fbb7b 19709
a2c02241
NR
19710@itemize @bullet
19711@item
19712@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 19713
a2c02241
NR
19714@item
19715@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 19716
a2c02241
NR
19717@item
19718@samp{$@var{regname}} --- a CPU register name
19719@end itemize
922fbb7b 19720
a2c02241 19721@subsubheading Result
922fbb7b 19722
a2c02241
NR
19723This operation returns the name, number of children and the type of the
19724object created. Type is returned as a string as the ones generated by
19725the @value{GDBN} CLI:
922fbb7b
AC
19726
19727@smallexample
a2c02241 19728 name="@var{name}",numchild="N",type="@var{type}"
dcaaae04
NR
19729@end smallexample
19730
a2c02241
NR
19731
19732@subheading The @code{-var-delete} Command
19733@findex -var-delete
922fbb7b
AC
19734
19735@subsubheading Synopsis
19736
19737@smallexample
22d8a470 19738 -var-delete [ -c ] @var{name}
922fbb7b
AC
19739@end smallexample
19740
a2c02241 19741Deletes a previously created variable object and all of its children.
22d8a470 19742With the @samp{-c} option, just deletes the children.
922fbb7b 19743
a2c02241 19744Returns an error if the object @var{name} is not found.
922fbb7b 19745
922fbb7b 19746
a2c02241
NR
19747@subheading The @code{-var-set-format} Command
19748@findex -var-set-format
922fbb7b 19749
a2c02241 19750@subsubheading Synopsis
922fbb7b
AC
19751
19752@smallexample
a2c02241 19753 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
19754@end smallexample
19755
a2c02241
NR
19756Sets the output format for the value of the object @var{name} to be
19757@var{format-spec}.
19758
19759The syntax for the @var{format-spec} is as follows:
19760
19761@smallexample
19762 @var{format-spec} @expansion{}
19763 @{binary | decimal | hexadecimal | octal | natural@}
19764@end smallexample
19765
c8b2f53c
VP
19766The natural format is the default format choosen automatically
19767based on the variable type (like decimal for an @code{int}, hex
19768for pointers, etc.).
19769
19770For a variable with children, the format is set only on the
19771variable itself, and the children are not affected.
a2c02241
NR
19772
19773@subheading The @code{-var-show-format} Command
19774@findex -var-show-format
922fbb7b
AC
19775
19776@subsubheading Synopsis
19777
19778@smallexample
a2c02241 19779 -var-show-format @var{name}
922fbb7b
AC
19780@end smallexample
19781
a2c02241 19782Returns the format used to display the value of the object @var{name}.
922fbb7b 19783
a2c02241
NR
19784@smallexample
19785 @var{format} @expansion{}
19786 @var{format-spec}
19787@end smallexample
922fbb7b 19788
922fbb7b 19789
a2c02241
NR
19790@subheading The @code{-var-info-num-children} Command
19791@findex -var-info-num-children
19792
19793@subsubheading Synopsis
19794
19795@smallexample
19796 -var-info-num-children @var{name}
19797@end smallexample
19798
19799Returns the number of children of a variable object @var{name}:
19800
19801@smallexample
19802 numchild=@var{n}
19803@end smallexample
19804
19805
19806@subheading The @code{-var-list-children} Command
19807@findex -var-list-children
19808
19809@subsubheading Synopsis
19810
19811@smallexample
19812 -var-list-children [@var{print-values}] @var{name}
19813@end smallexample
19814@anchor{-var-list-children}
19815
19816Return a list of the children of the specified variable object and
19817create variable objects for them, if they do not already exist. With
19818a single argument or if @var{print-values} has a value for of 0 or
19819@code{--no-values}, print only the names of the variables; if
19820@var{print-values} is 1 or @code{--all-values}, also print their
19821values; and if it is 2 or @code{--simple-values} print the name and
19822value for simple data types and just the name for arrays, structures
19823and unions.
922fbb7b
AC
19824
19825@subsubheading Example
19826
19827@smallexample
594fe323 19828(gdb)
a2c02241
NR
19829 -var-list-children n
19830 ^done,numchild=@var{n},children=[@{name=@var{name},
19831 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 19832(gdb)
a2c02241
NR
19833 -var-list-children --all-values n
19834 ^done,numchild=@var{n},children=[@{name=@var{name},
19835 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
19836@end smallexample
19837
922fbb7b 19838
a2c02241
NR
19839@subheading The @code{-var-info-type} Command
19840@findex -var-info-type
922fbb7b 19841
a2c02241
NR
19842@subsubheading Synopsis
19843
19844@smallexample
19845 -var-info-type @var{name}
19846@end smallexample
19847
19848Returns the type of the specified variable @var{name}. The type is
19849returned as a string in the same format as it is output by the
19850@value{GDBN} CLI:
19851
19852@smallexample
19853 type=@var{typename}
19854@end smallexample
19855
19856
19857@subheading The @code{-var-info-expression} Command
19858@findex -var-info-expression
922fbb7b
AC
19859
19860@subsubheading Synopsis
19861
19862@smallexample
a2c02241 19863 -var-info-expression @var{name}
922fbb7b
AC
19864@end smallexample
19865
02142340
VP
19866Returns a string that is suitable for presenting this
19867variable object in user interface. The string is generally
19868not valid expression in the current language, and cannot be evaluated.
19869
19870For example, if @code{a} is an array, and variable object
19871@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 19872
a2c02241 19873@smallexample
02142340
VP
19874(gdb) -var-info-expression A.1
19875^done,lang="C",exp="1"
a2c02241 19876@end smallexample
922fbb7b 19877
a2c02241 19878@noindent
02142340
VP
19879Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
19880
19881Note that the output of the @code{-var-list-children} command also
19882includes those expressions, so the @code{-var-info-expression} command
19883is of limited use.
19884
19885@subheading The @code{-var-info-path-expression} Command
19886@findex -var-info-path-expression
19887
19888@subsubheading Synopsis
19889
19890@smallexample
19891 -var-info-path-expression @var{name}
19892@end smallexample
19893
19894Returns an expression that can be evaluated in the current
19895context and will yield the same value that a variable object has.
19896Compare this with the @code{-var-info-expression} command, which
19897result can be used only for UI presentation. Typical use of
19898the @code{-var-info-path-expression} command is creating a
19899watchpoint from a variable object.
19900
19901For example, suppose @code{C} is a C@t{++} class, derived from class
19902@code{Base}, and that the @code{Base} class has a member called
19903@code{m_size}. Assume a variable @code{c} is has the type of
19904@code{C} and a variable object @code{C} was created for variable
19905@code{c}. Then, we'll get this output:
19906@smallexample
19907(gdb) -var-info-path-expression C.Base.public.m_size
19908^done,path_expr=((Base)c).m_size)
19909@end smallexample
922fbb7b 19910
a2c02241
NR
19911@subheading The @code{-var-show-attributes} Command
19912@findex -var-show-attributes
922fbb7b 19913
a2c02241 19914@subsubheading Synopsis
922fbb7b 19915
a2c02241
NR
19916@smallexample
19917 -var-show-attributes @var{name}
19918@end smallexample
922fbb7b 19919
a2c02241 19920List attributes of the specified variable object @var{name}:
922fbb7b
AC
19921
19922@smallexample
a2c02241 19923 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
19924@end smallexample
19925
a2c02241
NR
19926@noindent
19927where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
19928
19929@subheading The @code{-var-evaluate-expression} Command
19930@findex -var-evaluate-expression
19931
19932@subsubheading Synopsis
19933
19934@smallexample
19935 -var-evaluate-expression @var{name}
19936@end smallexample
19937
19938Evaluates the expression that is represented by the specified variable
c8b2f53c
VP
19939object and returns its value as a string. The format of the
19940string can be changed using the @code{-var-set-format} command.
a2c02241
NR
19941
19942@smallexample
19943 value=@var{value}
19944@end smallexample
19945
19946Note that one must invoke @code{-var-list-children} for a variable
19947before the value of a child variable can be evaluated.
19948
19949@subheading The @code{-var-assign} Command
19950@findex -var-assign
19951
19952@subsubheading Synopsis
19953
19954@smallexample
19955 -var-assign @var{name} @var{expression}
19956@end smallexample
19957
19958Assigns the value of @var{expression} to the variable object specified
19959by @var{name}. The object must be @samp{editable}. If the variable's
19960value is altered by the assign, the variable will show up in any
19961subsequent @code{-var-update} list.
19962
19963@subsubheading Example
922fbb7b
AC
19964
19965@smallexample
594fe323 19966(gdb)
a2c02241
NR
19967-var-assign var1 3
19968^done,value="3"
594fe323 19969(gdb)
a2c02241
NR
19970-var-update *
19971^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 19972(gdb)
922fbb7b
AC
19973@end smallexample
19974
a2c02241
NR
19975@subheading The @code{-var-update} Command
19976@findex -var-update
19977
19978@subsubheading Synopsis
19979
19980@smallexample
19981 -var-update [@var{print-values}] @{@var{name} | "*"@}
19982@end smallexample
19983
c8b2f53c
VP
19984Reevaluate the expressions corresponding to the variable object
19985@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
19986list of variable objects whose values have changed; @var{name} must
19987be a root variable object. Here, ``changed'' means that the result of
19988@code{-var-evaluate-expression} before and after the
19989@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
19990object names, all existing variable objects are updated, except
19991for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3
NR
19992@var{print-values} determines whether both names and values, or just
19993names are printed. The possible values of this options are the same
19994as for @code{-var-list-children} (@pxref{-var-list-children}). It is
19995recommended to use the @samp{--all-values} option, to reduce the
19996number of MI commands needed on each program stop.
c8b2f53c 19997
a2c02241
NR
19998
19999@subsubheading Example
922fbb7b
AC
20000
20001@smallexample
594fe323 20002(gdb)
a2c02241
NR
20003-var-assign var1 3
20004^done,value="3"
594fe323 20005(gdb)
a2c02241
NR
20006-var-update --all-values var1
20007^done,changelist=[@{name="var1",value="3",in_scope="true",
20008type_changed="false"@}]
594fe323 20009(gdb)
922fbb7b
AC
20010@end smallexample
20011
9f708cb2 20012@anchor{-var-update}
36ece8b3
NR
20013The field in_scope may take three values:
20014
20015@table @code
20016@item "true"
20017The variable object's current value is valid.
20018
20019@item "false"
20020The variable object does not currently hold a valid value but it may
20021hold one in the future if its associated expression comes back into
20022scope.
20023
20024@item "invalid"
20025The variable object no longer holds a valid value.
20026This can occur when the executable file being debugged has changed,
20027either through recompilation or by using the @value{GDBN} @code{file}
20028command. The front end should normally choose to delete these variable
20029objects.
20030@end table
20031
20032In the future new values may be added to this list so the front should
20033be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
20034
25d5ea92
VP
20035@subheading The @code{-var-set-frozen} Command
20036@findex -var-set-frozen
9f708cb2 20037@anchor{-var-set-frozen}
25d5ea92
VP
20038
20039@subsubheading Synopsis
20040
20041@smallexample
9f708cb2 20042 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
20043@end smallexample
20044
9f708cb2 20045Set the frozenness flag on the variable object @var{name}. The
25d5ea92 20046@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 20047frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 20048frozen, then neither itself, nor any of its children, are
9f708cb2 20049implicitly updated by @code{-var-update} of
25d5ea92
VP
20050a parent variable or by @code{-var-update *}. Only
20051@code{-var-update} of the variable itself will update its value and
20052values of its children. After a variable object is unfrozen, it is
20053implicitly updated by all subsequent @code{-var-update} operations.
20054Unfreezing a variable does not update it, only subsequent
20055@code{-var-update} does.
20056
20057@subsubheading Example
20058
20059@smallexample
20060(gdb)
20061-var-set-frozen V 1
20062^done
20063(gdb)
20064@end smallexample
20065
20066
a2c02241
NR
20067@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20068@node GDB/MI Data Manipulation
20069@section @sc{gdb/mi} Data Manipulation
922fbb7b 20070
a2c02241
NR
20071@cindex data manipulation, in @sc{gdb/mi}
20072@cindex @sc{gdb/mi}, data manipulation
20073This section describes the @sc{gdb/mi} commands that manipulate data:
20074examine memory and registers, evaluate expressions, etc.
20075
20076@c REMOVED FROM THE INTERFACE.
20077@c @subheading -data-assign
20078@c Change the value of a program variable. Plenty of side effects.
79a6e687 20079@c @subsubheading GDB Command
a2c02241
NR
20080@c set variable
20081@c @subsubheading Example
20082@c N.A.
20083
20084@subheading The @code{-data-disassemble} Command
20085@findex -data-disassemble
922fbb7b
AC
20086
20087@subsubheading Synopsis
20088
20089@smallexample
a2c02241
NR
20090 -data-disassemble
20091 [ -s @var{start-addr} -e @var{end-addr} ]
20092 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
20093 -- @var{mode}
922fbb7b
AC
20094@end smallexample
20095
a2c02241
NR
20096@noindent
20097Where:
20098
20099@table @samp
20100@item @var{start-addr}
20101is the beginning address (or @code{$pc})
20102@item @var{end-addr}
20103is the end address
20104@item @var{filename}
20105is the name of the file to disassemble
20106@item @var{linenum}
20107is the line number to disassemble around
20108@item @var{lines}
d3e8051b 20109is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
20110the whole function will be disassembled, in case no @var{end-addr} is
20111specified. If @var{end-addr} is specified as a non-zero value, and
20112@var{lines} is lower than the number of disassembly lines between
20113@var{start-addr} and @var{end-addr}, only @var{lines} lines are
20114displayed; if @var{lines} is higher than the number of lines between
20115@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
20116are displayed.
20117@item @var{mode}
20118is either 0 (meaning only disassembly) or 1 (meaning mixed source and
20119disassembly).
20120@end table
20121
20122@subsubheading Result
20123
20124The output for each instruction is composed of four fields:
20125
20126@itemize @bullet
20127@item Address
20128@item Func-name
20129@item Offset
20130@item Instruction
20131@end itemize
20132
20133Note that whatever included in the instruction field, is not manipulated
d3e8051b 20134directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
922fbb7b
AC
20135
20136@subsubheading @value{GDBN} Command
20137
a2c02241 20138There's no direct mapping from this command to the CLI.
922fbb7b
AC
20139
20140@subsubheading Example
20141
a2c02241
NR
20142Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
20143
922fbb7b 20144@smallexample
594fe323 20145(gdb)
a2c02241
NR
20146-data-disassemble -s $pc -e "$pc + 20" -- 0
20147^done,
20148asm_insns=[
20149@{address="0x000107c0",func-name="main",offset="4",
20150inst="mov 2, %o0"@},
20151@{address="0x000107c4",func-name="main",offset="8",
20152inst="sethi %hi(0x11800), %o2"@},
20153@{address="0x000107c8",func-name="main",offset="12",
20154inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
20155@{address="0x000107cc",func-name="main",offset="16",
20156inst="sethi %hi(0x11800), %o2"@},
20157@{address="0x000107d0",func-name="main",offset="20",
20158inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 20159(gdb)
a2c02241
NR
20160@end smallexample
20161
20162Disassemble the whole @code{main} function. Line 32 is part of
20163@code{main}.
20164
20165@smallexample
20166-data-disassemble -f basics.c -l 32 -- 0
20167^done,asm_insns=[
20168@{address="0x000107bc",func-name="main",offset="0",
20169inst="save %sp, -112, %sp"@},
20170@{address="0x000107c0",func-name="main",offset="4",
20171inst="mov 2, %o0"@},
20172@{address="0x000107c4",func-name="main",offset="8",
20173inst="sethi %hi(0x11800), %o2"@},
20174[@dots{}]
20175@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
20176@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 20177(gdb)
922fbb7b
AC
20178@end smallexample
20179
a2c02241 20180Disassemble 3 instructions from the start of @code{main}:
922fbb7b 20181
a2c02241 20182@smallexample
594fe323 20183(gdb)
a2c02241
NR
20184-data-disassemble -f basics.c -l 32 -n 3 -- 0
20185^done,asm_insns=[
20186@{address="0x000107bc",func-name="main",offset="0",
20187inst="save %sp, -112, %sp"@},
20188@{address="0x000107c0",func-name="main",offset="4",
20189inst="mov 2, %o0"@},
20190@{address="0x000107c4",func-name="main",offset="8",
20191inst="sethi %hi(0x11800), %o2"@}]
594fe323 20192(gdb)
a2c02241
NR
20193@end smallexample
20194
20195Disassemble 3 instructions from the start of @code{main} in mixed mode:
20196
20197@smallexample
594fe323 20198(gdb)
a2c02241
NR
20199-data-disassemble -f basics.c -l 32 -n 3 -- 1
20200^done,asm_insns=[
20201src_and_asm_line=@{line="31",
20202file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20203 testsuite/gdb.mi/basics.c",line_asm_insn=[
20204@{address="0x000107bc",func-name="main",offset="0",
20205inst="save %sp, -112, %sp"@}]@},
20206src_and_asm_line=@{line="32",
20207file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20208 testsuite/gdb.mi/basics.c",line_asm_insn=[
20209@{address="0x000107c0",func-name="main",offset="4",
20210inst="mov 2, %o0"@},
20211@{address="0x000107c4",func-name="main",offset="8",
20212inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 20213(gdb)
a2c02241
NR
20214@end smallexample
20215
20216
20217@subheading The @code{-data-evaluate-expression} Command
20218@findex -data-evaluate-expression
922fbb7b
AC
20219
20220@subsubheading Synopsis
20221
20222@smallexample
a2c02241 20223 -data-evaluate-expression @var{expr}
922fbb7b
AC
20224@end smallexample
20225
a2c02241
NR
20226Evaluate @var{expr} as an expression. The expression could contain an
20227inferior function call. The function call will execute synchronously.
20228If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
20229
20230@subsubheading @value{GDBN} Command
20231
a2c02241
NR
20232The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
20233@samp{call}. In @code{gdbtk} only, there's a corresponding
20234@samp{gdb_eval} command.
922fbb7b
AC
20235
20236@subsubheading Example
20237
a2c02241
NR
20238In the following example, the numbers that precede the commands are the
20239@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
20240Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
20241output.
20242
922fbb7b 20243@smallexample
a2c02241
NR
20244211-data-evaluate-expression A
20245211^done,value="1"
594fe323 20246(gdb)
a2c02241
NR
20247311-data-evaluate-expression &A
20248311^done,value="0xefffeb7c"
594fe323 20249(gdb)
a2c02241
NR
20250411-data-evaluate-expression A+3
20251411^done,value="4"
594fe323 20252(gdb)
a2c02241
NR
20253511-data-evaluate-expression "A + 3"
20254511^done,value="4"
594fe323 20255(gdb)
a2c02241 20256@end smallexample
922fbb7b
AC
20257
20258
a2c02241
NR
20259@subheading The @code{-data-list-changed-registers} Command
20260@findex -data-list-changed-registers
922fbb7b
AC
20261
20262@subsubheading Synopsis
20263
20264@smallexample
a2c02241 20265 -data-list-changed-registers
922fbb7b
AC
20266@end smallexample
20267
a2c02241 20268Display a list of the registers that have changed.
922fbb7b
AC
20269
20270@subsubheading @value{GDBN} Command
20271
a2c02241
NR
20272@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
20273has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
20274
20275@subsubheading Example
922fbb7b 20276
a2c02241 20277On a PPC MBX board:
922fbb7b
AC
20278
20279@smallexample
594fe323 20280(gdb)
a2c02241
NR
20281-exec-continue
20282^running
922fbb7b 20283
594fe323 20284(gdb)
a2c02241
NR
20285*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
20286args=[],file="try.c",fullname="/home/foo/bar/try.c",line="5"@}
594fe323 20287(gdb)
a2c02241
NR
20288-data-list-changed-registers
20289^done,changed-registers=["0","1","2","4","5","6","7","8","9",
20290"10","11","13","14","15","16","17","18","19","20","21","22","23",
20291"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 20292(gdb)
a2c02241 20293@end smallexample
922fbb7b
AC
20294
20295
a2c02241
NR
20296@subheading The @code{-data-list-register-names} Command
20297@findex -data-list-register-names
922fbb7b
AC
20298
20299@subsubheading Synopsis
20300
20301@smallexample
a2c02241 20302 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
20303@end smallexample
20304
a2c02241
NR
20305Show a list of register names for the current target. If no arguments
20306are given, it shows a list of the names of all the registers. If
20307integer numbers are given as arguments, it will print a list of the
20308names of the registers corresponding to the arguments. To ensure
20309consistency between a register name and its number, the output list may
20310include empty register names.
922fbb7b
AC
20311
20312@subsubheading @value{GDBN} Command
20313
a2c02241
NR
20314@value{GDBN} does not have a command which corresponds to
20315@samp{-data-list-register-names}. In @code{gdbtk} there is a
20316corresponding command @samp{gdb_regnames}.
922fbb7b
AC
20317
20318@subsubheading Example
922fbb7b 20319
a2c02241
NR
20320For the PPC MBX board:
20321@smallexample
594fe323 20322(gdb)
a2c02241
NR
20323-data-list-register-names
20324^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
20325"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
20326"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
20327"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
20328"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
20329"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
20330"", "pc","ps","cr","lr","ctr","xer"]
594fe323 20331(gdb)
a2c02241
NR
20332-data-list-register-names 1 2 3
20333^done,register-names=["r1","r2","r3"]
594fe323 20334(gdb)
a2c02241 20335@end smallexample
922fbb7b 20336
a2c02241
NR
20337@subheading The @code{-data-list-register-values} Command
20338@findex -data-list-register-values
922fbb7b
AC
20339
20340@subsubheading Synopsis
20341
20342@smallexample
a2c02241 20343 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
20344@end smallexample
20345
a2c02241
NR
20346Display the registers' contents. @var{fmt} is the format according to
20347which the registers' contents are to be returned, followed by an optional
20348list of numbers specifying the registers to display. A missing list of
20349numbers indicates that the contents of all the registers must be returned.
20350
20351Allowed formats for @var{fmt} are:
20352
20353@table @code
20354@item x
20355Hexadecimal
20356@item o
20357Octal
20358@item t
20359Binary
20360@item d
20361Decimal
20362@item r
20363Raw
20364@item N
20365Natural
20366@end table
922fbb7b
AC
20367
20368@subsubheading @value{GDBN} Command
20369
a2c02241
NR
20370The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
20371all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
20372
20373@subsubheading Example
922fbb7b 20374
a2c02241
NR
20375For a PPC MBX board (note: line breaks are for readability only, they
20376don't appear in the actual output):
20377
20378@smallexample
594fe323 20379(gdb)
a2c02241
NR
20380-data-list-register-values r 64 65
20381^done,register-values=[@{number="64",value="0xfe00a300"@},
20382@{number="65",value="0x00029002"@}]
594fe323 20383(gdb)
a2c02241
NR
20384-data-list-register-values x
20385^done,register-values=[@{number="0",value="0xfe0043c8"@},
20386@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
20387@{number="3",value="0x0"@},@{number="4",value="0xa"@},
20388@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
20389@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
20390@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
20391@{number="11",value="0x1"@},@{number="12",value="0x0"@},
20392@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
20393@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
20394@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
20395@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
20396@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
20397@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
20398@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
20399@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
20400@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
20401@{number="31",value="0x0"@},@{number="32",value="0x0"@},
20402@{number="33",value="0x0"@},@{number="34",value="0x0"@},
20403@{number="35",value="0x0"@},@{number="36",value="0x0"@},
20404@{number="37",value="0x0"@},@{number="38",value="0x0"@},
20405@{number="39",value="0x0"@},@{number="40",value="0x0"@},
20406@{number="41",value="0x0"@},@{number="42",value="0x0"@},
20407@{number="43",value="0x0"@},@{number="44",value="0x0"@},
20408@{number="45",value="0x0"@},@{number="46",value="0x0"@},
20409@{number="47",value="0x0"@},@{number="48",value="0x0"@},
20410@{number="49",value="0x0"@},@{number="50",value="0x0"@},
20411@{number="51",value="0x0"@},@{number="52",value="0x0"@},
20412@{number="53",value="0x0"@},@{number="54",value="0x0"@},
20413@{number="55",value="0x0"@},@{number="56",value="0x0"@},
20414@{number="57",value="0x0"@},@{number="58",value="0x0"@},
20415@{number="59",value="0x0"@},@{number="60",value="0x0"@},
20416@{number="61",value="0x0"@},@{number="62",value="0x0"@},
20417@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
20418@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
20419@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
20420@{number="69",value="0x20002b03"@}]
594fe323 20421(gdb)
a2c02241 20422@end smallexample
922fbb7b 20423
a2c02241
NR
20424
20425@subheading The @code{-data-read-memory} Command
20426@findex -data-read-memory
922fbb7b
AC
20427
20428@subsubheading Synopsis
20429
20430@smallexample
a2c02241
NR
20431 -data-read-memory [ -o @var{byte-offset} ]
20432 @var{address} @var{word-format} @var{word-size}
20433 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
20434@end smallexample
20435
a2c02241
NR
20436@noindent
20437where:
922fbb7b 20438
a2c02241
NR
20439@table @samp
20440@item @var{address}
20441An expression specifying the address of the first memory word to be
20442read. Complex expressions containing embedded white space should be
20443quoted using the C convention.
922fbb7b 20444
a2c02241
NR
20445@item @var{word-format}
20446The format to be used to print the memory words. The notation is the
20447same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 20448,Output Formats}).
922fbb7b 20449
a2c02241
NR
20450@item @var{word-size}
20451The size of each memory word in bytes.
922fbb7b 20452
a2c02241
NR
20453@item @var{nr-rows}
20454The number of rows in the output table.
922fbb7b 20455
a2c02241
NR
20456@item @var{nr-cols}
20457The number of columns in the output table.
922fbb7b 20458
a2c02241
NR
20459@item @var{aschar}
20460If present, indicates that each row should include an @sc{ascii} dump. The
20461value of @var{aschar} is used as a padding character when a byte is not a
20462member of the printable @sc{ascii} character set (printable @sc{ascii}
20463characters are those whose code is between 32 and 126, inclusively).
922fbb7b 20464
a2c02241
NR
20465@item @var{byte-offset}
20466An offset to add to the @var{address} before fetching memory.
20467@end table
922fbb7b 20468
a2c02241
NR
20469This command displays memory contents as a table of @var{nr-rows} by
20470@var{nr-cols} words, each word being @var{word-size} bytes. In total,
20471@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
20472(returned as @samp{total-bytes}). Should less than the requested number
20473of bytes be returned by the target, the missing words are identified
20474using @samp{N/A}. The number of bytes read from the target is returned
20475in @samp{nr-bytes} and the starting address used to read memory in
20476@samp{addr}.
20477
20478The address of the next/previous row or page is available in
20479@samp{next-row} and @samp{prev-row}, @samp{next-page} and
20480@samp{prev-page}.
922fbb7b
AC
20481
20482@subsubheading @value{GDBN} Command
20483
a2c02241
NR
20484The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
20485@samp{gdb_get_mem} memory read command.
922fbb7b
AC
20486
20487@subsubheading Example
32e7087d 20488
a2c02241
NR
20489Read six bytes of memory starting at @code{bytes+6} but then offset by
20490@code{-6} bytes. Format as three rows of two columns. One byte per
20491word. Display each word in hex.
32e7087d
JB
20492
20493@smallexample
594fe323 20494(gdb)
a2c02241
NR
204959-data-read-memory -o -6 -- bytes+6 x 1 3 2
204969^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
20497next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
20498prev-page="0x0000138a",memory=[
20499@{addr="0x00001390",data=["0x00","0x01"]@},
20500@{addr="0x00001392",data=["0x02","0x03"]@},
20501@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 20502(gdb)
32e7087d
JB
20503@end smallexample
20504
a2c02241
NR
20505Read two bytes of memory starting at address @code{shorts + 64} and
20506display as a single word formatted in decimal.
32e7087d 20507
32e7087d 20508@smallexample
594fe323 20509(gdb)
a2c02241
NR
205105-data-read-memory shorts+64 d 2 1 1
205115^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
20512next-row="0x00001512",prev-row="0x0000150e",
20513next-page="0x00001512",prev-page="0x0000150e",memory=[
20514@{addr="0x00001510",data=["128"]@}]
594fe323 20515(gdb)
32e7087d
JB
20516@end smallexample
20517
a2c02241
NR
20518Read thirty two bytes of memory starting at @code{bytes+16} and format
20519as eight rows of four columns. Include a string encoding with @samp{x}
20520used as the non-printable character.
922fbb7b
AC
20521
20522@smallexample
594fe323 20523(gdb)
a2c02241
NR
205244-data-read-memory bytes+16 x 1 8 4 x
205254^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
20526next-row="0x000013c0",prev-row="0x0000139c",
20527next-page="0x000013c0",prev-page="0x00001380",memory=[
20528@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
20529@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
20530@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
20531@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
20532@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
20533@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
20534@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
20535@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 20536(gdb)
922fbb7b
AC
20537@end smallexample
20538
a2c02241
NR
20539@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20540@node GDB/MI Tracepoint Commands
20541@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 20542
a2c02241 20543The tracepoint commands are not yet implemented.
922fbb7b 20544
a2c02241 20545@c @subheading -trace-actions
922fbb7b 20546
a2c02241 20547@c @subheading -trace-delete
922fbb7b 20548
a2c02241 20549@c @subheading -trace-disable
922fbb7b 20550
a2c02241 20551@c @subheading -trace-dump
922fbb7b 20552
a2c02241 20553@c @subheading -trace-enable
922fbb7b 20554
a2c02241 20555@c @subheading -trace-exists
922fbb7b 20556
a2c02241 20557@c @subheading -trace-find
922fbb7b 20558
a2c02241 20559@c @subheading -trace-frame-number
922fbb7b 20560
a2c02241 20561@c @subheading -trace-info
922fbb7b 20562
a2c02241 20563@c @subheading -trace-insert
922fbb7b 20564
a2c02241 20565@c @subheading -trace-list
922fbb7b 20566
a2c02241 20567@c @subheading -trace-pass-count
922fbb7b 20568
a2c02241 20569@c @subheading -trace-save
922fbb7b 20570
a2c02241 20571@c @subheading -trace-start
922fbb7b 20572
a2c02241 20573@c @subheading -trace-stop
922fbb7b 20574
922fbb7b 20575
a2c02241
NR
20576@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20577@node GDB/MI Symbol Query
20578@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
20579
20580
a2c02241
NR
20581@subheading The @code{-symbol-info-address} Command
20582@findex -symbol-info-address
922fbb7b
AC
20583
20584@subsubheading Synopsis
20585
20586@smallexample
a2c02241 20587 -symbol-info-address @var{symbol}
922fbb7b
AC
20588@end smallexample
20589
a2c02241 20590Describe where @var{symbol} is stored.
922fbb7b
AC
20591
20592@subsubheading @value{GDBN} Command
20593
a2c02241 20594The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
20595
20596@subsubheading Example
20597N.A.
20598
20599
a2c02241
NR
20600@subheading The @code{-symbol-info-file} Command
20601@findex -symbol-info-file
922fbb7b
AC
20602
20603@subsubheading Synopsis
20604
20605@smallexample
a2c02241 20606 -symbol-info-file
922fbb7b
AC
20607@end smallexample
20608
a2c02241 20609Show the file for the symbol.
922fbb7b 20610
a2c02241 20611@subsubheading @value{GDBN} Command
922fbb7b 20612
a2c02241
NR
20613There's no equivalent @value{GDBN} command. @code{gdbtk} has
20614@samp{gdb_find_file}.
922fbb7b
AC
20615
20616@subsubheading Example
20617N.A.
20618
20619
a2c02241
NR
20620@subheading The @code{-symbol-info-function} Command
20621@findex -symbol-info-function
922fbb7b
AC
20622
20623@subsubheading Synopsis
20624
20625@smallexample
a2c02241 20626 -symbol-info-function
922fbb7b
AC
20627@end smallexample
20628
a2c02241 20629Show which function the symbol lives in.
922fbb7b
AC
20630
20631@subsubheading @value{GDBN} Command
20632
a2c02241 20633@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
20634
20635@subsubheading Example
20636N.A.
20637
20638
a2c02241
NR
20639@subheading The @code{-symbol-info-line} Command
20640@findex -symbol-info-line
922fbb7b
AC
20641
20642@subsubheading Synopsis
20643
20644@smallexample
a2c02241 20645 -symbol-info-line
922fbb7b
AC
20646@end smallexample
20647
a2c02241 20648Show the core addresses of the code for a source line.
922fbb7b 20649
a2c02241 20650@subsubheading @value{GDBN} Command
922fbb7b 20651
a2c02241
NR
20652The corresponding @value{GDBN} command is @samp{info line}.
20653@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
20654
20655@subsubheading Example
a2c02241 20656N.A.
922fbb7b
AC
20657
20658
a2c02241
NR
20659@subheading The @code{-symbol-info-symbol} Command
20660@findex -symbol-info-symbol
07f31aa6
DJ
20661
20662@subsubheading Synopsis
20663
a2c02241
NR
20664@smallexample
20665 -symbol-info-symbol @var{addr}
20666@end smallexample
07f31aa6 20667
a2c02241 20668Describe what symbol is at location @var{addr}.
07f31aa6 20669
a2c02241 20670@subsubheading @value{GDBN} Command
07f31aa6 20671
a2c02241 20672The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
20673
20674@subsubheading Example
a2c02241 20675N.A.
07f31aa6
DJ
20676
20677
a2c02241
NR
20678@subheading The @code{-symbol-list-functions} Command
20679@findex -symbol-list-functions
922fbb7b
AC
20680
20681@subsubheading Synopsis
20682
20683@smallexample
a2c02241 20684 -symbol-list-functions
922fbb7b
AC
20685@end smallexample
20686
a2c02241 20687List the functions in the executable.
922fbb7b
AC
20688
20689@subsubheading @value{GDBN} Command
20690
a2c02241
NR
20691@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
20692@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
20693
20694@subsubheading Example
a2c02241 20695N.A.
922fbb7b
AC
20696
20697
a2c02241
NR
20698@subheading The @code{-symbol-list-lines} Command
20699@findex -symbol-list-lines
922fbb7b
AC
20700
20701@subsubheading Synopsis
20702
20703@smallexample
a2c02241 20704 -symbol-list-lines @var{filename}
922fbb7b
AC
20705@end smallexample
20706
a2c02241
NR
20707Print the list of lines that contain code and their associated program
20708addresses for the given source filename. The entries are sorted in
20709ascending PC order.
922fbb7b
AC
20710
20711@subsubheading @value{GDBN} Command
20712
a2c02241 20713There is no corresponding @value{GDBN} command.
922fbb7b
AC
20714
20715@subsubheading Example
a2c02241 20716@smallexample
594fe323 20717(gdb)
a2c02241
NR
20718-symbol-list-lines basics.c
20719^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 20720(gdb)
a2c02241 20721@end smallexample
922fbb7b
AC
20722
20723
a2c02241
NR
20724@subheading The @code{-symbol-list-types} Command
20725@findex -symbol-list-types
922fbb7b
AC
20726
20727@subsubheading Synopsis
20728
20729@smallexample
a2c02241 20730 -symbol-list-types
922fbb7b
AC
20731@end smallexample
20732
a2c02241 20733List all the type names.
922fbb7b
AC
20734
20735@subsubheading @value{GDBN} Command
20736
a2c02241
NR
20737The corresponding commands are @samp{info types} in @value{GDBN},
20738@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
20739
20740@subsubheading Example
20741N.A.
20742
20743
a2c02241
NR
20744@subheading The @code{-symbol-list-variables} Command
20745@findex -symbol-list-variables
922fbb7b
AC
20746
20747@subsubheading Synopsis
20748
20749@smallexample
a2c02241 20750 -symbol-list-variables
922fbb7b
AC
20751@end smallexample
20752
a2c02241 20753List all the global and static variable names.
922fbb7b
AC
20754
20755@subsubheading @value{GDBN} Command
20756
a2c02241 20757@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
20758
20759@subsubheading Example
20760N.A.
20761
20762
a2c02241
NR
20763@subheading The @code{-symbol-locate} Command
20764@findex -symbol-locate
922fbb7b
AC
20765
20766@subsubheading Synopsis
20767
20768@smallexample
a2c02241 20769 -symbol-locate
922fbb7b
AC
20770@end smallexample
20771
922fbb7b
AC
20772@subsubheading @value{GDBN} Command
20773
a2c02241 20774@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
20775
20776@subsubheading Example
20777N.A.
20778
20779
a2c02241
NR
20780@subheading The @code{-symbol-type} Command
20781@findex -symbol-type
922fbb7b
AC
20782
20783@subsubheading Synopsis
20784
20785@smallexample
a2c02241 20786 -symbol-type @var{variable}
922fbb7b
AC
20787@end smallexample
20788
a2c02241 20789Show type of @var{variable}.
922fbb7b 20790
a2c02241 20791@subsubheading @value{GDBN} Command
922fbb7b 20792
a2c02241
NR
20793The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
20794@samp{gdb_obj_variable}.
20795
20796@subsubheading Example
20797N.A.
20798
20799
20800@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20801@node GDB/MI File Commands
20802@section @sc{gdb/mi} File Commands
20803
20804This section describes the GDB/MI commands to specify executable file names
20805and to read in and obtain symbol table information.
20806
20807@subheading The @code{-file-exec-and-symbols} Command
20808@findex -file-exec-and-symbols
20809
20810@subsubheading Synopsis
922fbb7b
AC
20811
20812@smallexample
a2c02241 20813 -file-exec-and-symbols @var{file}
922fbb7b
AC
20814@end smallexample
20815
a2c02241
NR
20816Specify the executable file to be debugged. This file is the one from
20817which the symbol table is also read. If no file is specified, the
20818command clears the executable and symbol information. If breakpoints
20819are set when using this command with no arguments, @value{GDBN} will produce
20820error messages. Otherwise, no output is produced, except a completion
20821notification.
20822
922fbb7b
AC
20823@subsubheading @value{GDBN} Command
20824
a2c02241 20825The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
20826
20827@subsubheading Example
20828
20829@smallexample
594fe323 20830(gdb)
a2c02241
NR
20831-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
20832^done
594fe323 20833(gdb)
922fbb7b
AC
20834@end smallexample
20835
922fbb7b 20836
a2c02241
NR
20837@subheading The @code{-file-exec-file} Command
20838@findex -file-exec-file
922fbb7b
AC
20839
20840@subsubheading Synopsis
20841
20842@smallexample
a2c02241 20843 -file-exec-file @var{file}
922fbb7b
AC
20844@end smallexample
20845
a2c02241
NR
20846Specify the executable file to be debugged. Unlike
20847@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
20848from this file. If used without argument, @value{GDBN} clears the information
20849about the executable file. No output is produced, except a completion
20850notification.
922fbb7b 20851
a2c02241
NR
20852@subsubheading @value{GDBN} Command
20853
20854The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
20855
20856@subsubheading Example
a2c02241
NR
20857
20858@smallexample
594fe323 20859(gdb)
a2c02241
NR
20860-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
20861^done
594fe323 20862(gdb)
a2c02241 20863@end smallexample
922fbb7b
AC
20864
20865
a2c02241
NR
20866@subheading The @code{-file-list-exec-sections} Command
20867@findex -file-list-exec-sections
922fbb7b
AC
20868
20869@subsubheading Synopsis
20870
20871@smallexample
a2c02241 20872 -file-list-exec-sections
922fbb7b
AC
20873@end smallexample
20874
a2c02241
NR
20875List the sections of the current executable file.
20876
922fbb7b
AC
20877@subsubheading @value{GDBN} Command
20878
a2c02241
NR
20879The @value{GDBN} command @samp{info file} shows, among the rest, the same
20880information as this command. @code{gdbtk} has a corresponding command
20881@samp{gdb_load_info}.
922fbb7b
AC
20882
20883@subsubheading Example
20884N.A.
20885
20886
a2c02241
NR
20887@subheading The @code{-file-list-exec-source-file} Command
20888@findex -file-list-exec-source-file
922fbb7b
AC
20889
20890@subsubheading Synopsis
20891
20892@smallexample
a2c02241 20893 -file-list-exec-source-file
922fbb7b
AC
20894@end smallexample
20895
a2c02241
NR
20896List the line number, the current source file, and the absolute path
20897to the current source file for the current executable.
922fbb7b
AC
20898
20899@subsubheading @value{GDBN} Command
20900
a2c02241 20901The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
20902
20903@subsubheading Example
20904
922fbb7b 20905@smallexample
594fe323 20906(gdb)
a2c02241
NR
20907123-file-list-exec-source-file
20908123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
594fe323 20909(gdb)
922fbb7b
AC
20910@end smallexample
20911
20912
a2c02241
NR
20913@subheading The @code{-file-list-exec-source-files} Command
20914@findex -file-list-exec-source-files
922fbb7b
AC
20915
20916@subsubheading Synopsis
20917
20918@smallexample
a2c02241 20919 -file-list-exec-source-files
922fbb7b
AC
20920@end smallexample
20921
a2c02241
NR
20922List the source files for the current executable.
20923
3f94c067
BW
20924It will always output the filename, but only when @value{GDBN} can find
20925the absolute file name of a source file, will it output the fullname.
922fbb7b
AC
20926
20927@subsubheading @value{GDBN} Command
20928
a2c02241
NR
20929The @value{GDBN} equivalent is @samp{info sources}.
20930@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
20931
20932@subsubheading Example
922fbb7b 20933@smallexample
594fe323 20934(gdb)
a2c02241
NR
20935-file-list-exec-source-files
20936^done,files=[
20937@{file=foo.c,fullname=/home/foo.c@},
20938@{file=/home/bar.c,fullname=/home/bar.c@},
20939@{file=gdb_could_not_find_fullpath.c@}]
594fe323 20940(gdb)
922fbb7b
AC
20941@end smallexample
20942
a2c02241
NR
20943@subheading The @code{-file-list-shared-libraries} Command
20944@findex -file-list-shared-libraries
922fbb7b 20945
a2c02241 20946@subsubheading Synopsis
922fbb7b 20947
a2c02241
NR
20948@smallexample
20949 -file-list-shared-libraries
20950@end smallexample
922fbb7b 20951
a2c02241 20952List the shared libraries in the program.
922fbb7b 20953
a2c02241 20954@subsubheading @value{GDBN} Command
922fbb7b 20955
a2c02241 20956The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 20957
a2c02241
NR
20958@subsubheading Example
20959N.A.
922fbb7b
AC
20960
20961
a2c02241
NR
20962@subheading The @code{-file-list-symbol-files} Command
20963@findex -file-list-symbol-files
922fbb7b 20964
a2c02241 20965@subsubheading Synopsis
922fbb7b 20966
a2c02241
NR
20967@smallexample
20968 -file-list-symbol-files
20969@end smallexample
922fbb7b 20970
a2c02241 20971List symbol files.
922fbb7b 20972
a2c02241 20973@subsubheading @value{GDBN} Command
922fbb7b 20974
a2c02241 20975The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 20976
a2c02241
NR
20977@subsubheading Example
20978N.A.
922fbb7b 20979
922fbb7b 20980
a2c02241
NR
20981@subheading The @code{-file-symbol-file} Command
20982@findex -file-symbol-file
922fbb7b 20983
a2c02241 20984@subsubheading Synopsis
922fbb7b 20985
a2c02241
NR
20986@smallexample
20987 -file-symbol-file @var{file}
20988@end smallexample
922fbb7b 20989
a2c02241
NR
20990Read symbol table info from the specified @var{file} argument. When
20991used without arguments, clears @value{GDBN}'s symbol table info. No output is
20992produced, except for a completion notification.
922fbb7b 20993
a2c02241 20994@subsubheading @value{GDBN} Command
922fbb7b 20995
a2c02241 20996The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 20997
a2c02241 20998@subsubheading Example
922fbb7b 20999
a2c02241 21000@smallexample
594fe323 21001(gdb)
a2c02241
NR
21002-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
21003^done
594fe323 21004(gdb)
a2c02241 21005@end smallexample
922fbb7b 21006
a2c02241 21007@ignore
a2c02241
NR
21008@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21009@node GDB/MI Memory Overlay Commands
21010@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 21011
a2c02241 21012The memory overlay commands are not implemented.
922fbb7b 21013
a2c02241 21014@c @subheading -overlay-auto
922fbb7b 21015
a2c02241 21016@c @subheading -overlay-list-mapping-state
922fbb7b 21017
a2c02241 21018@c @subheading -overlay-list-overlays
922fbb7b 21019
a2c02241 21020@c @subheading -overlay-map
922fbb7b 21021
a2c02241 21022@c @subheading -overlay-off
922fbb7b 21023
a2c02241 21024@c @subheading -overlay-on
922fbb7b 21025
a2c02241 21026@c @subheading -overlay-unmap
922fbb7b 21027
a2c02241
NR
21028@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21029@node GDB/MI Signal Handling Commands
21030@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 21031
a2c02241 21032Signal handling commands are not implemented.
922fbb7b 21033
a2c02241 21034@c @subheading -signal-handle
922fbb7b 21035
a2c02241 21036@c @subheading -signal-list-handle-actions
922fbb7b 21037
a2c02241
NR
21038@c @subheading -signal-list-signal-types
21039@end ignore
922fbb7b 21040
922fbb7b 21041
a2c02241
NR
21042@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21043@node GDB/MI Target Manipulation
21044@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
21045
21046
a2c02241
NR
21047@subheading The @code{-target-attach} Command
21048@findex -target-attach
922fbb7b
AC
21049
21050@subsubheading Synopsis
21051
21052@smallexample
a2c02241 21053 -target-attach @var{pid} | @var{file}
922fbb7b
AC
21054@end smallexample
21055
a2c02241 21056Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
922fbb7b 21057
79a6e687 21058@subsubheading @value{GDBN} Command
922fbb7b 21059
a2c02241 21060The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 21061
a2c02241
NR
21062@subsubheading Example
21063N.A.
922fbb7b 21064
a2c02241
NR
21065
21066@subheading The @code{-target-compare-sections} Command
21067@findex -target-compare-sections
922fbb7b
AC
21068
21069@subsubheading Synopsis
21070
21071@smallexample
a2c02241 21072 -target-compare-sections [ @var{section} ]
922fbb7b
AC
21073@end smallexample
21074
a2c02241
NR
21075Compare data of section @var{section} on target to the exec file.
21076Without the argument, all sections are compared.
922fbb7b 21077
a2c02241 21078@subsubheading @value{GDBN} Command
922fbb7b 21079
a2c02241 21080The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 21081
a2c02241
NR
21082@subsubheading Example
21083N.A.
21084
21085
21086@subheading The @code{-target-detach} Command
21087@findex -target-detach
922fbb7b
AC
21088
21089@subsubheading Synopsis
21090
21091@smallexample
a2c02241 21092 -target-detach
922fbb7b
AC
21093@end smallexample
21094
a2c02241
NR
21095Detach from the remote target which normally resumes its execution.
21096There's no output.
21097
79a6e687 21098@subsubheading @value{GDBN} Command
a2c02241
NR
21099
21100The corresponding @value{GDBN} command is @samp{detach}.
21101
21102@subsubheading Example
922fbb7b
AC
21103
21104@smallexample
594fe323 21105(gdb)
a2c02241
NR
21106-target-detach
21107^done
594fe323 21108(gdb)
922fbb7b
AC
21109@end smallexample
21110
21111
a2c02241
NR
21112@subheading The @code{-target-disconnect} Command
21113@findex -target-disconnect
922fbb7b
AC
21114
21115@subsubheading Synopsis
21116
123dc839 21117@smallexample
a2c02241 21118 -target-disconnect
123dc839 21119@end smallexample
922fbb7b 21120
a2c02241
NR
21121Disconnect from the remote target. There's no output and the target is
21122generally not resumed.
21123
79a6e687 21124@subsubheading @value{GDBN} Command
a2c02241
NR
21125
21126The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
21127
21128@subsubheading Example
922fbb7b
AC
21129
21130@smallexample
594fe323 21131(gdb)
a2c02241
NR
21132-target-disconnect
21133^done
594fe323 21134(gdb)
922fbb7b
AC
21135@end smallexample
21136
21137
a2c02241
NR
21138@subheading The @code{-target-download} Command
21139@findex -target-download
922fbb7b
AC
21140
21141@subsubheading Synopsis
21142
21143@smallexample
a2c02241 21144 -target-download
922fbb7b
AC
21145@end smallexample
21146
a2c02241
NR
21147Loads the executable onto the remote target.
21148It prints out an update message every half second, which includes the fields:
21149
21150@table @samp
21151@item section
21152The name of the section.
21153@item section-sent
21154The size of what has been sent so far for that section.
21155@item section-size
21156The size of the section.
21157@item total-sent
21158The total size of what was sent so far (the current and the previous sections).
21159@item total-size
21160The size of the overall executable to download.
21161@end table
21162
21163@noindent
21164Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
21165@sc{gdb/mi} Output Syntax}).
21166
21167In addition, it prints the name and size of the sections, as they are
21168downloaded. These messages include the following fields:
21169
21170@table @samp
21171@item section
21172The name of the section.
21173@item section-size
21174The size of the section.
21175@item total-size
21176The size of the overall executable to download.
21177@end table
21178
21179@noindent
21180At the end, a summary is printed.
21181
21182@subsubheading @value{GDBN} Command
21183
21184The corresponding @value{GDBN} command is @samp{load}.
21185
21186@subsubheading Example
21187
21188Note: each status message appears on a single line. Here the messages
21189have been broken down so that they can fit onto a page.
922fbb7b
AC
21190
21191@smallexample
594fe323 21192(gdb)
a2c02241
NR
21193-target-download
21194+download,@{section=".text",section-size="6668",total-size="9880"@}
21195+download,@{section=".text",section-sent="512",section-size="6668",
21196total-sent="512",total-size="9880"@}
21197+download,@{section=".text",section-sent="1024",section-size="6668",
21198total-sent="1024",total-size="9880"@}
21199+download,@{section=".text",section-sent="1536",section-size="6668",
21200total-sent="1536",total-size="9880"@}
21201+download,@{section=".text",section-sent="2048",section-size="6668",
21202total-sent="2048",total-size="9880"@}
21203+download,@{section=".text",section-sent="2560",section-size="6668",
21204total-sent="2560",total-size="9880"@}
21205+download,@{section=".text",section-sent="3072",section-size="6668",
21206total-sent="3072",total-size="9880"@}
21207+download,@{section=".text",section-sent="3584",section-size="6668",
21208total-sent="3584",total-size="9880"@}
21209+download,@{section=".text",section-sent="4096",section-size="6668",
21210total-sent="4096",total-size="9880"@}
21211+download,@{section=".text",section-sent="4608",section-size="6668",
21212total-sent="4608",total-size="9880"@}
21213+download,@{section=".text",section-sent="5120",section-size="6668",
21214total-sent="5120",total-size="9880"@}
21215+download,@{section=".text",section-sent="5632",section-size="6668",
21216total-sent="5632",total-size="9880"@}
21217+download,@{section=".text",section-sent="6144",section-size="6668",
21218total-sent="6144",total-size="9880"@}
21219+download,@{section=".text",section-sent="6656",section-size="6668",
21220total-sent="6656",total-size="9880"@}
21221+download,@{section=".init",section-size="28",total-size="9880"@}
21222+download,@{section=".fini",section-size="28",total-size="9880"@}
21223+download,@{section=".data",section-size="3156",total-size="9880"@}
21224+download,@{section=".data",section-sent="512",section-size="3156",
21225total-sent="7236",total-size="9880"@}
21226+download,@{section=".data",section-sent="1024",section-size="3156",
21227total-sent="7748",total-size="9880"@}
21228+download,@{section=".data",section-sent="1536",section-size="3156",
21229total-sent="8260",total-size="9880"@}
21230+download,@{section=".data",section-sent="2048",section-size="3156",
21231total-sent="8772",total-size="9880"@}
21232+download,@{section=".data",section-sent="2560",section-size="3156",
21233total-sent="9284",total-size="9880"@}
21234+download,@{section=".data",section-sent="3072",section-size="3156",
21235total-sent="9796",total-size="9880"@}
21236^done,address="0x10004",load-size="9880",transfer-rate="6586",
21237write-rate="429"
594fe323 21238(gdb)
922fbb7b
AC
21239@end smallexample
21240
21241
a2c02241
NR
21242@subheading The @code{-target-exec-status} Command
21243@findex -target-exec-status
922fbb7b
AC
21244
21245@subsubheading Synopsis
21246
21247@smallexample
a2c02241 21248 -target-exec-status
922fbb7b
AC
21249@end smallexample
21250
a2c02241
NR
21251Provide information on the state of the target (whether it is running or
21252not, for instance).
922fbb7b 21253
a2c02241 21254@subsubheading @value{GDBN} Command
922fbb7b 21255
a2c02241
NR
21256There's no equivalent @value{GDBN} command.
21257
21258@subsubheading Example
21259N.A.
922fbb7b 21260
a2c02241
NR
21261
21262@subheading The @code{-target-list-available-targets} Command
21263@findex -target-list-available-targets
922fbb7b
AC
21264
21265@subsubheading Synopsis
21266
21267@smallexample
a2c02241 21268 -target-list-available-targets
922fbb7b
AC
21269@end smallexample
21270
a2c02241 21271List the possible targets to connect to.
922fbb7b 21272
a2c02241 21273@subsubheading @value{GDBN} Command
922fbb7b 21274
a2c02241 21275The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 21276
a2c02241
NR
21277@subsubheading Example
21278N.A.
21279
21280
21281@subheading The @code{-target-list-current-targets} Command
21282@findex -target-list-current-targets
922fbb7b
AC
21283
21284@subsubheading Synopsis
21285
21286@smallexample
a2c02241 21287 -target-list-current-targets
922fbb7b
AC
21288@end smallexample
21289
a2c02241 21290Describe the current target.
922fbb7b 21291
a2c02241 21292@subsubheading @value{GDBN} Command
922fbb7b 21293
a2c02241
NR
21294The corresponding information is printed by @samp{info file} (among
21295other things).
922fbb7b 21296
a2c02241
NR
21297@subsubheading Example
21298N.A.
21299
21300
21301@subheading The @code{-target-list-parameters} Command
21302@findex -target-list-parameters
922fbb7b
AC
21303
21304@subsubheading Synopsis
21305
21306@smallexample
a2c02241 21307 -target-list-parameters
922fbb7b
AC
21308@end smallexample
21309
a2c02241
NR
21310@c ????
21311
21312@subsubheading @value{GDBN} Command
21313
21314No equivalent.
922fbb7b
AC
21315
21316@subsubheading Example
a2c02241
NR
21317N.A.
21318
21319
21320@subheading The @code{-target-select} Command
21321@findex -target-select
21322
21323@subsubheading Synopsis
922fbb7b
AC
21324
21325@smallexample
a2c02241 21326 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
21327@end smallexample
21328
a2c02241 21329Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 21330
a2c02241
NR
21331@table @samp
21332@item @var{type}
21333The type of target, for instance @samp{async}, @samp{remote}, etc.
21334@item @var{parameters}
21335Device names, host names and the like. @xref{Target Commands, ,
79a6e687 21336Commands for Managing Targets}, for more details.
a2c02241
NR
21337@end table
21338
21339The output is a connection notification, followed by the address at
21340which the target program is, in the following form:
922fbb7b
AC
21341
21342@smallexample
a2c02241
NR
21343^connected,addr="@var{address}",func="@var{function name}",
21344 args=[@var{arg list}]
922fbb7b
AC
21345@end smallexample
21346
a2c02241
NR
21347@subsubheading @value{GDBN} Command
21348
21349The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
21350
21351@subsubheading Example
922fbb7b 21352
265eeb58 21353@smallexample
594fe323 21354(gdb)
a2c02241
NR
21355-target-select async /dev/ttya
21356^connected,addr="0xfe00a300",func="??",args=[]
594fe323 21357(gdb)
265eeb58 21358@end smallexample
ef21caaf 21359
a6b151f1
DJ
21360@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21361@node GDB/MI File Transfer Commands
21362@section @sc{gdb/mi} File Transfer Commands
21363
21364
21365@subheading The @code{-target-file-put} Command
21366@findex -target-file-put
21367
21368@subsubheading Synopsis
21369
21370@smallexample
21371 -target-file-put @var{hostfile} @var{targetfile}
21372@end smallexample
21373
21374Copy file @var{hostfile} from the host system (the machine running
21375@value{GDBN}) to @var{targetfile} on the target system.
21376
21377@subsubheading @value{GDBN} Command
21378
21379The corresponding @value{GDBN} command is @samp{remote put}.
21380
21381@subsubheading Example
21382
21383@smallexample
21384(gdb)
21385-target-file-put localfile remotefile
21386^done
21387(gdb)
21388@end smallexample
21389
21390
21391@subheading The @code{-target-file-put} Command
21392@findex -target-file-get
21393
21394@subsubheading Synopsis
21395
21396@smallexample
21397 -target-file-get @var{targetfile} @var{hostfile}
21398@end smallexample
21399
21400Copy file @var{targetfile} from the target system to @var{hostfile}
21401on the host system.
21402
21403@subsubheading @value{GDBN} Command
21404
21405The corresponding @value{GDBN} command is @samp{remote get}.
21406
21407@subsubheading Example
21408
21409@smallexample
21410(gdb)
21411-target-file-get remotefile localfile
21412^done
21413(gdb)
21414@end smallexample
21415
21416
21417@subheading The @code{-target-file-delete} Command
21418@findex -target-file-delete
21419
21420@subsubheading Synopsis
21421
21422@smallexample
21423 -target-file-delete @var{targetfile}
21424@end smallexample
21425
21426Delete @var{targetfile} from the target system.
21427
21428@subsubheading @value{GDBN} Command
21429
21430The corresponding @value{GDBN} command is @samp{remote delete}.
21431
21432@subsubheading Example
21433
21434@smallexample
21435(gdb)
21436-target-file-delete remotefile
21437^done
21438(gdb)
21439@end smallexample
21440
21441
ef21caaf
NR
21442@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21443@node GDB/MI Miscellaneous Commands
21444@section Miscellaneous @sc{gdb/mi} Commands
21445
21446@c @subheading -gdb-complete
21447
21448@subheading The @code{-gdb-exit} Command
21449@findex -gdb-exit
21450
21451@subsubheading Synopsis
21452
21453@smallexample
21454 -gdb-exit
21455@end smallexample
21456
21457Exit @value{GDBN} immediately.
21458
21459@subsubheading @value{GDBN} Command
21460
21461Approximately corresponds to @samp{quit}.
21462
21463@subsubheading Example
21464
21465@smallexample
594fe323 21466(gdb)
ef21caaf
NR
21467-gdb-exit
21468^exit
21469@end smallexample
21470
a2c02241
NR
21471
21472@subheading The @code{-exec-abort} Command
21473@findex -exec-abort
21474
21475@subsubheading Synopsis
21476
21477@smallexample
21478 -exec-abort
21479@end smallexample
21480
21481Kill the inferior running program.
21482
21483@subsubheading @value{GDBN} Command
21484
21485The corresponding @value{GDBN} command is @samp{kill}.
21486
21487@subsubheading Example
21488N.A.
21489
21490
ef21caaf
NR
21491@subheading The @code{-gdb-set} Command
21492@findex -gdb-set
21493
21494@subsubheading Synopsis
21495
21496@smallexample
21497 -gdb-set
21498@end smallexample
21499
21500Set an internal @value{GDBN} variable.
21501@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
21502
21503@subsubheading @value{GDBN} Command
21504
21505The corresponding @value{GDBN} command is @samp{set}.
21506
21507@subsubheading Example
21508
21509@smallexample
594fe323 21510(gdb)
ef21caaf
NR
21511-gdb-set $foo=3
21512^done
594fe323 21513(gdb)
ef21caaf
NR
21514@end smallexample
21515
21516
21517@subheading The @code{-gdb-show} Command
21518@findex -gdb-show
21519
21520@subsubheading Synopsis
21521
21522@smallexample
21523 -gdb-show
21524@end smallexample
21525
21526Show the current value of a @value{GDBN} variable.
21527
79a6e687 21528@subsubheading @value{GDBN} Command
ef21caaf
NR
21529
21530The corresponding @value{GDBN} command is @samp{show}.
21531
21532@subsubheading Example
21533
21534@smallexample
594fe323 21535(gdb)
ef21caaf
NR
21536-gdb-show annotate
21537^done,value="0"
594fe323 21538(gdb)
ef21caaf
NR
21539@end smallexample
21540
21541@c @subheading -gdb-source
21542
21543
21544@subheading The @code{-gdb-version} Command
21545@findex -gdb-version
21546
21547@subsubheading Synopsis
21548
21549@smallexample
21550 -gdb-version
21551@end smallexample
21552
21553Show version information for @value{GDBN}. Used mostly in testing.
21554
21555@subsubheading @value{GDBN} Command
21556
21557The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
21558default shows this information when you start an interactive session.
21559
21560@subsubheading Example
21561
21562@c This example modifies the actual output from GDB to avoid overfull
21563@c box in TeX.
21564@smallexample
594fe323 21565(gdb)
ef21caaf
NR
21566-gdb-version
21567~GNU gdb 5.2.1
21568~Copyright 2000 Free Software Foundation, Inc.
21569~GDB is free software, covered by the GNU General Public License, and
21570~you are welcome to change it and/or distribute copies of it under
21571~ certain conditions.
21572~Type "show copying" to see the conditions.
21573~There is absolutely no warranty for GDB. Type "show warranty" for
21574~ details.
21575~This GDB was configured as
21576 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
21577^done
594fe323 21578(gdb)
ef21caaf
NR
21579@end smallexample
21580
084344da
VP
21581@subheading The @code{-list-features} Command
21582@findex -list-features
21583
21584Returns a list of particular features of the MI protocol that
21585this version of gdb implements. A feature can be a command,
21586or a new field in an output of some command, or even an
21587important bugfix. While a frontend can sometimes detect presence
21588of a feature at runtime, it is easier to perform detection at debugger
21589startup.
21590
21591The command returns a list of strings, with each string naming an
21592available feature. Each returned string is just a name, it does not
21593have any internal structure. The list of possible feature names
21594is given below.
21595
21596Example output:
21597
21598@smallexample
21599(gdb) -list-features
21600^done,result=["feature1","feature2"]
21601@end smallexample
21602
21603The current list of features is:
21604
21605@itemize @minus
21606@item
21607@samp{frozen-varobjs}---indicates presence of the
21608@code{-var-set-frozen} command, as well as possible presense of the
21609@code{frozen} field in the output of @code{-varobj-create}.
21610@end itemize
21611
ef21caaf
NR
21612@subheading The @code{-interpreter-exec} Command
21613@findex -interpreter-exec
21614
21615@subheading Synopsis
21616
21617@smallexample
21618-interpreter-exec @var{interpreter} @var{command}
21619@end smallexample
a2c02241 21620@anchor{-interpreter-exec}
ef21caaf
NR
21621
21622Execute the specified @var{command} in the given @var{interpreter}.
21623
21624@subheading @value{GDBN} Command
21625
21626The corresponding @value{GDBN} command is @samp{interpreter-exec}.
21627
21628@subheading Example
21629
21630@smallexample
594fe323 21631(gdb)
ef21caaf
NR
21632-interpreter-exec console "break main"
21633&"During symbol reading, couldn't parse type; debugger out of date?.\n"
21634&"During symbol reading, bad structure-type format.\n"
21635~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
21636^done
594fe323 21637(gdb)
ef21caaf
NR
21638@end smallexample
21639
21640@subheading The @code{-inferior-tty-set} Command
21641@findex -inferior-tty-set
21642
21643@subheading Synopsis
21644
21645@smallexample
21646-inferior-tty-set /dev/pts/1
21647@end smallexample
21648
21649Set terminal for future runs of the program being debugged.
21650
21651@subheading @value{GDBN} Command
21652
21653The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
21654
21655@subheading Example
21656
21657@smallexample
594fe323 21658(gdb)
ef21caaf
NR
21659-inferior-tty-set /dev/pts/1
21660^done
594fe323 21661(gdb)
ef21caaf
NR
21662@end smallexample
21663
21664@subheading The @code{-inferior-tty-show} Command
21665@findex -inferior-tty-show
21666
21667@subheading Synopsis
21668
21669@smallexample
21670-inferior-tty-show
21671@end smallexample
21672
21673Show terminal for future runs of program being debugged.
21674
21675@subheading @value{GDBN} Command
21676
21677The corresponding @value{GDBN} command is @samp{show inferior-tty}.
21678
21679@subheading Example
21680
21681@smallexample
594fe323 21682(gdb)
ef21caaf
NR
21683-inferior-tty-set /dev/pts/1
21684^done
594fe323 21685(gdb)
ef21caaf
NR
21686-inferior-tty-show
21687^done,inferior_tty_terminal="/dev/pts/1"
594fe323 21688(gdb)
ef21caaf 21689@end smallexample
922fbb7b 21690
a4eefcd8
NR
21691@subheading The @code{-enable-timings} Command
21692@findex -enable-timings
21693
21694@subheading Synopsis
21695
21696@smallexample
21697-enable-timings [yes | no]
21698@end smallexample
21699
21700Toggle the printing of the wallclock, user and system times for an MI
21701command as a field in its output. This command is to help frontend
21702developers optimize the performance of their code. No argument is
21703equivalent to @samp{yes}.
21704
21705@subheading @value{GDBN} Command
21706
21707No equivalent.
21708
21709@subheading Example
21710
21711@smallexample
21712(gdb)
21713-enable-timings
21714^done
21715(gdb)
21716-break-insert main
21717^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
21718addr="0x080484ed",func="main",file="myprog.c",
21719fullname="/home/nickrob/myprog.c",line="73",times="0"@},
21720time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
21721(gdb)
21722-enable-timings no
21723^done
21724(gdb)
21725-exec-run
21726^running
21727(gdb)
21728*stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",
21729frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
21730@{name="argv",value="0xbfb60364"@}],file="myprog.c",
21731fullname="/home/nickrob/myprog.c",line="73"@}
21732(gdb)
21733@end smallexample
21734
922fbb7b
AC
21735@node Annotations
21736@chapter @value{GDBN} Annotations
21737
086432e2
AC
21738This chapter describes annotations in @value{GDBN}. Annotations were
21739designed to interface @value{GDBN} to graphical user interfaces or other
21740similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
21741relatively high level.
21742
d3e8051b 21743The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
21744(@pxref{GDB/MI}).
21745
922fbb7b
AC
21746@ignore
21747This is Edition @value{EDITION}, @value{DATE}.
21748@end ignore
21749
21750@menu
21751* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 21752* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
21753* Prompting:: Annotations marking @value{GDBN}'s need for input.
21754* Errors:: Annotations for error messages.
922fbb7b
AC
21755* Invalidation:: Some annotations describe things now invalid.
21756* Annotations for Running::
21757 Whether the program is running, how it stopped, etc.
21758* Source Annotations:: Annotations describing source code.
922fbb7b
AC
21759@end menu
21760
21761@node Annotations Overview
21762@section What is an Annotation?
21763@cindex annotations
21764
922fbb7b
AC
21765Annotations start with a newline character, two @samp{control-z}
21766characters, and the name of the annotation. If there is no additional
21767information associated with this annotation, the name of the annotation
21768is followed immediately by a newline. If there is additional
21769information, the name of the annotation is followed by a space, the
21770additional information, and a newline. The additional information
21771cannot contain newline characters.
21772
21773Any output not beginning with a newline and two @samp{control-z}
21774characters denotes literal output from @value{GDBN}. Currently there is
21775no need for @value{GDBN} to output a newline followed by two
21776@samp{control-z} characters, but if there was such a need, the
21777annotations could be extended with an @samp{escape} annotation which
21778means those three characters as output.
21779
086432e2
AC
21780The annotation @var{level}, which is specified using the
21781@option{--annotate} command line option (@pxref{Mode Options}), controls
21782how much information @value{GDBN} prints together with its prompt,
21783values of expressions, source lines, and other types of output. Level 0
d3e8051b 21784is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
21785subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
21786for programs that control @value{GDBN}, and level 2 annotations have
21787been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
21788Interface, annotate, GDB's Obsolete Annotations}).
21789
21790@table @code
21791@kindex set annotate
21792@item set annotate @var{level}
e09f16f9 21793The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 21794annotations to the specified @var{level}.
9c16f35a
EZ
21795
21796@item show annotate
21797@kindex show annotate
21798Show the current annotation level.
09d4efe1
EZ
21799@end table
21800
21801This chapter describes level 3 annotations.
086432e2 21802
922fbb7b
AC
21803A simple example of starting up @value{GDBN} with annotations is:
21804
21805@smallexample
086432e2
AC
21806$ @kbd{gdb --annotate=3}
21807GNU gdb 6.0
21808Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
21809GDB is free software, covered by the GNU General Public License,
21810and you are welcome to change it and/or distribute copies of it
21811under certain conditions.
21812Type "show copying" to see the conditions.
21813There is absolutely no warranty for GDB. Type "show warranty"
21814for details.
086432e2 21815This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
21816
21817^Z^Zpre-prompt
f7dc1244 21818(@value{GDBP})
922fbb7b 21819^Z^Zprompt
086432e2 21820@kbd{quit}
922fbb7b
AC
21821
21822^Z^Zpost-prompt
b383017d 21823$
922fbb7b
AC
21824@end smallexample
21825
21826Here @samp{quit} is input to @value{GDBN}; the rest is output from
21827@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
21828denotes a @samp{control-z} character) are annotations; the rest is
21829output from @value{GDBN}.
21830
9e6c4bd5
NR
21831@node Server Prefix
21832@section The Server Prefix
21833@cindex server prefix
21834
21835If you prefix a command with @samp{server } then it will not affect
21836the command history, nor will it affect @value{GDBN}'s notion of which
21837command to repeat if @key{RET} is pressed on a line by itself. This
21838means that commands can be run behind a user's back by a front-end in
21839a transparent manner.
21840
21841The server prefix does not affect the recording of values into the value
21842history; to print a value without recording it into the value history,
21843use the @code{output} command instead of the @code{print} command.
21844
922fbb7b
AC
21845@node Prompting
21846@section Annotation for @value{GDBN} Input
21847
21848@cindex annotations for prompts
21849When @value{GDBN} prompts for input, it annotates this fact so it is possible
21850to know when to send output, when the output from a given command is
21851over, etc.
21852
21853Different kinds of input each have a different @dfn{input type}. Each
21854input type has three annotations: a @code{pre-} annotation, which
21855denotes the beginning of any prompt which is being output, a plain
21856annotation, which denotes the end of the prompt, and then a @code{post-}
21857annotation which denotes the end of any echo which may (or may not) be
21858associated with the input. For example, the @code{prompt} input type
21859features the following annotations:
21860
21861@smallexample
21862^Z^Zpre-prompt
21863^Z^Zprompt
21864^Z^Zpost-prompt
21865@end smallexample
21866
21867The input types are
21868
21869@table @code
e5ac9b53
EZ
21870@findex pre-prompt annotation
21871@findex prompt annotation
21872@findex post-prompt annotation
922fbb7b
AC
21873@item prompt
21874When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
21875
e5ac9b53
EZ
21876@findex pre-commands annotation
21877@findex commands annotation
21878@findex post-commands annotation
922fbb7b
AC
21879@item commands
21880When @value{GDBN} prompts for a set of commands, like in the @code{commands}
21881command. The annotations are repeated for each command which is input.
21882
e5ac9b53
EZ
21883@findex pre-overload-choice annotation
21884@findex overload-choice annotation
21885@findex post-overload-choice annotation
922fbb7b
AC
21886@item overload-choice
21887When @value{GDBN} wants the user to select between various overloaded functions.
21888
e5ac9b53
EZ
21889@findex pre-query annotation
21890@findex query annotation
21891@findex post-query annotation
922fbb7b
AC
21892@item query
21893When @value{GDBN} wants the user to confirm a potentially dangerous operation.
21894
e5ac9b53
EZ
21895@findex pre-prompt-for-continue annotation
21896@findex prompt-for-continue annotation
21897@findex post-prompt-for-continue annotation
922fbb7b
AC
21898@item prompt-for-continue
21899When @value{GDBN} is asking the user to press return to continue. Note: Don't
21900expect this to work well; instead use @code{set height 0} to disable
21901prompting. This is because the counting of lines is buggy in the
21902presence of annotations.
21903@end table
21904
21905@node Errors
21906@section Errors
21907@cindex annotations for errors, warnings and interrupts
21908
e5ac9b53 21909@findex quit annotation
922fbb7b
AC
21910@smallexample
21911^Z^Zquit
21912@end smallexample
21913
21914This annotation occurs right before @value{GDBN} responds to an interrupt.
21915
e5ac9b53 21916@findex error annotation
922fbb7b
AC
21917@smallexample
21918^Z^Zerror
21919@end smallexample
21920
21921This annotation occurs right before @value{GDBN} responds to an error.
21922
21923Quit and error annotations indicate that any annotations which @value{GDBN} was
21924in the middle of may end abruptly. For example, if a
21925@code{value-history-begin} annotation is followed by a @code{error}, one
21926cannot expect to receive the matching @code{value-history-end}. One
21927cannot expect not to receive it either, however; an error annotation
21928does not necessarily mean that @value{GDBN} is immediately returning all the way
21929to the top level.
21930
e5ac9b53 21931@findex error-begin annotation
922fbb7b
AC
21932A quit or error annotation may be preceded by
21933
21934@smallexample
21935^Z^Zerror-begin
21936@end smallexample
21937
21938Any output between that and the quit or error annotation is the error
21939message.
21940
21941Warning messages are not yet annotated.
21942@c If we want to change that, need to fix warning(), type_error(),
21943@c range_error(), and possibly other places.
21944
922fbb7b
AC
21945@node Invalidation
21946@section Invalidation Notices
21947
21948@cindex annotations for invalidation messages
21949The following annotations say that certain pieces of state may have
21950changed.
21951
21952@table @code
e5ac9b53 21953@findex frames-invalid annotation
922fbb7b
AC
21954@item ^Z^Zframes-invalid
21955
21956The frames (for example, output from the @code{backtrace} command) may
21957have changed.
21958
e5ac9b53 21959@findex breakpoints-invalid annotation
922fbb7b
AC
21960@item ^Z^Zbreakpoints-invalid
21961
21962The breakpoints may have changed. For example, the user just added or
21963deleted a breakpoint.
21964@end table
21965
21966@node Annotations for Running
21967@section Running the Program
21968@cindex annotations for running programs
21969
e5ac9b53
EZ
21970@findex starting annotation
21971@findex stopping annotation
922fbb7b 21972When the program starts executing due to a @value{GDBN} command such as
b383017d 21973@code{step} or @code{continue},
922fbb7b
AC
21974
21975@smallexample
21976^Z^Zstarting
21977@end smallexample
21978
b383017d 21979is output. When the program stops,
922fbb7b
AC
21980
21981@smallexample
21982^Z^Zstopped
21983@end smallexample
21984
21985is output. Before the @code{stopped} annotation, a variety of
21986annotations describe how the program stopped.
21987
21988@table @code
e5ac9b53 21989@findex exited annotation
922fbb7b
AC
21990@item ^Z^Zexited @var{exit-status}
21991The program exited, and @var{exit-status} is the exit status (zero for
21992successful exit, otherwise nonzero).
21993
e5ac9b53
EZ
21994@findex signalled annotation
21995@findex signal-name annotation
21996@findex signal-name-end annotation
21997@findex signal-string annotation
21998@findex signal-string-end annotation
922fbb7b
AC
21999@item ^Z^Zsignalled
22000The program exited with a signal. After the @code{^Z^Zsignalled}, the
22001annotation continues:
22002
22003@smallexample
22004@var{intro-text}
22005^Z^Zsignal-name
22006@var{name}
22007^Z^Zsignal-name-end
22008@var{middle-text}
22009^Z^Zsignal-string
22010@var{string}
22011^Z^Zsignal-string-end
22012@var{end-text}
22013@end smallexample
22014
22015@noindent
22016where @var{name} is the name of the signal, such as @code{SIGILL} or
22017@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
22018as @code{Illegal Instruction} or @code{Segmentation fault}.
22019@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
22020user's benefit and have no particular format.
22021
e5ac9b53 22022@findex signal annotation
922fbb7b
AC
22023@item ^Z^Zsignal
22024The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
22025just saying that the program received the signal, not that it was
22026terminated with it.
22027
e5ac9b53 22028@findex breakpoint annotation
922fbb7b
AC
22029@item ^Z^Zbreakpoint @var{number}
22030The program hit breakpoint number @var{number}.
22031
e5ac9b53 22032@findex watchpoint annotation
922fbb7b
AC
22033@item ^Z^Zwatchpoint @var{number}
22034The program hit watchpoint number @var{number}.
22035@end table
22036
22037@node Source Annotations
22038@section Displaying Source
22039@cindex annotations for source display
22040
e5ac9b53 22041@findex source annotation
922fbb7b
AC
22042The following annotation is used instead of displaying source code:
22043
22044@smallexample
22045^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
22046@end smallexample
22047
22048where @var{filename} is an absolute file name indicating which source
22049file, @var{line} is the line number within that file (where 1 is the
22050first line in the file), @var{character} is the character position
22051within the file (where 0 is the first character in the file) (for most
22052debug formats this will necessarily point to the beginning of a line),
22053@var{middle} is @samp{middle} if @var{addr} is in the middle of the
22054line, or @samp{beg} if @var{addr} is at the beginning of the line, and
22055@var{addr} is the address in the target program associated with the
22056source which is being displayed. @var{addr} is in the form @samp{0x}
22057followed by one or more lowercase hex digits (note that this does not
22058depend on the language).
22059
8e04817f
AC
22060@node GDB Bugs
22061@chapter Reporting Bugs in @value{GDBN}
22062@cindex bugs in @value{GDBN}
22063@cindex reporting bugs in @value{GDBN}
c906108c 22064
8e04817f 22065Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 22066
8e04817f
AC
22067Reporting a bug may help you by bringing a solution to your problem, or it
22068may not. But in any case the principal function of a bug report is to help
22069the entire community by making the next version of @value{GDBN} work better. Bug
22070reports are your contribution to the maintenance of @value{GDBN}.
c906108c 22071
8e04817f
AC
22072In order for a bug report to serve its purpose, you must include the
22073information that enables us to fix the bug.
c4555f82
SC
22074
22075@menu
8e04817f
AC
22076* Bug Criteria:: Have you found a bug?
22077* Bug Reporting:: How to report bugs
c4555f82
SC
22078@end menu
22079
8e04817f 22080@node Bug Criteria
79a6e687 22081@section Have You Found a Bug?
8e04817f 22082@cindex bug criteria
c4555f82 22083
8e04817f 22084If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
22085
22086@itemize @bullet
8e04817f
AC
22087@cindex fatal signal
22088@cindex debugger crash
22089@cindex crash of debugger
c4555f82 22090@item
8e04817f
AC
22091If the debugger gets a fatal signal, for any input whatever, that is a
22092@value{GDBN} bug. Reliable debuggers never crash.
22093
22094@cindex error on valid input
22095@item
22096If @value{GDBN} produces an error message for valid input, that is a
22097bug. (Note that if you're cross debugging, the problem may also be
22098somewhere in the connection to the target.)
c4555f82 22099
8e04817f 22100@cindex invalid input
c4555f82 22101@item
8e04817f
AC
22102If @value{GDBN} does not produce an error message for invalid input,
22103that is a bug. However, you should note that your idea of
22104``invalid input'' might be our idea of ``an extension'' or ``support
22105for traditional practice''.
22106
22107@item
22108If you are an experienced user of debugging tools, your suggestions
22109for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
22110@end itemize
22111
8e04817f 22112@node Bug Reporting
79a6e687 22113@section How to Report Bugs
8e04817f
AC
22114@cindex bug reports
22115@cindex @value{GDBN} bugs, reporting
22116
22117A number of companies and individuals offer support for @sc{gnu} products.
22118If you obtained @value{GDBN} from a support organization, we recommend you
22119contact that organization first.
22120
22121You can find contact information for many support companies and
22122individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
22123distribution.
22124@c should add a web page ref...
22125
129188f6 22126In any event, we also recommend that you submit bug reports for
d3e8051b 22127@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
22128@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
22129page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
22130be used.
8e04817f
AC
22131
22132@strong{Do not send bug reports to @samp{info-gdb}, or to
22133@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
22134not want to receive bug reports. Those that do have arranged to receive
22135@samp{bug-gdb}.
22136
22137The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
22138serves as a repeater. The mailing list and the newsgroup carry exactly
22139the same messages. Often people think of posting bug reports to the
22140newsgroup instead of mailing them. This appears to work, but it has one
22141problem which can be crucial: a newsgroup posting often lacks a mail
22142path back to the sender. Thus, if we need to ask for more information,
22143we may be unable to reach you. For this reason, it is better to send
22144bug reports to the mailing list.
c4555f82 22145
8e04817f
AC
22146The fundamental principle of reporting bugs usefully is this:
22147@strong{report all the facts}. If you are not sure whether to state a
22148fact or leave it out, state it!
c4555f82 22149
8e04817f
AC
22150Often people omit facts because they think they know what causes the
22151problem and assume that some details do not matter. Thus, you might
22152assume that the name of the variable you use in an example does not matter.
22153Well, probably it does not, but one cannot be sure. Perhaps the bug is a
22154stray memory reference which happens to fetch from the location where that
22155name is stored in memory; perhaps, if the name were different, the contents
22156of that location would fool the debugger into doing the right thing despite
22157the bug. Play it safe and give a specific, complete example. That is the
22158easiest thing for you to do, and the most helpful.
c4555f82 22159
8e04817f
AC
22160Keep in mind that the purpose of a bug report is to enable us to fix the
22161bug. It may be that the bug has been reported previously, but neither
22162you nor we can know that unless your bug report is complete and
22163self-contained.
c4555f82 22164
8e04817f
AC
22165Sometimes people give a few sketchy facts and ask, ``Does this ring a
22166bell?'' Those bug reports are useless, and we urge everyone to
22167@emph{refuse to respond to them} except to chide the sender to report
22168bugs properly.
22169
22170To enable us to fix the bug, you should include all these things:
c4555f82
SC
22171
22172@itemize @bullet
22173@item
8e04817f
AC
22174The version of @value{GDBN}. @value{GDBN} announces it if you start
22175with no arguments; you can also print it at any time using @code{show
22176version}.
c4555f82 22177
8e04817f
AC
22178Without this, we will not know whether there is any point in looking for
22179the bug in the current version of @value{GDBN}.
c4555f82
SC
22180
22181@item
8e04817f
AC
22182The type of machine you are using, and the operating system name and
22183version number.
c4555f82
SC
22184
22185@item
c1468174 22186What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 22187``@value{GCC}--2.8.1''.
c4555f82
SC
22188
22189@item
8e04817f 22190What compiler (and its version) was used to compile the program you are
c1468174 22191debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
22192C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
22193to get this information; for other compilers, see the documentation for
22194those compilers.
c4555f82 22195
8e04817f
AC
22196@item
22197The command arguments you gave the compiler to compile your example and
22198observe the bug. For example, did you use @samp{-O}? To guarantee
22199you will not omit something important, list them all. A copy of the
22200Makefile (or the output from make) is sufficient.
c4555f82 22201
8e04817f
AC
22202If we were to try to guess the arguments, we would probably guess wrong
22203and then we might not encounter the bug.
c4555f82 22204
8e04817f
AC
22205@item
22206A complete input script, and all necessary source files, that will
22207reproduce the bug.
c4555f82 22208
8e04817f
AC
22209@item
22210A description of what behavior you observe that you believe is
22211incorrect. For example, ``It gets a fatal signal.''
c4555f82 22212
8e04817f
AC
22213Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
22214will certainly notice it. But if the bug is incorrect output, we might
22215not notice unless it is glaringly wrong. You might as well not give us
22216a chance to make a mistake.
c4555f82 22217
8e04817f
AC
22218Even if the problem you experience is a fatal signal, you should still
22219say so explicitly. Suppose something strange is going on, such as, your
22220copy of @value{GDBN} is out of synch, or you have encountered a bug in
22221the C library on your system. (This has happened!) Your copy might
22222crash and ours would not. If you told us to expect a crash, then when
22223ours fails to crash, we would know that the bug was not happening for
22224us. If you had not told us to expect a crash, then we would not be able
22225to draw any conclusion from our observations.
c4555f82 22226
e0c07bf0
MC
22227@pindex script
22228@cindex recording a session script
22229To collect all this information, you can use a session recording program
22230such as @command{script}, which is available on many Unix systems.
22231Just run your @value{GDBN} session inside @command{script} and then
22232include the @file{typescript} file with your bug report.
22233
22234Another way to record a @value{GDBN} session is to run @value{GDBN}
22235inside Emacs and then save the entire buffer to a file.
22236
8e04817f
AC
22237@item
22238If you wish to suggest changes to the @value{GDBN} source, send us context
22239diffs. If you even discuss something in the @value{GDBN} source, refer to
22240it by context, not by line number.
c4555f82 22241
8e04817f
AC
22242The line numbers in our development sources will not match those in your
22243sources. Your line numbers would convey no useful information to us.
c4555f82 22244
8e04817f 22245@end itemize
c4555f82 22246
8e04817f 22247Here are some things that are not necessary:
c4555f82 22248
8e04817f
AC
22249@itemize @bullet
22250@item
22251A description of the envelope of the bug.
c4555f82 22252
8e04817f
AC
22253Often people who encounter a bug spend a lot of time investigating
22254which changes to the input file will make the bug go away and which
22255changes will not affect it.
c4555f82 22256
8e04817f
AC
22257This is often time consuming and not very useful, because the way we
22258will find the bug is by running a single example under the debugger
22259with breakpoints, not by pure deduction from a series of examples.
22260We recommend that you save your time for something else.
c4555f82 22261
8e04817f
AC
22262Of course, if you can find a simpler example to report @emph{instead}
22263of the original one, that is a convenience for us. Errors in the
22264output will be easier to spot, running under the debugger will take
22265less time, and so on.
c4555f82 22266
8e04817f
AC
22267However, simplification is not vital; if you do not want to do this,
22268report the bug anyway and send us the entire test case you used.
c4555f82 22269
8e04817f
AC
22270@item
22271A patch for the bug.
c4555f82 22272
8e04817f
AC
22273A patch for the bug does help us if it is a good one. But do not omit
22274the necessary information, such as the test case, on the assumption that
22275a patch is all we need. We might see problems with your patch and decide
22276to fix the problem another way, or we might not understand it at all.
c4555f82 22277
8e04817f
AC
22278Sometimes with a program as complicated as @value{GDBN} it is very hard to
22279construct an example that will make the program follow a certain path
22280through the code. If you do not send us the example, we will not be able
22281to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 22282
8e04817f
AC
22283And if we cannot understand what bug you are trying to fix, or why your
22284patch should be an improvement, we will not install it. A test case will
22285help us to understand.
c4555f82 22286
8e04817f
AC
22287@item
22288A guess about what the bug is or what it depends on.
c4555f82 22289
8e04817f
AC
22290Such guesses are usually wrong. Even we cannot guess right about such
22291things without first using the debugger to find the facts.
22292@end itemize
c4555f82 22293
8e04817f
AC
22294@c The readline documentation is distributed with the readline code
22295@c and consists of the two following files:
22296@c rluser.texinfo
22297@c inc-hist.texinfo
22298@c Use -I with makeinfo to point to the appropriate directory,
22299@c environment var TEXINPUTS with TeX.
5bdf8622 22300@include rluser.texi
8e04817f 22301@include inc-hist.texinfo
c4555f82 22302
c4555f82 22303
8e04817f
AC
22304@node Formatting Documentation
22305@appendix Formatting Documentation
c4555f82 22306
8e04817f
AC
22307@cindex @value{GDBN} reference card
22308@cindex reference card
22309The @value{GDBN} 4 release includes an already-formatted reference card, ready
22310for printing with PostScript or Ghostscript, in the @file{gdb}
22311subdirectory of the main source directory@footnote{In
22312@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
22313release.}. If you can use PostScript or Ghostscript with your printer,
22314you can print the reference card immediately with @file{refcard.ps}.
c4555f82 22315
8e04817f
AC
22316The release also includes the source for the reference card. You
22317can format it, using @TeX{}, by typing:
c4555f82 22318
474c8240 22319@smallexample
8e04817f 22320make refcard.dvi
474c8240 22321@end smallexample
c4555f82 22322
8e04817f
AC
22323The @value{GDBN} reference card is designed to print in @dfn{landscape}
22324mode on US ``letter'' size paper;
22325that is, on a sheet 11 inches wide by 8.5 inches
22326high. You will need to specify this form of printing as an option to
22327your @sc{dvi} output program.
c4555f82 22328
8e04817f 22329@cindex documentation
c4555f82 22330
8e04817f
AC
22331All the documentation for @value{GDBN} comes as part of the machine-readable
22332distribution. The documentation is written in Texinfo format, which is
22333a documentation system that uses a single source file to produce both
22334on-line information and a printed manual. You can use one of the Info
22335formatting commands to create the on-line version of the documentation
22336and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 22337
8e04817f
AC
22338@value{GDBN} includes an already formatted copy of the on-line Info
22339version of this manual in the @file{gdb} subdirectory. The main Info
22340file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
22341subordinate files matching @samp{gdb.info*} in the same directory. If
22342necessary, you can print out these files, or read them with any editor;
22343but they are easier to read using the @code{info} subsystem in @sc{gnu}
22344Emacs or the standalone @code{info} program, available as part of the
22345@sc{gnu} Texinfo distribution.
c4555f82 22346
8e04817f
AC
22347If you want to format these Info files yourself, you need one of the
22348Info formatting programs, such as @code{texinfo-format-buffer} or
22349@code{makeinfo}.
c4555f82 22350
8e04817f
AC
22351If you have @code{makeinfo} installed, and are in the top level
22352@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
22353version @value{GDBVN}), you can make the Info file by typing:
c4555f82 22354
474c8240 22355@smallexample
8e04817f
AC
22356cd gdb
22357make gdb.info
474c8240 22358@end smallexample
c4555f82 22359
8e04817f
AC
22360If you want to typeset and print copies of this manual, you need @TeX{},
22361a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
22362Texinfo definitions file.
c4555f82 22363
8e04817f
AC
22364@TeX{} is a typesetting program; it does not print files directly, but
22365produces output files called @sc{dvi} files. To print a typeset
22366document, you need a program to print @sc{dvi} files. If your system
22367has @TeX{} installed, chances are it has such a program. The precise
22368command to use depends on your system; @kbd{lpr -d} is common; another
22369(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
22370require a file name without any extension or a @samp{.dvi} extension.
c4555f82 22371
8e04817f
AC
22372@TeX{} also requires a macro definitions file called
22373@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
22374written in Texinfo format. On its own, @TeX{} cannot either read or
22375typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
22376and is located in the @file{gdb-@var{version-number}/texinfo}
22377directory.
c4555f82 22378
8e04817f 22379If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 22380typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
22381subdirectory of the main source directory (for example, to
22382@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 22383
474c8240 22384@smallexample
8e04817f 22385make gdb.dvi
474c8240 22386@end smallexample
c4555f82 22387
8e04817f 22388Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 22389
8e04817f
AC
22390@node Installing GDB
22391@appendix Installing @value{GDBN}
8e04817f 22392@cindex installation
c4555f82 22393
7fa2210b
DJ
22394@menu
22395* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 22396* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
22397* Separate Objdir:: Compiling @value{GDBN} in another directory
22398* Config Names:: Specifying names for hosts and targets
22399* Configure Options:: Summary of options for configure
22400@end menu
22401
22402@node Requirements
79a6e687 22403@section Requirements for Building @value{GDBN}
7fa2210b
DJ
22404@cindex building @value{GDBN}, requirements for
22405
22406Building @value{GDBN} requires various tools and packages to be available.
22407Other packages will be used only if they are found.
22408
79a6e687 22409@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
22410@table @asis
22411@item ISO C90 compiler
22412@value{GDBN} is written in ISO C90. It should be buildable with any
22413working C90 compiler, e.g.@: GCC.
22414
22415@end table
22416
79a6e687 22417@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
22418@table @asis
22419@item Expat
123dc839 22420@anchor{Expat}
7fa2210b
DJ
22421@value{GDBN} can use the Expat XML parsing library. This library may be
22422included with your operating system distribution; if it is not, you
22423can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 22424The @file{configure} script will search for this library in several
7fa2210b
DJ
22425standard locations; if it is installed in an unusual path, you can
22426use the @option{--with-libexpat-prefix} option to specify its location.
22427
9cceb671
DJ
22428Expat is used for:
22429
22430@itemize @bullet
22431@item
22432Remote protocol memory maps (@pxref{Memory Map Format})
22433@item
22434Target descriptions (@pxref{Target Descriptions})
22435@item
22436Remote shared library lists (@pxref{Library List Format})
22437@item
22438MS-Windows shared libraries (@pxref{Shared Libraries})
22439@end itemize
7fa2210b
DJ
22440
22441@end table
22442
22443@node Running Configure
db2e3e2e 22444@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 22445@cindex configuring @value{GDBN}
db2e3e2e 22446@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
22447of preparing @value{GDBN} for installation; you can then use @code{make} to
22448build the @code{gdb} program.
22449@iftex
22450@c irrelevant in info file; it's as current as the code it lives with.
22451@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
22452look at the @file{README} file in the sources; we may have improved the
22453installation procedures since publishing this manual.}
22454@end iftex
c4555f82 22455
8e04817f
AC
22456The @value{GDBN} distribution includes all the source code you need for
22457@value{GDBN} in a single directory, whose name is usually composed by
22458appending the version number to @samp{gdb}.
c4555f82 22459
8e04817f
AC
22460For example, the @value{GDBN} version @value{GDBVN} distribution is in the
22461@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 22462
8e04817f
AC
22463@table @code
22464@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
22465script for configuring @value{GDBN} and all its supporting libraries
c4555f82 22466
8e04817f
AC
22467@item gdb-@value{GDBVN}/gdb
22468the source specific to @value{GDBN} itself
c4555f82 22469
8e04817f
AC
22470@item gdb-@value{GDBVN}/bfd
22471source for the Binary File Descriptor library
c906108c 22472
8e04817f
AC
22473@item gdb-@value{GDBVN}/include
22474@sc{gnu} include files
c906108c 22475
8e04817f
AC
22476@item gdb-@value{GDBVN}/libiberty
22477source for the @samp{-liberty} free software library
c906108c 22478
8e04817f
AC
22479@item gdb-@value{GDBVN}/opcodes
22480source for the library of opcode tables and disassemblers
c906108c 22481
8e04817f
AC
22482@item gdb-@value{GDBVN}/readline
22483source for the @sc{gnu} command-line interface
c906108c 22484
8e04817f
AC
22485@item gdb-@value{GDBVN}/glob
22486source for the @sc{gnu} filename pattern-matching subroutine
c906108c 22487
8e04817f
AC
22488@item gdb-@value{GDBVN}/mmalloc
22489source for the @sc{gnu} memory-mapped malloc package
22490@end table
c906108c 22491
db2e3e2e 22492The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
22493from the @file{gdb-@var{version-number}} source directory, which in
22494this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 22495
8e04817f 22496First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 22497if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
22498identifier for the platform on which @value{GDBN} will run as an
22499argument.
c906108c 22500
8e04817f 22501For example:
c906108c 22502
474c8240 22503@smallexample
8e04817f
AC
22504cd gdb-@value{GDBVN}
22505./configure @var{host}
22506make
474c8240 22507@end smallexample
c906108c 22508
8e04817f
AC
22509@noindent
22510where @var{host} is an identifier such as @samp{sun4} or
22511@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 22512(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 22513correct value by examining your system.)
c906108c 22514
8e04817f
AC
22515Running @samp{configure @var{host}} and then running @code{make} builds the
22516@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
22517libraries, then @code{gdb} itself. The configured source files, and the
22518binaries, are left in the corresponding source directories.
c906108c 22519
8e04817f 22520@need 750
db2e3e2e 22521@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
22522system does not recognize this automatically when you run a different
22523shell, you may need to run @code{sh} on it explicitly:
c906108c 22524
474c8240 22525@smallexample
8e04817f 22526sh configure @var{host}
474c8240 22527@end smallexample
c906108c 22528
db2e3e2e 22529If you run @file{configure} from a directory that contains source
8e04817f 22530directories for multiple libraries or programs, such as the
db2e3e2e
BW
22531@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
22532@file{configure}
8e04817f
AC
22533creates configuration files for every directory level underneath (unless
22534you tell it not to, with the @samp{--norecursion} option).
22535
db2e3e2e 22536You should run the @file{configure} script from the top directory in the
94e91d6d 22537source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 22538@file{configure} from one of the subdirectories, you will configure only
94e91d6d 22539that subdirectory. That is usually not what you want. In particular,
db2e3e2e 22540if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
22541of the @file{gdb-@var{version-number}} directory, you will omit the
22542configuration of @file{bfd}, @file{readline}, and other sibling
22543directories of the @file{gdb} subdirectory. This leads to build errors
22544about missing include files such as @file{bfd/bfd.h}.
c906108c 22545
8e04817f
AC
22546You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
22547However, you should make sure that the shell on your path (named by
22548the @samp{SHELL} environment variable) is publicly readable. Remember
22549that @value{GDBN} uses the shell to start your program---some systems refuse to
22550let @value{GDBN} debug child processes whose programs are not readable.
c906108c 22551
8e04817f 22552@node Separate Objdir
79a6e687 22553@section Compiling @value{GDBN} in Another Directory
c906108c 22554
8e04817f
AC
22555If you want to run @value{GDBN} versions for several host or target machines,
22556you need a different @code{gdb} compiled for each combination of
db2e3e2e 22557host and target. @file{configure} is designed to make this easy by
8e04817f
AC
22558allowing you to generate each configuration in a separate subdirectory,
22559rather than in the source directory. If your @code{make} program
22560handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
22561@code{make} in each of these directories builds the @code{gdb}
22562program specified there.
c906108c 22563
db2e3e2e 22564To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 22565with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
22566(You also need to specify a path to find @file{configure}
22567itself from your working directory. If the path to @file{configure}
8e04817f
AC
22568would be the same as the argument to @samp{--srcdir}, you can leave out
22569the @samp{--srcdir} option; it is assumed.)
c906108c 22570
8e04817f
AC
22571For example, with version @value{GDBVN}, you can build @value{GDBN} in a
22572separate directory for a Sun 4 like this:
c906108c 22573
474c8240 22574@smallexample
8e04817f
AC
22575@group
22576cd gdb-@value{GDBVN}
22577mkdir ../gdb-sun4
22578cd ../gdb-sun4
22579../gdb-@value{GDBVN}/configure sun4
22580make
22581@end group
474c8240 22582@end smallexample
c906108c 22583
db2e3e2e 22584When @file{configure} builds a configuration using a remote source
8e04817f
AC
22585directory, it creates a tree for the binaries with the same structure
22586(and using the same names) as the tree under the source directory. In
22587the example, you'd find the Sun 4 library @file{libiberty.a} in the
22588directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
22589@file{gdb-sun4/gdb}.
c906108c 22590
94e91d6d
MC
22591Make sure that your path to the @file{configure} script has just one
22592instance of @file{gdb} in it. If your path to @file{configure} looks
22593like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
22594one subdirectory of @value{GDBN}, not the whole package. This leads to
22595build errors about missing include files such as @file{bfd/bfd.h}.
22596
8e04817f
AC
22597One popular reason to build several @value{GDBN} configurations in separate
22598directories is to configure @value{GDBN} for cross-compiling (where
22599@value{GDBN} runs on one machine---the @dfn{host}---while debugging
22600programs that run on another machine---the @dfn{target}).
22601You specify a cross-debugging target by
db2e3e2e 22602giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 22603
8e04817f
AC
22604When you run @code{make} to build a program or library, you must run
22605it in a configured directory---whatever directory you were in when you
db2e3e2e 22606called @file{configure} (or one of its subdirectories).
c906108c 22607
db2e3e2e 22608The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
22609directory also runs recursively. If you type @code{make} in a source
22610directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
22611directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
22612will build all the required libraries, and then build GDB.
c906108c 22613
8e04817f
AC
22614When you have multiple hosts or targets configured in separate
22615directories, you can run @code{make} on them in parallel (for example,
22616if they are NFS-mounted on each of the hosts); they will not interfere
22617with each other.
c906108c 22618
8e04817f 22619@node Config Names
79a6e687 22620@section Specifying Names for Hosts and Targets
c906108c 22621
db2e3e2e 22622The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
22623script are based on a three-part naming scheme, but some short predefined
22624aliases are also supported. The full naming scheme encodes three pieces
22625of information in the following pattern:
c906108c 22626
474c8240 22627@smallexample
8e04817f 22628@var{architecture}-@var{vendor}-@var{os}
474c8240 22629@end smallexample
c906108c 22630
8e04817f
AC
22631For example, you can use the alias @code{sun4} as a @var{host} argument,
22632or as the value for @var{target} in a @code{--target=@var{target}}
22633option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 22634
db2e3e2e 22635The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 22636any query facility to list all supported host and target names or
db2e3e2e 22637aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
22638@code{config.sub} to map abbreviations to full names; you can read the
22639script, if you wish, or you can use it to test your guesses on
22640abbreviations---for example:
c906108c 22641
8e04817f
AC
22642@smallexample
22643% sh config.sub i386-linux
22644i386-pc-linux-gnu
22645% sh config.sub alpha-linux
22646alpha-unknown-linux-gnu
22647% sh config.sub hp9k700
22648hppa1.1-hp-hpux
22649% sh config.sub sun4
22650sparc-sun-sunos4.1.1
22651% sh config.sub sun3
22652m68k-sun-sunos4.1.1
22653% sh config.sub i986v
22654Invalid configuration `i986v': machine `i986v' not recognized
22655@end smallexample
c906108c 22656
8e04817f
AC
22657@noindent
22658@code{config.sub} is also distributed in the @value{GDBN} source
22659directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 22660
8e04817f 22661@node Configure Options
db2e3e2e 22662@section @file{configure} Options
c906108c 22663
db2e3e2e
BW
22664Here is a summary of the @file{configure} options and arguments that
22665are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 22666several other options not listed here. @inforef{What Configure
db2e3e2e 22667Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 22668
474c8240 22669@smallexample
8e04817f
AC
22670configure @r{[}--help@r{]}
22671 @r{[}--prefix=@var{dir}@r{]}
22672 @r{[}--exec-prefix=@var{dir}@r{]}
22673 @r{[}--srcdir=@var{dirname}@r{]}
22674 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
22675 @r{[}--target=@var{target}@r{]}
22676 @var{host}
474c8240 22677@end smallexample
c906108c 22678
8e04817f
AC
22679@noindent
22680You may introduce options with a single @samp{-} rather than
22681@samp{--} if you prefer; but you may abbreviate option names if you use
22682@samp{--}.
c906108c 22683
8e04817f
AC
22684@table @code
22685@item --help
db2e3e2e 22686Display a quick summary of how to invoke @file{configure}.
c906108c 22687
8e04817f
AC
22688@item --prefix=@var{dir}
22689Configure the source to install programs and files under directory
22690@file{@var{dir}}.
c906108c 22691
8e04817f
AC
22692@item --exec-prefix=@var{dir}
22693Configure the source to install programs under directory
22694@file{@var{dir}}.
c906108c 22695
8e04817f
AC
22696@c avoid splitting the warning from the explanation:
22697@need 2000
22698@item --srcdir=@var{dirname}
22699@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
22700@code{make} that implements the @code{VPATH} feature.}@*
22701Use this option to make configurations in directories separate from the
22702@value{GDBN} source directories. Among other things, you can use this to
22703build (or maintain) several configurations simultaneously, in separate
db2e3e2e 22704directories. @file{configure} writes configuration-specific files in
8e04817f 22705the current directory, but arranges for them to use the source in the
db2e3e2e 22706directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
22707the working directory in parallel to the source directories below
22708@var{dirname}.
c906108c 22709
8e04817f 22710@item --norecursion
db2e3e2e 22711Configure only the directory level where @file{configure} is executed; do not
8e04817f 22712propagate configuration to subdirectories.
c906108c 22713
8e04817f
AC
22714@item --target=@var{target}
22715Configure @value{GDBN} for cross-debugging programs running on the specified
22716@var{target}. Without this option, @value{GDBN} is configured to debug
22717programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 22718
8e04817f 22719There is no convenient way to generate a list of all available targets.
c906108c 22720
8e04817f
AC
22721@item @var{host} @dots{}
22722Configure @value{GDBN} to run on the specified @var{host}.
c906108c 22723
8e04817f
AC
22724There is no convenient way to generate a list of all available hosts.
22725@end table
c906108c 22726
8e04817f
AC
22727There are many other options available as well, but they are generally
22728needed for special purposes only.
c906108c 22729
8e04817f
AC
22730@node Maintenance Commands
22731@appendix Maintenance Commands
22732@cindex maintenance commands
22733@cindex internal commands
c906108c 22734
8e04817f 22735In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
22736includes a number of commands intended for @value{GDBN} developers,
22737that are not documented elsewhere in this manual. These commands are
da316a69
EZ
22738provided here for reference. (For commands that turn on debugging
22739messages, see @ref{Debugging Output}.)
c906108c 22740
8e04817f 22741@table @code
09d4efe1
EZ
22742@kindex maint agent
22743@item maint agent @var{expression}
22744Translate the given @var{expression} into remote agent bytecodes.
22745This command is useful for debugging the Agent Expression mechanism
22746(@pxref{Agent Expressions}).
22747
8e04817f
AC
22748@kindex maint info breakpoints
22749@item @anchor{maint info breakpoints}maint info breakpoints
22750Using the same format as @samp{info breakpoints}, display both the
22751breakpoints you've set explicitly, and those @value{GDBN} is using for
22752internal purposes. Internal breakpoints are shown with negative
22753breakpoint numbers. The type column identifies what kind of breakpoint
22754is shown:
c906108c 22755
8e04817f
AC
22756@table @code
22757@item breakpoint
22758Normal, explicitly set breakpoint.
c906108c 22759
8e04817f
AC
22760@item watchpoint
22761Normal, explicitly set watchpoint.
c906108c 22762
8e04817f
AC
22763@item longjmp
22764Internal breakpoint, used to handle correctly stepping through
22765@code{longjmp} calls.
c906108c 22766
8e04817f
AC
22767@item longjmp resume
22768Internal breakpoint at the target of a @code{longjmp}.
c906108c 22769
8e04817f
AC
22770@item until
22771Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 22772
8e04817f
AC
22773@item finish
22774Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 22775
8e04817f
AC
22776@item shlib events
22777Shared library events.
c906108c 22778
8e04817f 22779@end table
c906108c 22780
09d4efe1
EZ
22781@kindex maint check-symtabs
22782@item maint check-symtabs
22783Check the consistency of psymtabs and symtabs.
22784
22785@kindex maint cplus first_component
22786@item maint cplus first_component @var{name}
22787Print the first C@t{++} class/namespace component of @var{name}.
22788
22789@kindex maint cplus namespace
22790@item maint cplus namespace
22791Print the list of possible C@t{++} namespaces.
22792
22793@kindex maint demangle
22794@item maint demangle @var{name}
d3e8051b 22795Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
22796
22797@kindex maint deprecate
22798@kindex maint undeprecate
22799@cindex deprecated commands
22800@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
22801@itemx maint undeprecate @var{command}
22802Deprecate or undeprecate the named @var{command}. Deprecated commands
22803cause @value{GDBN} to issue a warning when you use them. The optional
22804argument @var{replacement} says which newer command should be used in
22805favor of the deprecated one; if it is given, @value{GDBN} will mention
22806the replacement as part of the warning.
22807
22808@kindex maint dump-me
22809@item maint dump-me
721c2651 22810@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 22811Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
22812This is supported only on systems which support aborting a program
22813with the @code{SIGQUIT} signal.
09d4efe1 22814
8d30a00d
AC
22815@kindex maint internal-error
22816@kindex maint internal-warning
09d4efe1
EZ
22817@item maint internal-error @r{[}@var{message-text}@r{]}
22818@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
22819Cause @value{GDBN} to call the internal function @code{internal_error}
22820or @code{internal_warning} and hence behave as though an internal error
22821or internal warning has been detected. In addition to reporting the
22822internal problem, these functions give the user the opportunity to
22823either quit @value{GDBN} or create a core file of the current
22824@value{GDBN} session.
22825
09d4efe1
EZ
22826These commands take an optional parameter @var{message-text} that is
22827used as the text of the error or warning message.
22828
d3e8051b 22829Here's an example of using @code{internal-error}:
09d4efe1 22830
8d30a00d 22831@smallexample
f7dc1244 22832(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
22833@dots{}/maint.c:121: internal-error: testing, 1, 2
22834A problem internal to GDB has been detected. Further
22835debugging may prove unreliable.
22836Quit this debugging session? (y or n) @kbd{n}
22837Create a core file? (y or n) @kbd{n}
f7dc1244 22838(@value{GDBP})
8d30a00d
AC
22839@end smallexample
22840
09d4efe1
EZ
22841@kindex maint packet
22842@item maint packet @var{text}
22843If @value{GDBN} is talking to an inferior via the serial protocol,
22844then this command sends the string @var{text} to the inferior, and
22845displays the response packet. @value{GDBN} supplies the initial
22846@samp{$} character, the terminating @samp{#} character, and the
22847checksum.
22848
22849@kindex maint print architecture
22850@item maint print architecture @r{[}@var{file}@r{]}
22851Print the entire architecture configuration. The optional argument
22852@var{file} names the file where the output goes.
8d30a00d 22853
81adfced
DJ
22854@kindex maint print c-tdesc
22855@item maint print c-tdesc
22856Print the current target description (@pxref{Target Descriptions}) as
22857a C source file. The created source file can be used in @value{GDBN}
22858when an XML parser is not available to parse the description.
22859
00905d52
AC
22860@kindex maint print dummy-frames
22861@item maint print dummy-frames
00905d52
AC
22862Prints the contents of @value{GDBN}'s internal dummy-frame stack.
22863
22864@smallexample
f7dc1244 22865(@value{GDBP}) @kbd{b add}
00905d52 22866@dots{}
f7dc1244 22867(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
22868Breakpoint 2, add (a=2, b=3) at @dots{}
2286958 return (a + b);
22870The program being debugged stopped while in a function called from GDB.
22871@dots{}
f7dc1244 22872(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
228730x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
22874 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
22875 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 22876(@value{GDBP})
00905d52
AC
22877@end smallexample
22878
22879Takes an optional file parameter.
22880
0680b120
AC
22881@kindex maint print registers
22882@kindex maint print raw-registers
22883@kindex maint print cooked-registers
617073a9 22884@kindex maint print register-groups
09d4efe1
EZ
22885@item maint print registers @r{[}@var{file}@r{]}
22886@itemx maint print raw-registers @r{[}@var{file}@r{]}
22887@itemx maint print cooked-registers @r{[}@var{file}@r{]}
22888@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
22889Print @value{GDBN}'s internal register data structures.
22890
617073a9
AC
22891The command @code{maint print raw-registers} includes the contents of
22892the raw register cache; the command @code{maint print cooked-registers}
22893includes the (cooked) value of all registers; and the command
22894@code{maint print register-groups} includes the groups that each
22895register is a member of. @xref{Registers,, Registers, gdbint,
22896@value{GDBN} Internals}.
0680b120 22897
09d4efe1
EZ
22898These commands take an optional parameter, a file name to which to
22899write the information.
0680b120 22900
617073a9 22901@kindex maint print reggroups
09d4efe1
EZ
22902@item maint print reggroups @r{[}@var{file}@r{]}
22903Print @value{GDBN}'s internal register group data structures. The
22904optional argument @var{file} tells to what file to write the
22905information.
617073a9 22906
09d4efe1 22907The register groups info looks like this:
617073a9
AC
22908
22909@smallexample
f7dc1244 22910(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
22911 Group Type
22912 general user
22913 float user
22914 all user
22915 vector user
22916 system user
22917 save internal
22918 restore internal
617073a9
AC
22919@end smallexample
22920
09d4efe1
EZ
22921@kindex flushregs
22922@item flushregs
22923This command forces @value{GDBN} to flush its internal register cache.
22924
22925@kindex maint print objfiles
22926@cindex info for known object files
22927@item maint print objfiles
22928Print a dump of all known object files. For each object file, this
22929command prints its name, address in memory, and all of its psymtabs
22930and symtabs.
22931
22932@kindex maint print statistics
22933@cindex bcache statistics
22934@item maint print statistics
22935This command prints, for each object file in the program, various data
22936about that object file followed by the byte cache (@dfn{bcache})
22937statistics for the object file. The objfile data includes the number
d3e8051b 22938of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
22939defined by the objfile, the number of as yet unexpanded psym tables,
22940the number of line tables and string tables, and the amount of memory
22941used by the various tables. The bcache statistics include the counts,
22942sizes, and counts of duplicates of all and unique objects, max,
22943average, and median entry size, total memory used and its overhead and
22944savings, and various measures of the hash table size and chain
22945lengths.
22946
c7ba131e
JB
22947@kindex maint print target-stack
22948@cindex target stack description
22949@item maint print target-stack
22950A @dfn{target} is an interface between the debugger and a particular
22951kind of file or process. Targets can be stacked in @dfn{strata},
22952so that more than one target can potentially respond to a request.
22953In particular, memory accesses will walk down the stack of targets
22954until they find a target that is interested in handling that particular
22955address.
22956
22957This command prints a short description of each layer that was pushed on
22958the @dfn{target stack}, starting from the top layer down to the bottom one.
22959
09d4efe1
EZ
22960@kindex maint print type
22961@cindex type chain of a data type
22962@item maint print type @var{expr}
22963Print the type chain for a type specified by @var{expr}. The argument
22964can be either a type name or a symbol. If it is a symbol, the type of
22965that symbol is described. The type chain produced by this command is
22966a recursive definition of the data type as stored in @value{GDBN}'s
22967data structures, including its flags and contained types.
22968
22969@kindex maint set dwarf2 max-cache-age
22970@kindex maint show dwarf2 max-cache-age
22971@item maint set dwarf2 max-cache-age
22972@itemx maint show dwarf2 max-cache-age
22973Control the DWARF 2 compilation unit cache.
22974
22975@cindex DWARF 2 compilation units cache
22976In object files with inter-compilation-unit references, such as those
22977produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
22978reader needs to frequently refer to previously read compilation units.
22979This setting controls how long a compilation unit will remain in the
22980cache if it is not referenced. A higher limit means that cached
22981compilation units will be stored in memory longer, and more total
22982memory will be used. Setting it to zero disables caching, which will
22983slow down @value{GDBN} startup, but reduce memory consumption.
22984
e7ba9c65
DJ
22985@kindex maint set profile
22986@kindex maint show profile
22987@cindex profiling GDB
22988@item maint set profile
22989@itemx maint show profile
22990Control profiling of @value{GDBN}.
22991
22992Profiling will be disabled until you use the @samp{maint set profile}
22993command to enable it. When you enable profiling, the system will begin
22994collecting timing and execution count data; when you disable profiling or
22995exit @value{GDBN}, the results will be written to a log file. Remember that
22996if you use profiling, @value{GDBN} will overwrite the profiling log file
22997(often called @file{gmon.out}). If you have a record of important profiling
22998data in a @file{gmon.out} file, be sure to move it to a safe location.
22999
23000Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 23001compiled with the @samp{-pg} compiler option.
e7ba9c65 23002
09d4efe1
EZ
23003@kindex maint show-debug-regs
23004@cindex x86 hardware debug registers
23005@item maint show-debug-regs
23006Control whether to show variables that mirror the x86 hardware debug
23007registers. Use @code{ON} to enable, @code{OFF} to disable. If
3f94c067 23008enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
23009removes a hardware breakpoint or watchpoint, and when the inferior
23010triggers a hardware-assisted breakpoint or watchpoint.
23011
23012@kindex maint space
23013@cindex memory used by commands
23014@item maint space
23015Control whether to display memory usage for each command. If set to a
23016nonzero value, @value{GDBN} will display how much memory each command
23017took, following the command's own output. This can also be requested
23018by invoking @value{GDBN} with the @option{--statistics} command-line
23019switch (@pxref{Mode Options}).
23020
23021@kindex maint time
23022@cindex time of command execution
23023@item maint time
23024Control whether to display the execution time for each command. If
23025set to a nonzero value, @value{GDBN} will display how much time it
23026took to execute each command, following the command's own output.
23027This can also be requested by invoking @value{GDBN} with the
23028@option{--statistics} command-line switch (@pxref{Mode Options}).
23029
23030@kindex maint translate-address
23031@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
23032Find the symbol stored at the location specified by the address
23033@var{addr} and an optional section name @var{section}. If found,
23034@value{GDBN} prints the name of the closest symbol and an offset from
23035the symbol's location to the specified address. This is similar to
23036the @code{info address} command (@pxref{Symbols}), except that this
23037command also allows to find symbols in other sections.
ae038cb0 23038
8e04817f 23039@end table
c906108c 23040
9c16f35a
EZ
23041The following command is useful for non-interactive invocations of
23042@value{GDBN}, such as in the test suite.
23043
23044@table @code
23045@item set watchdog @var{nsec}
23046@kindex set watchdog
23047@cindex watchdog timer
23048@cindex timeout for commands
23049Set the maximum number of seconds @value{GDBN} will wait for the
23050target operation to finish. If this time expires, @value{GDBN}
23051reports and error and the command is aborted.
23052
23053@item show watchdog
23054Show the current setting of the target wait timeout.
23055@end table
c906108c 23056
e0ce93ac 23057@node Remote Protocol
8e04817f 23058@appendix @value{GDBN} Remote Serial Protocol
c906108c 23059
ee2d5c50
AC
23060@menu
23061* Overview::
23062* Packets::
23063* Stop Reply Packets::
23064* General Query Packets::
23065* Register Packet Format::
9d29849a 23066* Tracepoint Packets::
a6b151f1 23067* Host I/O Packets::
9a6253be 23068* Interrupts::
ee2d5c50 23069* Examples::
79a6e687 23070* File-I/O Remote Protocol Extension::
cfa9d6d9 23071* Library List Format::
79a6e687 23072* Memory Map Format::
ee2d5c50
AC
23073@end menu
23074
23075@node Overview
23076@section Overview
23077
8e04817f
AC
23078There may be occasions when you need to know something about the
23079protocol---for example, if there is only one serial port to your target
23080machine, you might want your program to do something special if it
23081recognizes a packet meant for @value{GDBN}.
c906108c 23082
d2c6833e 23083In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 23084transmitted and received data, respectively.
c906108c 23085
8e04817f
AC
23086@cindex protocol, @value{GDBN} remote serial
23087@cindex serial protocol, @value{GDBN} remote
23088@cindex remote serial protocol
23089All @value{GDBN} commands and responses (other than acknowledgments) are
23090sent as a @var{packet}. A @var{packet} is introduced with the character
23091@samp{$}, the actual @var{packet-data}, and the terminating character
23092@samp{#} followed by a two-digit @var{checksum}:
c906108c 23093
474c8240 23094@smallexample
8e04817f 23095@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 23096@end smallexample
8e04817f 23097@noindent
c906108c 23098
8e04817f
AC
23099@cindex checksum, for @value{GDBN} remote
23100@noindent
23101The two-digit @var{checksum} is computed as the modulo 256 sum of all
23102characters between the leading @samp{$} and the trailing @samp{#} (an
23103eight bit unsigned checksum).
c906108c 23104
8e04817f
AC
23105Implementors should note that prior to @value{GDBN} 5.0 the protocol
23106specification also included an optional two-digit @var{sequence-id}:
c906108c 23107
474c8240 23108@smallexample
8e04817f 23109@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 23110@end smallexample
c906108c 23111
8e04817f
AC
23112@cindex sequence-id, for @value{GDBN} remote
23113@noindent
23114That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
23115has never output @var{sequence-id}s. Stubs that handle packets added
23116since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 23117
8e04817f
AC
23118@cindex acknowledgment, for @value{GDBN} remote
23119When either the host or the target machine receives a packet, the first
23120response expected is an acknowledgment: either @samp{+} (to indicate
23121the package was received correctly) or @samp{-} (to request
23122retransmission):
c906108c 23123
474c8240 23124@smallexample
d2c6833e
AC
23125-> @code{$}@var{packet-data}@code{#}@var{checksum}
23126<- @code{+}
474c8240 23127@end smallexample
8e04817f 23128@noindent
53a5351d 23129
8e04817f
AC
23130The host (@value{GDBN}) sends @var{command}s, and the target (the
23131debugging stub incorporated in your program) sends a @var{response}. In
23132the case of step and continue @var{command}s, the response is only sent
23133when the operation has completed (the target has again stopped).
c906108c 23134
8e04817f
AC
23135@var{packet-data} consists of a sequence of characters with the
23136exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
23137exceptions).
c906108c 23138
ee2d5c50 23139@cindex remote protocol, field separator
0876f84a 23140Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 23141@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 23142@sc{hex} with leading zeros suppressed.
c906108c 23143
8e04817f
AC
23144Implementors should note that prior to @value{GDBN} 5.0, the character
23145@samp{:} could not appear as the third character in a packet (as it
23146would potentially conflict with the @var{sequence-id}).
c906108c 23147
0876f84a
DJ
23148@cindex remote protocol, binary data
23149@anchor{Binary Data}
23150Binary data in most packets is encoded either as two hexadecimal
23151digits per byte of binary data. This allowed the traditional remote
23152protocol to work over connections which were only seven-bit clean.
23153Some packets designed more recently assume an eight-bit clean
23154connection, and use a more efficient encoding to send and receive
23155binary data.
23156
23157The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
23158as an escape character. Any escaped byte is transmitted as the escape
23159character followed by the original character XORed with @code{0x20}.
23160For example, the byte @code{0x7d} would be transmitted as the two
23161bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
23162@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
23163@samp{@}}) must always be escaped. Responses sent by the stub
23164must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
23165is not interpreted as the start of a run-length encoded sequence
23166(described next).
23167
1d3811f6
DJ
23168Response @var{data} can be run-length encoded to save space.
23169Run-length encoding replaces runs of identical characters with one
23170instance of the repeated character, followed by a @samp{*} and a
23171repeat count. The repeat count is itself sent encoded, to avoid
23172binary characters in @var{data}: a value of @var{n} is sent as
23173@code{@var{n}+29}. For a repeat count greater or equal to 3, this
23174produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
23175code 32) for a repeat count of 3. (This is because run-length
23176encoding starts to win for counts 3 or more.) Thus, for example,
23177@samp{0* } is a run-length encoding of ``0000'': the space character
23178after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
231793}} more times.
23180
23181The printable characters @samp{#} and @samp{$} or with a numeric value
23182greater than 126 must not be used. Runs of six repeats (@samp{#}) or
23183seven repeats (@samp{$}) can be expanded using a repeat count of only
23184five (@samp{"}). For example, @samp{00000000} can be encoded as
23185@samp{0*"00}.
c906108c 23186
8e04817f
AC
23187The error response returned for some packets includes a two character
23188error number. That number is not well defined.
c906108c 23189
f8da2bff 23190@cindex empty response, for unsupported packets
8e04817f
AC
23191For any @var{command} not supported by the stub, an empty response
23192(@samp{$#00}) should be returned. That way it is possible to extend the
23193protocol. A newer @value{GDBN} can tell if a packet is supported based
23194on that response.
c906108c 23195
b383017d
RM
23196A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
23197@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 23198optional.
c906108c 23199
ee2d5c50
AC
23200@node Packets
23201@section Packets
23202
23203The following table provides a complete list of all currently defined
23204@var{command}s and their corresponding response @var{data}.
79a6e687 23205@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 23206I/O extension of the remote protocol.
ee2d5c50 23207
b8ff78ce
JB
23208Each packet's description has a template showing the packet's overall
23209syntax, followed by an explanation of the packet's meaning. We
23210include spaces in some of the templates for clarity; these are not
23211part of the packet's syntax. No @value{GDBN} packet uses spaces to
23212separate its components. For example, a template like @samp{foo
23213@var{bar} @var{baz}} describes a packet beginning with the three ASCII
23214bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 23215@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
23216@samp{foo} and the @var{bar}, or between the @var{bar} and the
23217@var{baz}.
23218
8ffe2530
JB
23219Note that all packet forms beginning with an upper- or lower-case
23220letter, other than those described here, are reserved for future use.
23221
b8ff78ce 23222Here are the packet descriptions.
ee2d5c50 23223
b8ff78ce 23224@table @samp
ee2d5c50 23225
b8ff78ce
JB
23226@item !
23227@cindex @samp{!} packet
8e04817f
AC
23228Enable extended mode. In extended mode, the remote server is made
23229persistent. The @samp{R} packet is used to restart the program being
23230debugged.
ee2d5c50
AC
23231
23232Reply:
23233@table @samp
23234@item OK
8e04817f 23235The remote target both supports and has enabled extended mode.
ee2d5c50 23236@end table
c906108c 23237
b8ff78ce
JB
23238@item ?
23239@cindex @samp{?} packet
ee2d5c50
AC
23240Indicate the reason the target halted. The reply is the same as for
23241step and continue.
c906108c 23242
ee2d5c50
AC
23243Reply:
23244@xref{Stop Reply Packets}, for the reply specifications.
23245
b8ff78ce
JB
23246@item A @var{arglen},@var{argnum},@var{arg},@dots{}
23247@cindex @samp{A} packet
23248Initialized @code{argv[]} array passed into program. @var{arglen}
23249specifies the number of bytes in the hex encoded byte stream
23250@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
23251
23252Reply:
23253@table @samp
23254@item OK
b8ff78ce
JB
23255The arguments were set.
23256@item E @var{NN}
23257An error occurred.
ee2d5c50
AC
23258@end table
23259
b8ff78ce
JB
23260@item b @var{baud}
23261@cindex @samp{b} packet
23262(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
23263Change the serial line speed to @var{baud}.
23264
23265JTC: @emph{When does the transport layer state change? When it's
23266received, or after the ACK is transmitted. In either case, there are
23267problems if the command or the acknowledgment packet is dropped.}
23268
23269Stan: @emph{If people really wanted to add something like this, and get
23270it working for the first time, they ought to modify ser-unix.c to send
23271some kind of out-of-band message to a specially-setup stub and have the
23272switch happen "in between" packets, so that from remote protocol's point
23273of view, nothing actually happened.}
23274
b8ff78ce
JB
23275@item B @var{addr},@var{mode}
23276@cindex @samp{B} packet
8e04817f 23277Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
23278breakpoint at @var{addr}.
23279
b8ff78ce 23280Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 23281(@pxref{insert breakpoint or watchpoint packet}).
c906108c 23282
4f553f88 23283@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
23284@cindex @samp{c} packet
23285Continue. @var{addr} is address to resume. If @var{addr} is omitted,
23286resume at current address.
c906108c 23287
ee2d5c50
AC
23288Reply:
23289@xref{Stop Reply Packets}, for the reply specifications.
23290
4f553f88 23291@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 23292@cindex @samp{C} packet
8e04817f 23293Continue with signal @var{sig} (hex signal number). If
b8ff78ce 23294@samp{;@var{addr}} is omitted, resume at same address.
c906108c 23295
ee2d5c50
AC
23296Reply:
23297@xref{Stop Reply Packets}, for the reply specifications.
c906108c 23298
b8ff78ce
JB
23299@item d
23300@cindex @samp{d} packet
ee2d5c50
AC
23301Toggle debug flag.
23302
b8ff78ce
JB
23303Don't use this packet; instead, define a general set packet
23304(@pxref{General Query Packets}).
ee2d5c50 23305
b8ff78ce
JB
23306@item D
23307@cindex @samp{D} packet
ee2d5c50 23308Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 23309before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
23310
23311Reply:
23312@table @samp
10fac096
NW
23313@item OK
23314for success
b8ff78ce 23315@item E @var{NN}
10fac096 23316for an error
ee2d5c50 23317@end table
c906108c 23318
b8ff78ce
JB
23319@item F @var{RC},@var{EE},@var{CF};@var{XX}
23320@cindex @samp{F} packet
23321A reply from @value{GDBN} to an @samp{F} packet sent by the target.
23322This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 23323Remote Protocol Extension}, for the specification.
ee2d5c50 23324
b8ff78ce 23325@item g
ee2d5c50 23326@anchor{read registers packet}
b8ff78ce 23327@cindex @samp{g} packet
ee2d5c50
AC
23328Read general registers.
23329
23330Reply:
23331@table @samp
23332@item @var{XX@dots{}}
8e04817f
AC
23333Each byte of register data is described by two hex digits. The bytes
23334with the register are transmitted in target byte order. The size of
b8ff78ce 23335each register and their position within the @samp{g} packet are
4a9bb1df
UW
23336determined by the @value{GDBN} internal gdbarch functions
23337@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce
JB
23338specification of several standard @samp{g} packets is specified below.
23339@item E @var{NN}
ee2d5c50
AC
23340for an error.
23341@end table
c906108c 23342
b8ff78ce
JB
23343@item G @var{XX@dots{}}
23344@cindex @samp{G} packet
23345Write general registers. @xref{read registers packet}, for a
23346description of the @var{XX@dots{}} data.
ee2d5c50
AC
23347
23348Reply:
23349@table @samp
23350@item OK
23351for success
b8ff78ce 23352@item E @var{NN}
ee2d5c50
AC
23353for an error
23354@end table
23355
b8ff78ce
JB
23356@item H @var{c} @var{t}
23357@cindex @samp{H} packet
8e04817f 23358Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
23359@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
23360should be @samp{c} for step and continue operations, @samp{g} for other
b8ff78ce
JB
23361operations. The thread designator @var{t} may be @samp{-1}, meaning all
23362the threads, a thread number, or @samp{0} which means pick any thread.
ee2d5c50
AC
23363
23364Reply:
23365@table @samp
23366@item OK
23367for success
b8ff78ce 23368@item E @var{NN}
ee2d5c50
AC
23369for an error
23370@end table
c906108c 23371
8e04817f
AC
23372@c FIXME: JTC:
23373@c 'H': How restrictive (or permissive) is the thread model. If a
23374@c thread is selected and stopped, are other threads allowed
23375@c to continue to execute? As I mentioned above, I think the
23376@c semantics of each command when a thread is selected must be
23377@c described. For example:
23378@c
23379@c 'g': If the stub supports threads and a specific thread is
23380@c selected, returns the register block from that thread;
23381@c otherwise returns current registers.
23382@c
23383@c 'G' If the stub supports threads and a specific thread is
23384@c selected, sets the registers of the register block of
23385@c that thread; otherwise sets current registers.
c906108c 23386
b8ff78ce 23387@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 23388@anchor{cycle step packet}
b8ff78ce
JB
23389@cindex @samp{i} packet
23390Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
23391present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
23392step starting at that address.
c906108c 23393
b8ff78ce
JB
23394@item I
23395@cindex @samp{I} packet
23396Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
23397step packet}.
ee2d5c50 23398
b8ff78ce
JB
23399@item k
23400@cindex @samp{k} packet
23401Kill request.
c906108c 23402
ac282366 23403FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
23404thread context has been selected (i.e.@: does 'k' kill only that
23405thread?)}.
c906108c 23406
b8ff78ce
JB
23407@item m @var{addr},@var{length}
23408@cindex @samp{m} packet
8e04817f 23409Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
23410Note that @var{addr} may not be aligned to any particular boundary.
23411
23412The stub need not use any particular size or alignment when gathering
23413data from memory for the response; even if @var{addr} is word-aligned
23414and @var{length} is a multiple of the word size, the stub is free to
23415use byte accesses, or not. For this reason, this packet may not be
23416suitable for accessing memory-mapped I/O devices.
c43c5473
JB
23417@cindex alignment of remote memory accesses
23418@cindex size of remote memory accesses
23419@cindex memory, alignment and size of remote accesses
c906108c 23420
ee2d5c50
AC
23421Reply:
23422@table @samp
23423@item @var{XX@dots{}}
599b237a 23424Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
23425number. The reply may contain fewer bytes than requested if the
23426server was able to read only part of the region of memory.
23427@item E @var{NN}
ee2d5c50
AC
23428@var{NN} is errno
23429@end table
23430
b8ff78ce
JB
23431@item M @var{addr},@var{length}:@var{XX@dots{}}
23432@cindex @samp{M} packet
8e04817f 23433Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 23434@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 23435hexadecimal number.
ee2d5c50
AC
23436
23437Reply:
23438@table @samp
23439@item OK
23440for success
b8ff78ce 23441@item E @var{NN}
8e04817f
AC
23442for an error (this includes the case where only part of the data was
23443written).
ee2d5c50 23444@end table
c906108c 23445
b8ff78ce
JB
23446@item p @var{n}
23447@cindex @samp{p} packet
23448Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
23449@xref{read registers packet}, for a description of how the returned
23450register value is encoded.
ee2d5c50
AC
23451
23452Reply:
23453@table @samp
2e868123
AC
23454@item @var{XX@dots{}}
23455the register's value
b8ff78ce 23456@item E @var{NN}
2e868123
AC
23457for an error
23458@item
23459Indicating an unrecognized @var{query}.
ee2d5c50
AC
23460@end table
23461
b8ff78ce 23462@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 23463@anchor{write register packet}
b8ff78ce
JB
23464@cindex @samp{P} packet
23465Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 23466number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 23467digits for each byte in the register (target byte order).
c906108c 23468
ee2d5c50
AC
23469Reply:
23470@table @samp
23471@item OK
23472for success
b8ff78ce 23473@item E @var{NN}
ee2d5c50
AC
23474for an error
23475@end table
23476
5f3bebba
JB
23477@item q @var{name} @var{params}@dots{}
23478@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 23479@cindex @samp{q} packet
b8ff78ce 23480@cindex @samp{Q} packet
5f3bebba
JB
23481General query (@samp{q}) and set (@samp{Q}). These packets are
23482described fully in @ref{General Query Packets}.
c906108c 23483
b8ff78ce
JB
23484@item r
23485@cindex @samp{r} packet
8e04817f 23486Reset the entire system.
c906108c 23487
b8ff78ce 23488Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 23489
b8ff78ce
JB
23490@item R @var{XX}
23491@cindex @samp{R} packet
8e04817f
AC
23492Restart the program being debugged. @var{XX}, while needed, is ignored.
23493This packet is only available in extended mode.
ee2d5c50 23494
8e04817f 23495The @samp{R} packet has no reply.
ee2d5c50 23496
4f553f88 23497@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
23498@cindex @samp{s} packet
23499Single step. @var{addr} is the address at which to resume. If
23500@var{addr} is omitted, resume at same address.
c906108c 23501
ee2d5c50
AC
23502Reply:
23503@xref{Stop Reply Packets}, for the reply specifications.
23504
4f553f88 23505@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 23506@anchor{step with signal packet}
b8ff78ce
JB
23507@cindex @samp{S} packet
23508Step with signal. This is analogous to the @samp{C} packet, but
23509requests a single-step, rather than a normal resumption of execution.
c906108c 23510
ee2d5c50
AC
23511Reply:
23512@xref{Stop Reply Packets}, for the reply specifications.
23513
b8ff78ce
JB
23514@item t @var{addr}:@var{PP},@var{MM}
23515@cindex @samp{t} packet
8e04817f 23516Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
23517@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
23518@var{addr} must be at least 3 digits.
c906108c 23519
b8ff78ce
JB
23520@item T @var{XX}
23521@cindex @samp{T} packet
ee2d5c50 23522Find out if the thread XX is alive.
c906108c 23523
ee2d5c50
AC
23524Reply:
23525@table @samp
23526@item OK
23527thread is still alive
b8ff78ce 23528@item E @var{NN}
ee2d5c50
AC
23529thread is dead
23530@end table
23531
b8ff78ce
JB
23532@item v
23533Packets starting with @samp{v} are identified by a multi-letter name,
23534up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 23535
b8ff78ce
JB
23536@item vCont@r{[};@var{action}@r{[}:@var{tid}@r{]]}@dots{}
23537@cindex @samp{vCont} packet
23538Resume the inferior, specifying different actions for each thread.
86d30acc
DJ
23539If an action is specified with no @var{tid}, then it is applied to any
23540threads that don't have a specific action specified; if no default action is
23541specified then other threads should remain stopped. Specifying multiple
23542default actions is an error; specifying no actions is also an error.
23543Thread IDs are specified in hexadecimal. Currently supported actions are:
23544
b8ff78ce 23545@table @samp
86d30acc
DJ
23546@item c
23547Continue.
b8ff78ce 23548@item C @var{sig}
86d30acc
DJ
23549Continue with signal @var{sig}. @var{sig} should be two hex digits.
23550@item s
23551Step.
b8ff78ce 23552@item S @var{sig}
86d30acc
DJ
23553Step with signal @var{sig}. @var{sig} should be two hex digits.
23554@end table
23555
23556The optional @var{addr} argument normally associated with these packets is
b8ff78ce 23557not supported in @samp{vCont}.
86d30acc
DJ
23558
23559Reply:
23560@xref{Stop Reply Packets}, for the reply specifications.
23561
b8ff78ce
JB
23562@item vCont?
23563@cindex @samp{vCont?} packet
d3e8051b 23564Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
23565
23566Reply:
23567@table @samp
b8ff78ce
JB
23568@item vCont@r{[};@var{action}@dots{}@r{]}
23569The @samp{vCont} packet is supported. Each @var{action} is a supported
23570command in the @samp{vCont} packet.
86d30acc 23571@item
b8ff78ce 23572The @samp{vCont} packet is not supported.
86d30acc 23573@end table
ee2d5c50 23574
a6b151f1
DJ
23575@item vFile:@var{operation}:@var{parameter}@dots{}
23576@cindex @samp{vFile} packet
23577Perform a file operation on the target system. For details,
23578see @ref{Host I/O Packets}.
23579
68437a39
DJ
23580@item vFlashErase:@var{addr},@var{length}
23581@cindex @samp{vFlashErase} packet
23582Direct the stub to erase @var{length} bytes of flash starting at
23583@var{addr}. The region may enclose any number of flash blocks, but
23584its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
23585flash block size appearing in the memory map (@pxref{Memory Map
23586Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
23587together, and sends a @samp{vFlashDone} request after each group; the
23588stub is allowed to delay erase operation until the @samp{vFlashDone}
23589packet is received.
23590
23591Reply:
23592@table @samp
23593@item OK
23594for success
23595@item E @var{NN}
23596for an error
23597@end table
23598
23599@item vFlashWrite:@var{addr}:@var{XX@dots{}}
23600@cindex @samp{vFlashWrite} packet
23601Direct the stub to write data to flash address @var{addr}. The data
23602is passed in binary form using the same encoding as for the @samp{X}
23603packet (@pxref{Binary Data}). The memory ranges specified by
23604@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
23605not overlap, and must appear in order of increasing addresses
23606(although @samp{vFlashErase} packets for higher addresses may already
23607have been received; the ordering is guaranteed only between
23608@samp{vFlashWrite} packets). If a packet writes to an address that was
23609neither erased by a preceding @samp{vFlashErase} packet nor by some other
23610target-specific method, the results are unpredictable.
23611
23612
23613Reply:
23614@table @samp
23615@item OK
23616for success
23617@item E.memtype
23618for vFlashWrite addressing non-flash memory
23619@item E @var{NN}
23620for an error
23621@end table
23622
23623@item vFlashDone
23624@cindex @samp{vFlashDone} packet
23625Indicate to the stub that flash programming operation is finished.
23626The stub is permitted to delay or batch the effects of a group of
23627@samp{vFlashErase} and @samp{vFlashWrite} packets until a
23628@samp{vFlashDone} packet is received. The contents of the affected
23629regions of flash memory are unpredictable until the @samp{vFlashDone}
23630request is completed.
23631
b8ff78ce 23632@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 23633@anchor{X packet}
b8ff78ce
JB
23634@cindex @samp{X} packet
23635Write data to memory, where the data is transmitted in binary.
23636@var{addr} is address, @var{length} is number of bytes,
0876f84a 23637@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 23638
ee2d5c50
AC
23639Reply:
23640@table @samp
23641@item OK
23642for success
b8ff78ce 23643@item E @var{NN}
ee2d5c50
AC
23644for an error
23645@end table
23646
b8ff78ce
JB
23647@item z @var{type},@var{addr},@var{length}
23648@itemx Z @var{type},@var{addr},@var{length}
2f870471 23649@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
23650@cindex @samp{z} packet
23651@cindex @samp{Z} packets
23652Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
2f870471
AC
23653watchpoint starting at address @var{address} and covering the next
23654@var{length} bytes.
ee2d5c50 23655
2f870471
AC
23656Each breakpoint and watchpoint packet @var{type} is documented
23657separately.
23658
512217c7
AC
23659@emph{Implementation notes: A remote target shall return an empty string
23660for an unrecognized breakpoint or watchpoint packet @var{type}. A
23661remote target shall support either both or neither of a given
b8ff78ce 23662@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
23663avoid potential problems with duplicate packets, the operations should
23664be implemented in an idempotent way.}
23665
b8ff78ce
JB
23666@item z0,@var{addr},@var{length}
23667@itemx Z0,@var{addr},@var{length}
23668@cindex @samp{z0} packet
23669@cindex @samp{Z0} packet
23670Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
23671@var{addr} of size @var{length}.
2f870471
AC
23672
23673A memory breakpoint is implemented by replacing the instruction at
23674@var{addr} with a software breakpoint or trap instruction. The
b8ff78ce 23675@var{length} is used by targets that indicates the size of the
2f870471
AC
23676breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
23677@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 23678
2f870471
AC
23679@emph{Implementation note: It is possible for a target to copy or move
23680code that contains memory breakpoints (e.g., when implementing
23681overlays). The behavior of this packet, in the presence of such a
23682target, is not defined.}
c906108c 23683
ee2d5c50
AC
23684Reply:
23685@table @samp
2f870471
AC
23686@item OK
23687success
23688@item
23689not supported
b8ff78ce 23690@item E @var{NN}
ee2d5c50 23691for an error
2f870471
AC
23692@end table
23693
b8ff78ce
JB
23694@item z1,@var{addr},@var{length}
23695@itemx Z1,@var{addr},@var{length}
23696@cindex @samp{z1} packet
23697@cindex @samp{Z1} packet
23698Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
23699address @var{addr} of size @var{length}.
2f870471
AC
23700
23701A hardware breakpoint is implemented using a mechanism that is not
23702dependant on being able to modify the target's memory.
23703
23704@emph{Implementation note: A hardware breakpoint is not affected by code
23705movement.}
23706
23707Reply:
23708@table @samp
ee2d5c50 23709@item OK
2f870471
AC
23710success
23711@item
23712not supported
b8ff78ce 23713@item E @var{NN}
2f870471
AC
23714for an error
23715@end table
23716
b8ff78ce
JB
23717@item z2,@var{addr},@var{length}
23718@itemx Z2,@var{addr},@var{length}
23719@cindex @samp{z2} packet
23720@cindex @samp{Z2} packet
23721Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
2f870471
AC
23722
23723Reply:
23724@table @samp
23725@item OK
23726success
23727@item
23728not supported
b8ff78ce 23729@item E @var{NN}
2f870471
AC
23730for an error
23731@end table
23732
b8ff78ce
JB
23733@item z3,@var{addr},@var{length}
23734@itemx Z3,@var{addr},@var{length}
23735@cindex @samp{z3} packet
23736@cindex @samp{Z3} packet
23737Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
2f870471
AC
23738
23739Reply:
23740@table @samp
23741@item OK
23742success
23743@item
23744not supported
b8ff78ce 23745@item E @var{NN}
2f870471
AC
23746for an error
23747@end table
23748
b8ff78ce
JB
23749@item z4,@var{addr},@var{length}
23750@itemx Z4,@var{addr},@var{length}
23751@cindex @samp{z4} packet
23752@cindex @samp{Z4} packet
23753Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
2f870471
AC
23754
23755Reply:
23756@table @samp
23757@item OK
23758success
23759@item
23760not supported
b8ff78ce 23761@item E @var{NN}
2f870471 23762for an error
ee2d5c50
AC
23763@end table
23764
23765@end table
c906108c 23766
ee2d5c50
AC
23767@node Stop Reply Packets
23768@section Stop Reply Packets
23769@cindex stop reply packets
c906108c 23770
8e04817f
AC
23771The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
23772receive any of the below as a reply. In the case of the @samp{C},
23773@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
b8ff78ce 23774when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
23775number} is defined by the header @file{include/gdb/signals.h} in the
23776@value{GDBN} source code.
c906108c 23777
b8ff78ce
JB
23778As in the description of request packets, we include spaces in the
23779reply templates for clarity; these are not part of the reply packet's
23780syntax. No @value{GDBN} stop reply packet uses spaces to separate its
23781components.
c906108c 23782
b8ff78ce 23783@table @samp
ee2d5c50 23784
b8ff78ce 23785@item S @var{AA}
599b237a 23786The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
23787number). This is equivalent to a @samp{T} response with no
23788@var{n}:@var{r} pairs.
c906108c 23789
b8ff78ce
JB
23790@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
23791@cindex @samp{T} packet reply
599b237a 23792The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
23793number). This is equivalent to an @samp{S} response, except that the
23794@samp{@var{n}:@var{r}} pairs can carry values of important registers
23795and other information directly in the stop reply packet, reducing
23796round-trip latency. Single-step and breakpoint traps are reported
23797this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
23798
23799@itemize @bullet
b8ff78ce 23800@item
599b237a 23801If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
23802corresponding @var{r} gives that register's value. @var{r} is a
23803series of bytes in target byte order, with each byte given by a
23804two-digit hex number.
cfa9d6d9 23805
b8ff78ce
JB
23806@item
23807If @var{n} is @samp{thread}, then @var{r} is the thread process ID, in
23808hex.
cfa9d6d9 23809
b8ff78ce 23810@item
cfa9d6d9
DJ
23811If @var{n} is a recognized @dfn{stop reason}, it describes a more
23812specific event that stopped the target. The currently defined stop
23813reasons are listed below. @var{aa} should be @samp{05}, the trap
23814signal. At most one stop reason should be present.
23815
b8ff78ce
JB
23816@item
23817Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
23818and go on to the next; this allows us to extend the protocol in the
23819future.
cfa9d6d9
DJ
23820@end itemize
23821
23822The currently defined stop reasons are:
23823
23824@table @samp
23825@item watch
23826@itemx rwatch
23827@itemx awatch
23828The packet indicates a watchpoint hit, and @var{r} is the data address, in
23829hex.
23830
23831@cindex shared library events, remote reply
23832@item library
23833The packet indicates that the loaded libraries have changed.
23834@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
23835list of loaded libraries. @var{r} is ignored.
23836@end table
ee2d5c50 23837
b8ff78ce 23838@item W @var{AA}
8e04817f 23839The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
23840applicable to certain targets.
23841
b8ff78ce 23842@item X @var{AA}
8e04817f 23843The process terminated with signal @var{AA}.
c906108c 23844
b8ff78ce
JB
23845@item O @var{XX}@dots{}
23846@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
23847written as the program's console output. This can happen at any time
23848while the program is running and the debugger should continue to wait
23849for @samp{W}, @samp{T}, etc.
0ce1b118 23850
b8ff78ce 23851@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
23852@var{call-id} is the identifier which says which host system call should
23853be called. This is just the name of the function. Translation into the
23854correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 23855@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
23856system calls.
23857
b8ff78ce
JB
23858@samp{@var{parameter}@dots{}} is a list of parameters as defined for
23859this very system call.
0ce1b118 23860
b8ff78ce
JB
23861The target replies with this packet when it expects @value{GDBN} to
23862call a host system call on behalf of the target. @value{GDBN} replies
23863with an appropriate @samp{F} packet and keeps up waiting for the next
23864reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
23865or @samp{s} action is expected to be continued. @xref{File-I/O Remote
23866Protocol Extension}, for more details.
0ce1b118 23867
ee2d5c50
AC
23868@end table
23869
23870@node General Query Packets
23871@section General Query Packets
9c16f35a 23872@cindex remote query requests
c906108c 23873
5f3bebba
JB
23874Packets starting with @samp{q} are @dfn{general query packets};
23875packets starting with @samp{Q} are @dfn{general set packets}. General
23876query and set packets are a semi-unified form for retrieving and
23877sending information to and from the stub.
23878
23879The initial letter of a query or set packet is followed by a name
23880indicating what sort of thing the packet applies to. For example,
23881@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
23882definitions with the stub. These packet names follow some
23883conventions:
23884
23885@itemize @bullet
23886@item
23887The name must not contain commas, colons or semicolons.
23888@item
23889Most @value{GDBN} query and set packets have a leading upper case
23890letter.
23891@item
23892The names of custom vendor packets should use a company prefix, in
23893lower case, followed by a period. For example, packets designed at
23894the Acme Corporation might begin with @samp{qacme.foo} (for querying
23895foos) or @samp{Qacme.bar} (for setting bars).
23896@end itemize
23897
aa56d27a
JB
23898The name of a query or set packet should be separated from any
23899parameters by a @samp{:}; the parameters themselves should be
23900separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
23901full packet name, and check for a separator or the end of the packet,
23902in case two packet names share a common prefix. New packets should not begin
23903with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
23904packets predate these conventions, and have arguments without any terminator
23905for the packet name; we suspect they are in widespread use in places that
23906are difficult to upgrade. The @samp{qC} packet has no arguments, but some
23907existing stubs (e.g.@: RedBoot) are known to not check for the end of the
23908packet.}.
c906108c 23909
b8ff78ce
JB
23910Like the descriptions of the other packets, each description here
23911has a template showing the packet's overall syntax, followed by an
23912explanation of the packet's meaning. We include spaces in some of the
23913templates for clarity; these are not part of the packet's syntax. No
23914@value{GDBN} packet uses spaces to separate its components.
23915
5f3bebba
JB
23916Here are the currently defined query and set packets:
23917
b8ff78ce 23918@table @samp
c906108c 23919
b8ff78ce 23920@item qC
9c16f35a 23921@cindex current thread, remote request
b8ff78ce 23922@cindex @samp{qC} packet
ee2d5c50
AC
23923Return the current thread id.
23924
23925Reply:
23926@table @samp
b8ff78ce 23927@item QC @var{pid}
599b237a 23928Where @var{pid} is an unsigned hexadecimal process id.
b8ff78ce 23929@item @r{(anything else)}
ee2d5c50
AC
23930Any other reply implies the old pid.
23931@end table
23932
b8ff78ce 23933@item qCRC:@var{addr},@var{length}
ff2587ec 23934@cindex CRC of memory block, remote request
b8ff78ce
JB
23935@cindex @samp{qCRC} packet
23936Compute the CRC checksum of a block of memory.
ff2587ec
WZ
23937Reply:
23938@table @samp
b8ff78ce 23939@item E @var{NN}
ff2587ec 23940An error (such as memory fault)
b8ff78ce
JB
23941@item C @var{crc32}
23942The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
23943@end table
23944
b8ff78ce
JB
23945@item qfThreadInfo
23946@itemx qsThreadInfo
9c16f35a 23947@cindex list active threads, remote request
b8ff78ce
JB
23948@cindex @samp{qfThreadInfo} packet
23949@cindex @samp{qsThreadInfo} packet
23950Obtain a list of all active thread ids from the target (OS). Since there
8e04817f
AC
23951may be too many active threads to fit into one reply packet, this query
23952works iteratively: it may require more than one query/reply sequence to
23953obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
23954be the @samp{qfThreadInfo} query; subsequent queries in the
23955sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 23956
b8ff78ce 23957NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
23958
23959Reply:
23960@table @samp
b8ff78ce 23961@item m @var{id}
ee2d5c50 23962A single thread id
b8ff78ce 23963@item m @var{id},@var{id}@dots{}
ee2d5c50 23964a comma-separated list of thread ids
b8ff78ce
JB
23965@item l
23966(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
23967@end table
23968
23969In response to each query, the target will reply with a list of one or
e1aac25b
JB
23970more thread ids, in big-endian unsigned hex, separated by commas.
23971@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce
JB
23972ids (using the @samp{qs} form of the query), until the target responds
23973with @samp{l} (lower-case el, for @dfn{last}).
c906108c 23974
b8ff78ce 23975@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 23976@cindex get thread-local storage address, remote request
b8ff78ce 23977@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
23978Fetch the address associated with thread local storage specified
23979by @var{thread-id}, @var{offset}, and @var{lm}.
23980
23981@var{thread-id} is the (big endian, hex encoded) thread id associated with the
23982thread for which to fetch the TLS address.
23983
23984@var{offset} is the (big endian, hex encoded) offset associated with the
23985thread local variable. (This offset is obtained from the debug
23986information associated with the variable.)
23987
db2e3e2e 23988@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
ff2587ec
WZ
23989the load module associated with the thread local storage. For example,
23990a @sc{gnu}/Linux system will pass the link map address of the shared
23991object associated with the thread local storage under consideration.
23992Other operating environments may choose to represent the load module
23993differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
23994
23995Reply:
b8ff78ce
JB
23996@table @samp
23997@item @var{XX}@dots{}
ff2587ec
WZ
23998Hex encoded (big endian) bytes representing the address of the thread
23999local storage requested.
24000
b8ff78ce
JB
24001@item E @var{nn}
24002An error occurred. @var{nn} are hex digits.
ff2587ec 24003
b8ff78ce
JB
24004@item
24005An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
24006@end table
24007
b8ff78ce 24008@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
24009Obtain thread information from RTOS. Where: @var{startflag} (one hex
24010digit) is one to indicate the first query and zero to indicate a
24011subsequent query; @var{threadcount} (two hex digits) is the maximum
24012number of threads the response packet can contain; and @var{nextthread}
24013(eight hex digits), for subsequent queries (@var{startflag} is zero), is
24014returned in the response as @var{argthread}.
ee2d5c50 24015
b8ff78ce 24016Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
24017
24018Reply:
24019@table @samp
b8ff78ce 24020@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
24021Where: @var{count} (two hex digits) is the number of threads being
24022returned; @var{done} (one hex digit) is zero to indicate more threads
24023and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 24024digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 24025is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 24026digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 24027@end table
c906108c 24028
b8ff78ce 24029@item qOffsets
9c16f35a 24030@cindex section offsets, remote request
b8ff78ce 24031@cindex @samp{qOffsets} packet
31d99776
DJ
24032Get section offsets that the target used when relocating the downloaded
24033image.
c906108c 24034
ee2d5c50
AC
24035Reply:
24036@table @samp
31d99776
DJ
24037@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
24038Relocate the @code{Text} section by @var{xxx} from its original address.
24039Relocate the @code{Data} section by @var{yyy} from its original address.
24040If the object file format provides segment information (e.g.@: @sc{elf}
24041@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
24042segments by the supplied offsets.
24043
24044@emph{Note: while a @code{Bss} offset may be included in the response,
24045@value{GDBN} ignores this and instead applies the @code{Data} offset
24046to the @code{Bss} section.}
24047
24048@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
24049Relocate the first segment of the object file, which conventionally
24050contains program code, to a starting address of @var{xxx}. If
24051@samp{DataSeg} is specified, relocate the second segment, which
24052conventionally contains modifiable data, to a starting address of
24053@var{yyy}. @value{GDBN} will report an error if the object file
24054does not contain segment information, or does not contain at least
24055as many segments as mentioned in the reply. Extra segments are
24056kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
24057@end table
24058
b8ff78ce 24059@item qP @var{mode} @var{threadid}
9c16f35a 24060@cindex thread information, remote request
b8ff78ce 24061@cindex @samp{qP} packet
8e04817f
AC
24062Returns information on @var{threadid}. Where: @var{mode} is a hex
24063encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50 24064
aa56d27a
JB
24065Don't use this packet; use the @samp{qThreadExtraInfo} query instead
24066(see below).
24067
b8ff78ce 24068Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 24069
89be2091
DJ
24070@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
24071@cindex pass signals to inferior, remote request
24072@cindex @samp{QPassSignals} packet
23181151 24073@anchor{QPassSignals}
89be2091
DJ
24074Each listed @var{signal} should be passed directly to the inferior process.
24075Signals are numbered identically to continue packets and stop replies
24076(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
24077strictly greater than the previous item. These signals do not need to stop
24078the inferior, or be reported to @value{GDBN}. All other signals should be
24079reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
24080combine; any earlier @samp{QPassSignals} list is completely replaced by the
24081new list. This packet improves performance when using @samp{handle
24082@var{signal} nostop noprint pass}.
24083
24084Reply:
24085@table @samp
24086@item OK
24087The request succeeded.
24088
24089@item E @var{nn}
24090An error occurred. @var{nn} are hex digits.
24091
24092@item
24093An empty reply indicates that @samp{QPassSignals} is not supported by
24094the stub.
24095@end table
24096
24097Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 24098command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
24099This packet is not probed by default; the remote stub must request it,
24100by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24101
b8ff78ce 24102@item qRcmd,@var{command}
ff2587ec 24103@cindex execute remote command, remote request
b8ff78ce 24104@cindex @samp{qRcmd} packet
ff2587ec 24105@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
24106execution. Invalid commands should be reported using the output
24107string. Before the final result packet, the target may also respond
24108with a number of intermediate @samp{O@var{output}} console output
24109packets. @emph{Implementors should note that providing access to a
24110stubs's interpreter may have security implications}.
fa93a9d8 24111
ff2587ec
WZ
24112Reply:
24113@table @samp
24114@item OK
24115A command response with no output.
24116@item @var{OUTPUT}
24117A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 24118@item E @var{NN}
ff2587ec 24119Indicate a badly formed request.
b8ff78ce
JB
24120@item
24121An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 24122@end table
fa93a9d8 24123
aa56d27a
JB
24124(Note that the @code{qRcmd} packet's name is separated from the
24125command by a @samp{,}, not a @samp{:}, contrary to the naming
24126conventions above. Please don't use this packet as a model for new
24127packets.)
24128
be2a5f71
DJ
24129@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
24130@cindex supported packets, remote query
24131@cindex features of the remote protocol
24132@cindex @samp{qSupported} packet
0876f84a 24133@anchor{qSupported}
be2a5f71
DJ
24134Tell the remote stub about features supported by @value{GDBN}, and
24135query the stub for features it supports. This packet allows
24136@value{GDBN} and the remote stub to take advantage of each others'
24137features. @samp{qSupported} also consolidates multiple feature probes
24138at startup, to improve @value{GDBN} performance---a single larger
24139packet performs better than multiple smaller probe packets on
24140high-latency links. Some features may enable behavior which must not
24141be on by default, e.g.@: because it would confuse older clients or
24142stubs. Other features may describe packets which could be
24143automatically probed for, but are not. These features must be
24144reported before @value{GDBN} will use them. This ``default
24145unsupported'' behavior is not appropriate for all packets, but it
24146helps to keep the initial connection time under control with new
24147versions of @value{GDBN} which support increasing numbers of packets.
24148
24149Reply:
24150@table @samp
24151@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
24152The stub supports or does not support each returned @var{stubfeature},
24153depending on the form of each @var{stubfeature} (see below for the
24154possible forms).
24155@item
24156An empty reply indicates that @samp{qSupported} is not recognized,
24157or that no features needed to be reported to @value{GDBN}.
24158@end table
24159
24160The allowed forms for each feature (either a @var{gdbfeature} in the
24161@samp{qSupported} packet, or a @var{stubfeature} in the response)
24162are:
24163
24164@table @samp
24165@item @var{name}=@var{value}
24166The remote protocol feature @var{name} is supported, and associated
24167with the specified @var{value}. The format of @var{value} depends
24168on the feature, but it must not include a semicolon.
24169@item @var{name}+
24170The remote protocol feature @var{name} is supported, and does not
24171need an associated value.
24172@item @var{name}-
24173The remote protocol feature @var{name} is not supported.
24174@item @var{name}?
24175The remote protocol feature @var{name} may be supported, and
24176@value{GDBN} should auto-detect support in some other way when it is
24177needed. This form will not be used for @var{gdbfeature} notifications,
24178but may be used for @var{stubfeature} responses.
24179@end table
24180
24181Whenever the stub receives a @samp{qSupported} request, the
24182supplied set of @value{GDBN} features should override any previous
24183request. This allows @value{GDBN} to put the stub in a known
24184state, even if the stub had previously been communicating with
24185a different version of @value{GDBN}.
24186
24187No values of @var{gdbfeature} (for the packet sent by @value{GDBN})
24188are defined yet. Stubs should ignore any unknown values for
24189@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
24190packet supports receiving packets of unlimited length (earlier
24191versions of @value{GDBN} may reject overly long responses). Values
24192for @var{gdbfeature} may be defined in the future to let the stub take
24193advantage of new features in @value{GDBN}, e.g.@: incompatible
24194improvements in the remote protocol---support for unlimited length
24195responses would be a @var{gdbfeature} example, if it were not implied by
24196the @samp{qSupported} query. The stub's reply should be independent
24197of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
24198describes all the features it supports, and then the stub replies with
24199all the features it supports.
24200
24201Similarly, @value{GDBN} will silently ignore unrecognized stub feature
24202responses, as long as each response uses one of the standard forms.
24203
24204Some features are flags. A stub which supports a flag feature
24205should respond with a @samp{+} form response. Other features
24206require values, and the stub should respond with an @samp{=}
24207form response.
24208
24209Each feature has a default value, which @value{GDBN} will use if
24210@samp{qSupported} is not available or if the feature is not mentioned
24211in the @samp{qSupported} response. The default values are fixed; a
24212stub is free to omit any feature responses that match the defaults.
24213
24214Not all features can be probed, but for those which can, the probing
24215mechanism is useful: in some cases, a stub's internal
24216architecture may not allow the protocol layer to know some information
24217about the underlying target in advance. This is especially common in
24218stubs which may be configured for multiple targets.
24219
24220These are the currently defined stub features and their properties:
24221
cfa9d6d9 24222@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
24223@c NOTE: The first row should be @headitem, but we do not yet require
24224@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 24225@item Feature Name
be2a5f71
DJ
24226@tab Value Required
24227@tab Default
24228@tab Probe Allowed
24229
24230@item @samp{PacketSize}
24231@tab Yes
24232@tab @samp{-}
24233@tab No
24234
0876f84a
DJ
24235@item @samp{qXfer:auxv:read}
24236@tab No
24237@tab @samp{-}
24238@tab Yes
24239
23181151
DJ
24240@item @samp{qXfer:features:read}
24241@tab No
24242@tab @samp{-}
24243@tab Yes
24244
cfa9d6d9
DJ
24245@item @samp{qXfer:libraries:read}
24246@tab No
24247@tab @samp{-}
24248@tab Yes
24249
68437a39
DJ
24250@item @samp{qXfer:memory-map:read}
24251@tab No
24252@tab @samp{-}
24253@tab Yes
24254
0e7f50da
UW
24255@item @samp{qXfer:spu:read}
24256@tab No
24257@tab @samp{-}
24258@tab Yes
24259
24260@item @samp{qXfer:spu:write}
24261@tab No
24262@tab @samp{-}
24263@tab Yes
24264
89be2091
DJ
24265@item @samp{QPassSignals}
24266@tab No
24267@tab @samp{-}
24268@tab Yes
24269
be2a5f71
DJ
24270@end multitable
24271
24272These are the currently defined stub features, in more detail:
24273
24274@table @samp
24275@cindex packet size, remote protocol
24276@item PacketSize=@var{bytes}
24277The remote stub can accept packets up to at least @var{bytes} in
24278length. @value{GDBN} will send packets up to this size for bulk
24279transfers, and will never send larger packets. This is a limit on the
24280data characters in the packet, including the frame and checksum.
24281There is no trailing NUL byte in a remote protocol packet; if the stub
24282stores packets in a NUL-terminated format, it should allow an extra
24283byte in its buffer for the NUL. If this stub feature is not supported,
24284@value{GDBN} guesses based on the size of the @samp{g} packet response.
24285
0876f84a
DJ
24286@item qXfer:auxv:read
24287The remote stub understands the @samp{qXfer:auxv:read} packet
24288(@pxref{qXfer auxiliary vector read}).
24289
23181151
DJ
24290@item qXfer:features:read
24291The remote stub understands the @samp{qXfer:features:read} packet
24292(@pxref{qXfer target description read}).
24293
cfa9d6d9
DJ
24294@item qXfer:libraries:read
24295The remote stub understands the @samp{qXfer:libraries:read} packet
24296(@pxref{qXfer library list read}).
24297
23181151
DJ
24298@item qXfer:memory-map:read
24299The remote stub understands the @samp{qXfer:memory-map:read} packet
24300(@pxref{qXfer memory map read}).
24301
0e7f50da
UW
24302@item qXfer:spu:read
24303The remote stub understands the @samp{qXfer:spu:read} packet
24304(@pxref{qXfer spu read}).
24305
24306@item qXfer:spu:write
24307The remote stub understands the @samp{qXfer:spu:write} packet
24308(@pxref{qXfer spu write}).
24309
23181151
DJ
24310@item QPassSignals
24311The remote stub understands the @samp{QPassSignals} packet
24312(@pxref{QPassSignals}).
24313
be2a5f71
DJ
24314@end table
24315
b8ff78ce 24316@item qSymbol::
ff2587ec 24317@cindex symbol lookup, remote request
b8ff78ce 24318@cindex @samp{qSymbol} packet
ff2587ec
WZ
24319Notify the target that @value{GDBN} is prepared to serve symbol lookup
24320requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
24321
24322Reply:
ff2587ec 24323@table @samp
b8ff78ce 24324@item OK
ff2587ec 24325The target does not need to look up any (more) symbols.
b8ff78ce 24326@item qSymbol:@var{sym_name}
ff2587ec
WZ
24327The target requests the value of symbol @var{sym_name} (hex encoded).
24328@value{GDBN} may provide the value by using the
b8ff78ce
JB
24329@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
24330below.
ff2587ec 24331@end table
83761cbd 24332
b8ff78ce 24333@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
24334Set the value of @var{sym_name} to @var{sym_value}.
24335
24336@var{sym_name} (hex encoded) is the name of a symbol whose value the
24337target has previously requested.
24338
24339@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
24340@value{GDBN} cannot supply a value for @var{sym_name}, then this field
24341will be empty.
24342
24343Reply:
24344@table @samp
b8ff78ce 24345@item OK
ff2587ec 24346The target does not need to look up any (more) symbols.
b8ff78ce 24347@item qSymbol:@var{sym_name}
ff2587ec
WZ
24348The target requests the value of a new symbol @var{sym_name} (hex
24349encoded). @value{GDBN} will continue to supply the values of symbols
24350(if available), until the target ceases to request them.
fa93a9d8 24351@end table
0abb7bc7 24352
9d29849a
JB
24353@item QTDP
24354@itemx QTFrame
24355@xref{Tracepoint Packets}.
24356
b8ff78ce 24357@item qThreadExtraInfo,@var{id}
ff2587ec 24358@cindex thread attributes info, remote request
b8ff78ce
JB
24359@cindex @samp{qThreadExtraInfo} packet
24360Obtain a printable string description of a thread's attributes from
24361the target OS. @var{id} is a thread-id in big-endian hex. This
24362string may contain anything that the target OS thinks is interesting
24363for @value{GDBN} to tell the user about the thread. The string is
24364displayed in @value{GDBN}'s @code{info threads} display. Some
24365examples of possible thread extra info strings are @samp{Runnable}, or
24366@samp{Blocked on Mutex}.
ff2587ec
WZ
24367
24368Reply:
24369@table @samp
b8ff78ce
JB
24370@item @var{XX}@dots{}
24371Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
24372comprising the printable string containing the extra information about
24373the thread's attributes.
ff2587ec 24374@end table
814e32d7 24375
aa56d27a
JB
24376(Note that the @code{qThreadExtraInfo} packet's name is separated from
24377the command by a @samp{,}, not a @samp{:}, contrary to the naming
24378conventions above. Please don't use this packet as a model for new
24379packets.)
24380
9d29849a
JB
24381@item QTStart
24382@itemx QTStop
24383@itemx QTinit
24384@itemx QTro
24385@itemx qTStatus
24386@xref{Tracepoint Packets}.
24387
0876f84a
DJ
24388@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
24389@cindex read special object, remote request
24390@cindex @samp{qXfer} packet
68437a39 24391@anchor{qXfer read}
0876f84a
DJ
24392Read uninterpreted bytes from the target's special data area
24393identified by the keyword @var{object}. Request @var{length} bytes
24394starting at @var{offset} bytes into the data. The content and
0e7f50da 24395encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
24396additional details about what data to access.
24397
24398Here are the specific requests of this form defined so far. All
24399@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
24400formats, listed below.
24401
24402@table @samp
24403@item qXfer:auxv:read::@var{offset},@var{length}
24404@anchor{qXfer auxiliary vector read}
24405Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 24406auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
24407
24408This packet is not probed by default; the remote stub must request it,
89be2091 24409by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 24410
23181151
DJ
24411@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
24412@anchor{qXfer target description read}
24413Access the @dfn{target description}. @xref{Target Descriptions}. The
24414annex specifies which XML document to access. The main description is
24415always loaded from the @samp{target.xml} annex.
24416
24417This packet is not probed by default; the remote stub must request it,
24418by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24419
cfa9d6d9
DJ
24420@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
24421@anchor{qXfer library list read}
24422Access the target's list of loaded libraries. @xref{Library List Format}.
24423The annex part of the generic @samp{qXfer} packet must be empty
24424(@pxref{qXfer read}).
24425
24426Targets which maintain a list of libraries in the program's memory do
24427not need to implement this packet; it is designed for platforms where
24428the operating system manages the list of loaded libraries.
24429
24430This packet is not probed by default; the remote stub must request it,
24431by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24432
68437a39
DJ
24433@item qXfer:memory-map:read::@var{offset},@var{length}
24434@anchor{qXfer memory map read}
79a6e687 24435Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
24436annex part of the generic @samp{qXfer} packet must be empty
24437(@pxref{qXfer read}).
24438
0e7f50da
UW
24439This packet is not probed by default; the remote stub must request it,
24440by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24441
24442@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
24443@anchor{qXfer spu read}
24444Read contents of an @code{spufs} file on the target system. The
24445annex specifies which file to read; it must be of the form
24446@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
24447in the target process, and @var{name} identifes the @code{spufs} file
24448in that context to be accessed.
24449
68437a39
DJ
24450This packet is not probed by default; the remote stub must request it,
24451by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24452@end table
24453
0876f84a
DJ
24454Reply:
24455@table @samp
24456@item m @var{data}
24457Data @var{data} (@pxref{Binary Data}) has been read from the
24458target. There may be more data at a higher address (although
24459it is permitted to return @samp{m} even for the last valid
24460block of data, as long as at least one byte of data was read).
24461@var{data} may have fewer bytes than the @var{length} in the
24462request.
24463
24464@item l @var{data}
24465Data @var{data} (@pxref{Binary Data}) has been read from the target.
24466There is no more data to be read. @var{data} may have fewer bytes
24467than the @var{length} in the request.
24468
24469@item l
24470The @var{offset} in the request is at the end of the data.
24471There is no more data to be read.
24472
24473@item E00
24474The request was malformed, or @var{annex} was invalid.
24475
24476@item E @var{nn}
24477The offset was invalid, or there was an error encountered reading the data.
24478@var{nn} is a hex-encoded @code{errno} value.
24479
24480@item
24481An empty reply indicates the @var{object} string was not recognized by
24482the stub, or that the object does not support reading.
24483@end table
24484
24485@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
24486@cindex write data into object, remote request
24487Write uninterpreted bytes into the target's special data area
24488identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 24489into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 24490(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 24491is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
24492to access.
24493
0e7f50da
UW
24494Here are the specific requests of this form defined so far. All
24495@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
24496formats, listed below.
24497
24498@table @samp
24499@item qXfer:@var{spu}:write:@var{annex}:@var{offset}:@var{data}@dots{}
24500@anchor{qXfer spu write}
24501Write @var{data} to an @code{spufs} file on the target system. The
24502annex specifies which file to write; it must be of the form
24503@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
24504in the target process, and @var{name} identifes the @code{spufs} file
24505in that context to be accessed.
24506
24507This packet is not probed by default; the remote stub must request it,
24508by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24509@end table
0876f84a
DJ
24510
24511Reply:
24512@table @samp
24513@item @var{nn}
24514@var{nn} (hex encoded) is the number of bytes written.
24515This may be fewer bytes than supplied in the request.
24516
24517@item E00
24518The request was malformed, or @var{annex} was invalid.
24519
24520@item E @var{nn}
24521The offset was invalid, or there was an error encountered writing the data.
24522@var{nn} is a hex-encoded @code{errno} value.
24523
24524@item
24525An empty reply indicates the @var{object} string was not
24526recognized by the stub, or that the object does not support writing.
24527@end table
24528
24529@item qXfer:@var{object}:@var{operation}:@dots{}
24530Requests of this form may be added in the future. When a stub does
24531not recognize the @var{object} keyword, or its support for
24532@var{object} does not recognize the @var{operation} keyword, the stub
24533must respond with an empty packet.
24534
ee2d5c50
AC
24535@end table
24536
24537@node Register Packet Format
24538@section Register Packet Format
eb12ee30 24539
b8ff78ce 24540The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
24541In the below, some thirty-two bit registers are transferred as
24542sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
24543to fill the space allocated. Register bytes are transferred in target
24544byte order. The two nibbles within a register byte are transferred
ee2d5c50 24545most-significant - least-significant.
eb12ee30 24546
ee2d5c50 24547@table @r
eb12ee30 24548
8e04817f 24549@item MIPS32
ee2d5c50 24550
599b237a 24551All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
2455232 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
24553registers; fsr; fir; fp.
eb12ee30 24554
8e04817f 24555@item MIPS64
ee2d5c50 24556
599b237a 24557All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
24558thirty-two bit registers such as @code{sr}). The ordering is the same
24559as @code{MIPS32}.
eb12ee30 24560
ee2d5c50
AC
24561@end table
24562
9d29849a
JB
24563@node Tracepoint Packets
24564@section Tracepoint Packets
24565@cindex tracepoint packets
24566@cindex packets, tracepoint
24567
24568Here we describe the packets @value{GDBN} uses to implement
24569tracepoints (@pxref{Tracepoints}).
24570
24571@table @samp
24572
24573@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
24574Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
24575is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
24576the tracepoint is disabled. @var{step} is the tracepoint's step
24577count, and @var{pass} is its pass count. If the trailing @samp{-} is
24578present, further @samp{QTDP} packets will follow to specify this
24579tracepoint's actions.
24580
24581Replies:
24582@table @samp
24583@item OK
24584The packet was understood and carried out.
24585@item
24586The packet was not recognized.
24587@end table
24588
24589@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
24590Define actions to be taken when a tracepoint is hit. @var{n} and
24591@var{addr} must be the same as in the initial @samp{QTDP} packet for
24592this tracepoint. This packet may only be sent immediately after
24593another @samp{QTDP} packet that ended with a @samp{-}. If the
24594trailing @samp{-} is present, further @samp{QTDP} packets will follow,
24595specifying more actions for this tracepoint.
24596
24597In the series of action packets for a given tracepoint, at most one
24598can have an @samp{S} before its first @var{action}. If such a packet
24599is sent, it and the following packets define ``while-stepping''
24600actions. Any prior packets define ordinary actions --- that is, those
24601taken when the tracepoint is first hit. If no action packet has an
24602@samp{S}, then all the packets in the series specify ordinary
24603tracepoint actions.
24604
24605The @samp{@var{action}@dots{}} portion of the packet is a series of
24606actions, concatenated without separators. Each action has one of the
24607following forms:
24608
24609@table @samp
24610
24611@item R @var{mask}
24612Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 24613a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
24614@var{i} should be collected. (The least significant bit is numbered
24615zero.) Note that @var{mask} may be any number of digits long; it may
24616not fit in a 32-bit word.
24617
24618@item M @var{basereg},@var{offset},@var{len}
24619Collect @var{len} bytes of memory starting at the address in register
24620number @var{basereg}, plus @var{offset}. If @var{basereg} is
24621@samp{-1}, then the range has a fixed address: @var{offset} is the
24622address of the lowest byte to collect. The @var{basereg},
599b237a 24623@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
24624values (the @samp{-1} value for @var{basereg} is a special case).
24625
24626@item X @var{len},@var{expr}
24627Evaluate @var{expr}, whose length is @var{len}, and collect memory as
24628it directs. @var{expr} is an agent expression, as described in
24629@ref{Agent Expressions}. Each byte of the expression is encoded as a
24630two-digit hex number in the packet; @var{len} is the number of bytes
24631in the expression (and thus one-half the number of hex digits in the
24632packet).
24633
24634@end table
24635
24636Any number of actions may be packed together in a single @samp{QTDP}
24637packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
24638length (400 bytes, for many stubs). There may be only one @samp{R}
24639action per tracepoint, and it must precede any @samp{M} or @samp{X}
24640actions. Any registers referred to by @samp{M} and @samp{X} actions
24641must be collected by a preceding @samp{R} action. (The
24642``while-stepping'' actions are treated as if they were attached to a
24643separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
24644
24645Replies:
24646@table @samp
24647@item OK
24648The packet was understood and carried out.
24649@item
24650The packet was not recognized.
24651@end table
24652
24653@item QTFrame:@var{n}
24654Select the @var{n}'th tracepoint frame from the buffer, and use the
24655register and memory contents recorded there to answer subsequent
24656request packets from @value{GDBN}.
24657
24658A successful reply from the stub indicates that the stub has found the
24659requested frame. The response is a series of parts, concatenated
24660without separators, describing the frame we selected. Each part has
24661one of the following forms:
24662
24663@table @samp
24664@item F @var{f}
24665The selected frame is number @var{n} in the trace frame buffer;
599b237a 24666@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
24667was no frame matching the criteria in the request packet.
24668
24669@item T @var{t}
24670The selected trace frame records a hit of tracepoint number @var{t};
599b237a 24671@var{t} is a hexadecimal number.
9d29849a
JB
24672
24673@end table
24674
24675@item QTFrame:pc:@var{addr}
24676Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24677currently selected frame whose PC is @var{addr};
599b237a 24678@var{addr} is a hexadecimal number.
9d29849a
JB
24679
24680@item QTFrame:tdp:@var{t}
24681Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24682currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 24683is a hexadecimal number.
9d29849a
JB
24684
24685@item QTFrame:range:@var{start}:@var{end}
24686Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24687currently selected frame whose PC is between @var{start} (inclusive)
599b237a 24688and @var{end} (exclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
24689numbers.
24690
24691@item QTFrame:outside:@var{start}:@var{end}
24692Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
24693frame @emph{outside} the given range of addresses.
24694
24695@item QTStart
24696Begin the tracepoint experiment. Begin collecting data from tracepoint
24697hits in the trace frame buffer.
24698
24699@item QTStop
24700End the tracepoint experiment. Stop collecting trace frames.
24701
24702@item QTinit
24703Clear the table of tracepoints, and empty the trace frame buffer.
24704
24705@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
24706Establish the given ranges of memory as ``transparent''. The stub
24707will answer requests for these ranges from memory's current contents,
24708if they were not collected as part of the tracepoint hit.
24709
24710@value{GDBN} uses this to mark read-only regions of memory, like those
24711containing program code. Since these areas never change, they should
24712still have the same contents they did when the tracepoint was hit, so
24713there's no reason for the stub to refuse to provide their contents.
24714
24715@item qTStatus
24716Ask the stub if there is a trace experiment running right now.
24717
24718Replies:
24719@table @samp
24720@item T0
24721There is no trace experiment running.
24722@item T1
24723There is a trace experiment running.
24724@end table
24725
24726@end table
24727
24728
a6b151f1
DJ
24729@node Host I/O Packets
24730@section Host I/O Packets
24731@cindex Host I/O, remote protocol
24732@cindex file transfer, remote protocol
24733
24734The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
24735operations on the far side of a remote link. For example, Host I/O is
24736used to upload and download files to a remote target with its own
24737filesystem. Host I/O uses the same constant values and data structure
24738layout as the target-initiated File-I/O protocol. However, the
24739Host I/O packets are structured differently. The target-initiated
24740protocol relies on target memory to store parameters and buffers.
24741Host I/O requests are initiated by @value{GDBN}, and the
24742target's memory is not involved. @xref{File-I/O Remote Protocol
24743Extension}, for more details on the target-initiated protocol.
24744
24745The Host I/O request packets all encode a single operation along with
24746its arguments. They have this format:
24747
24748@table @samp
24749
24750@item vFile:@var{operation}: @var{parameter}@dots{}
24751@var{operation} is the name of the particular request; the target
24752should compare the entire packet name up to the second colon when checking
24753for a supported operation. The format of @var{parameter} depends on
24754the operation. Numbers are always passed in hexadecimal. Negative
24755numbers have an explicit minus sign (i.e.@: two's complement is not
24756used). Strings (e.g.@: filenames) are encoded as a series of
24757hexadecimal bytes. The last argument to a system call may be a
24758buffer of escaped binary data (@pxref{Binary Data}).
24759
24760@end table
24761
24762The valid responses to Host I/O packets are:
24763
24764@table @samp
24765
24766@item F @var{result} [, @var{errno}] [; @var{attachment}]
24767@var{result} is the integer value returned by this operation, usually
24768non-negative for success and -1 for errors. If an error has occured,
24769@var{errno} will be included in the result. @var{errno} will have a
24770value defined by the File-I/O protocol (@pxref{Errno Values}). For
24771operations which return data, @var{attachment} supplies the data as a
24772binary buffer. Binary buffers in response packets are escaped in the
24773normal way (@pxref{Binary Data}). See the individual packet
24774documentation for the interpretation of @var{result} and
24775@var{attachment}.
24776
24777@item
24778An empty response indicates that this operation is not recognized.
24779
24780@end table
24781
24782These are the supported Host I/O operations:
24783
24784@table @samp
24785@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
24786Open a file at @var{pathname} and return a file descriptor for it, or
24787return -1 if an error occurs. @var{pathname} is a string,
24788@var{flags} is an integer indicating a mask of open flags
24789(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
24790of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 24791@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
24792
24793@item vFile:close: @var{fd}
24794Close the open file corresponding to @var{fd} and return 0, or
24795-1 if an error occurs.
24796
24797@item vFile:pread: @var{fd}, @var{count}, @var{offset}
24798Read data from the open file corresponding to @var{fd}. Up to
24799@var{count} bytes will be read from the file, starting at @var{offset}
24800relative to the start of the file. The target may read fewer bytes;
24801common reasons include packet size limits and an end-of-file
24802condition. The number of bytes read is returned. Zero should only be
24803returned for a successful read at the end of the file, or if
24804@var{count} was zero.
24805
24806The data read should be returned as a binary attachment on success.
24807If zero bytes were read, the response should include an empty binary
24808attachment (i.e.@: a trailing semicolon). The return value is the
24809number of target bytes read; the binary attachment may be longer if
24810some characters were escaped.
24811
24812@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
24813Write @var{data} (a binary buffer) to the open file corresponding
24814to @var{fd}. Start the write at @var{offset} from the start of the
24815file. Unlike many @code{write} system calls, there is no
24816separate @var{count} argument; the length of @var{data} in the
24817packet is used. @samp{vFile:write} returns the number of bytes written,
24818which may be shorter than the length of @var{data}, or -1 if an
24819error occurred.
24820
24821@item vFile:unlink: @var{pathname}
24822Delete the file at @var{pathname} on the target. Return 0,
24823or -1 if an error occurs. @var{pathname} is a string.
24824
24825@end table
24826
9a6253be
KB
24827@node Interrupts
24828@section Interrupts
24829@cindex interrupts (remote protocol)
24830
24831When a program on the remote target is running, @value{GDBN} may
24832attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
24833control of which is specified via @value{GDBN}'s @samp{remotebreak}
24834setting (@pxref{set remotebreak}).
24835
24836The precise meaning of @code{BREAK} is defined by the transport
24837mechanism and may, in fact, be undefined. @value{GDBN} does
24838not currently define a @code{BREAK} mechanism for any of the network
24839interfaces.
24840
24841@samp{Ctrl-C}, on the other hand, is defined and implemented for all
24842transport mechanisms. It is represented by sending the single byte
24843@code{0x03} without any of the usual packet overhead described in
24844the Overview section (@pxref{Overview}). When a @code{0x03} byte is
24845transmitted as part of a packet, it is considered to be packet data
24846and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 24847(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
24848@code{0x03} as part of its packet.
24849
24850Stubs are not required to recognize these interrupt mechanisms and the
24851precise meaning associated with receipt of the interrupt is
24852implementation defined. If the stub is successful at interrupting the
24853running program, it is expected that it will send one of the Stop
24854Reply Packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
24855of successfully stopping the program. Interrupts received while the
24856program is stopped will be discarded.
24857
ee2d5c50
AC
24858@node Examples
24859@section Examples
eb12ee30 24860
8e04817f
AC
24861Example sequence of a target being re-started. Notice how the restart
24862does not get any direct output:
eb12ee30 24863
474c8240 24864@smallexample
d2c6833e
AC
24865-> @code{R00}
24866<- @code{+}
8e04817f 24867@emph{target restarts}
d2c6833e 24868-> @code{?}
8e04817f 24869<- @code{+}
d2c6833e
AC
24870<- @code{T001:1234123412341234}
24871-> @code{+}
474c8240 24872@end smallexample
eb12ee30 24873
8e04817f 24874Example sequence of a target being stepped by a single instruction:
eb12ee30 24875
474c8240 24876@smallexample
d2c6833e 24877-> @code{G1445@dots{}}
8e04817f 24878<- @code{+}
d2c6833e
AC
24879-> @code{s}
24880<- @code{+}
24881@emph{time passes}
24882<- @code{T001:1234123412341234}
8e04817f 24883-> @code{+}
d2c6833e 24884-> @code{g}
8e04817f 24885<- @code{+}
d2c6833e
AC
24886<- @code{1455@dots{}}
24887-> @code{+}
474c8240 24888@end smallexample
eb12ee30 24889
79a6e687
BW
24890@node File-I/O Remote Protocol Extension
24891@section File-I/O Remote Protocol Extension
0ce1b118
CV
24892@cindex File-I/O remote protocol extension
24893
24894@menu
24895* File-I/O Overview::
79a6e687
BW
24896* Protocol Basics::
24897* The F Request Packet::
24898* The F Reply Packet::
24899* The Ctrl-C Message::
0ce1b118 24900* Console I/O::
79a6e687 24901* List of Supported Calls::
db2e3e2e 24902* Protocol-specific Representation of Datatypes::
0ce1b118
CV
24903* Constants::
24904* File-I/O Examples::
24905@end menu
24906
24907@node File-I/O Overview
24908@subsection File-I/O Overview
24909@cindex file-i/o overview
24910
9c16f35a 24911The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 24912target to use the host's file system and console I/O to perform various
0ce1b118 24913system calls. System calls on the target system are translated into a
fc320d37
SL
24914remote protocol packet to the host system, which then performs the needed
24915actions and returns a response packet to the target system.
0ce1b118
CV
24916This simulates file system operations even on targets that lack file systems.
24917
fc320d37
SL
24918The protocol is defined to be independent of both the host and target systems.
24919It uses its own internal representation of datatypes and values. Both
0ce1b118 24920@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
24921translating the system-dependent value representations into the internal
24922protocol representations when data is transmitted.
0ce1b118 24923
fc320d37
SL
24924The communication is synchronous. A system call is possible only when
24925@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
24926or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 24927the target is stopped to allow deterministic access to the target's
fc320d37
SL
24928memory. Therefore File-I/O is not interruptible by target signals. On
24929the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 24930(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
24931
24932The target's request to perform a host system call does not finish
24933the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
24934after finishing the system call, the target returns to continuing the
24935previous activity (continue, step). No additional continue or step
24936request from @value{GDBN} is required.
24937
24938@smallexample
f7dc1244 24939(@value{GDBP}) continue
0ce1b118
CV
24940 <- target requests 'system call X'
24941 target is stopped, @value{GDBN} executes system call
3f94c067
BW
24942 -> @value{GDBN} returns result
24943 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
24944 <- target hits breakpoint and sends a Txx packet
24945@end smallexample
24946
fc320d37
SL
24947The protocol only supports I/O on the console and to regular files on
24948the host file system. Character or block special devices, pipes,
24949named pipes, sockets or any other communication method on the host
0ce1b118
CV
24950system are not supported by this protocol.
24951
79a6e687
BW
24952@node Protocol Basics
24953@subsection Protocol Basics
0ce1b118
CV
24954@cindex protocol basics, file-i/o
24955
fc320d37
SL
24956The File-I/O protocol uses the @code{F} packet as the request as well
24957as reply packet. Since a File-I/O system call can only occur when
24958@value{GDBN} is waiting for a response from the continuing or stepping target,
24959the File-I/O request is a reply that @value{GDBN} has to expect as a result
24960of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
24961This @code{F} packet contains all information needed to allow @value{GDBN}
24962to call the appropriate host system call:
24963
24964@itemize @bullet
b383017d 24965@item
0ce1b118
CV
24966A unique identifier for the requested system call.
24967
24968@item
24969All parameters to the system call. Pointers are given as addresses
24970in the target memory address space. Pointers to strings are given as
b383017d 24971pointer/length pair. Numerical values are given as they are.
db2e3e2e 24972Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
24973
24974@end itemize
24975
fc320d37 24976At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
24977
24978@itemize @bullet
b383017d 24979@item
fc320d37
SL
24980If the parameters include pointer values to data needed as input to a
24981system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
24982standard @code{m} packet request. This additional communication has to be
24983expected by the target implementation and is handled as any other @code{m}
24984packet.
24985
24986@item
24987@value{GDBN} translates all value from protocol representation to host
24988representation as needed. Datatypes are coerced into the host types.
24989
24990@item
fc320d37 24991@value{GDBN} calls the system call.
0ce1b118
CV
24992
24993@item
24994It then coerces datatypes back to protocol representation.
24995
24996@item
fc320d37
SL
24997If the system call is expected to return data in buffer space specified
24998by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
24999target using a @code{M} or @code{X} packet. This packet has to be expected
25000by the target implementation and is handled as any other @code{M} or @code{X}
25001packet.
25002
25003@end itemize
25004
25005Eventually @value{GDBN} replies with another @code{F} packet which contains all
25006necessary information for the target to continue. This at least contains
25007
25008@itemize @bullet
25009@item
25010Return value.
25011
25012@item
25013@code{errno}, if has been changed by the system call.
25014
25015@item
25016``Ctrl-C'' flag.
25017
25018@end itemize
25019
25020After having done the needed type and value coercion, the target continues
25021the latest continue or step action.
25022
79a6e687
BW
25023@node The F Request Packet
25024@subsection The @code{F} Request Packet
0ce1b118
CV
25025@cindex file-i/o request packet
25026@cindex @code{F} request packet
25027
25028The @code{F} request packet has the following format:
25029
25030@table @samp
fc320d37 25031@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
25032
25033@var{call-id} is the identifier to indicate the host system call to be called.
25034This is just the name of the function.
25035
fc320d37
SL
25036@var{parameter@dots{}} are the parameters to the system call.
25037Parameters are hexadecimal integer values, either the actual values in case
25038of scalar datatypes, pointers to target buffer space in case of compound
25039datatypes and unspecified memory areas, or pointer/length pairs in case
25040of string parameters. These are appended to the @var{call-id} as a
25041comma-delimited list. All values are transmitted in ASCII
25042string representation, pointer/length pairs separated by a slash.
0ce1b118 25043
b383017d 25044@end table
0ce1b118 25045
fc320d37 25046
0ce1b118 25047
79a6e687
BW
25048@node The F Reply Packet
25049@subsection The @code{F} Reply Packet
0ce1b118
CV
25050@cindex file-i/o reply packet
25051@cindex @code{F} reply packet
25052
25053The @code{F} reply packet has the following format:
25054
25055@table @samp
25056
d3bdde98 25057@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
25058
25059@var{retcode} is the return code of the system call as hexadecimal value.
25060
db2e3e2e
BW
25061@var{errno} is the @code{errno} set by the call, in protocol-specific
25062representation.
0ce1b118
CV
25063This parameter can be omitted if the call was successful.
25064
fc320d37
SL
25065@var{Ctrl-C flag} is only sent if the user requested a break. In this
25066case, @var{errno} must be sent as well, even if the call was successful.
25067The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
25068
25069@smallexample
25070F0,0,C
25071@end smallexample
25072
25073@noindent
fc320d37 25074or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
25075
25076@smallexample
25077F-1,4,C
25078@end smallexample
25079
25080@noindent
db2e3e2e 25081assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
25082
25083@end table
25084
0ce1b118 25085
79a6e687
BW
25086@node The Ctrl-C Message
25087@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
25088@cindex ctrl-c message, in file-i/o protocol
25089
c8aa23ab 25090If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 25091reply packet (@pxref{The F Reply Packet}),
fc320d37 25092the target should behave as if it had
0ce1b118 25093gotten a break message. The meaning for the target is ``system call
fc320d37 25094interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 25095(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 25096packet.
fc320d37
SL
25097
25098It's important for the target to know in which
25099state the system call was interrupted. There are two possible cases:
0ce1b118
CV
25100
25101@itemize @bullet
25102@item
25103The system call hasn't been performed on the host yet.
25104
25105@item
25106The system call on the host has been finished.
25107
25108@end itemize
25109
25110These two states can be distinguished by the target by the value of the
25111returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
25112call hasn't been performed. This is equivalent to the @code{EINTR} handling
25113on POSIX systems. In any other case, the target may presume that the
fc320d37 25114system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
25115as if the break message arrived right after the system call.
25116
fc320d37 25117@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
25118yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
25119@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
25120before the user requests a break, the full action must be finished by
25121@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
25122The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
25123or the full action has been completed.
25124
25125@node Console I/O
25126@subsection Console I/O
25127@cindex console i/o as part of file-i/o
25128
d3e8051b 25129By default and if not explicitly closed by the target system, the file
0ce1b118
CV
25130descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
25131on the @value{GDBN} console is handled as any other file output operation
25132(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
25133by @value{GDBN} so that after the target read request from file descriptor
251340 all following typing is buffered until either one of the following
25135conditions is met:
25136
25137@itemize @bullet
25138@item
c8aa23ab 25139The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
25140@code{read}
25141system call is treated as finished.
25142
25143@item
7f9087cb 25144The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 25145newline.
0ce1b118
CV
25146
25147@item
c8aa23ab
EZ
25148The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
25149character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
25150
25151@end itemize
25152
fc320d37
SL
25153If the user has typed more characters than fit in the buffer given to
25154the @code{read} call, the trailing characters are buffered in @value{GDBN} until
25155either another @code{read(0, @dots{})} is requested by the target, or debugging
25156is stopped at the user's request.
0ce1b118 25157
0ce1b118 25158
79a6e687
BW
25159@node List of Supported Calls
25160@subsection List of Supported Calls
0ce1b118
CV
25161@cindex list of supported file-i/o calls
25162
25163@menu
25164* open::
25165* close::
25166* read::
25167* write::
25168* lseek::
25169* rename::
25170* unlink::
25171* stat/fstat::
25172* gettimeofday::
25173* isatty::
25174* system::
25175@end menu
25176
25177@node open
25178@unnumberedsubsubsec open
25179@cindex open, file-i/o system call
25180
fc320d37
SL
25181@table @asis
25182@item Synopsis:
0ce1b118 25183@smallexample
0ce1b118
CV
25184int open(const char *pathname, int flags);
25185int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
25186@end smallexample
25187
fc320d37
SL
25188@item Request:
25189@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
25190
0ce1b118 25191@noindent
fc320d37 25192@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
25193
25194@table @code
b383017d 25195@item O_CREAT
0ce1b118
CV
25196If the file does not exist it will be created. The host
25197rules apply as far as file ownership and time stamps
25198are concerned.
25199
b383017d 25200@item O_EXCL
fc320d37 25201When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
25202an error and open() fails.
25203
b383017d 25204@item O_TRUNC
0ce1b118 25205If the file already exists and the open mode allows
fc320d37
SL
25206writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
25207truncated to zero length.
0ce1b118 25208
b383017d 25209@item O_APPEND
0ce1b118
CV
25210The file is opened in append mode.
25211
b383017d 25212@item O_RDONLY
0ce1b118
CV
25213The file is opened for reading only.
25214
b383017d 25215@item O_WRONLY
0ce1b118
CV
25216The file is opened for writing only.
25217
b383017d 25218@item O_RDWR
0ce1b118 25219The file is opened for reading and writing.
fc320d37 25220@end table
0ce1b118
CV
25221
25222@noindent
fc320d37 25223Other bits are silently ignored.
0ce1b118 25224
0ce1b118
CV
25225
25226@noindent
fc320d37 25227@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
25228
25229@table @code
b383017d 25230@item S_IRUSR
0ce1b118
CV
25231User has read permission.
25232
b383017d 25233@item S_IWUSR
0ce1b118
CV
25234User has write permission.
25235
b383017d 25236@item S_IRGRP
0ce1b118
CV
25237Group has read permission.
25238
b383017d 25239@item S_IWGRP
0ce1b118
CV
25240Group has write permission.
25241
b383017d 25242@item S_IROTH
0ce1b118
CV
25243Others have read permission.
25244
b383017d 25245@item S_IWOTH
0ce1b118 25246Others have write permission.
fc320d37 25247@end table
0ce1b118
CV
25248
25249@noindent
fc320d37 25250Other bits are silently ignored.
0ce1b118 25251
0ce1b118 25252
fc320d37
SL
25253@item Return value:
25254@code{open} returns the new file descriptor or -1 if an error
25255occurred.
0ce1b118 25256
fc320d37 25257@item Errors:
0ce1b118
CV
25258
25259@table @code
b383017d 25260@item EEXIST
fc320d37 25261@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 25262
b383017d 25263@item EISDIR
fc320d37 25264@var{pathname} refers to a directory.
0ce1b118 25265
b383017d 25266@item EACCES
0ce1b118
CV
25267The requested access is not allowed.
25268
25269@item ENAMETOOLONG
fc320d37 25270@var{pathname} was too long.
0ce1b118 25271
b383017d 25272@item ENOENT
fc320d37 25273A directory component in @var{pathname} does not exist.
0ce1b118 25274
b383017d 25275@item ENODEV
fc320d37 25276@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 25277
b383017d 25278@item EROFS
fc320d37 25279@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
25280write access was requested.
25281
b383017d 25282@item EFAULT
fc320d37 25283@var{pathname} is an invalid pointer value.
0ce1b118 25284
b383017d 25285@item ENOSPC
0ce1b118
CV
25286No space on device to create the file.
25287
b383017d 25288@item EMFILE
0ce1b118
CV
25289The process already has the maximum number of files open.
25290
b383017d 25291@item ENFILE
0ce1b118
CV
25292The limit on the total number of files open on the system
25293has been reached.
25294
b383017d 25295@item EINTR
0ce1b118
CV
25296The call was interrupted by the user.
25297@end table
25298
fc320d37
SL
25299@end table
25300
0ce1b118
CV
25301@node close
25302@unnumberedsubsubsec close
25303@cindex close, file-i/o system call
25304
fc320d37
SL
25305@table @asis
25306@item Synopsis:
0ce1b118 25307@smallexample
0ce1b118 25308int close(int fd);
fc320d37 25309@end smallexample
0ce1b118 25310
fc320d37
SL
25311@item Request:
25312@samp{Fclose,@var{fd}}
0ce1b118 25313
fc320d37
SL
25314@item Return value:
25315@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 25316
fc320d37 25317@item Errors:
0ce1b118
CV
25318
25319@table @code
b383017d 25320@item EBADF
fc320d37 25321@var{fd} isn't a valid open file descriptor.
0ce1b118 25322
b383017d 25323@item EINTR
0ce1b118
CV
25324The call was interrupted by the user.
25325@end table
25326
fc320d37
SL
25327@end table
25328
0ce1b118
CV
25329@node read
25330@unnumberedsubsubsec read
25331@cindex read, file-i/o system call
25332
fc320d37
SL
25333@table @asis
25334@item Synopsis:
0ce1b118 25335@smallexample
0ce1b118 25336int read(int fd, void *buf, unsigned int count);
fc320d37 25337@end smallexample
0ce1b118 25338
fc320d37
SL
25339@item Request:
25340@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 25341
fc320d37 25342@item Return value:
0ce1b118
CV
25343On success, the number of bytes read is returned.
25344Zero indicates end of file. If count is zero, read
b383017d 25345returns zero as well. On error, -1 is returned.
0ce1b118 25346
fc320d37 25347@item Errors:
0ce1b118
CV
25348
25349@table @code
b383017d 25350@item EBADF
fc320d37 25351@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
25352reading.
25353
b383017d 25354@item EFAULT
fc320d37 25355@var{bufptr} is an invalid pointer value.
0ce1b118 25356
b383017d 25357@item EINTR
0ce1b118
CV
25358The call was interrupted by the user.
25359@end table
25360
fc320d37
SL
25361@end table
25362
0ce1b118
CV
25363@node write
25364@unnumberedsubsubsec write
25365@cindex write, file-i/o system call
25366
fc320d37
SL
25367@table @asis
25368@item Synopsis:
0ce1b118 25369@smallexample
0ce1b118 25370int write(int fd, const void *buf, unsigned int count);
fc320d37 25371@end smallexample
0ce1b118 25372
fc320d37
SL
25373@item Request:
25374@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 25375
fc320d37 25376@item Return value:
0ce1b118
CV
25377On success, the number of bytes written are returned.
25378Zero indicates nothing was written. On error, -1
25379is returned.
25380
fc320d37 25381@item Errors:
0ce1b118
CV
25382
25383@table @code
b383017d 25384@item EBADF
fc320d37 25385@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
25386writing.
25387
b383017d 25388@item EFAULT
fc320d37 25389@var{bufptr} is an invalid pointer value.
0ce1b118 25390
b383017d 25391@item EFBIG
0ce1b118 25392An attempt was made to write a file that exceeds the
db2e3e2e 25393host-specific maximum file size allowed.
0ce1b118 25394
b383017d 25395@item ENOSPC
0ce1b118
CV
25396No space on device to write the data.
25397
b383017d 25398@item EINTR
0ce1b118
CV
25399The call was interrupted by the user.
25400@end table
25401
fc320d37
SL
25402@end table
25403
0ce1b118
CV
25404@node lseek
25405@unnumberedsubsubsec lseek
25406@cindex lseek, file-i/o system call
25407
fc320d37
SL
25408@table @asis
25409@item Synopsis:
0ce1b118 25410@smallexample
0ce1b118 25411long lseek (int fd, long offset, int flag);
0ce1b118
CV
25412@end smallexample
25413
fc320d37
SL
25414@item Request:
25415@samp{Flseek,@var{fd},@var{offset},@var{flag}}
25416
25417@var{flag} is one of:
0ce1b118
CV
25418
25419@table @code
b383017d 25420@item SEEK_SET
fc320d37 25421The offset is set to @var{offset} bytes.
0ce1b118 25422
b383017d 25423@item SEEK_CUR
fc320d37 25424The offset is set to its current location plus @var{offset}
0ce1b118
CV
25425bytes.
25426
b383017d 25427@item SEEK_END
fc320d37 25428The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
25429bytes.
25430@end table
25431
fc320d37 25432@item Return value:
0ce1b118
CV
25433On success, the resulting unsigned offset in bytes from
25434the beginning of the file is returned. Otherwise, a
25435value of -1 is returned.
25436
fc320d37 25437@item Errors:
0ce1b118
CV
25438
25439@table @code
b383017d 25440@item EBADF
fc320d37 25441@var{fd} is not a valid open file descriptor.
0ce1b118 25442
b383017d 25443@item ESPIPE
fc320d37 25444@var{fd} is associated with the @value{GDBN} console.
0ce1b118 25445
b383017d 25446@item EINVAL
fc320d37 25447@var{flag} is not a proper value.
0ce1b118 25448
b383017d 25449@item EINTR
0ce1b118
CV
25450The call was interrupted by the user.
25451@end table
25452
fc320d37
SL
25453@end table
25454
0ce1b118
CV
25455@node rename
25456@unnumberedsubsubsec rename
25457@cindex rename, file-i/o system call
25458
fc320d37
SL
25459@table @asis
25460@item Synopsis:
0ce1b118 25461@smallexample
0ce1b118 25462int rename(const char *oldpath, const char *newpath);
fc320d37 25463@end smallexample
0ce1b118 25464
fc320d37
SL
25465@item Request:
25466@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 25467
fc320d37 25468@item Return value:
0ce1b118
CV
25469On success, zero is returned. On error, -1 is returned.
25470
fc320d37 25471@item Errors:
0ce1b118
CV
25472
25473@table @code
b383017d 25474@item EISDIR
fc320d37 25475@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
25476directory.
25477
b383017d 25478@item EEXIST
fc320d37 25479@var{newpath} is a non-empty directory.
0ce1b118 25480
b383017d 25481@item EBUSY
fc320d37 25482@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
25483process.
25484
b383017d 25485@item EINVAL
0ce1b118
CV
25486An attempt was made to make a directory a subdirectory
25487of itself.
25488
b383017d 25489@item ENOTDIR
fc320d37
SL
25490A component used as a directory in @var{oldpath} or new
25491path is not a directory. Or @var{oldpath} is a directory
25492and @var{newpath} exists but is not a directory.
0ce1b118 25493
b383017d 25494@item EFAULT
fc320d37 25495@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 25496
b383017d 25497@item EACCES
0ce1b118
CV
25498No access to the file or the path of the file.
25499
25500@item ENAMETOOLONG
b383017d 25501
fc320d37 25502@var{oldpath} or @var{newpath} was too long.
0ce1b118 25503
b383017d 25504@item ENOENT
fc320d37 25505A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 25506
b383017d 25507@item EROFS
0ce1b118
CV
25508The file is on a read-only filesystem.
25509
b383017d 25510@item ENOSPC
0ce1b118
CV
25511The device containing the file has no room for the new
25512directory entry.
25513
b383017d 25514@item EINTR
0ce1b118
CV
25515The call was interrupted by the user.
25516@end table
25517
fc320d37
SL
25518@end table
25519
0ce1b118
CV
25520@node unlink
25521@unnumberedsubsubsec unlink
25522@cindex unlink, file-i/o system call
25523
fc320d37
SL
25524@table @asis
25525@item Synopsis:
0ce1b118 25526@smallexample
0ce1b118 25527int unlink(const char *pathname);
fc320d37 25528@end smallexample
0ce1b118 25529
fc320d37
SL
25530@item Request:
25531@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 25532
fc320d37 25533@item Return value:
0ce1b118
CV
25534On success, zero is returned. On error, -1 is returned.
25535
fc320d37 25536@item Errors:
0ce1b118
CV
25537
25538@table @code
b383017d 25539@item EACCES
0ce1b118
CV
25540No access to the file or the path of the file.
25541
b383017d 25542@item EPERM
0ce1b118
CV
25543The system does not allow unlinking of directories.
25544
b383017d 25545@item EBUSY
fc320d37 25546The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
25547being used by another process.
25548
b383017d 25549@item EFAULT
fc320d37 25550@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
25551
25552@item ENAMETOOLONG
fc320d37 25553@var{pathname} was too long.
0ce1b118 25554
b383017d 25555@item ENOENT
fc320d37 25556A directory component in @var{pathname} does not exist.
0ce1b118 25557
b383017d 25558@item ENOTDIR
0ce1b118
CV
25559A component of the path is not a directory.
25560
b383017d 25561@item EROFS
0ce1b118
CV
25562The file is on a read-only filesystem.
25563
b383017d 25564@item EINTR
0ce1b118
CV
25565The call was interrupted by the user.
25566@end table
25567
fc320d37
SL
25568@end table
25569
0ce1b118
CV
25570@node stat/fstat
25571@unnumberedsubsubsec stat/fstat
25572@cindex fstat, file-i/o system call
25573@cindex stat, file-i/o system call
25574
fc320d37
SL
25575@table @asis
25576@item Synopsis:
0ce1b118 25577@smallexample
0ce1b118
CV
25578int stat(const char *pathname, struct stat *buf);
25579int fstat(int fd, struct stat *buf);
fc320d37 25580@end smallexample
0ce1b118 25581
fc320d37
SL
25582@item Request:
25583@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
25584@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 25585
fc320d37 25586@item Return value:
0ce1b118
CV
25587On success, zero is returned. On error, -1 is returned.
25588
fc320d37 25589@item Errors:
0ce1b118
CV
25590
25591@table @code
b383017d 25592@item EBADF
fc320d37 25593@var{fd} is not a valid open file.
0ce1b118 25594
b383017d 25595@item ENOENT
fc320d37 25596A directory component in @var{pathname} does not exist or the
0ce1b118
CV
25597path is an empty string.
25598
b383017d 25599@item ENOTDIR
0ce1b118
CV
25600A component of the path is not a directory.
25601
b383017d 25602@item EFAULT
fc320d37 25603@var{pathnameptr} is an invalid pointer value.
0ce1b118 25604
b383017d 25605@item EACCES
0ce1b118
CV
25606No access to the file or the path of the file.
25607
25608@item ENAMETOOLONG
fc320d37 25609@var{pathname} was too long.
0ce1b118 25610
b383017d 25611@item EINTR
0ce1b118
CV
25612The call was interrupted by the user.
25613@end table
25614
fc320d37
SL
25615@end table
25616
0ce1b118
CV
25617@node gettimeofday
25618@unnumberedsubsubsec gettimeofday
25619@cindex gettimeofday, file-i/o system call
25620
fc320d37
SL
25621@table @asis
25622@item Synopsis:
0ce1b118 25623@smallexample
0ce1b118 25624int gettimeofday(struct timeval *tv, void *tz);
fc320d37 25625@end smallexample
0ce1b118 25626
fc320d37
SL
25627@item Request:
25628@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 25629
fc320d37 25630@item Return value:
0ce1b118
CV
25631On success, 0 is returned, -1 otherwise.
25632
fc320d37 25633@item Errors:
0ce1b118
CV
25634
25635@table @code
b383017d 25636@item EINVAL
fc320d37 25637@var{tz} is a non-NULL pointer.
0ce1b118 25638
b383017d 25639@item EFAULT
fc320d37
SL
25640@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
25641@end table
25642
0ce1b118
CV
25643@end table
25644
25645@node isatty
25646@unnumberedsubsubsec isatty
25647@cindex isatty, file-i/o system call
25648
fc320d37
SL
25649@table @asis
25650@item Synopsis:
0ce1b118 25651@smallexample
0ce1b118 25652int isatty(int fd);
fc320d37 25653@end smallexample
0ce1b118 25654
fc320d37
SL
25655@item Request:
25656@samp{Fisatty,@var{fd}}
0ce1b118 25657
fc320d37
SL
25658@item Return value:
25659Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 25660
fc320d37 25661@item Errors:
0ce1b118
CV
25662
25663@table @code
b383017d 25664@item EINTR
0ce1b118
CV
25665The call was interrupted by the user.
25666@end table
25667
fc320d37
SL
25668@end table
25669
25670Note that the @code{isatty} call is treated as a special case: it returns
256711 to the target if the file descriptor is attached
25672to the @value{GDBN} console, 0 otherwise. Implementing through system calls
25673would require implementing @code{ioctl} and would be more complex than
25674needed.
25675
25676
0ce1b118
CV
25677@node system
25678@unnumberedsubsubsec system
25679@cindex system, file-i/o system call
25680
fc320d37
SL
25681@table @asis
25682@item Synopsis:
0ce1b118 25683@smallexample
0ce1b118 25684int system(const char *command);
fc320d37 25685@end smallexample
0ce1b118 25686
fc320d37
SL
25687@item Request:
25688@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 25689
fc320d37 25690@item Return value:
5600ea19
NS
25691If @var{len} is zero, the return value indicates whether a shell is
25692available. A zero return value indicates a shell is not available.
25693For non-zero @var{len}, the value returned is -1 on error and the
25694return status of the command otherwise. Only the exit status of the
25695command is returned, which is extracted from the host's @code{system}
25696return value by calling @code{WEXITSTATUS(retval)}. In case
25697@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 25698
fc320d37 25699@item Errors:
0ce1b118
CV
25700
25701@table @code
b383017d 25702@item EINTR
0ce1b118
CV
25703The call was interrupted by the user.
25704@end table
25705
fc320d37
SL
25706@end table
25707
25708@value{GDBN} takes over the full task of calling the necessary host calls
25709to perform the @code{system} call. The return value of @code{system} on
25710the host is simplified before it's returned
25711to the target. Any termination signal information from the child process
25712is discarded, and the return value consists
25713entirely of the exit status of the called command.
25714
25715Due to security concerns, the @code{system} call is by default refused
25716by @value{GDBN}. The user has to allow this call explicitly with the
25717@code{set remote system-call-allowed 1} command.
25718
25719@table @code
25720@item set remote system-call-allowed
25721@kindex set remote system-call-allowed
25722Control whether to allow the @code{system} calls in the File I/O
25723protocol for the remote target. The default is zero (disabled).
25724
25725@item show remote system-call-allowed
25726@kindex show remote system-call-allowed
25727Show whether the @code{system} calls are allowed in the File I/O
25728protocol.
25729@end table
25730
db2e3e2e
BW
25731@node Protocol-specific Representation of Datatypes
25732@subsection Protocol-specific Representation of Datatypes
25733@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
25734
25735@menu
79a6e687
BW
25736* Integral Datatypes::
25737* Pointer Values::
25738* Memory Transfer::
0ce1b118
CV
25739* struct stat::
25740* struct timeval::
25741@end menu
25742
79a6e687
BW
25743@node Integral Datatypes
25744@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
25745@cindex integral datatypes, in file-i/o protocol
25746
fc320d37
SL
25747The integral datatypes used in the system calls are @code{int},
25748@code{unsigned int}, @code{long}, @code{unsigned long},
25749@code{mode_t}, and @code{time_t}.
0ce1b118 25750
fc320d37 25751@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
25752implemented as 32 bit values in this protocol.
25753
fc320d37 25754@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 25755
0ce1b118
CV
25756@xref{Limits}, for corresponding MIN and MAX values (similar to those
25757in @file{limits.h}) to allow range checking on host and target.
25758
25759@code{time_t} datatypes are defined as seconds since the Epoch.
25760
25761All integral datatypes transferred as part of a memory read or write of a
25762structured datatype e.g.@: a @code{struct stat} have to be given in big endian
25763byte order.
25764
79a6e687
BW
25765@node Pointer Values
25766@unnumberedsubsubsec Pointer Values
0ce1b118
CV
25767@cindex pointer values, in file-i/o protocol
25768
25769Pointers to target data are transmitted as they are. An exception
25770is made for pointers to buffers for which the length isn't
25771transmitted as part of the function call, namely strings. Strings
25772are transmitted as a pointer/length pair, both as hex values, e.g.@:
25773
25774@smallexample
25775@code{1aaf/12}
25776@end smallexample
25777
25778@noindent
25779which is a pointer to data of length 18 bytes at position 0x1aaf.
25780The length is defined as the full string length in bytes, including
fc320d37
SL
25781the trailing null byte. For example, the string @code{"hello world"}
25782at address 0x123456 is transmitted as
0ce1b118
CV
25783
25784@smallexample
fc320d37 25785@code{123456/d}
0ce1b118
CV
25786@end smallexample
25787
79a6e687
BW
25788@node Memory Transfer
25789@unnumberedsubsubsec Memory Transfer
fc320d37
SL
25790@cindex memory transfer, in file-i/o protocol
25791
25792Structured data which is transferred using a memory read or write (for
db2e3e2e 25793example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
25794with all scalar multibyte datatypes being big endian. Translation to
25795this representation needs to be done both by the target before the @code{F}
25796packet is sent, and by @value{GDBN} before
25797it transfers memory to the target. Transferred pointers to structured
25798data should point to the already-coerced data at any time.
0ce1b118 25799
0ce1b118
CV
25800
25801@node struct stat
25802@unnumberedsubsubsec struct stat
25803@cindex struct stat, in file-i/o protocol
25804
fc320d37
SL
25805The buffer of type @code{struct stat} used by the target and @value{GDBN}
25806is defined as follows:
0ce1b118
CV
25807
25808@smallexample
25809struct stat @{
25810 unsigned int st_dev; /* device */
25811 unsigned int st_ino; /* inode */
25812 mode_t st_mode; /* protection */
25813 unsigned int st_nlink; /* number of hard links */
25814 unsigned int st_uid; /* user ID of owner */
25815 unsigned int st_gid; /* group ID of owner */
25816 unsigned int st_rdev; /* device type (if inode device) */
25817 unsigned long st_size; /* total size, in bytes */
25818 unsigned long st_blksize; /* blocksize for filesystem I/O */
25819 unsigned long st_blocks; /* number of blocks allocated */
25820 time_t st_atime; /* time of last access */
25821 time_t st_mtime; /* time of last modification */
25822 time_t st_ctime; /* time of last change */
25823@};
25824@end smallexample
25825
fc320d37 25826The integral datatypes conform to the definitions given in the
79a6e687 25827appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
25828structure is of size 64 bytes.
25829
25830The values of several fields have a restricted meaning and/or
25831range of values.
25832
fc320d37 25833@table @code
0ce1b118 25834
fc320d37
SL
25835@item st_dev
25836A value of 0 represents a file, 1 the console.
0ce1b118 25837
fc320d37
SL
25838@item st_ino
25839No valid meaning for the target. Transmitted unchanged.
0ce1b118 25840
fc320d37
SL
25841@item st_mode
25842Valid mode bits are described in @ref{Constants}. Any other
25843bits have currently no meaning for the target.
0ce1b118 25844
fc320d37
SL
25845@item st_uid
25846@itemx st_gid
25847@itemx st_rdev
25848No valid meaning for the target. Transmitted unchanged.
0ce1b118 25849
fc320d37
SL
25850@item st_atime
25851@itemx st_mtime
25852@itemx st_ctime
25853These values have a host and file system dependent
25854accuracy. Especially on Windows hosts, the file system may not
25855support exact timing values.
25856@end table
0ce1b118 25857
fc320d37
SL
25858The target gets a @code{struct stat} of the above representation and is
25859responsible for coercing it to the target representation before
0ce1b118
CV
25860continuing.
25861
fc320d37
SL
25862Note that due to size differences between the host, target, and protocol
25863representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
25864get truncated on the target.
25865
25866@node struct timeval
25867@unnumberedsubsubsec struct timeval
25868@cindex struct timeval, in file-i/o protocol
25869
fc320d37 25870The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
25871is defined as follows:
25872
25873@smallexample
b383017d 25874struct timeval @{
0ce1b118
CV
25875 time_t tv_sec; /* second */
25876 long tv_usec; /* microsecond */
25877@};
25878@end smallexample
25879
fc320d37 25880The integral datatypes conform to the definitions given in the
79a6e687 25881appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
25882structure is of size 8 bytes.
25883
25884@node Constants
25885@subsection Constants
25886@cindex constants, in file-i/o protocol
25887
25888The following values are used for the constants inside of the
fc320d37 25889protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
25890values before and after the call as needed.
25891
25892@menu
79a6e687
BW
25893* Open Flags::
25894* mode_t Values::
25895* Errno Values::
25896* Lseek Flags::
0ce1b118
CV
25897* Limits::
25898@end menu
25899
79a6e687
BW
25900@node Open Flags
25901@unnumberedsubsubsec Open Flags
0ce1b118
CV
25902@cindex open flags, in file-i/o protocol
25903
25904All values are given in hexadecimal representation.
25905
25906@smallexample
25907 O_RDONLY 0x0
25908 O_WRONLY 0x1
25909 O_RDWR 0x2
25910 O_APPEND 0x8
25911 O_CREAT 0x200
25912 O_TRUNC 0x400
25913 O_EXCL 0x800
25914@end smallexample
25915
79a6e687
BW
25916@node mode_t Values
25917@unnumberedsubsubsec mode_t Values
0ce1b118
CV
25918@cindex mode_t values, in file-i/o protocol
25919
25920All values are given in octal representation.
25921
25922@smallexample
25923 S_IFREG 0100000
25924 S_IFDIR 040000
25925 S_IRUSR 0400
25926 S_IWUSR 0200
25927 S_IXUSR 0100
25928 S_IRGRP 040
25929 S_IWGRP 020
25930 S_IXGRP 010
25931 S_IROTH 04
25932 S_IWOTH 02
25933 S_IXOTH 01
25934@end smallexample
25935
79a6e687
BW
25936@node Errno Values
25937@unnumberedsubsubsec Errno Values
0ce1b118
CV
25938@cindex errno values, in file-i/o protocol
25939
25940All values are given in decimal representation.
25941
25942@smallexample
25943 EPERM 1
25944 ENOENT 2
25945 EINTR 4
25946 EBADF 9
25947 EACCES 13
25948 EFAULT 14
25949 EBUSY 16
25950 EEXIST 17
25951 ENODEV 19
25952 ENOTDIR 20
25953 EISDIR 21
25954 EINVAL 22
25955 ENFILE 23
25956 EMFILE 24
25957 EFBIG 27
25958 ENOSPC 28
25959 ESPIPE 29
25960 EROFS 30
25961 ENAMETOOLONG 91
25962 EUNKNOWN 9999
25963@end smallexample
25964
fc320d37 25965 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
25966 any error value not in the list of supported error numbers.
25967
79a6e687
BW
25968@node Lseek Flags
25969@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
25970@cindex lseek flags, in file-i/o protocol
25971
25972@smallexample
25973 SEEK_SET 0
25974 SEEK_CUR 1
25975 SEEK_END 2
25976@end smallexample
25977
25978@node Limits
25979@unnumberedsubsubsec Limits
25980@cindex limits, in file-i/o protocol
25981
25982All values are given in decimal representation.
25983
25984@smallexample
25985 INT_MIN -2147483648
25986 INT_MAX 2147483647
25987 UINT_MAX 4294967295
25988 LONG_MIN -9223372036854775808
25989 LONG_MAX 9223372036854775807
25990 ULONG_MAX 18446744073709551615
25991@end smallexample
25992
25993@node File-I/O Examples
25994@subsection File-I/O Examples
25995@cindex file-i/o examples
25996
25997Example sequence of a write call, file descriptor 3, buffer is at target
25998address 0x1234, 6 bytes should be written:
25999
26000@smallexample
26001<- @code{Fwrite,3,1234,6}
26002@emph{request memory read from target}
26003-> @code{m1234,6}
26004<- XXXXXX
26005@emph{return "6 bytes written"}
26006-> @code{F6}
26007@end smallexample
26008
26009Example sequence of a read call, file descriptor 3, buffer is at target
26010address 0x1234, 6 bytes should be read:
26011
26012@smallexample
26013<- @code{Fread,3,1234,6}
26014@emph{request memory write to target}
26015-> @code{X1234,6:XXXXXX}
26016@emph{return "6 bytes read"}
26017-> @code{F6}
26018@end smallexample
26019
26020Example sequence of a read call, call fails on the host due to invalid
fc320d37 26021file descriptor (@code{EBADF}):
0ce1b118
CV
26022
26023@smallexample
26024<- @code{Fread,3,1234,6}
26025-> @code{F-1,9}
26026@end smallexample
26027
c8aa23ab 26028Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
26029host is called:
26030
26031@smallexample
26032<- @code{Fread,3,1234,6}
26033-> @code{F-1,4,C}
26034<- @code{T02}
26035@end smallexample
26036
c8aa23ab 26037Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
26038host is called:
26039
26040@smallexample
26041<- @code{Fread,3,1234,6}
26042-> @code{X1234,6:XXXXXX}
26043<- @code{T02}
26044@end smallexample
26045
cfa9d6d9
DJ
26046@node Library List Format
26047@section Library List Format
26048@cindex library list format, remote protocol
26049
26050On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
26051same process as your application to manage libraries. In this case,
26052@value{GDBN} can use the loader's symbol table and normal memory
26053operations to maintain a list of shared libraries. On other
26054platforms, the operating system manages loaded libraries.
26055@value{GDBN} can not retrieve the list of currently loaded libraries
26056through memory operations, so it uses the @samp{qXfer:libraries:read}
26057packet (@pxref{qXfer library list read}) instead. The remote stub
26058queries the target's operating system and reports which libraries
26059are loaded.
26060
26061The @samp{qXfer:libraries:read} packet returns an XML document which
26062lists loaded libraries and their offsets. Each library has an
26063associated name and one or more segment base addresses, which report
26064where the library was loaded in memory. The segment bases are start
26065addresses, not relocation offsets; they do not depend on the library's
26066link-time base addresses.
26067
9cceb671
DJ
26068@value{GDBN} must be linked with the Expat library to support XML
26069library lists. @xref{Expat}.
26070
cfa9d6d9
DJ
26071A simple memory map, with one loaded library relocated by a single
26072offset, looks like this:
26073
26074@smallexample
26075<library-list>
26076 <library name="/lib/libc.so.6">
26077 <segment address="0x10000000"/>
26078 </library>
26079</library-list>
26080@end smallexample
26081
26082The format of a library list is described by this DTD:
26083
26084@smallexample
26085<!-- library-list: Root element with versioning -->
26086<!ELEMENT library-list (library)*>
26087<!ATTLIST library-list version CDATA #FIXED "1.0">
26088<!ELEMENT library (segment)*>
26089<!ATTLIST library name CDATA #REQUIRED>
26090<!ELEMENT segment EMPTY>
26091<!ATTLIST segment address CDATA #REQUIRED>
26092@end smallexample
26093
79a6e687
BW
26094@node Memory Map Format
26095@section Memory Map Format
68437a39
DJ
26096@cindex memory map format
26097
26098To be able to write into flash memory, @value{GDBN} needs to obtain a
26099memory map from the target. This section describes the format of the
26100memory map.
26101
26102The memory map is obtained using the @samp{qXfer:memory-map:read}
26103(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
26104lists memory regions.
26105
26106@value{GDBN} must be linked with the Expat library to support XML
26107memory maps. @xref{Expat}.
26108
26109The top-level structure of the document is shown below:
68437a39
DJ
26110
26111@smallexample
26112<?xml version="1.0"?>
26113<!DOCTYPE memory-map
26114 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
26115 "http://sourceware.org/gdb/gdb-memory-map.dtd">
26116<memory-map>
26117 region...
26118</memory-map>
26119@end smallexample
26120
26121Each region can be either:
26122
26123@itemize
26124
26125@item
26126A region of RAM starting at @var{addr} and extending for @var{length}
26127bytes from there:
26128
26129@smallexample
26130<memory type="ram" start="@var{addr}" length="@var{length}"/>
26131@end smallexample
26132
26133
26134@item
26135A region of read-only memory:
26136
26137@smallexample
26138<memory type="rom" start="@var{addr}" length="@var{length}"/>
26139@end smallexample
26140
26141
26142@item
26143A region of flash memory, with erasure blocks @var{blocksize}
26144bytes in length:
26145
26146@smallexample
26147<memory type="flash" start="@var{addr}" length="@var{length}">
26148 <property name="blocksize">@var{blocksize}</property>
26149</memory>
26150@end smallexample
26151
26152@end itemize
26153
26154Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
26155by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
26156packets to write to addresses in such ranges.
26157
26158The formal DTD for memory map format is given below:
26159
26160@smallexample
26161<!-- ................................................... -->
26162<!-- Memory Map XML DTD ................................ -->
26163<!-- File: memory-map.dtd .............................. -->
26164<!-- .................................... .............. -->
26165<!-- memory-map.dtd -->
26166<!-- memory-map: Root element with versioning -->
26167<!ELEMENT memory-map (memory | property)>
26168<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
26169<!ELEMENT memory (property)>
26170<!-- memory: Specifies a memory region,
26171 and its type, or device. -->
26172<!ATTLIST memory type CDATA #REQUIRED
26173 start CDATA #REQUIRED
26174 length CDATA #REQUIRED
26175 device CDATA #IMPLIED>
26176<!-- property: Generic attribute tag -->
26177<!ELEMENT property (#PCDATA | property)*>
26178<!ATTLIST property name CDATA #REQUIRED>
26179@end smallexample
26180
f418dd93
DJ
26181@include agentexpr.texi
26182
23181151
DJ
26183@node Target Descriptions
26184@appendix Target Descriptions
26185@cindex target descriptions
26186
26187@strong{Warning:} target descriptions are still under active development,
26188and the contents and format may change between @value{GDBN} releases.
26189The format is expected to stabilize in the future.
26190
26191One of the challenges of using @value{GDBN} to debug embedded systems
26192is that there are so many minor variants of each processor
26193architecture in use. It is common practice for vendors to start with
26194a standard processor core --- ARM, PowerPC, or MIPS, for example ---
26195and then make changes to adapt it to a particular market niche. Some
26196architectures have hundreds of variants, available from dozens of
26197vendors. This leads to a number of problems:
26198
26199@itemize @bullet
26200@item
26201With so many different customized processors, it is difficult for
26202the @value{GDBN} maintainers to keep up with the changes.
26203@item
26204Since individual variants may have short lifetimes or limited
26205audiences, it may not be worthwhile to carry information about every
26206variant in the @value{GDBN} source tree.
26207@item
26208When @value{GDBN} does support the architecture of the embedded system
26209at hand, the task of finding the correct architecture name to give the
26210@command{set architecture} command can be error-prone.
26211@end itemize
26212
26213To address these problems, the @value{GDBN} remote protocol allows a
26214target system to not only identify itself to @value{GDBN}, but to
26215actually describe its own features. This lets @value{GDBN} support
26216processor variants it has never seen before --- to the extent that the
26217descriptions are accurate, and that @value{GDBN} understands them.
26218
9cceb671
DJ
26219@value{GDBN} must be linked with the Expat library to support XML
26220target descriptions. @xref{Expat}.
123dc839 26221
23181151
DJ
26222@menu
26223* Retrieving Descriptions:: How descriptions are fetched from a target.
26224* Target Description Format:: The contents of a target description.
123dc839
DJ
26225* Predefined Target Types:: Standard types available for target
26226 descriptions.
26227* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
26228@end menu
26229
26230@node Retrieving Descriptions
26231@section Retrieving Descriptions
26232
26233Target descriptions can be read from the target automatically, or
26234specified by the user manually. The default behavior is to read the
26235description from the target. @value{GDBN} retrieves it via the remote
26236protocol using @samp{qXfer} requests (@pxref{General Query Packets,
26237qXfer}). The @var{annex} in the @samp{qXfer} packet will be
26238@samp{target.xml}. The contents of the @samp{target.xml} annex are an
26239XML document, of the form described in @ref{Target Description
26240Format}.
26241
26242Alternatively, you can specify a file to read for the target description.
26243If a file is set, the target will not be queried. The commands to
26244specify a file are:
26245
26246@table @code
26247@cindex set tdesc filename
26248@item set tdesc filename @var{path}
26249Read the target description from @var{path}.
26250
26251@cindex unset tdesc filename
26252@item unset tdesc filename
26253Do not read the XML target description from a file. @value{GDBN}
26254will use the description supplied by the current target.
26255
26256@cindex show tdesc filename
26257@item show tdesc filename
26258Show the filename to read for a target description, if any.
26259@end table
26260
26261
26262@node Target Description Format
26263@section Target Description Format
26264@cindex target descriptions, XML format
26265
26266A target description annex is an @uref{http://www.w3.org/XML/, XML}
26267document which complies with the Document Type Definition provided in
26268the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
26269means you can use generally available tools like @command{xmllint} to
26270check that your feature descriptions are well-formed and valid.
26271However, to help people unfamiliar with XML write descriptions for
26272their targets, we also describe the grammar here.
26273
123dc839
DJ
26274Target descriptions can identify the architecture of the remote target
26275and (for some architectures) provide information about custom register
26276sets. @value{GDBN} can use this information to autoconfigure for your
26277target, or to warn you if you connect to an unsupported target.
23181151
DJ
26278
26279Here is a simple target description:
26280
123dc839 26281@smallexample
1780a0ed 26282<target version="1.0">
23181151
DJ
26283 <architecture>i386:x86-64</architecture>
26284</target>
123dc839 26285@end smallexample
23181151
DJ
26286
26287@noindent
26288This minimal description only says that the target uses
26289the x86-64 architecture.
26290
123dc839
DJ
26291A target description has the following overall form, with [ ] marking
26292optional elements and @dots{} marking repeatable elements. The elements
26293are explained further below.
23181151 26294
123dc839 26295@smallexample
23181151
DJ
26296<?xml version="1.0"?>
26297<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 26298<target version="1.0">
123dc839
DJ
26299 @r{[}@var{architecture}@r{]}
26300 @r{[}@var{feature}@dots{}@r{]}
23181151 26301</target>
123dc839 26302@end smallexample
23181151
DJ
26303
26304@noindent
26305The description is generally insensitive to whitespace and line
26306breaks, under the usual common-sense rules. The XML version
26307declaration and document type declaration can generally be omitted
26308(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
26309useful for XML validation tools. The @samp{version} attribute for
26310@samp{<target>} may also be omitted, but we recommend
26311including it; if future versions of @value{GDBN} use an incompatible
26312revision of @file{gdb-target.dtd}, they will detect and report
26313the version mismatch.
23181151 26314
108546a0
DJ
26315@subsection Inclusion
26316@cindex target descriptions, inclusion
26317@cindex XInclude
26318@ifnotinfo
26319@cindex <xi:include>
26320@end ifnotinfo
26321
26322It can sometimes be valuable to split a target description up into
26323several different annexes, either for organizational purposes, or to
26324share files between different possible target descriptions. You can
26325divide a description into multiple files by replacing any element of
26326the target description with an inclusion directive of the form:
26327
123dc839 26328@smallexample
108546a0 26329<xi:include href="@var{document}"/>
123dc839 26330@end smallexample
108546a0
DJ
26331
26332@noindent
26333When @value{GDBN} encounters an element of this form, it will retrieve
26334the named XML @var{document}, and replace the inclusion directive with
26335the contents of that document. If the current description was read
26336using @samp{qXfer}, then so will be the included document;
26337@var{document} will be interpreted as the name of an annex. If the
26338current description was read from a file, @value{GDBN} will look for
26339@var{document} as a file in the same directory where it found the
26340original description.
26341
123dc839
DJ
26342@subsection Architecture
26343@cindex <architecture>
26344
26345An @samp{<architecture>} element has this form:
26346
26347@smallexample
26348 <architecture>@var{arch}</architecture>
26349@end smallexample
26350
26351@var{arch} is an architecture name from the same selection
26352accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
26353Debugging Target}).
26354
26355@subsection Features
26356@cindex <feature>
26357
26358Each @samp{<feature>} describes some logical portion of the target
26359system. Features are currently used to describe available CPU
26360registers and the types of their contents. A @samp{<feature>} element
26361has this form:
26362
26363@smallexample
26364<feature name="@var{name}">
26365 @r{[}@var{type}@dots{}@r{]}
26366 @var{reg}@dots{}
26367</feature>
26368@end smallexample
26369
26370@noindent
26371Each feature's name should be unique within the description. The name
26372of a feature does not matter unless @value{GDBN} has some special
26373knowledge of the contents of that feature; if it does, the feature
26374should have its standard name. @xref{Standard Target Features}.
26375
26376@subsection Types
26377
26378Any register's value is a collection of bits which @value{GDBN} must
26379interpret. The default interpretation is a two's complement integer,
26380but other types can be requested by name in the register description.
26381Some predefined types are provided by @value{GDBN} (@pxref{Predefined
26382Target Types}), and the description can define additional composite types.
26383
26384Each type element must have an @samp{id} attribute, which gives
26385a unique (within the containing @samp{<feature>}) name to the type.
26386Types must be defined before they are used.
26387
26388@cindex <vector>
26389Some targets offer vector registers, which can be treated as arrays
26390of scalar elements. These types are written as @samp{<vector>} elements,
26391specifying the array element type, @var{type}, and the number of elements,
26392@var{count}:
26393
26394@smallexample
26395<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
26396@end smallexample
26397
26398@cindex <union>
26399If a register's value is usefully viewed in multiple ways, define it
26400with a union type containing the useful representations. The
26401@samp{<union>} element contains one or more @samp{<field>} elements,
26402each of which has a @var{name} and a @var{type}:
26403
26404@smallexample
26405<union id="@var{id}">
26406 <field name="@var{name}" type="@var{type}"/>
26407 @dots{}
26408</union>
26409@end smallexample
26410
26411@subsection Registers
26412@cindex <reg>
26413
26414Each register is represented as an element with this form:
26415
26416@smallexample
26417<reg name="@var{name}"
26418 bitsize="@var{size}"
26419 @r{[}regnum="@var{num}"@r{]}
26420 @r{[}save-restore="@var{save-restore}"@r{]}
26421 @r{[}type="@var{type}"@r{]}
26422 @r{[}group="@var{group}"@r{]}/>
26423@end smallexample
26424
26425@noindent
26426The components are as follows:
26427
26428@table @var
26429
26430@item name
26431The register's name; it must be unique within the target description.
26432
26433@item bitsize
26434The register's size, in bits.
26435
26436@item regnum
26437The register's number. If omitted, a register's number is one greater
26438than that of the previous register (either in the current feature or in
26439a preceeding feature); the first register in the target description
26440defaults to zero. This register number is used to read or write
26441the register; e.g.@: it is used in the remote @code{p} and @code{P}
26442packets, and registers appear in the @code{g} and @code{G} packets
26443in order of increasing register number.
26444
26445@item save-restore
26446Whether the register should be preserved across inferior function
26447calls; this must be either @code{yes} or @code{no}. The default is
26448@code{yes}, which is appropriate for most registers except for
26449some system control registers; this is not related to the target's
26450ABI.
26451
26452@item type
26453The type of the register. @var{type} may be a predefined type, a type
26454defined in the current feature, or one of the special types @code{int}
26455and @code{float}. @code{int} is an integer type of the correct size
26456for @var{bitsize}, and @code{float} is a floating point type (in the
26457architecture's normal floating point format) of the correct size for
26458@var{bitsize}. The default is @code{int}.
26459
26460@item group
26461The register group to which this register belongs. @var{group} must
26462be either @code{general}, @code{float}, or @code{vector}. If no
26463@var{group} is specified, @value{GDBN} will not display the register
26464in @code{info registers}.
26465
26466@end table
26467
26468@node Predefined Target Types
26469@section Predefined Target Types
26470@cindex target descriptions, predefined types
26471
26472Type definitions in the self-description can build up composite types
26473from basic building blocks, but can not define fundamental types. Instead,
26474standard identifiers are provided by @value{GDBN} for the fundamental
26475types. The currently supported types are:
26476
26477@table @code
26478
26479@item int8
26480@itemx int16
26481@itemx int32
26482@itemx int64
7cc46491 26483@itemx int128
123dc839
DJ
26484Signed integer types holding the specified number of bits.
26485
26486@item uint8
26487@itemx uint16
26488@itemx uint32
26489@itemx uint64
7cc46491 26490@itemx uint128
123dc839
DJ
26491Unsigned integer types holding the specified number of bits.
26492
26493@item code_ptr
26494@itemx data_ptr
26495Pointers to unspecified code and data. The program counter and
26496any dedicated return address register may be marked as code
26497pointers; printing a code pointer converts it into a symbolic
26498address. The stack pointer and any dedicated address registers
26499may be marked as data pointers.
26500
6e3bbd1a
PB
26501@item ieee_single
26502Single precision IEEE floating point.
26503
26504@item ieee_double
26505Double precision IEEE floating point.
26506
123dc839
DJ
26507@item arm_fpa_ext
26508The 12-byte extended precision format used by ARM FPA registers.
26509
26510@end table
26511
26512@node Standard Target Features
26513@section Standard Target Features
26514@cindex target descriptions, standard features
26515
26516A target description must contain either no registers or all the
26517target's registers. If the description contains no registers, then
26518@value{GDBN} will assume a default register layout, selected based on
26519the architecture. If the description contains any registers, the
26520default layout will not be used; the standard registers must be
26521described in the target description, in such a way that @value{GDBN}
26522can recognize them.
26523
26524This is accomplished by giving specific names to feature elements
26525which contain standard registers. @value{GDBN} will look for features
26526with those names and verify that they contain the expected registers;
26527if any known feature is missing required registers, or if any required
26528feature is missing, @value{GDBN} will reject the target
26529description. You can add additional registers to any of the
26530standard features --- @value{GDBN} will display them just as if
26531they were added to an unrecognized feature.
26532
26533This section lists the known features and their expected contents.
26534Sample XML documents for these features are included in the
26535@value{GDBN} source tree, in the directory @file{gdb/features}.
26536
26537Names recognized by @value{GDBN} should include the name of the
26538company or organization which selected the name, and the overall
26539architecture to which the feature applies; so e.g.@: the feature
26540containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
26541
ff6f572f
DJ
26542The names of registers are not case sensitive for the purpose
26543of recognizing standard features, but @value{GDBN} will only display
26544registers using the capitalization used in the description.
26545
e9c17194
VP
26546@menu
26547* ARM Features::
26548* M68K Features::
26549@end menu
26550
26551
26552@node ARM Features
123dc839
DJ
26553@subsection ARM Features
26554@cindex target descriptions, ARM features
26555
26556The @samp{org.gnu.gdb.arm.core} feature is required for ARM targets.
26557It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
26558@samp{lr}, @samp{pc}, and @samp{cpsr}.
26559
26560The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
26561should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
26562
ff6f572f
DJ
26563The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
26564it should contain at least registers @samp{wR0} through @samp{wR15} and
26565@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
26566@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 26567
f8b73d13
DJ
26568@subsection MIPS Features
26569@cindex target descriptions, MIPS features
26570
26571The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
26572It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
26573@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
26574on the target.
26575
26576The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
26577contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
26578registers. They may be 32-bit or 64-bit depending on the target.
26579
26580The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
26581it may be optional in a future version of @value{GDBN}. It should
26582contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
26583@samp{fir}. They may be 32-bit or 64-bit depending on the target.
26584
822b6570
DJ
26585The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
26586contain a single register, @samp{restart}, which is used by the
26587Linux kernel to control restartable syscalls.
26588
e9c17194
VP
26589@node M68K Features
26590@subsection M68K Features
26591@cindex target descriptions, M68K features
26592
26593@table @code
26594@item @samp{org.gnu.gdb.m68k.core}
26595@itemx @samp{org.gnu.gdb.coldfire.core}
26596@itemx @samp{org.gnu.gdb.fido.core}
26597One of those features must be always present.
26598The feature that is present determines which flavor of m86k is
26599used. The feature that is present should contain registers
26600@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
26601@samp{sp}, @samp{ps} and @samp{pc}.
26602
26603@item @samp{org.gnu.gdb.coldfire.fp}
26604This feature is optional. If present, it should contain registers
26605@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
26606@samp{fpiaddr}.
26607@end table
26608
7cc46491
DJ
26609@subsection PowerPC Features
26610@cindex target descriptions, PowerPC features
26611
26612The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
26613targets. It should contain registers @samp{r0} through @samp{r31},
26614@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
26615@samp{xer}. They may be 32-bit or 64-bit depending on the target.
26616
26617The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
26618contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
26619
26620The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
26621contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
26622and @samp{vrsave}.
26623
26624The @samp{org.gnu.gdb.power.spe} feature is optional. It should
26625contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
26626@samp{spefscr}. SPE targets should provide 32-bit registers in
26627@samp{org.gnu.gdb.power.core} and provide the upper halves in
26628@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
26629these to present registers @samp{ev0} through @samp{ev31} to the
26630user.
26631
aab4e0ec 26632@include gpl.texi
eb12ee30 26633
2154891a 26634@raisesections
6826cf00 26635@include fdl.texi
2154891a 26636@lowersections
6826cf00 26637
6d2ebf8b 26638@node Index
c906108c
SS
26639@unnumbered Index
26640
26641@printindex cp
26642
26643@tex
26644% I think something like @colophon should be in texinfo. In the
26645% meantime:
26646\long\def\colophon{\hbox to0pt{}\vfill
26647\centerline{The body of this manual is set in}
26648\centerline{\fontname\tenrm,}
26649\centerline{with headings in {\bf\fontname\tenbf}}
26650\centerline{and examples in {\tt\fontname\tentt}.}
26651\centerline{{\it\fontname\tenit\/},}
26652\centerline{{\bf\fontname\tenbf}, and}
26653\centerline{{\sl\fontname\tensl\/}}
26654\centerline{are used for emphasis.}\vfill}
26655\page\colophon
26656% Blame: doc@cygnus.com, 1991.
26657@end tex
26658
c906108c 26659@bye
This page took 2.628067 seconds and 4 git commands to generate.