daily update
[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,
9d2897ad 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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
89c73ade 24@syncodeindex tp cp
c906108c 25
41afff9a 26@c readline appendices use @vindex, @findex and @ftable,
48e934c6 27@c annotate.texi and gdbmi use @findex.
c906108c 28@syncodeindex vr cp
41afff9a 29@syncodeindex fn cp
c906108c
SS
30
31@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 32@c This is updated by GNU Press.
e9c75b65 33@set EDITION Ninth
c906108c 34
87885426
FN
35@c !!set GDB edit command default editor
36@set EDITOR /bin/ex
c906108c 37
6c0e9fb3 38@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 39
c906108c 40@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 41@c manuals to an info tree.
03727ca6 42@dircategory Software development
96a2c332 43@direntry
03727ca6 44* Gdb: (gdb). The GNU debugger.
96a2c332
SS
45@end direntry
46
a67ec3f4
JM
47@copying
48Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
9d2897ad 491998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
a67ec3f4 50Free Software Foundation, Inc.
c906108c 51
e9c75b65 52Permission is granted to copy, distribute and/or modify this document
4f5d9f07 53under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 54any later version published by the Free Software Foundation; with the
959acfd1
EZ
55Invariant Sections being ``Free Software'' and ``Free Software Needs
56Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
57and with the Back-Cover Texts as in (a) below.
c906108c 58
b8533aec
DJ
59(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
60this GNU Manual. Buying copies from GNU Press supports the FSF in
61developing GNU and promoting software freedom.''
a67ec3f4
JM
62@end copying
63
64@ifnottex
65This file documents the @sc{gnu} debugger @value{GDBN}.
66
67This is the @value{EDITION} Edition, of @cite{Debugging with
68@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
69@ifset VERSION_PACKAGE
70@value{VERSION_PACKAGE}
71@end ifset
72Version @value{GDBVN}.
73
74@insertcopying
75@end ifnottex
c906108c
SS
76
77@titlepage
78@title Debugging with @value{GDBN}
79@subtitle The @sc{gnu} Source-Level Debugger
c906108c 80@sp 1
c906108c 81@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
82@ifset VERSION_PACKAGE
83@sp 1
84@subtitle @value{VERSION_PACKAGE}
85@end ifset
9e9c5ae7 86@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 87@page
c906108c
SS
88@tex
89{\parskip=0pt
c16158bc 90\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
91\hfill {\it Debugging with @value{GDBN}}\par
92\hfill \TeX{}info \texinfoversion\par
93}
94@end tex
53a5351d 95
c906108c 96@vskip 0pt plus 1filll
c906108c 97Published by the Free Software Foundation @*
c02a867d
EZ
9851 Franklin Street, Fifth Floor,
99Boston, MA 02110-1301, USA@*
6d2ebf8b 100ISBN 1-882114-77-9 @*
e9c75b65 101
a67ec3f4 102@insertcopying
3fb6a982
JB
103@page
104This edition of the GDB manual is dedicated to the memory of Fred
105Fish. Fred was a long-standing contributor to GDB and to Free
106software in general. We will miss him.
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
c16158bc
JM
117This is the @value{EDITION} Edition, for @value{GDBN}
118@ifset VERSION_PACKAGE
119@value{VERSION_PACKAGE}
120@end ifset
121Version @value{GDBVN}.
c906108c 122
9d2897ad 123Copyright (C) 1988-2010 Free Software Foundation, Inc.
6d2ebf8b 124
3fb6a982
JB
125This edition of the GDB manual is dedicated to the memory of Fred
126Fish. Fred was a long-standing contributor to GDB and to Free
127software in general. We will miss him.
128
6d2ebf8b
SS
129@menu
130* Summary:: Summary of @value{GDBN}
131* Sample Session:: A sample @value{GDBN} session
132
133* Invocation:: Getting in and out of @value{GDBN}
134* Commands:: @value{GDBN} commands
135* Running:: Running programs under @value{GDBN}
136* Stopping:: Stopping and continuing
bacec72f 137* Reverse Execution:: Running programs backward
a2311334 138* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
139* Stack:: Examining the stack
140* Source:: Examining source files
141* Data:: Examining data
edb3359d 142* Optimized Code:: Debugging optimized code
e2e0bcd1 143* Macros:: Preprocessor Macros
b37052ae 144* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 145* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
146
147* Languages:: Using @value{GDBN} with different languages
148
149* Symbols:: Examining the symbol table
150* Altering:: Altering execution
151* GDB Files:: @value{GDBN} files
152* Targets:: Specifying a debugging target
6b2f586d 153* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
154* Configurations:: Configuration-specific information
155* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 156* Extending GDB:: Extending @value{GDBN}
21c294e6 157* Interpreters:: Command Interpreters
c8f4133a 158* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 159* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 160* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 161* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 162* JIT Interface:: Using the JIT debugging interface.
6d2ebf8b
SS
163
164* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 165
39037522
TT
166@ifset SYSTEM_READLINE
167* Command Line Editing: (rluserman). Command Line Editing
168* Using History Interactively: (history). Using History Interactively
169@end ifset
170@ifclear SYSTEM_READLINE
6d2ebf8b
SS
171* Command Line Editing:: Command Line Editing
172* Using History Interactively:: Using History Interactively
39037522 173@end ifclear
0869d01b 174* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 175* Installing GDB:: Installing GDB
eb12ee30 176* Maintenance Commands:: Maintenance Commands
e0ce93ac 177* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 178* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
179* Target Descriptions:: How targets can describe themselves to
180 @value{GDBN}
07e059b5
VP
181* Operating System Information:: Getting additional information from
182 the operating system
00bf0b85 183* Trace File Format:: GDB trace file format
aab4e0ec
AC
184* Copying:: GNU General Public License says
185 how you can copy and share GDB
6826cf00 186* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
187* Index:: Index
188@end menu
189
6c0e9fb3 190@end ifnottex
c906108c 191
449f3b6c 192@contents
449f3b6c 193
6d2ebf8b 194@node Summary
c906108c
SS
195@unnumbered Summary of @value{GDBN}
196
197The purpose of a debugger such as @value{GDBN} is to allow you to see what is
198going on ``inside'' another program while it executes---or what another
199program was doing at the moment it crashed.
200
201@value{GDBN} can do four main kinds of things (plus other things in support of
202these) to help you catch bugs in the act:
203
204@itemize @bullet
205@item
206Start your program, specifying anything that might affect its behavior.
207
208@item
209Make your program stop on specified conditions.
210
211@item
212Examine what has happened, when your program has stopped.
213
214@item
215Change things in your program, so you can experiment with correcting the
216effects of one bug and go on to learn about another.
217@end itemize
218
49efadf5 219You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 220For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
221For more information, see @ref{C,,C and C++}.
222
6aecb9c2
JB
223Support for D is partial. For information on D, see
224@ref{D,,D}.
225
cce74817 226@cindex Modula-2
e632838e
AC
227Support for Modula-2 is partial. For information on Modula-2, see
228@ref{Modula-2,,Modula-2}.
c906108c 229
f4b8a18d
KW
230Support for OpenCL C is partial. For information on OpenCL C, see
231@ref{OpenCL C,,OpenCL C}.
232
cce74817
JM
233@cindex Pascal
234Debugging Pascal programs which use sets, subranges, file variables, or
235nested functions does not currently work. @value{GDBN} does not support
236entering expressions, printing values, or similar features using Pascal
237syntax.
c906108c 238
c906108c
SS
239@cindex Fortran
240@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 241it may be necessary to refer to some variables with a trailing
cce74817 242underscore.
c906108c 243
b37303ee
AF
244@value{GDBN} can be used to debug programs written in Objective-C,
245using either the Apple/NeXT or the GNU Objective-C runtime.
246
c906108c
SS
247@menu
248* Free Software:: Freely redistributable software
249* Contributors:: Contributors to GDB
250@end menu
251
6d2ebf8b 252@node Free Software
79a6e687 253@unnumberedsec Free Software
c906108c 254
5d161b24 255@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
256General Public License
257(GPL). The GPL gives you the freedom to copy or adapt a licensed
258program---but every person getting a copy also gets with it the
259freedom to modify that copy (which means that they must get access to
260the source code), and the freedom to distribute further copies.
261Typical software companies use copyrights to limit your freedoms; the
262Free Software Foundation uses the GPL to preserve these freedoms.
263
264Fundamentally, the General Public License is a license which says that
265you have these freedoms and that you cannot take these freedoms away
266from anyone else.
267
2666264b 268@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
269
270The biggest deficiency in the free software community today is not in
271the software---it is the lack of good free documentation that we can
272include with the free software. Many of our most important
273programs do not come with free reference manuals and free introductory
274texts. Documentation is an essential part of any software package;
275when an important free software package does not come with a free
276manual and a free tutorial, that is a major gap. We have many such
277gaps today.
278
279Consider Perl, for instance. The tutorial manuals that people
280normally use are non-free. How did this come about? Because the
281authors of those manuals published them with restrictive terms---no
282copying, no modification, source files not available---which exclude
283them from the free software world.
284
285That wasn't the first time this sort of thing happened, and it was far
286from the last. Many times we have heard a GNU user eagerly describe a
287manual that he is writing, his intended contribution to the community,
288only to learn that he had ruined everything by signing a publication
289contract to make it non-free.
290
291Free documentation, like free software, is a matter of freedom, not
292price. The problem with the non-free manual is not that publishers
293charge a price for printed copies---that in itself is fine. (The Free
294Software Foundation sells printed copies of manuals, too.) The
295problem is the restrictions on the use of the manual. Free manuals
296are available in source code form, and give you permission to copy and
297modify. Non-free manuals do not allow this.
298
299The criteria of freedom for a free manual are roughly the same as for
300free software. Redistribution (including the normal kinds of
301commercial redistribution) must be permitted, so that the manual can
302accompany every copy of the program, both on-line and on paper.
303
304Permission for modification of the technical content is crucial too.
305When people modify the software, adding or changing features, if they
306are conscientious they will change the manual too---so they can
307provide accurate and clear documentation for the modified program. A
308manual that leaves you no choice but to write a new manual to document
309a changed version of the program is not really available to our
310community.
311
312Some kinds of limits on the way modification is handled are
313acceptable. For example, requirements to preserve the original
314author's copyright notice, the distribution terms, or the list of
315authors, are ok. It is also no problem to require modified versions
316to include notice that they were modified. Even entire sections that
317may not be deleted or changed are acceptable, as long as they deal
318with nontechnical topics (like this one). These kinds of restrictions
319are acceptable because they don't obstruct the community's normal use
320of the manual.
321
322However, it must be possible to modify all the @emph{technical}
323content of the manual, and then distribute the result in all the usual
324media, through all the usual channels. Otherwise, the restrictions
325obstruct the use of the manual, it is not free, and we need another
326manual to replace it.
327
328Please spread the word about this issue. Our community continues to
329lose manuals to proprietary publishing. If we spread the word that
330free software needs free reference manuals and free tutorials, perhaps
331the next person who wants to contribute by writing documentation will
332realize, before it is too late, that only free manuals contribute to
333the free software community.
334
335If you are writing documentation, please insist on publishing it under
336the GNU Free Documentation License or another free documentation
337license. Remember that this decision requires your approval---you
338don't have to let the publisher decide. Some commercial publishers
339will use a free license if you insist, but they will not propose the
340option; it is up to you to raise the issue and say firmly that this is
341what you want. If the publisher you are dealing with refuses, please
342try other publishers. If you're not sure whether a proposed license
42584a72 343is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
344
345You can encourage commercial publishers to sell more free, copylefted
346manuals and tutorials by buying them, and particularly by buying
347copies from the publishers that paid for their writing or for major
348improvements. Meanwhile, try to avoid buying non-free documentation
349at all. Check the distribution terms of a manual before you buy it,
350and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
351Check the history of the book, and try to reward the publishers that
352have paid or pay the authors to work on it.
959acfd1
EZ
353
354The Free Software Foundation maintains a list of free documentation
355published by other publishers, at
356@url{http://www.fsf.org/doc/other-free-books.html}.
357
6d2ebf8b 358@node Contributors
96a2c332
SS
359@unnumberedsec Contributors to @value{GDBN}
360
361Richard Stallman was the original author of @value{GDBN}, and of many
362other @sc{gnu} programs. Many others have contributed to its
363development. This section attempts to credit major contributors. One
364of the virtues of free software is that everyone is free to contribute
365to it; with regret, we cannot actually acknowledge everyone here. The
366file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
367blow-by-blow account.
368
369Changes much prior to version 2.0 are lost in the mists of time.
370
371@quotation
372@emph{Plea:} Additions to this section are particularly welcome. If you
373or your friends (or enemies, to be evenhanded) have been unfairly
374omitted from this list, we would like to add your names!
375@end quotation
376
377So that they may not regard their many labors as thankless, we
378particularly thank those who shepherded @value{GDBN} through major
379releases:
7ba3cf9c 380Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
381Jim Blandy (release 4.18);
382Jason Molenda (release 4.17);
383Stan Shebs (release 4.14);
384Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
385Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
386John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
387Jim Kingdon (releases 3.5, 3.4, and 3.3);
388and Randy Smith (releases 3.2, 3.1, and 3.0).
389
390Richard Stallman, assisted at various times by Peter TerMaat, Chris
391Hanson, and Richard Mlynarik, handled releases through 2.8.
392
b37052ae
EZ
393Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
394in @value{GDBN}, with significant additional contributions from Per
395Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
396demangler. Early work on C@t{++} was by Peter TerMaat (who also did
397much general update work leading to release 3.0).
c906108c 398
b37052ae 399@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
400object-file formats; BFD was a joint project of David V.
401Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
402
403David Johnson wrote the original COFF support; Pace Willison did
404the original support for encapsulated COFF.
405
0179ffac 406Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
407
408Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
409Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
410support.
411Jean-Daniel Fekete contributed Sun 386i support.
412Chris Hanson improved the HP9000 support.
413Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
414David Johnson contributed Encore Umax support.
415Jyrki Kuoppala contributed Altos 3068 support.
416Jeff Law contributed HP PA and SOM support.
417Keith Packard contributed NS32K support.
418Doug Rabson contributed Acorn Risc Machine support.
419Bob Rusk contributed Harris Nighthawk CX-UX support.
420Chris Smith contributed Convex support (and Fortran debugging).
421Jonathan Stone contributed Pyramid support.
422Michael Tiemann contributed SPARC support.
423Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
424Pace Willison contributed Intel 386 support.
425Jay Vosburgh contributed Symmetry support.
a37295f9 426Marko Mlinar contributed OpenRISC 1000 support.
c906108c 427
1104b9e7 428Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
429
430Rich Schaefer and Peter Schauer helped with support of SunOS shared
431libraries.
432
433Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
434about several machine instruction sets.
435
436Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
437remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
438contributed remote debugging modules for the i960, VxWorks, A29K UDI,
439and RDI targets, respectively.
440
441Brian Fox is the author of the readline libraries providing
442command-line editing and command history.
443
7a292a7a
SS
444Andrew Beers of SUNY Buffalo wrote the language-switching code, the
445Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 446
5d161b24 447Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 448He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 449symbols.
c906108c 450
f24c5e49
KI
451Hitachi America (now Renesas America), Ltd. sponsored the support for
452H8/300, H8/500, and Super-H processors.
c906108c
SS
453
454NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
455
f24c5e49
KI
456Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
457processors.
c906108c
SS
458
459Toshiba sponsored the support for the TX39 Mips processor.
460
461Matsushita sponsored the support for the MN10200 and MN10300 processors.
462
96a2c332 463Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
464
465Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
466watchpoints.
467
468Michael Snyder added support for tracepoints.
469
470Stu Grossman wrote gdbserver.
471
472Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 473nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
474
475The following people at the Hewlett-Packard Company contributed
476support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 477(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
478compiler, and the Text User Interface (nee Terminal User Interface):
479Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
480Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
481provided HP-specific information in this manual.
c906108c 482
b37052ae
EZ
483DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
484Robert Hoehne made significant contributions to the DJGPP port.
485
96a2c332
SS
486Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
487development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
488fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
489Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
490Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
491Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
492Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
493addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
494JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
495Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
496Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
497Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
498Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
499Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
500Zuhn have made contributions both large and small.
c906108c 501
ffed4509
AC
502Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
503Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
504
e2e0bcd1
JB
505Jim Blandy added support for preprocessor macros, while working for Red
506Hat.
c906108c 507
a9967aef
AC
508Andrew Cagney designed @value{GDBN}'s architecture vector. Many
509people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
510Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
511Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
512Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
513with the migration of old architectures to this new framework.
514
c5e30d01
AC
515Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
516unwinder framework, this consisting of a fresh new design featuring
517frame IDs, independent frame sniffers, and the sentinel frame. Mark
518Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
519libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 520trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
521complete rewrite of the architecture's frame code, were carried out by
522Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
523Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
524Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
525Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
526Weigand.
527
ca3bf3bd
DJ
528Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
529Tensilica, Inc.@: contributed support for Xtensa processors. Others
530who have worked on the Xtensa port of @value{GDBN} in the past include
531Steve Tjiang, John Newlin, and Scott Foehner.
532
08be9d71
ME
533Michael Eager and staff of Xilinx, Inc., contributed support for the
534Xilinx MicroBlaze architecture.
535
6d2ebf8b 536@node Sample Session
c906108c
SS
537@chapter A Sample @value{GDBN} Session
538
539You can use this manual at your leisure to read all about @value{GDBN}.
540However, a handful of commands are enough to get started using the
541debugger. This chapter illustrates those commands.
542
543@iftex
544In this sample session, we emphasize user input like this: @b{input},
545to make it easier to pick out from the surrounding output.
546@end iftex
547
548@c FIXME: this example may not be appropriate for some configs, where
549@c FIXME...primary interest is in remote use.
550
551One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
552processor) exhibits the following bug: sometimes, when we change its
553quote strings from the default, the commands used to capture one macro
554definition within another stop working. In the following short @code{m4}
555session, we define a macro @code{foo} which expands to @code{0000}; we
556then use the @code{m4} built-in @code{defn} to define @code{bar} as the
557same thing. However, when we change the open quote string to
558@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
559procedure fails to define a new synonym @code{baz}:
560
561@smallexample
562$ @b{cd gnu/m4}
563$ @b{./m4}
564@b{define(foo,0000)}
565
566@b{foo}
5670000
568@b{define(bar,defn(`foo'))}
569
570@b{bar}
5710000
572@b{changequote(<QUOTE>,<UNQUOTE>)}
573
574@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
575@b{baz}
c8aa23ab 576@b{Ctrl-d}
c906108c
SS
577m4: End of input: 0: fatal error: EOF in string
578@end smallexample
579
580@noindent
581Let us use @value{GDBN} to try to see what is going on.
582
c906108c
SS
583@smallexample
584$ @b{@value{GDBP} m4}
585@c FIXME: this falsifies the exact text played out, to permit smallbook
586@c FIXME... format to come out better.
587@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 588 of it under certain conditions; type "show copying" to see
c906108c 589 the conditions.
5d161b24 590There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
591 for details.
592
593@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
594(@value{GDBP})
595@end smallexample
c906108c
SS
596
597@noindent
598@value{GDBN} reads only enough symbol data to know where to find the
599rest when needed; as a result, the first prompt comes up very quickly.
600We now tell @value{GDBN} to use a narrower display width than usual, so
601that examples fit in this manual.
602
603@smallexample
604(@value{GDBP}) @b{set width 70}
605@end smallexample
606
607@noindent
608We need to see how the @code{m4} built-in @code{changequote} works.
609Having looked at the source, we know the relevant subroutine is
610@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
611@code{break} command.
612
613@smallexample
614(@value{GDBP}) @b{break m4_changequote}
615Breakpoint 1 at 0x62f4: file builtin.c, line 879.
616@end smallexample
617
618@noindent
619Using the @code{run} command, we start @code{m4} running under @value{GDBN}
620control; as long as control does not reach the @code{m4_changequote}
621subroutine, the program runs as usual:
622
623@smallexample
624(@value{GDBP}) @b{run}
625Starting program: /work/Editorial/gdb/gnu/m4/m4
626@b{define(foo,0000)}
627
628@b{foo}
6290000
630@end smallexample
631
632@noindent
633To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
634suspends execution of @code{m4}, displaying information about the
635context where it stops.
636
637@smallexample
638@b{changequote(<QUOTE>,<UNQUOTE>)}
639
5d161b24 640Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
641 at builtin.c:879
642879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
643@end smallexample
644
645@noindent
646Now we use the command @code{n} (@code{next}) to advance execution to
647the next line of the current function.
648
649@smallexample
650(@value{GDBP}) @b{n}
651882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
652 : nil,
653@end smallexample
654
655@noindent
656@code{set_quotes} looks like a promising subroutine. We can go into it
657by using the command @code{s} (@code{step}) instead of @code{next}.
658@code{step} goes to the next line to be executed in @emph{any}
659subroutine, so it steps into @code{set_quotes}.
660
661@smallexample
662(@value{GDBP}) @b{s}
663set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
664 at input.c:530
665530 if (lquote != def_lquote)
666@end smallexample
667
668@noindent
669The display that shows the subroutine where @code{m4} is now
670suspended (and its arguments) is called a stack frame display. It
671shows a summary of the stack. We can use the @code{backtrace}
672command (which can also be spelled @code{bt}), to see where we are
673in the stack as a whole: the @code{backtrace} command displays a
674stack frame for each active subroutine.
675
676@smallexample
677(@value{GDBP}) @b{bt}
678#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
679 at input.c:530
5d161b24 680#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
681 at builtin.c:882
682#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
683#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
684 at macro.c:71
685#4 0x79dc in expand_input () at macro.c:40
686#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
687@end smallexample
688
689@noindent
690We step through a few more lines to see what happens. The first two
691times, we can use @samp{s}; the next two times we use @code{n} to avoid
692falling into the @code{xstrdup} subroutine.
693
694@smallexample
695(@value{GDBP}) @b{s}
6960x3b5c 532 if (rquote != def_rquote)
697(@value{GDBP}) @b{s}
6980x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
699def_lquote : xstrdup(lq);
700(@value{GDBP}) @b{n}
701536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
702 : xstrdup(rq);
703(@value{GDBP}) @b{n}
704538 len_lquote = strlen(rquote);
705@end smallexample
706
707@noindent
708The last line displayed looks a little odd; we can examine the variables
709@code{lquote} and @code{rquote} to see if they are in fact the new left
710and right quotes we specified. We use the command @code{p}
711(@code{print}) to see their values.
712
713@smallexample
714(@value{GDBP}) @b{p lquote}
715$1 = 0x35d40 "<QUOTE>"
716(@value{GDBP}) @b{p rquote}
717$2 = 0x35d50 "<UNQUOTE>"
718@end smallexample
719
720@noindent
721@code{lquote} and @code{rquote} are indeed the new left and right quotes.
722To look at some context, we can display ten lines of source
723surrounding the current line with the @code{l} (@code{list}) command.
724
725@smallexample
726(@value{GDBP}) @b{l}
727533 xfree(rquote);
728534
729535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
730 : xstrdup (lq);
731536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
732 : xstrdup (rq);
733537
734538 len_lquote = strlen(rquote);
735539 len_rquote = strlen(lquote);
736540 @}
737541
738542 void
739@end smallexample
740
741@noindent
742Let us step past the two lines that set @code{len_lquote} and
743@code{len_rquote}, and then examine the values of those variables.
744
745@smallexample
746(@value{GDBP}) @b{n}
747539 len_rquote = strlen(lquote);
748(@value{GDBP}) @b{n}
749540 @}
750(@value{GDBP}) @b{p len_lquote}
751$3 = 9
752(@value{GDBP}) @b{p len_rquote}
753$4 = 7
754@end smallexample
755
756@noindent
757That certainly looks wrong, assuming @code{len_lquote} and
758@code{len_rquote} are meant to be the lengths of @code{lquote} and
759@code{rquote} respectively. We can set them to better values using
760the @code{p} command, since it can print the value of
761any expression---and that expression can include subroutine calls and
762assignments.
763
764@smallexample
765(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
766$5 = 7
767(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
768$6 = 9
769@end smallexample
770
771@noindent
772Is that enough to fix the problem of using the new quotes with the
773@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
774executing with the @code{c} (@code{continue}) command, and then try the
775example that caused trouble initially:
776
777@smallexample
778(@value{GDBP}) @b{c}
779Continuing.
780
781@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
782
783baz
7840000
785@end smallexample
786
787@noindent
788Success! The new quotes now work just as well as the default ones. The
789problem seems to have been just the two typos defining the wrong
790lengths. We allow @code{m4} exit by giving it an EOF as input:
791
792@smallexample
c8aa23ab 793@b{Ctrl-d}
c906108c
SS
794Program exited normally.
795@end smallexample
796
797@noindent
798The message @samp{Program exited normally.} is from @value{GDBN}; it
799indicates @code{m4} has finished executing. We can end our @value{GDBN}
800session with the @value{GDBN} @code{quit} command.
801
802@smallexample
803(@value{GDBP}) @b{quit}
804@end smallexample
c906108c 805
6d2ebf8b 806@node Invocation
c906108c
SS
807@chapter Getting In and Out of @value{GDBN}
808
809This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 810The essentials are:
c906108c 811@itemize @bullet
5d161b24 812@item
53a5351d 813type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 814@item
c8aa23ab 815type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
816@end itemize
817
818@menu
819* Invoking GDB:: How to start @value{GDBN}
820* Quitting GDB:: How to quit @value{GDBN}
821* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 822* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
823@end menu
824
6d2ebf8b 825@node Invoking GDB
c906108c
SS
826@section Invoking @value{GDBN}
827
c906108c
SS
828Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
829@value{GDBN} reads commands from the terminal until you tell it to exit.
830
831You can also run @code{@value{GDBP}} with a variety of arguments and options,
832to specify more of your debugging environment at the outset.
833
c906108c
SS
834The command-line options described here are designed
835to cover a variety of situations; in some environments, some of these
5d161b24 836options may effectively be unavailable.
c906108c
SS
837
838The most usual way to start @value{GDBN} is with one argument,
839specifying an executable program:
840
474c8240 841@smallexample
c906108c 842@value{GDBP} @var{program}
474c8240 843@end smallexample
c906108c 844
c906108c
SS
845@noindent
846You can also start with both an executable program and a core file
847specified:
848
474c8240 849@smallexample
c906108c 850@value{GDBP} @var{program} @var{core}
474c8240 851@end smallexample
c906108c
SS
852
853You can, instead, specify a process ID as a second argument, if you want
854to debug a running process:
855
474c8240 856@smallexample
c906108c 857@value{GDBP} @var{program} 1234
474c8240 858@end smallexample
c906108c
SS
859
860@noindent
861would attach @value{GDBN} to process @code{1234} (unless you also have a file
862named @file{1234}; @value{GDBN} does check for a core file first).
863
c906108c 864Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
865complete operating system; when you use @value{GDBN} as a remote
866debugger attached to a bare board, there may not be any notion of
867``process'', and there is often no way to get a core dump. @value{GDBN}
868will warn you if it is unable to attach or to read core dumps.
c906108c 869
aa26fa3a
TT
870You can optionally have @code{@value{GDBP}} pass any arguments after the
871executable file to the inferior using @code{--args}. This option stops
872option processing.
474c8240 873@smallexample
3f94c067 874@value{GDBP} --args gcc -O2 -c foo.c
474c8240 875@end smallexample
aa26fa3a
TT
876This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
877@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
878
96a2c332 879You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
880@value{GDBN}'s non-warranty, by specifying @code{-silent}:
881
882@smallexample
883@value{GDBP} -silent
884@end smallexample
885
886@noindent
887You can further control how @value{GDBN} starts up by using command-line
888options. @value{GDBN} itself can remind you of the options available.
889
890@noindent
891Type
892
474c8240 893@smallexample
c906108c 894@value{GDBP} -help
474c8240 895@end smallexample
c906108c
SS
896
897@noindent
898to display all available options and briefly describe their use
899(@samp{@value{GDBP} -h} is a shorter equivalent).
900
901All options and command line arguments you give are processed
902in sequential order. The order makes a difference when the
903@samp{-x} option is used.
904
905
906@menu
c906108c
SS
907* File Options:: Choosing files
908* Mode Options:: Choosing modes
6fc08d32 909* Startup:: What @value{GDBN} does during startup
c906108c
SS
910@end menu
911
6d2ebf8b 912@node File Options
79a6e687 913@subsection Choosing Files
c906108c 914
2df3850c 915When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
916specifying an executable file and core file (or process ID). This is
917the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 918@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
919first argument that does not have an associated option flag as
920equivalent to the @samp{-se} option followed by that argument; and the
921second argument that does not have an associated option flag, if any, as
922equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
923If the second argument begins with a decimal digit, @value{GDBN} will
924first attempt to attach to it as a process, and if that fails, attempt
925to open it as a corefile. If you have a corefile whose name begins with
b383017d 926a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 927prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
928
929If @value{GDBN} has not been configured to included core file support,
930such as for most embedded targets, then it will complain about a second
931argument and ignore it.
c906108c
SS
932
933Many options have both long and short forms; both are shown in the
934following list. @value{GDBN} also recognizes the long forms if you truncate
935them, so long as enough of the option is present to be unambiguous.
936(If you prefer, you can flag option arguments with @samp{--} rather
937than @samp{-}, though we illustrate the more usual convention.)
938
d700128c
EZ
939@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
940@c way, both those who look for -foo and --foo in the index, will find
941@c it.
942
c906108c
SS
943@table @code
944@item -symbols @var{file}
945@itemx -s @var{file}
d700128c
EZ
946@cindex @code{--symbols}
947@cindex @code{-s}
c906108c
SS
948Read symbol table from file @var{file}.
949
950@item -exec @var{file}
951@itemx -e @var{file}
d700128c
EZ
952@cindex @code{--exec}
953@cindex @code{-e}
7a292a7a
SS
954Use file @var{file} as the executable file to execute when appropriate,
955and for examining pure data in conjunction with a core dump.
c906108c
SS
956
957@item -se @var{file}
d700128c 958@cindex @code{--se}
c906108c
SS
959Read symbol table from file @var{file} and use it as the executable
960file.
961
c906108c
SS
962@item -core @var{file}
963@itemx -c @var{file}
d700128c
EZ
964@cindex @code{--core}
965@cindex @code{-c}
b383017d 966Use file @var{file} as a core dump to examine.
c906108c 967
19837790
MS
968@item -pid @var{number}
969@itemx -p @var{number}
970@cindex @code{--pid}
971@cindex @code{-p}
972Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
973
974@item -command @var{file}
975@itemx -x @var{file}
d700128c
EZ
976@cindex @code{--command}
977@cindex @code{-x}
95433b34
JB
978Execute commands from file @var{file}. The contents of this file is
979evaluated exactly as the @code{source} command would.
8150ff9c 980@xref{Command Files,, Command files}.
c906108c 981
8a5a3c82
AS
982@item -eval-command @var{command}
983@itemx -ex @var{command}
984@cindex @code{--eval-command}
985@cindex @code{-ex}
986Execute a single @value{GDBN} command.
987
988This option may be used multiple times to call multiple commands. It may
989also be interleaved with @samp{-command} as required.
990
991@smallexample
992@value{GDBP} -ex 'target sim' -ex 'load' \
993 -x setbreakpoints -ex 'run' a.out
994@end smallexample
995
c906108c
SS
996@item -directory @var{directory}
997@itemx -d @var{directory}
d700128c
EZ
998@cindex @code{--directory}
999@cindex @code{-d}
4b505b12 1000Add @var{directory} to the path to search for source and script files.
c906108c 1001
c906108c
SS
1002@item -r
1003@itemx -readnow
d700128c
EZ
1004@cindex @code{--readnow}
1005@cindex @code{-r}
c906108c
SS
1006Read each symbol file's entire symbol table immediately, rather than
1007the default, which is to read it incrementally as it is needed.
1008This makes startup slower, but makes future operations faster.
53a5351d 1009
c906108c
SS
1010@end table
1011
6d2ebf8b 1012@node Mode Options
79a6e687 1013@subsection Choosing Modes
c906108c
SS
1014
1015You can run @value{GDBN} in various alternative modes---for example, in
1016batch mode or quiet mode.
1017
1018@table @code
1019@item -nx
1020@itemx -n
d700128c
EZ
1021@cindex @code{--nx}
1022@cindex @code{-n}
96565e91 1023Do not execute commands found in any initialization files. Normally,
2df3850c
JM
1024@value{GDBN} executes the commands in these files after all the command
1025options and arguments have been processed. @xref{Command Files,,Command
79a6e687 1026Files}.
c906108c
SS
1027
1028@item -quiet
d700128c 1029@itemx -silent
c906108c 1030@itemx -q
d700128c
EZ
1031@cindex @code{--quiet}
1032@cindex @code{--silent}
1033@cindex @code{-q}
c906108c
SS
1034``Quiet''. Do not print the introductory and copyright messages. These
1035messages are also suppressed in batch mode.
1036
1037@item -batch
d700128c 1038@cindex @code{--batch}
c906108c
SS
1039Run in batch mode. Exit with status @code{0} after processing all the
1040command files specified with @samp{-x} (and all commands from
1041initialization files, if not inhibited with @samp{-n}). Exit with
1042nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1043in the command files. Batch mode also disables pagination, sets unlimited
1044terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1045off} were in effect (@pxref{Messages/Warnings}).
c906108c 1046
2df3850c
JM
1047Batch mode may be useful for running @value{GDBN} as a filter, for
1048example to download and run a program on another computer; in order to
1049make this more useful, the message
c906108c 1050
474c8240 1051@smallexample
c906108c 1052Program exited normally.
474c8240 1053@end smallexample
c906108c
SS
1054
1055@noindent
2df3850c
JM
1056(which is ordinarily issued whenever a program running under
1057@value{GDBN} control terminates) is not issued when running in batch
1058mode.
1059
1a088d06
AS
1060@item -batch-silent
1061@cindex @code{--batch-silent}
1062Run in batch mode exactly like @samp{-batch}, but totally silently. All
1063@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1064unaffected). This is much quieter than @samp{-silent} and would be useless
1065for an interactive session.
1066
1067This is particularly useful when using targets that give @samp{Loading section}
1068messages, for example.
1069
1070Note that targets that give their output via @value{GDBN}, as opposed to
1071writing directly to @code{stdout}, will also be made silent.
1072
4b0ad762
AS
1073@item -return-child-result
1074@cindex @code{--return-child-result}
1075The return code from @value{GDBN} will be the return code from the child
1076process (the process being debugged), with the following exceptions:
1077
1078@itemize @bullet
1079@item
1080@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1081internal error. In this case the exit code is the same as it would have been
1082without @samp{-return-child-result}.
1083@item
1084The user quits with an explicit value. E.g., @samp{quit 1}.
1085@item
1086The child process never runs, or is not allowed to terminate, in which case
1087the exit code will be -1.
1088@end itemize
1089
1090This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1091when @value{GDBN} is being used as a remote program loader or simulator
1092interface.
1093
2df3850c
JM
1094@item -nowindows
1095@itemx -nw
d700128c
EZ
1096@cindex @code{--nowindows}
1097@cindex @code{-nw}
2df3850c 1098``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1099(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1100interface. If no GUI is available, this option has no effect.
1101
1102@item -windows
1103@itemx -w
d700128c
EZ
1104@cindex @code{--windows}
1105@cindex @code{-w}
2df3850c
JM
1106If @value{GDBN} includes a GUI, then this option requires it to be
1107used if possible.
c906108c
SS
1108
1109@item -cd @var{directory}
d700128c 1110@cindex @code{--cd}
c906108c
SS
1111Run @value{GDBN} using @var{directory} as its working directory,
1112instead of the current directory.
1113
c906108c
SS
1114@item -fullname
1115@itemx -f
d700128c
EZ
1116@cindex @code{--fullname}
1117@cindex @code{-f}
7a292a7a
SS
1118@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1119subprocess. It tells @value{GDBN} to output the full file name and line
1120number in a standard, recognizable fashion each time a stack frame is
1121displayed (which includes each time your program stops). This
1122recognizable format looks like two @samp{\032} characters, followed by
1123the file name, line number and character position separated by colons,
1124and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1125@samp{\032} characters as a signal to display the source code for the
1126frame.
c906108c 1127
d700128c
EZ
1128@item -epoch
1129@cindex @code{--epoch}
1130The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1131@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1132routines so as to allow Epoch to display values of expressions in a
1133separate window.
1134
1135@item -annotate @var{level}
1136@cindex @code{--annotate}
1137This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1138effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1139(@pxref{Annotations}). The annotation @var{level} controls how much
1140information @value{GDBN} prints together with its prompt, values of
1141expressions, source lines, and other types of output. Level 0 is the
1142normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1143@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1144that control @value{GDBN}, and level 2 has been deprecated.
1145
265eeb58 1146The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1147(@pxref{GDB/MI}).
d700128c 1148
aa26fa3a
TT
1149@item --args
1150@cindex @code{--args}
1151Change interpretation of command line so that arguments following the
1152executable file are passed as command line arguments to the inferior.
1153This option stops option processing.
1154
2df3850c
JM
1155@item -baud @var{bps}
1156@itemx -b @var{bps}
d700128c
EZ
1157@cindex @code{--baud}
1158@cindex @code{-b}
c906108c
SS
1159Set the line speed (baud rate or bits per second) of any serial
1160interface used by @value{GDBN} for remote debugging.
c906108c 1161
f47b1503
AS
1162@item -l @var{timeout}
1163@cindex @code{-l}
1164Set the timeout (in seconds) of any communication used by @value{GDBN}
1165for remote debugging.
1166
c906108c 1167@item -tty @var{device}
d700128c
EZ
1168@itemx -t @var{device}
1169@cindex @code{--tty}
1170@cindex @code{-t}
c906108c
SS
1171Run using @var{device} for your program's standard input and output.
1172@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1173
53a5351d 1174@c resolve the situation of these eventually
c4555f82
SC
1175@item -tui
1176@cindex @code{--tui}
d0d5df6f
AC
1177Activate the @dfn{Text User Interface} when starting. The Text User
1178Interface manages several text windows on the terminal, showing
1179source, assembly, registers and @value{GDBN} command outputs
1180(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1181Text User Interface can be enabled by invoking the program
46ba6afa 1182@samp{@value{GDBTUI}}. Do not use this option if you run @value{GDBN} from
d0d5df6f 1183Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1184
1185@c @item -xdb
d700128c 1186@c @cindex @code{--xdb}
53a5351d
JM
1187@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1188@c For information, see the file @file{xdb_trans.html}, which is usually
1189@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1190@c systems.
1191
d700128c
EZ
1192@item -interpreter @var{interp}
1193@cindex @code{--interpreter}
1194Use the interpreter @var{interp} for interface with the controlling
1195program or device. This option is meant to be set by programs which
94bbb2c0 1196communicate with @value{GDBN} using it as a back end.
21c294e6 1197@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1198
da0f9dcd 1199@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1200@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1201The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1202previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1203selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1204@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1205
1206@item -write
1207@cindex @code{--write}
1208Open the executable and core files for both reading and writing. This
1209is equivalent to the @samp{set write on} command inside @value{GDBN}
1210(@pxref{Patching}).
1211
1212@item -statistics
1213@cindex @code{--statistics}
1214This option causes @value{GDBN} to print statistics about time and
1215memory usage after it completes each command and returns to the prompt.
1216
1217@item -version
1218@cindex @code{--version}
1219This option causes @value{GDBN} to print its version number and
1220no-warranty blurb, and exit.
1221
c906108c
SS
1222@end table
1223
6fc08d32 1224@node Startup
79a6e687 1225@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1226@cindex @value{GDBN} startup
1227
1228Here's the description of what @value{GDBN} does during session startup:
1229
1230@enumerate
1231@item
1232Sets up the command interpreter as specified by the command line
1233(@pxref{Mode Options, interpreter}).
1234
1235@item
1236@cindex init file
098b41a6
JG
1237Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1238used when building @value{GDBN}; @pxref{System-wide configuration,
1239 ,System-wide configuration and settings}) and executes all the commands in
1240that file.
1241
1242@item
1243Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1244DOS/Windows systems, the home directory is the one pointed to by the
1245@code{HOME} environment variable.} and executes all the commands in
1246that file.
1247
1248@item
1249Processes command line options and operands.
1250
1251@item
1252Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1253working directory. This is only done if the current directory is
1254different from your home directory. Thus, you can have more than one
1255init file, one generic in your home directory, and another, specific
1256to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1257@value{GDBN}.
1258
1259@item
1260Reads command files specified by the @samp{-x} option. @xref{Command
1261Files}, for more details about @value{GDBN} command files.
1262
1263@item
1264Reads the command history recorded in the @dfn{history file}.
d620b259 1265@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1266files where @value{GDBN} records it.
1267@end enumerate
1268
1269Init files use the same syntax as @dfn{command files} (@pxref{Command
1270Files}) and are processed by @value{GDBN} in the same way. The init
1271file in your home directory can set options (such as @samp{set
1272complaints}) that affect subsequent processing of command line options
1273and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1274option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1275
098b41a6
JG
1276To display the list of init files loaded by gdb at startup, you
1277can use @kbd{gdb --help}.
1278
6fc08d32
EZ
1279@cindex init file name
1280@cindex @file{.gdbinit}
119b882a 1281@cindex @file{gdb.ini}
8807d78b 1282The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1283The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1284the limitations of file names imposed by DOS filesystems. The Windows
1285ports of @value{GDBN} use the standard name, but if they find a
1286@file{gdb.ini} file, they warn you about that and suggest to rename
1287the file to the standard name.
1288
6fc08d32 1289
6d2ebf8b 1290@node Quitting GDB
c906108c
SS
1291@section Quitting @value{GDBN}
1292@cindex exiting @value{GDBN}
1293@cindex leaving @value{GDBN}
1294
1295@table @code
1296@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1297@kindex q @r{(@code{quit})}
96a2c332
SS
1298@item quit @r{[}@var{expression}@r{]}
1299@itemx q
1300To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1301@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1302do not supply @var{expression}, @value{GDBN} will terminate normally;
1303otherwise it will terminate using the result of @var{expression} as the
1304error code.
c906108c
SS
1305@end table
1306
1307@cindex interrupt
c8aa23ab 1308An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1309terminates the action of any @value{GDBN} command that is in progress and
1310returns to @value{GDBN} command level. It is safe to type the interrupt
1311character at any time because @value{GDBN} does not allow it to take effect
1312until a time when it is safe.
1313
c906108c
SS
1314If you have been using @value{GDBN} to control an attached process or
1315device, you can release it with the @code{detach} command
79a6e687 1316(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1317
6d2ebf8b 1318@node Shell Commands
79a6e687 1319@section Shell Commands
c906108c
SS
1320
1321If you need to execute occasional shell commands during your
1322debugging session, there is no need to leave or suspend @value{GDBN}; you can
1323just use the @code{shell} command.
1324
1325@table @code
1326@kindex shell
1327@cindex shell escape
1328@item shell @var{command string}
1329Invoke a standard shell to execute @var{command string}.
c906108c 1330If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1331shell to run. Otherwise @value{GDBN} uses the default shell
1332(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1333@end table
1334
1335The utility @code{make} is often needed in development environments.
1336You do not have to use the @code{shell} command for this purpose in
1337@value{GDBN}:
1338
1339@table @code
1340@kindex make
1341@cindex calling make
1342@item make @var{make-args}
1343Execute the @code{make} program with the specified
1344arguments. This is equivalent to @samp{shell make @var{make-args}}.
1345@end table
1346
79a6e687
BW
1347@node Logging Output
1348@section Logging Output
0fac0b41 1349@cindex logging @value{GDBN} output
9c16f35a 1350@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1351
1352You may want to save the output of @value{GDBN} commands to a file.
1353There are several commands to control @value{GDBN}'s logging.
1354
1355@table @code
1356@kindex set logging
1357@item set logging on
1358Enable logging.
1359@item set logging off
1360Disable logging.
9c16f35a 1361@cindex logging file name
0fac0b41
DJ
1362@item set logging file @var{file}
1363Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1364@item set logging overwrite [on|off]
1365By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1366you want @code{set logging on} to overwrite the logfile instead.
1367@item set logging redirect [on|off]
1368By default, @value{GDBN} output will go to both the terminal and the logfile.
1369Set @code{redirect} if you want output to go only to the log file.
1370@kindex show logging
1371@item show logging
1372Show the current values of the logging settings.
1373@end table
1374
6d2ebf8b 1375@node Commands
c906108c
SS
1376@chapter @value{GDBN} Commands
1377
1378You can abbreviate a @value{GDBN} command to the first few letters of the command
1379name, if that abbreviation is unambiguous; and you can repeat certain
1380@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1381key to get @value{GDBN} to fill out the rest of a word in a command (or to
1382show you the alternatives available, if there is more than one possibility).
1383
1384@menu
1385* Command Syntax:: How to give commands to @value{GDBN}
1386* Completion:: Command completion
1387* Help:: How to ask @value{GDBN} for help
1388@end menu
1389
6d2ebf8b 1390@node Command Syntax
79a6e687 1391@section Command Syntax
c906108c
SS
1392
1393A @value{GDBN} command is a single line of input. There is no limit on
1394how long it can be. It starts with a command name, which is followed by
1395arguments whose meaning depends on the command name. For example, the
1396command @code{step} accepts an argument which is the number of times to
1397step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1398with no arguments. Some commands do not allow any arguments.
c906108c
SS
1399
1400@cindex abbreviation
1401@value{GDBN} command names may always be truncated if that abbreviation is
1402unambiguous. Other possible command abbreviations are listed in the
1403documentation for individual commands. In some cases, even ambiguous
1404abbreviations are allowed; for example, @code{s} is specially defined as
1405equivalent to @code{step} even though there are other commands whose
1406names start with @code{s}. You can test abbreviations by using them as
1407arguments to the @code{help} command.
1408
1409@cindex repeating commands
41afff9a 1410@kindex RET @r{(repeat last command)}
c906108c 1411A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1412repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1413will not repeat this way; these are commands whose unintentional
1414repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1415repeat. User-defined commands can disable this feature; see
1416@ref{Define, dont-repeat}.
c906108c
SS
1417
1418The @code{list} and @code{x} commands, when you repeat them with
1419@key{RET}, construct new arguments rather than repeating
1420exactly as typed. This permits easy scanning of source or memory.
1421
1422@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1423output, in a way similar to the common utility @code{more}
79a6e687 1424(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1425@key{RET} too many in this situation, @value{GDBN} disables command
1426repetition after any command that generates this sort of display.
1427
41afff9a 1428@kindex # @r{(a comment)}
c906108c
SS
1429@cindex comment
1430Any text from a @kbd{#} to the end of the line is a comment; it does
1431nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1432Files,,Command Files}).
c906108c 1433
88118b3a 1434@cindex repeating command sequences
c8aa23ab
EZ
1435@kindex Ctrl-o @r{(operate-and-get-next)}
1436The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1437commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1438then fetches the next line relative to the current line from the history
1439for editing.
1440
6d2ebf8b 1441@node Completion
79a6e687 1442@section Command Completion
c906108c
SS
1443
1444@cindex completion
1445@cindex word completion
1446@value{GDBN} can fill in the rest of a word in a command for you, if there is
1447only one possibility; it can also show you what the valid possibilities
1448are for the next word in a command, at any time. This works for @value{GDBN}
1449commands, @value{GDBN} subcommands, and the names of symbols in your program.
1450
1451Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1452of a word. If there is only one possibility, @value{GDBN} fills in the
1453word, and waits for you to finish the command (or press @key{RET} to
1454enter it). For example, if you type
1455
1456@c FIXME "@key" does not distinguish its argument sufficiently to permit
1457@c complete accuracy in these examples; space introduced for clarity.
1458@c If texinfo enhancements make it unnecessary, it would be nice to
1459@c replace " @key" by "@key" in the following...
474c8240 1460@smallexample
c906108c 1461(@value{GDBP}) info bre @key{TAB}
474c8240 1462@end smallexample
c906108c
SS
1463
1464@noindent
1465@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1466the only @code{info} subcommand beginning with @samp{bre}:
1467
474c8240 1468@smallexample
c906108c 1469(@value{GDBP}) info breakpoints
474c8240 1470@end smallexample
c906108c
SS
1471
1472@noindent
1473You can either press @key{RET} at this point, to run the @code{info
1474breakpoints} command, or backspace and enter something else, if
1475@samp{breakpoints} does not look like the command you expected. (If you
1476were sure you wanted @code{info breakpoints} in the first place, you
1477might as well just type @key{RET} immediately after @samp{info bre},
1478to exploit command abbreviations rather than command completion).
1479
1480If there is more than one possibility for the next word when you press
1481@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1482characters and try again, or just press @key{TAB} a second time;
1483@value{GDBN} displays all the possible completions for that word. For
1484example, you might want to set a breakpoint on a subroutine whose name
1485begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1486just sounds the bell. Typing @key{TAB} again displays all the
1487function names in your program that begin with those characters, for
1488example:
1489
474c8240 1490@smallexample
c906108c
SS
1491(@value{GDBP}) b make_ @key{TAB}
1492@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1493make_a_section_from_file make_environ
1494make_abs_section make_function_type
1495make_blockvector make_pointer_type
1496make_cleanup make_reference_type
c906108c
SS
1497make_command make_symbol_completion_list
1498(@value{GDBP}) b make_
474c8240 1499@end smallexample
c906108c
SS
1500
1501@noindent
1502After displaying the available possibilities, @value{GDBN} copies your
1503partial input (@samp{b make_} in the example) so you can finish the
1504command.
1505
1506If you just want to see the list of alternatives in the first place, you
b37052ae 1507can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1508means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1509key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1510one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1511
1512@cindex quotes in commands
1513@cindex completion of quoted strings
1514Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1515parentheses or other characters that @value{GDBN} normally excludes from
1516its notion of a word. To permit word completion to work in this
1517situation, you may enclose words in @code{'} (single quote marks) in
1518@value{GDBN} commands.
c906108c 1519
c906108c 1520The most likely situation where you might need this is in typing the
b37052ae
EZ
1521name of a C@t{++} function. This is because C@t{++} allows function
1522overloading (multiple definitions of the same function, distinguished
1523by argument type). For example, when you want to set a breakpoint you
1524may need to distinguish whether you mean the version of @code{name}
1525that takes an @code{int} parameter, @code{name(int)}, or the version
1526that takes a @code{float} parameter, @code{name(float)}. To use the
1527word-completion facilities in this situation, type a single quote
1528@code{'} at the beginning of the function name. This alerts
1529@value{GDBN} that it may need to consider more information than usual
1530when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1531
474c8240 1532@smallexample
96a2c332 1533(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1534bubble(double,double) bubble(int,int)
1535(@value{GDBP}) b 'bubble(
474c8240 1536@end smallexample
c906108c
SS
1537
1538In some cases, @value{GDBN} can tell that completing a name requires using
1539quotes. When this happens, @value{GDBN} inserts the quote for you (while
1540completing as much as it can) if you do not type the quote in the first
1541place:
1542
474c8240 1543@smallexample
c906108c
SS
1544(@value{GDBP}) b bub @key{TAB}
1545@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1546(@value{GDBP}) b 'bubble(
474c8240 1547@end smallexample
c906108c
SS
1548
1549@noindent
1550In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1551you have not yet started typing the argument list when you ask for
1552completion on an overloaded symbol.
1553
79a6e687
BW
1554For more information about overloaded functions, see @ref{C Plus Plus
1555Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1556overload-resolution off} to disable overload resolution;
79a6e687 1557see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1558
65d12d83
TT
1559@cindex completion of structure field names
1560@cindex structure field name completion
1561@cindex completion of union field names
1562@cindex union field name completion
1563When completing in an expression which looks up a field in a
1564structure, @value{GDBN} also tries@footnote{The completer can be
1565confused by certain kinds of invalid expressions. Also, it only
1566examines the static type of the expression, not the dynamic type.} to
1567limit completions to the field names available in the type of the
1568left-hand-side:
1569
1570@smallexample
1571(@value{GDBP}) p gdb_stdout.@kbd{M-?}
1572magic to_delete to_fputs to_put to_rewind
1573to_data to_flush to_isatty to_read to_write
1574@end smallexample
1575
1576@noindent
1577This is because the @code{gdb_stdout} is a variable of the type
1578@code{struct ui_file} that is defined in @value{GDBN} sources as
1579follows:
1580
1581@smallexample
1582struct ui_file
1583@{
1584 int *magic;
1585 ui_file_flush_ftype *to_flush;
1586 ui_file_write_ftype *to_write;
1587 ui_file_fputs_ftype *to_fputs;
1588 ui_file_read_ftype *to_read;
1589 ui_file_delete_ftype *to_delete;
1590 ui_file_isatty_ftype *to_isatty;
1591 ui_file_rewind_ftype *to_rewind;
1592 ui_file_put_ftype *to_put;
1593 void *to_data;
1594@}
1595@end smallexample
1596
c906108c 1597
6d2ebf8b 1598@node Help
79a6e687 1599@section Getting Help
c906108c
SS
1600@cindex online documentation
1601@kindex help
1602
5d161b24 1603You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1604using the command @code{help}.
1605
1606@table @code
41afff9a 1607@kindex h @r{(@code{help})}
c906108c
SS
1608@item help
1609@itemx h
1610You can use @code{help} (abbreviated @code{h}) with no arguments to
1611display a short list of named classes of commands:
1612
1613@smallexample
1614(@value{GDBP}) help
1615List of classes of commands:
1616
2df3850c 1617aliases -- Aliases of other commands
c906108c 1618breakpoints -- Making program stop at certain points
2df3850c 1619data -- Examining data
c906108c 1620files -- Specifying and examining files
2df3850c
JM
1621internals -- Maintenance commands
1622obscure -- Obscure features
1623running -- Running the program
1624stack -- Examining the stack
c906108c
SS
1625status -- Status inquiries
1626support -- Support facilities
12c27660 1627tracepoints -- Tracing of program execution without
96a2c332 1628 stopping the program
c906108c 1629user-defined -- User-defined commands
c906108c 1630
5d161b24 1631Type "help" followed by a class name for a list of
c906108c 1632commands in that class.
5d161b24 1633Type "help" followed by command name for full
c906108c
SS
1634documentation.
1635Command name abbreviations are allowed if unambiguous.
1636(@value{GDBP})
1637@end smallexample
96a2c332 1638@c the above line break eliminates huge line overfull...
c906108c
SS
1639
1640@item help @var{class}
1641Using one of the general help classes as an argument, you can get a
1642list of the individual commands in that class. For example, here is the
1643help display for the class @code{status}:
1644
1645@smallexample
1646(@value{GDBP}) help status
1647Status inquiries.
1648
1649List of commands:
1650
1651@c Line break in "show" line falsifies real output, but needed
1652@c to fit in smallbook page size.
2df3850c 1653info -- Generic command for showing things
12c27660 1654 about the program being debugged
2df3850c 1655show -- Generic command for showing things
12c27660 1656 about the debugger
c906108c 1657
5d161b24 1658Type "help" followed by command name for full
c906108c
SS
1659documentation.
1660Command name abbreviations are allowed if unambiguous.
1661(@value{GDBP})
1662@end smallexample
1663
1664@item help @var{command}
1665With a command name as @code{help} argument, @value{GDBN} displays a
1666short paragraph on how to use that command.
1667
6837a0a2
DB
1668@kindex apropos
1669@item apropos @var{args}
09d4efe1 1670The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1671commands, and their documentation, for the regular expression specified in
99e008fe 1672@var{args}. It prints out all matches found. For example:
6837a0a2
DB
1673
1674@smallexample
1675apropos reload
1676@end smallexample
1677
b37052ae
EZ
1678@noindent
1679results in:
6837a0a2
DB
1680
1681@smallexample
6d2ebf8b
SS
1682@c @group
1683set symbol-reloading -- Set dynamic symbol table reloading
12c27660 1684 multiple times in one run
6d2ebf8b 1685show symbol-reloading -- Show dynamic symbol table reloading
12c27660 1686 multiple times in one run
6d2ebf8b 1687@c @end group
6837a0a2
DB
1688@end smallexample
1689
c906108c
SS
1690@kindex complete
1691@item complete @var{args}
1692The @code{complete @var{args}} command lists all the possible completions
1693for the beginning of a command. Use @var{args} to specify the beginning of the
1694command you want completed. For example:
1695
1696@smallexample
1697complete i
1698@end smallexample
1699
1700@noindent results in:
1701
1702@smallexample
1703@group
2df3850c
JM
1704if
1705ignore
c906108c
SS
1706info
1707inspect
c906108c
SS
1708@end group
1709@end smallexample
1710
1711@noindent This is intended for use by @sc{gnu} Emacs.
1712@end table
1713
1714In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1715and @code{show} to inquire about the state of your program, or the state
1716of @value{GDBN} itself. Each command supports many topics of inquiry; this
1717manual introduces each of them in the appropriate context. The listings
1718under @code{info} and under @code{show} in the Index point to
1719all the sub-commands. @xref{Index}.
1720
1721@c @group
1722@table @code
1723@kindex info
41afff9a 1724@kindex i @r{(@code{info})}
c906108c
SS
1725@item info
1726This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1727program. For example, you can show the arguments passed to a function
c906108c
SS
1728with @code{info args}, list the registers currently in use with @code{info
1729registers}, or list the breakpoints you have set with @code{info breakpoints}.
1730You can get a complete list of the @code{info} sub-commands with
1731@w{@code{help info}}.
1732
1733@kindex set
1734@item set
5d161b24 1735You can assign the result of an expression to an environment variable with
c906108c
SS
1736@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1737@code{set prompt $}.
1738
1739@kindex show
1740@item show
5d161b24 1741In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1742@value{GDBN} itself.
1743You can change most of the things you can @code{show}, by using the
1744related command @code{set}; for example, you can control what number
1745system is used for displays with @code{set radix}, or simply inquire
1746which is currently in use with @code{show radix}.
1747
1748@kindex info set
1749To display all the settable parameters and their current
1750values, you can use @code{show} with no arguments; you may also use
1751@code{info set}. Both commands produce the same display.
1752@c FIXME: "info set" violates the rule that "info" is for state of
1753@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1754@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1755@end table
1756@c @end group
1757
1758Here are three miscellaneous @code{show} subcommands, all of which are
1759exceptional in lacking corresponding @code{set} commands:
1760
1761@table @code
1762@kindex show version
9c16f35a 1763@cindex @value{GDBN} version number
c906108c
SS
1764@item show version
1765Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1766information in @value{GDBN} bug-reports. If multiple versions of
1767@value{GDBN} are in use at your site, you may need to determine which
1768version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1769commands are introduced, and old ones may wither away. Also, many
1770system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1771variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1772The version number is the same as the one announced when you start
1773@value{GDBN}.
c906108c
SS
1774
1775@kindex show copying
09d4efe1 1776@kindex info copying
9c16f35a 1777@cindex display @value{GDBN} copyright
c906108c 1778@item show copying
09d4efe1 1779@itemx info copying
c906108c
SS
1780Display information about permission for copying @value{GDBN}.
1781
1782@kindex show warranty
09d4efe1 1783@kindex info warranty
c906108c 1784@item show warranty
09d4efe1 1785@itemx info warranty
2df3850c 1786Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1787if your version of @value{GDBN} comes with one.
2df3850c 1788
c906108c
SS
1789@end table
1790
6d2ebf8b 1791@node Running
c906108c
SS
1792@chapter Running Programs Under @value{GDBN}
1793
1794When you run a program under @value{GDBN}, you must first generate
1795debugging information when you compile it.
7a292a7a
SS
1796
1797You may start @value{GDBN} with its arguments, if any, in an environment
1798of your choice. If you are doing native debugging, you may redirect
1799your program's input and output, debug an already running process, or
1800kill a child process.
c906108c
SS
1801
1802@menu
1803* Compilation:: Compiling for debugging
1804* Starting:: Starting your program
c906108c
SS
1805* Arguments:: Your program's arguments
1806* Environment:: Your program's environment
c906108c
SS
1807
1808* Working Directory:: Your program's working directory
1809* Input/Output:: Your program's input and output
1810* Attach:: Debugging an already-running process
1811* Kill Process:: Killing the child process
c906108c 1812
6c95b8df 1813* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 1814* Threads:: Debugging programs with multiple threads
6c95b8df 1815* Forks:: Debugging forks
5c95884b 1816* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1817@end menu
1818
6d2ebf8b 1819@node Compilation
79a6e687 1820@section Compiling for Debugging
c906108c
SS
1821
1822In order to debug a program effectively, you need to generate
1823debugging information when you compile it. This debugging information
1824is stored in the object file; it describes the data type of each
1825variable or function and the correspondence between source line numbers
1826and addresses in the executable code.
1827
1828To request debugging information, specify the @samp{-g} option when you run
1829the compiler.
1830
514c4d71 1831Programs that are to be shipped to your customers are compiled with
edb3359d 1832optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
1833compilers are unable to handle the @samp{-g} and @samp{-O} options
1834together. Using those compilers, you cannot generate optimized
c906108c
SS
1835executables containing debugging information.
1836
514c4d71 1837@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1838without @samp{-O}, making it possible to debug optimized code. We
1839recommend that you @emph{always} use @samp{-g} whenever you compile a
1840program. You may think your program is correct, but there is no sense
edb3359d 1841in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
1842
1843Older versions of the @sc{gnu} C compiler permitted a variant option
1844@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1845format; if your @sc{gnu} C compiler has this option, do not use it.
1846
514c4d71
EZ
1847@value{GDBN} knows about preprocessor macros and can show you their
1848expansion (@pxref{Macros}). Most compilers do not include information
1849about preprocessor macros in the debugging information if you specify
1850the @option{-g} flag alone, because this information is rather large.
1851Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1852provides macro information if you specify the options
1853@option{-gdwarf-2} and @option{-g3}; the former option requests
1854debugging information in the Dwarf 2 format, and the latter requests
1855``extra information''. In the future, we hope to find more compact
1856ways to represent macro information, so that it can be included with
1857@option{-g} alone.
1858
c906108c 1859@need 2000
6d2ebf8b 1860@node Starting
79a6e687 1861@section Starting your Program
c906108c
SS
1862@cindex starting
1863@cindex running
1864
1865@table @code
1866@kindex run
41afff9a 1867@kindex r @r{(@code{run})}
c906108c
SS
1868@item run
1869@itemx r
7a292a7a
SS
1870Use the @code{run} command to start your program under @value{GDBN}.
1871You must first specify the program name (except on VxWorks) with an
1872argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1873@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
79a6e687 1874(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
1875
1876@end table
1877
c906108c
SS
1878If you are running your program in an execution environment that
1879supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
1880that process run your program. In some environments without processes,
1881@code{run} jumps to the start of your program. Other targets,
1882like @samp{remote}, are always running. If you get an error
1883message like this one:
1884
1885@smallexample
1886The "remote" target does not support "run".
1887Try "help target" or "continue".
1888@end smallexample
1889
1890@noindent
1891then use @code{continue} to run your program. You may need @code{load}
1892first (@pxref{load}).
c906108c
SS
1893
1894The execution of a program is affected by certain information it
1895receives from its superior. @value{GDBN} provides ways to specify this
1896information, which you must do @emph{before} starting your program. (You
1897can change it after starting your program, but such changes only affect
1898your program the next time you start it.) This information may be
1899divided into four categories:
1900
1901@table @asis
1902@item The @emph{arguments.}
1903Specify the arguments to give your program as the arguments of the
1904@code{run} command. If a shell is available on your target, the shell
1905is used to pass the arguments, so that you may use normal conventions
1906(such as wildcard expansion or variable substitution) in describing
1907the arguments.
1908In Unix systems, you can control which shell is used with the
1909@code{SHELL} environment variable.
79a6e687 1910@xref{Arguments, ,Your Program's Arguments}.
c906108c
SS
1911
1912@item The @emph{environment.}
1913Your program normally inherits its environment from @value{GDBN}, but you can
1914use the @value{GDBN} commands @code{set environment} and @code{unset
1915environment} to change parts of the environment that affect
79a6e687 1916your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
1917
1918@item The @emph{working directory.}
1919Your program inherits its working directory from @value{GDBN}. You can set
1920the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 1921@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
1922
1923@item The @emph{standard input and output.}
1924Your program normally uses the same device for standard input and
1925standard output as @value{GDBN} is using. You can redirect input and output
1926in the @code{run} command line, or you can use the @code{tty} command to
1927set a different device for your program.
79a6e687 1928@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
1929
1930@cindex pipes
1931@emph{Warning:} While input and output redirection work, you cannot use
1932pipes to pass the output of the program you are debugging to another
1933program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1934wrong program.
1935@end table
c906108c
SS
1936
1937When you issue the @code{run} command, your program begins to execute
79a6e687 1938immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
1939of how to arrange for your program to stop. Once your program has
1940stopped, you may call functions in your program, using the @code{print}
1941or @code{call} commands. @xref{Data, ,Examining Data}.
1942
1943If the modification time of your symbol file has changed since the last
1944time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1945table, and reads it again. When it does this, @value{GDBN} tries to retain
1946your current breakpoints.
1947
4e8b0763
JB
1948@table @code
1949@kindex start
1950@item start
1951@cindex run to main procedure
1952The name of the main procedure can vary from language to language.
1953With C or C@t{++}, the main procedure name is always @code{main}, but
1954other languages such as Ada do not require a specific name for their
1955main procedure. The debugger provides a convenient way to start the
1956execution of the program and to stop at the beginning of the main
1957procedure, depending on the language used.
1958
1959The @samp{start} command does the equivalent of setting a temporary
1960breakpoint at the beginning of the main procedure and then invoking
1961the @samp{run} command.
1962
f018e82f
EZ
1963@cindex elaboration phase
1964Some programs contain an @dfn{elaboration} phase where some startup code is
1965executed before the main procedure is called. This depends on the
1966languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1967constructors for static and global objects are executed before
1968@code{main} is called. It is therefore possible that the debugger stops
1969before reaching the main procedure. However, the temporary breakpoint
1970will remain to halt execution.
1971
1972Specify the arguments to give to your program as arguments to the
1973@samp{start} command. These arguments will be given verbatim to the
1974underlying @samp{run} command. Note that the same arguments will be
1975reused if no argument is provided during subsequent calls to
1976@samp{start} or @samp{run}.
1977
1978It is sometimes necessary to debug the program during elaboration. In
1979these cases, using the @code{start} command would stop the execution of
1980your program too late, as the program would have already completed the
1981elaboration phase. Under these circumstances, insert breakpoints in your
1982elaboration code before running your program.
ccd213ac
DJ
1983
1984@kindex set exec-wrapper
1985@item set exec-wrapper @var{wrapper}
1986@itemx show exec-wrapper
1987@itemx unset exec-wrapper
1988When @samp{exec-wrapper} is set, the specified wrapper is used to
1989launch programs for debugging. @value{GDBN} starts your program
1990with a shell command of the form @kbd{exec @var{wrapper}
1991@var{program}}. Quoting is added to @var{program} and its
1992arguments, but not to @var{wrapper}, so you should add quotes if
1993appropriate for your shell. The wrapper runs until it executes
1994your program, and then @value{GDBN} takes control.
1995
1996You can use any program that eventually calls @code{execve} with
1997its arguments as a wrapper. Several standard Unix utilities do
1998this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
1999with @code{exec "$@@"} will also work.
2000
2001For example, you can use @code{env} to pass an environment variable to
2002the debugged program, without setting the variable in your shell's
2003environment:
2004
2005@smallexample
2006(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2007(@value{GDBP}) run
2008@end smallexample
2009
2010This command is available when debugging locally on most targets, excluding
2011@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2012
10568435
JK
2013@kindex set disable-randomization
2014@item set disable-randomization
2015@itemx set disable-randomization on
2016This option (enabled by default in @value{GDBN}) will turn off the native
2017randomization of the virtual address space of the started program. This option
2018is useful for multiple debugging sessions to make the execution better
2019reproducible and memory addresses reusable across debugging sessions.
2020
2021This feature is implemented only on @sc{gnu}/Linux. You can get the same
2022behavior using
2023
2024@smallexample
2025(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2026@end smallexample
2027
2028@item set disable-randomization off
2029Leave the behavior of the started executable unchanged. Some bugs rear their
2030ugly heads only when the program is loaded at certain addresses. If your bug
2031disappears when you run the program under @value{GDBN}, that might be because
2032@value{GDBN} by default disables the address randomization on platforms, such
2033as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2034disable-randomization off} to try to reproduce such elusive bugs.
2035
2036The virtual address space randomization is implemented only on @sc{gnu}/Linux.
2037It protects the programs against some kinds of security attacks. In these
2038cases the attacker needs to know the exact location of a concrete executable
2039code. Randomizing its location makes it impossible to inject jumps misusing
2040a code at its expected addresses.
2041
2042Prelinking shared libraries provides a startup performance advantage but it
2043makes addresses in these libraries predictable for privileged processes by
2044having just unprivileged access at the target system. Reading the shared
2045library binary gives enough information for assembling the malicious code
2046misusing it. Still even a prelinked shared library can get loaded at a new
2047random address just requiring the regular relocation process during the
2048startup. Shared libraries not already prelinked are always loaded at
2049a randomly chosen address.
2050
2051Position independent executables (PIE) contain position independent code
2052similar to the shared libraries and therefore such executables get loaded at
2053a randomly chosen address upon startup. PIE executables always load even
2054already prelinked shared libraries at a random address. You can build such
2055executable using @command{gcc -fPIE -pie}.
2056
2057Heap (malloc storage), stack and custom mmap areas are always placed randomly
2058(as long as the randomization is enabled).
2059
2060@item show disable-randomization
2061Show the current setting of the explicit disable of the native randomization of
2062the virtual address space of the started program.
2063
4e8b0763
JB
2064@end table
2065
6d2ebf8b 2066@node Arguments
79a6e687 2067@section Your Program's Arguments
c906108c
SS
2068
2069@cindex arguments (to your program)
2070The arguments to your program can be specified by the arguments of the
5d161b24 2071@code{run} command.
c906108c
SS
2072They are passed to a shell, which expands wildcard characters and
2073performs redirection of I/O, and thence to your program. Your
2074@code{SHELL} environment variable (if it exists) specifies what shell
2075@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2076the default shell (@file{/bin/sh} on Unix).
2077
2078On non-Unix systems, the program is usually invoked directly by
2079@value{GDBN}, which emulates I/O redirection via the appropriate system
2080calls, and the wildcard characters are expanded by the startup code of
2081the program, not by the shell.
c906108c
SS
2082
2083@code{run} with no arguments uses the same arguments used by the previous
2084@code{run}, or those set by the @code{set args} command.
2085
c906108c 2086@table @code
41afff9a 2087@kindex set args
c906108c
SS
2088@item set args
2089Specify the arguments to be used the next time your program is run. If
2090@code{set args} has no arguments, @code{run} executes your program
2091with no arguments. Once you have run your program with arguments,
2092using @code{set args} before the next @code{run} is the only way to run
2093it again without arguments.
2094
2095@kindex show args
2096@item show args
2097Show the arguments to give your program when it is started.
2098@end table
2099
6d2ebf8b 2100@node Environment
79a6e687 2101@section Your Program's Environment
c906108c
SS
2102
2103@cindex environment (of your program)
2104The @dfn{environment} consists of a set of environment variables and
2105their values. Environment variables conventionally record such things as
2106your user name, your home directory, your terminal type, and your search
2107path for programs to run. Usually you set up environment variables with
2108the shell and they are inherited by all the other programs you run. When
2109debugging, it can be useful to try running your program with a modified
2110environment without having to start @value{GDBN} over again.
2111
2112@table @code
2113@kindex path
2114@item path @var{directory}
2115Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2116(the search path for executables) that will be passed to your program.
2117The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2118You may specify several directory names, separated by whitespace or by a
2119system-dependent separator character (@samp{:} on Unix, @samp{;} on
2120MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2121is moved to the front, so it is searched sooner.
c906108c
SS
2122
2123You can use the string @samp{$cwd} to refer to whatever is the current
2124working directory at the time @value{GDBN} searches the path. If you
2125use @samp{.} instead, it refers to the directory where you executed the
2126@code{path} command. @value{GDBN} replaces @samp{.} in the
2127@var{directory} argument (with the current path) before adding
2128@var{directory} to the search path.
2129@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2130@c document that, since repeating it would be a no-op.
2131
2132@kindex show paths
2133@item show paths
2134Display the list of search paths for executables (the @code{PATH}
2135environment variable).
2136
2137@kindex show environment
2138@item show environment @r{[}@var{varname}@r{]}
2139Print the value of environment variable @var{varname} to be given to
2140your program when it starts. If you do not supply @var{varname},
2141print the names and values of all environment variables to be given to
2142your program. You can abbreviate @code{environment} as @code{env}.
2143
2144@kindex set environment
53a5351d 2145@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
2146Set environment variable @var{varname} to @var{value}. The value
2147changes for your program only, not for @value{GDBN} itself. @var{value} may
2148be any string; the values of environment variables are just strings, and
2149any interpretation is supplied by your program itself. The @var{value}
2150parameter is optional; if it is eliminated, the variable is set to a
2151null value.
2152@c "any string" here does not include leading, trailing
2153@c blanks. Gnu asks: does anyone care?
2154
2155For example, this command:
2156
474c8240 2157@smallexample
c906108c 2158set env USER = foo
474c8240 2159@end smallexample
c906108c
SS
2160
2161@noindent
d4f3574e 2162tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2163@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2164are not actually required.)
2165
2166@kindex unset environment
2167@item unset environment @var{varname}
2168Remove variable @var{varname} from the environment to be passed to your
2169program. This is different from @samp{set env @var{varname} =};
2170@code{unset environment} removes the variable from the environment,
2171rather than assigning it an empty value.
2172@end table
2173
d4f3574e
SS
2174@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2175the shell indicated
c906108c
SS
2176by your @code{SHELL} environment variable if it exists (or
2177@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2178that runs an initialization file---such as @file{.cshrc} for C-shell, or
2179@file{.bashrc} for BASH---any variables you set in that file affect
2180your program. You may wish to move setting of environment variables to
2181files that are only run when you sign on, such as @file{.login} or
2182@file{.profile}.
2183
6d2ebf8b 2184@node Working Directory
79a6e687 2185@section Your Program's Working Directory
c906108c
SS
2186
2187@cindex working directory (of your program)
2188Each time you start your program with @code{run}, it inherits its
2189working directory from the current working directory of @value{GDBN}.
2190The @value{GDBN} working directory is initially whatever it inherited
2191from its parent process (typically the shell), but you can specify a new
2192working directory in @value{GDBN} with the @code{cd} command.
2193
2194The @value{GDBN} working directory also serves as a default for the commands
2195that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2196Specify Files}.
c906108c
SS
2197
2198@table @code
2199@kindex cd
721c2651 2200@cindex change working directory
c906108c
SS
2201@item cd @var{directory}
2202Set the @value{GDBN} working directory to @var{directory}.
2203
2204@kindex pwd
2205@item pwd
2206Print the @value{GDBN} working directory.
2207@end table
2208
60bf7e09
EZ
2209It is generally impossible to find the current working directory of
2210the process being debugged (since a program can change its directory
2211during its run). If you work on a system where @value{GDBN} is
2212configured with the @file{/proc} support, you can use the @code{info
2213proc} command (@pxref{SVR4 Process Information}) to find out the
2214current working directory of the debuggee.
2215
6d2ebf8b 2216@node Input/Output
79a6e687 2217@section Your Program's Input and Output
c906108c
SS
2218
2219@cindex redirection
2220@cindex i/o
2221@cindex terminal
2222By default, the program you run under @value{GDBN} does input and output to
5d161b24 2223the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2224to its own terminal modes to interact with you, but it records the terminal
2225modes your program was using and switches back to them when you continue
2226running your program.
2227
2228@table @code
2229@kindex info terminal
2230@item info terminal
2231Displays information recorded by @value{GDBN} about the terminal modes your
2232program is using.
2233@end table
2234
2235You can redirect your program's input and/or output using shell
2236redirection with the @code{run} command. For example,
2237
474c8240 2238@smallexample
c906108c 2239run > outfile
474c8240 2240@end smallexample
c906108c
SS
2241
2242@noindent
2243starts your program, diverting its output to the file @file{outfile}.
2244
2245@kindex tty
2246@cindex controlling terminal
2247Another way to specify where your program should do input and output is
2248with the @code{tty} command. This command accepts a file name as
2249argument, and causes this file to be the default for future @code{run}
2250commands. It also resets the controlling terminal for the child
2251process, for future @code{run} commands. For example,
2252
474c8240 2253@smallexample
c906108c 2254tty /dev/ttyb
474c8240 2255@end smallexample
c906108c
SS
2256
2257@noindent
2258directs that processes started with subsequent @code{run} commands
2259default to do input and output on the terminal @file{/dev/ttyb} and have
2260that as their controlling terminal.
2261
2262An explicit redirection in @code{run} overrides the @code{tty} command's
2263effect on the input/output device, but not its effect on the controlling
2264terminal.
2265
2266When you use the @code{tty} command or redirect input in the @code{run}
2267command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2268for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2269for @code{set inferior-tty}.
2270
2271@cindex inferior tty
2272@cindex set inferior controlling terminal
2273You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2274display the name of the terminal that will be used for future runs of your
2275program.
2276
2277@table @code
2278@item set inferior-tty /dev/ttyb
2279@kindex set inferior-tty
2280Set the tty for the program being debugged to /dev/ttyb.
2281
2282@item show inferior-tty
2283@kindex show inferior-tty
2284Show the current tty for the program being debugged.
2285@end table
c906108c 2286
6d2ebf8b 2287@node Attach
79a6e687 2288@section Debugging an Already-running Process
c906108c
SS
2289@kindex attach
2290@cindex attach
2291
2292@table @code
2293@item attach @var{process-id}
2294This command attaches to a running process---one that was started
2295outside @value{GDBN}. (@code{info files} shows your active
2296targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2297find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2298or with the @samp{jobs -l} shell command.
2299
2300@code{attach} does not repeat if you press @key{RET} a second time after
2301executing the command.
2302@end table
2303
2304To use @code{attach}, your program must be running in an environment
2305which supports processes; for example, @code{attach} does not work for
2306programs on bare-board targets that lack an operating system. You must
2307also have permission to send the process a signal.
2308
2309When you use @code{attach}, the debugger finds the program running in
2310the process first by looking in the current working directory, then (if
2311the program is not found) by using the source file search path
79a6e687 2312(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2313the @code{file} command to load the program. @xref{Files, ,Commands to
2314Specify Files}.
2315
2316The first thing @value{GDBN} does after arranging to debug the specified
2317process is to stop it. You can examine and modify an attached process
53a5351d
JM
2318with all the @value{GDBN} commands that are ordinarily available when
2319you start processes with @code{run}. You can insert breakpoints; you
2320can step and continue; you can modify storage. If you would rather the
2321process continue running, you may use the @code{continue} command after
c906108c
SS
2322attaching @value{GDBN} to the process.
2323
2324@table @code
2325@kindex detach
2326@item detach
2327When you have finished debugging the attached process, you can use the
2328@code{detach} command to release it from @value{GDBN} control. Detaching
2329the process continues its execution. After the @code{detach} command,
2330that process and @value{GDBN} become completely independent once more, and you
2331are ready to @code{attach} another process or start one with @code{run}.
2332@code{detach} does not repeat if you press @key{RET} again after
2333executing the command.
2334@end table
2335
159fcc13
JK
2336If you exit @value{GDBN} while you have an attached process, you detach
2337that process. If you use the @code{run} command, you kill that process.
2338By default, @value{GDBN} asks for confirmation if you try to do either of these
2339things; you can control whether or not you need to confirm by using the
2340@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2341Messages}).
c906108c 2342
6d2ebf8b 2343@node Kill Process
79a6e687 2344@section Killing the Child Process
c906108c
SS
2345
2346@table @code
2347@kindex kill
2348@item kill
2349Kill the child process in which your program is running under @value{GDBN}.
2350@end table
2351
2352This command is useful if you wish to debug a core dump instead of a
2353running process. @value{GDBN} ignores any core dump file while your program
2354is running.
2355
2356On some operating systems, a program cannot be executed outside @value{GDBN}
2357while you have breakpoints set on it inside @value{GDBN}. You can use the
2358@code{kill} command in this situation to permit running your program
2359outside the debugger.
2360
2361The @code{kill} command is also useful if you wish to recompile and
2362relink your program, since on many systems it is impossible to modify an
2363executable file while it is running in a process. In this case, when you
2364next type @code{run}, @value{GDBN} notices that the file has changed, and
2365reads the symbol table again (while trying to preserve your current
2366breakpoint settings).
2367
6c95b8df
PA
2368@node Inferiors and Programs
2369@section Debugging Multiple Inferiors and Programs
b77209e0 2370
6c95b8df
PA
2371@value{GDBN} lets you run and debug multiple programs in a single
2372session. In addition, @value{GDBN} on some systems may let you run
2373several programs simultaneously (otherwise you have to exit from one
2374before starting another). In the most general case, you can have
2375multiple threads of execution in each of multiple processes, launched
2376from multiple executables.
b77209e0
PA
2377
2378@cindex inferior
2379@value{GDBN} represents the state of each program execution with an
2380object called an @dfn{inferior}. An inferior typically corresponds to
2381a process, but is more general and applies also to targets that do not
2382have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2383may be retained after a process exits. Inferiors have unique
2384identifiers that are different from process ids. Usually each
2385inferior will also have its own distinct address space, although some
2386embedded targets may have several inferiors running in different parts
2387of a single address space. Each inferior may in turn have multiple
2388threads running in it.
b77209e0 2389
6c95b8df
PA
2390To find out what inferiors exist at any moment, use @w{@code{info
2391inferiors}}:
b77209e0
PA
2392
2393@table @code
2394@kindex info inferiors
2395@item info inferiors
2396Print a list of all inferiors currently being managed by @value{GDBN}.
3a1ff0b6
PA
2397
2398@value{GDBN} displays for each inferior (in this order):
2399
2400@enumerate
2401@item
2402the inferior number assigned by @value{GDBN}
2403
2404@item
2405the target system's inferior identifier
6c95b8df
PA
2406
2407@item
2408the name of the executable the inferior is running.
2409
3a1ff0b6
PA
2410@end enumerate
2411
2412@noindent
2413An asterisk @samp{*} preceding the @value{GDBN} inferior number
2414indicates the current inferior.
2415
2416For example,
2277426b 2417@end table
3a1ff0b6
PA
2418@c end table here to get a little more width for example
2419
2420@smallexample
2421(@value{GDBP}) info inferiors
6c95b8df
PA
2422 Num Description Executable
2423 2 process 2307 hello
2424* 1 process 3401 goodbye
3a1ff0b6 2425@end smallexample
2277426b
PA
2426
2427To switch focus between inferiors, use the @code{inferior} command:
2428
2429@table @code
3a1ff0b6
PA
2430@kindex inferior @var{infno}
2431@item inferior @var{infno}
2432Make inferior number @var{infno} the current inferior. The argument
2433@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2434in the first field of the @samp{info inferiors} display.
2277426b
PA
2435@end table
2436
6c95b8df
PA
2437
2438You can get multiple executables into a debugging session via the
2439@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2440systems @value{GDBN} can add inferiors to the debug session
2441automatically by following calls to @code{fork} and @code{exec}. To
2442remove inferiors from the debugging session use the
2443@w{@code{remove-inferior}} command.
2444
2445@table @code
2446@kindex add-inferior
2447@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2448Adds @var{n} inferiors to be run using @var{executable} as the
2449executable. @var{n} defaults to 1. If no executable is specified,
2450the inferiors begins empty, with no program. You can still assign or
2451change the program assigned to the inferior at any time by using the
2452@code{file} command with the executable name as its argument.
2453
2454@kindex clone-inferior
2455@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2456Adds @var{n} inferiors ready to execute the same program as inferior
2457@var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2458number of the current inferior. This is a convenient command when you
2459want to run another instance of the inferior you are debugging.
2460
2461@smallexample
2462(@value{GDBP}) info inferiors
2463 Num Description Executable
2464* 1 process 29964 helloworld
2465(@value{GDBP}) clone-inferior
2466Added inferior 2.
24671 inferiors added.
2468(@value{GDBP}) info inferiors
2469 Num Description Executable
2470 2 <null> helloworld
2471* 1 process 29964 helloworld
2472@end smallexample
2473
2474You can now simply switch focus to inferior 2 and run it.
2475
2476@kindex remove-inferior
2477@item remove-inferior @var{infno}
2478Removes the inferior @var{infno}. It is not possible to remove an
2479inferior that is running with this command. For those, use the
2480@code{kill} or @code{detach} command first.
2481
2482@end table
2483
2484To quit debugging one of the running inferiors that is not the current
2485inferior, you can either detach from it by using the @w{@code{detach
2486inferior}} command (allowing it to run independently), or kill it
2487using the @w{@code{kill inferior}} command:
2277426b
PA
2488
2489@table @code
3a1ff0b6
PA
2490@kindex detach inferior @var{infno}
2491@item detach inferior @var{infno}
2277426b 2492Detach from the inferior identified by @value{GDBN} inferior number
6c13bbe1
HZ
2493@var{infno}. Note that the inferior's entry still stays on the list
2494of inferiors shown by @code{info inferiors}, but its Description will
2495show @samp{<null>}.
2277426b 2496
3a1ff0b6
PA
2497@kindex kill inferior @var{infno}
2498@item kill inferior @var{infno}
2277426b 2499Kill the inferior identified by @value{GDBN} inferior number
6c13bbe1
HZ
2500@var{infno}. Note that the inferior's entry still stays on the list
2501of inferiors shown by @code{info inferiors}, but its Description will
2502show @samp{<null>}.
2277426b
PA
2503@end table
2504
6c95b8df
PA
2505After the successful completion of a command such as @code{detach},
2506@code{detach inferior}, @code{kill} or @code{kill inferior}, or after
2507a normal process exit, the inferior is still valid and listed with
2508@code{info inferiors}, ready to be restarted.
2509
2510
2277426b
PA
2511To be notified when inferiors are started or exit under @value{GDBN}'s
2512control use @w{@code{set print inferior-events}}:
b77209e0 2513
2277426b 2514@table @code
b77209e0
PA
2515@kindex set print inferior-events
2516@cindex print messages on inferior start and exit
2517@item set print inferior-events
2518@itemx set print inferior-events on
2519@itemx set print inferior-events off
2520The @code{set print inferior-events} command allows you to enable or
2521disable printing of messages when @value{GDBN} notices that new
2522inferiors have started or that inferiors have exited or have been
2523detached. By default, these messages will not be printed.
2524
2525@kindex show print inferior-events
2526@item show print inferior-events
2527Show whether messages will be printed when @value{GDBN} detects that
2528inferiors have started, exited or have been detached.
2529@end table
2530
6c95b8df
PA
2531Many commands will work the same with multiple programs as with a
2532single program: e.g., @code{print myglobal} will simply display the
2533value of @code{myglobal} in the current inferior.
2534
2535
2536Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2537get more info about the relationship of inferiors, programs, address
2538spaces in a debug session. You can do that with the @w{@code{maint
2539info program-spaces}} command.
2540
2541@table @code
2542@kindex maint info program-spaces
2543@item maint info program-spaces
2544Print a list of all program spaces currently being managed by
2545@value{GDBN}.
2546
2547@value{GDBN} displays for each program space (in this order):
2548
2549@enumerate
2550@item
2551the program space number assigned by @value{GDBN}
2552
2553@item
2554the name of the executable loaded into the program space, with e.g.,
2555the @code{file} command.
2556
2557@end enumerate
2558
2559@noindent
2560An asterisk @samp{*} preceding the @value{GDBN} program space number
2561indicates the current program space.
2562
2563In addition, below each program space line, @value{GDBN} prints extra
2564information that isn't suitable to display in tabular form. For
2565example, the list of inferiors bound to the program space.
2566
2567@smallexample
2568(@value{GDBP}) maint info program-spaces
2569 Id Executable
2570 2 goodbye
2571 Bound inferiors: ID 1 (process 21561)
2572* 1 hello
2573@end smallexample
2574
2575Here we can see that no inferior is running the program @code{hello},
2576while @code{process 21561} is running the program @code{goodbye}. On
2577some targets, it is possible that multiple inferiors are bound to the
2578same program space. The most common example is that of debugging both
2579the parent and child processes of a @code{vfork} call. For example,
2580
2581@smallexample
2582(@value{GDBP}) maint info program-spaces
2583 Id Executable
2584* 1 vfork-test
2585 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2586@end smallexample
2587
2588Here, both inferior 2 and inferior 1 are running in the same program
2589space as a result of inferior 1 having executed a @code{vfork} call.
2590@end table
2591
6d2ebf8b 2592@node Threads
79a6e687 2593@section Debugging Programs with Multiple Threads
c906108c
SS
2594
2595@cindex threads of execution
2596@cindex multiple threads
2597@cindex switching threads
2598In some operating systems, such as HP-UX and Solaris, a single program
2599may have more than one @dfn{thread} of execution. The precise semantics
2600of threads differ from one operating system to another, but in general
2601the threads of a single program are akin to multiple processes---except
2602that they share one address space (that is, they can all examine and
2603modify the same variables). On the other hand, each thread has its own
2604registers and execution stack, and perhaps private memory.
2605
2606@value{GDBN} provides these facilities for debugging multi-thread
2607programs:
2608
2609@itemize @bullet
2610@item automatic notification of new threads
2611@item @samp{thread @var{threadno}}, a command to switch among threads
2612@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2613@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2614a command to apply a command to a list of threads
2615@item thread-specific breakpoints
93815fbf
VP
2616@item @samp{set print thread-events}, which controls printing of
2617messages on thread start and exit.
17a37d48
PP
2618@item @samp{set libthread-db-search-path @var{path}}, which lets
2619the user specify which @code{libthread_db} to use if the default choice
2620isn't compatible with the program.
c906108c
SS
2621@end itemize
2622
c906108c
SS
2623@quotation
2624@emph{Warning:} These facilities are not yet available on every
2625@value{GDBN} configuration where the operating system supports threads.
2626If your @value{GDBN} does not support threads, these commands have no
2627effect. For example, a system without thread support shows no output
2628from @samp{info threads}, and always rejects the @code{thread} command,
2629like this:
2630
2631@smallexample
2632(@value{GDBP}) info threads
2633(@value{GDBP}) thread 1
2634Thread ID 1 not known. Use the "info threads" command to
2635see the IDs of currently known threads.
2636@end smallexample
2637@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2638@c doesn't support threads"?
2639@end quotation
c906108c
SS
2640
2641@cindex focus of debugging
2642@cindex current thread
2643The @value{GDBN} thread debugging facility allows you to observe all
2644threads while your program runs---but whenever @value{GDBN} takes
2645control, one thread in particular is always the focus of debugging.
2646This thread is called the @dfn{current thread}. Debugging commands show
2647program information from the perspective of the current thread.
2648
41afff9a 2649@cindex @code{New} @var{systag} message
c906108c
SS
2650@cindex thread identifier (system)
2651@c FIXME-implementors!! It would be more helpful if the [New...] message
2652@c included GDB's numeric thread handle, so you could just go to that
2653@c thread without first checking `info threads'.
2654Whenever @value{GDBN} detects a new thread in your program, it displays
2655the target system's identification for the thread with a message in the
2656form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2657whose form varies depending on the particular system. For example, on
8807d78b 2658@sc{gnu}/Linux, you might see
c906108c 2659
474c8240 2660@smallexample
8807d78b 2661[New Thread 46912507313328 (LWP 25582)]
474c8240 2662@end smallexample
c906108c
SS
2663
2664@noindent
2665when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2666the @var{systag} is simply something like @samp{process 368}, with no
2667further qualifier.
2668
2669@c FIXME!! (1) Does the [New...] message appear even for the very first
2670@c thread of a program, or does it only appear for the
6ca652b0 2671@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2672@c program?
2673@c (2) *Is* there necessarily a first thread always? Or do some
2674@c multithread systems permit starting a program with multiple
5d161b24 2675@c threads ab initio?
c906108c
SS
2676
2677@cindex thread number
2678@cindex thread identifier (GDB)
2679For debugging purposes, @value{GDBN} associates its own thread
2680number---always a single integer---with each thread in your program.
2681
2682@table @code
2683@kindex info threads
2684@item info threads
2685Display a summary of all threads currently in your
2686program. @value{GDBN} displays for each thread (in this order):
2687
2688@enumerate
09d4efe1
EZ
2689@item
2690the thread number assigned by @value{GDBN}
c906108c 2691
09d4efe1
EZ
2692@item
2693the target system's thread identifier (@var{systag})
c906108c 2694
09d4efe1
EZ
2695@item
2696the current stack frame summary for that thread
c906108c
SS
2697@end enumerate
2698
2699@noindent
2700An asterisk @samp{*} to the left of the @value{GDBN} thread number
2701indicates the current thread.
2702
5d161b24 2703For example,
c906108c
SS
2704@end table
2705@c end table here to get a little more width for example
2706
2707@smallexample
2708(@value{GDBP}) info threads
2709 3 process 35 thread 27 0x34e5 in sigpause ()
2710 2 process 35 thread 23 0x34e5 in sigpause ()
2711* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2712 at threadtest.c:68
2713@end smallexample
53a5351d
JM
2714
2715On HP-UX systems:
c906108c 2716
4644b6e3
EZ
2717@cindex debugging multithreaded programs (on HP-UX)
2718@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2719For debugging purposes, @value{GDBN} associates its own thread
2720number---a small integer assigned in thread-creation order---with each
2721thread in your program.
2722
41afff9a
EZ
2723@cindex @code{New} @var{systag} message, on HP-UX
2724@cindex thread identifier (system), on HP-UX
c906108c
SS
2725@c FIXME-implementors!! It would be more helpful if the [New...] message
2726@c included GDB's numeric thread handle, so you could just go to that
2727@c thread without first checking `info threads'.
2728Whenever @value{GDBN} detects a new thread in your program, it displays
2729both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2730form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2731whose form varies depending on the particular system. For example, on
2732HP-UX, you see
2733
474c8240 2734@smallexample
c906108c 2735[New thread 2 (system thread 26594)]
474c8240 2736@end smallexample
c906108c
SS
2737
2738@noindent
5d161b24 2739when @value{GDBN} notices a new thread.
c906108c
SS
2740
2741@table @code
4644b6e3 2742@kindex info threads (HP-UX)
c906108c
SS
2743@item info threads
2744Display a summary of all threads currently in your
2745program. @value{GDBN} displays for each thread (in this order):
2746
2747@enumerate
2748@item the thread number assigned by @value{GDBN}
2749
2750@item the target system's thread identifier (@var{systag})
2751
2752@item the current stack frame summary for that thread
2753@end enumerate
2754
2755@noindent
2756An asterisk @samp{*} to the left of the @value{GDBN} thread number
2757indicates the current thread.
2758
5d161b24 2759For example,
c906108c
SS
2760@end table
2761@c end table here to get a little more width for example
2762
474c8240 2763@smallexample
c906108c 2764(@value{GDBP}) info threads
6d2ebf8b
SS
2765 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2766 at quicksort.c:137
2767 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2768 from /usr/lib/libc.2
2769 1 system thread 27905 0x7b003498 in _brk () \@*
2770 from /usr/lib/libc.2
474c8240 2771@end smallexample
c906108c 2772
c45da7e6
EZ
2773On Solaris, you can display more information about user threads with a
2774Solaris-specific command:
2775
2776@table @code
2777@item maint info sol-threads
2778@kindex maint info sol-threads
2779@cindex thread info (Solaris)
2780Display info on Solaris user threads.
2781@end table
2782
c906108c
SS
2783@table @code
2784@kindex thread @var{threadno}
2785@item thread @var{threadno}
2786Make thread number @var{threadno} the current thread. The command
2787argument @var{threadno} is the internal @value{GDBN} thread number, as
2788shown in the first field of the @samp{info threads} display.
2789@value{GDBN} responds by displaying the system identifier of the thread
2790you selected, and its current stack frame summary:
2791
2792@smallexample
2793@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2794(@value{GDBP}) thread 2
c906108c 2795[Switching to process 35 thread 23]
c906108c
SS
27960x34e5 in sigpause ()
2797@end smallexample
2798
2799@noindent
2800As with the @samp{[New @dots{}]} message, the form of the text after
2801@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2802threads.
c906108c 2803
6aed2dbc
SS
2804@vindex $_thread@r{, convenience variable}
2805The debugger convenience variable @samp{$_thread} contains the number
2806of the current thread. You may find this useful in writing breakpoint
2807conditional expressions, command scripts, and so forth. See
2808@xref{Convenience Vars,, Convenience Variables}, for general
2809information on convenience variables.
2810
9c16f35a 2811@kindex thread apply
638ac427 2812@cindex apply command to several threads
839c27b7
EZ
2813@item thread apply [@var{threadno}] [@var{all}] @var{command}
2814The @code{thread apply} command allows you to apply the named
2815@var{command} to one or more threads. Specify the numbers of the
2816threads that you want affected with the command argument
2817@var{threadno}. It can be a single thread number, one of the numbers
2818shown in the first field of the @samp{info threads} display; or it
2819could be a range of thread numbers, as in @code{2-4}. To apply a
2820command to all threads, type @kbd{thread apply all @var{command}}.
93815fbf
VP
2821
2822@kindex set print thread-events
2823@cindex print messages on thread start and exit
2824@item set print thread-events
2825@itemx set print thread-events on
2826@itemx set print thread-events off
2827The @code{set print thread-events} command allows you to enable or
2828disable printing of messages when @value{GDBN} notices that new threads have
2829started or that threads have exited. By default, these messages will
2830be printed if detection of these events is supported by the target.
2831Note that these messages cannot be disabled on all targets.
2832
2833@kindex show print thread-events
2834@item show print thread-events
2835Show whether messages will be printed when @value{GDBN} detects that threads
2836have started and exited.
c906108c
SS
2837@end table
2838
79a6e687 2839@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
2840more information about how @value{GDBN} behaves when you stop and start
2841programs with multiple threads.
2842
79a6e687 2843@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 2844watchpoints in programs with multiple threads.
c906108c 2845
17a37d48
PP
2846@table @code
2847@kindex set libthread-db-search-path
2848@cindex search path for @code{libthread_db}
2849@item set libthread-db-search-path @r{[}@var{path}@r{]}
2850If this variable is set, @var{path} is a colon-separated list of
2851directories @value{GDBN} will use to search for @code{libthread_db}.
2852If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
2853an empty list.
2854
2855On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2856@code{libthread_db} library to obtain information about threads in the
2857inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
2858to find @code{libthread_db}. If that fails, @value{GDBN} will continue
2859with default system shared library directories, and finally the directory
2860from which @code{libpthread} was loaded in the inferior process.
2861
2862For any @code{libthread_db} library @value{GDBN} finds in above directories,
2863@value{GDBN} attempts to initialize it with the current inferior process.
2864If this initialization fails (which could happen because of a version
2865mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2866will unload @code{libthread_db}, and continue with the next directory.
2867If none of @code{libthread_db} libraries initialize successfully,
2868@value{GDBN} will issue a warning and thread debugging will be disabled.
2869
2870Setting @code{libthread-db-search-path} is currently implemented
2871only on some platforms.
2872
2873@kindex show libthread-db-search-path
2874@item show libthread-db-search-path
2875Display current libthread_db search path.
02d868e8
PP
2876
2877@kindex set debug libthread-db
2878@kindex show debug libthread-db
2879@cindex debugging @code{libthread_db}
2880@item set debug libthread-db
2881@itemx show debug libthread-db
2882Turns on or off display of @code{libthread_db}-related events.
2883Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
2884@end table
2885
6c95b8df
PA
2886@node Forks
2887@section Debugging Forks
c906108c
SS
2888
2889@cindex fork, debugging programs which call
2890@cindex multiple processes
2891@cindex processes, multiple
53a5351d
JM
2892On most systems, @value{GDBN} has no special support for debugging
2893programs which create additional processes using the @code{fork}
2894function. When a program forks, @value{GDBN} will continue to debug the
2895parent process and the child process will run unimpeded. If you have
2896set a breakpoint in any code which the child then executes, the child
2897will get a @code{SIGTRAP} signal which (unless it catches the signal)
2898will cause it to terminate.
c906108c
SS
2899
2900However, if you want to debug the child process there is a workaround
2901which isn't too painful. Put a call to @code{sleep} in the code which
2902the child process executes after the fork. It may be useful to sleep
2903only if a certain environment variable is set, or a certain file exists,
2904so that the delay need not occur when you don't want to run @value{GDBN}
2905on the child. While the child is sleeping, use the @code{ps} program to
2906get its process ID. Then tell @value{GDBN} (a new invocation of
2907@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2908the child process (@pxref{Attach}). From that point on you can debug
c906108c 2909the child process just like any other process which you attached to.
c906108c 2910
b51970ac
DJ
2911On some systems, @value{GDBN} provides support for debugging programs that
2912create additional processes using the @code{fork} or @code{vfork} functions.
2913Currently, the only platforms with this feature are HP-UX (11.x and later
a6b151f1 2914only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
c906108c
SS
2915
2916By default, when a program forks, @value{GDBN} will continue to debug
2917the parent process and the child process will run unimpeded.
2918
2919If you want to follow the child process instead of the parent process,
2920use the command @w{@code{set follow-fork-mode}}.
2921
2922@table @code
2923@kindex set follow-fork-mode
2924@item set follow-fork-mode @var{mode}
2925Set the debugger response to a program call of @code{fork} or
2926@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2927process. The @var{mode} argument can be:
c906108c
SS
2928
2929@table @code
2930@item parent
2931The original process is debugged after a fork. The child process runs
2df3850c 2932unimpeded. This is the default.
c906108c
SS
2933
2934@item child
2935The new process is debugged after a fork. The parent process runs
2936unimpeded.
2937
c906108c
SS
2938@end table
2939
9c16f35a 2940@kindex show follow-fork-mode
c906108c 2941@item show follow-fork-mode
2df3850c 2942Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2943@end table
2944
5c95884b
MS
2945@cindex debugging multiple processes
2946On Linux, if you want to debug both the parent and child processes, use the
2947command @w{@code{set detach-on-fork}}.
2948
2949@table @code
2950@kindex set detach-on-fork
2951@item set detach-on-fork @var{mode}
2952Tells gdb whether to detach one of the processes after a fork, or
2953retain debugger control over them both.
2954
2955@table @code
2956@item on
2957The child process (or parent process, depending on the value of
2958@code{follow-fork-mode}) will be detached and allowed to run
2959independently. This is the default.
2960
2961@item off
2962Both processes will be held under the control of @value{GDBN}.
2963One process (child or parent, depending on the value of
2964@code{follow-fork-mode}) is debugged as usual, while the other
2965is held suspended.
2966
2967@end table
2968
11310833
NR
2969@kindex show detach-on-fork
2970@item show detach-on-fork
2971Show whether detach-on-fork mode is on/off.
5c95884b
MS
2972@end table
2973
2277426b
PA
2974If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
2975will retain control of all forked processes (including nested forks).
2976You can list the forked processes under the control of @value{GDBN} by
2977using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
2978to another by using the @code{inferior} command (@pxref{Inferiors and
2979Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
2980
2981To quit debugging one of the forked processes, you can either detach
2277426b
PA
2982from it by using the @w{@code{detach inferior}} command (allowing it
2983to run independently), or kill it using the @w{@code{kill inferior}}
6c95b8df
PA
2984command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
2985and Programs}.
5c95884b 2986
c906108c
SS
2987If you ask to debug a child process and a @code{vfork} is followed by an
2988@code{exec}, @value{GDBN} executes the new target up to the first
2989breakpoint in the new target. If you have a breakpoint set on
2990@code{main} in your original program, the breakpoint will also be set on
2991the child process's @code{main}.
2992
2277426b
PA
2993On some systems, when a child process is spawned by @code{vfork}, you
2994cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
2995
2996If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
2997call executes, the new target restarts. To restart the parent
2998process, use the @code{file} command with the parent executable name
2999as its argument. By default, after an @code{exec} call executes,
3000@value{GDBN} discards the symbols of the previous executable image.
3001You can change this behaviour with the @w{@code{set follow-exec-mode}}
3002command.
3003
3004@table @code
3005@kindex set follow-exec-mode
3006@item set follow-exec-mode @var{mode}
3007
3008Set debugger response to a program call of @code{exec}. An
3009@code{exec} call replaces the program image of a process.
3010
3011@code{follow-exec-mode} can be:
3012
3013@table @code
3014@item new
3015@value{GDBN} creates a new inferior and rebinds the process to this
3016new inferior. The program the process was running before the
3017@code{exec} call can be restarted afterwards by restarting the
3018original inferior.
3019
3020For example:
3021
3022@smallexample
3023(@value{GDBP}) info inferiors
3024(gdb) info inferior
3025 Id Description Executable
3026* 1 <null> prog1
3027(@value{GDBP}) run
3028process 12020 is executing new program: prog2
3029Program exited normally.
3030(@value{GDBP}) info inferiors
3031 Id Description Executable
3032* 2 <null> prog2
3033 1 <null> prog1
3034@end smallexample
3035
3036@item same
3037@value{GDBN} keeps the process bound to the same inferior. The new
3038executable image replaces the previous executable loaded in the
3039inferior. Restarting the inferior after the @code{exec} call, with
3040e.g., the @code{run} command, restarts the executable the process was
3041running after the @code{exec} call. This is the default mode.
3042
3043For example:
3044
3045@smallexample
3046(@value{GDBP}) info inferiors
3047 Id Description Executable
3048* 1 <null> prog1
3049(@value{GDBP}) run
3050process 12020 is executing new program: prog2
3051Program exited normally.
3052(@value{GDBP}) info inferiors
3053 Id Description Executable
3054* 1 <null> prog2
3055@end smallexample
3056
3057@end table
3058@end table
c906108c
SS
3059
3060You can use the @code{catch} command to make @value{GDBN} stop whenever
3061a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3062Catchpoints, ,Setting Catchpoints}.
c906108c 3063
5c95884b 3064@node Checkpoint/Restart
79a6e687 3065@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3066
3067@cindex checkpoint
3068@cindex restart
3069@cindex bookmark
3070@cindex snapshot of a process
3071@cindex rewind program state
3072
3073On certain operating systems@footnote{Currently, only
3074@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3075program's state, called a @dfn{checkpoint}, and come back to it
3076later.
3077
3078Returning to a checkpoint effectively undoes everything that has
3079happened in the program since the @code{checkpoint} was saved. This
3080includes changes in memory, registers, and even (within some limits)
3081system state. Effectively, it is like going back in time to the
3082moment when the checkpoint was saved.
3083
3084Thus, if you're stepping thru a program and you think you're
3085getting close to the point where things go wrong, you can save
3086a checkpoint. Then, if you accidentally go too far and miss
3087the critical statement, instead of having to restart your program
3088from the beginning, you can just go back to the checkpoint and
3089start again from there.
3090
3091This can be especially useful if it takes a lot of time or
3092steps to reach the point where you think the bug occurs.
3093
3094To use the @code{checkpoint}/@code{restart} method of debugging:
3095
3096@table @code
3097@kindex checkpoint
3098@item checkpoint
3099Save a snapshot of the debugged program's current execution state.
3100The @code{checkpoint} command takes no arguments, but each checkpoint
3101is assigned a small integer id, similar to a breakpoint id.
3102
3103@kindex info checkpoints
3104@item info checkpoints
3105List the checkpoints that have been saved in the current debugging
3106session. For each checkpoint, the following information will be
3107listed:
3108
3109@table @code
3110@item Checkpoint ID
3111@item Process ID
3112@item Code Address
3113@item Source line, or label
3114@end table
3115
3116@kindex restart @var{checkpoint-id}
3117@item restart @var{checkpoint-id}
3118Restore the program state that was saved as checkpoint number
3119@var{checkpoint-id}. All program variables, registers, stack frames
3120etc.@: will be returned to the values that they had when the checkpoint
3121was saved. In essence, gdb will ``wind back the clock'' to the point
3122in time when the checkpoint was saved.
3123
3124Note that breakpoints, @value{GDBN} variables, command history etc.
3125are not affected by restoring a checkpoint. In general, a checkpoint
3126only restores things that reside in the program being debugged, not in
3127the debugger.
3128
b8db102d
MS
3129@kindex delete checkpoint @var{checkpoint-id}
3130@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3131Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3132
3133@end table
3134
3135Returning to a previously saved checkpoint will restore the user state
3136of the program being debugged, plus a significant subset of the system
3137(OS) state, including file pointers. It won't ``un-write'' data from
3138a file, but it will rewind the file pointer to the previous location,
3139so that the previously written data can be overwritten. For files
3140opened in read mode, the pointer will also be restored so that the
3141previously read data can be read again.
3142
3143Of course, characters that have been sent to a printer (or other
3144external device) cannot be ``snatched back'', and characters received
3145from eg.@: a serial device can be removed from internal program buffers,
3146but they cannot be ``pushed back'' into the serial pipeline, ready to
3147be received again. Similarly, the actual contents of files that have
3148been changed cannot be restored (at this time).
3149
3150However, within those constraints, you actually can ``rewind'' your
3151program to a previously saved point in time, and begin debugging it
3152again --- and you can change the course of events so as to debug a
3153different execution path this time.
3154
3155@cindex checkpoints and process id
3156Finally, there is one bit of internal program state that will be
3157different when you return to a checkpoint --- the program's process
3158id. Each checkpoint will have a unique process id (or @var{pid}),
3159and each will be different from the program's original @var{pid}.
3160If your program has saved a local copy of its process id, this could
3161potentially pose a problem.
3162
79a6e687 3163@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3164
3165On some systems such as @sc{gnu}/Linux, address space randomization
3166is performed on new processes for security reasons. This makes it
3167difficult or impossible to set a breakpoint, or watchpoint, on an
3168absolute address if you have to restart the program, since the
3169absolute location of a symbol will change from one execution to the
3170next.
3171
3172A checkpoint, however, is an @emph{identical} copy of a process.
3173Therefore if you create a checkpoint at (eg.@:) the start of main,
3174and simply return to that checkpoint instead of restarting the
3175process, you can avoid the effects of address randomization and
3176your symbols will all stay in the same place.
3177
6d2ebf8b 3178@node Stopping
c906108c
SS
3179@chapter Stopping and Continuing
3180
3181The principal purposes of using a debugger are so that you can stop your
3182program before it terminates; or so that, if your program runs into
3183trouble, you can investigate and find out why.
3184
7a292a7a
SS
3185Inside @value{GDBN}, your program may stop for any of several reasons,
3186such as a signal, a breakpoint, or reaching a new line after a
3187@value{GDBN} command such as @code{step}. You may then examine and
3188change variables, set new breakpoints or remove old ones, and then
3189continue execution. Usually, the messages shown by @value{GDBN} provide
3190ample explanation of the status of your program---but you can also
3191explicitly request this information at any time.
c906108c
SS
3192
3193@table @code
3194@kindex info program
3195@item info program
3196Display information about the status of your program: whether it is
7a292a7a 3197running or not, what process it is, and why it stopped.
c906108c
SS
3198@end table
3199
3200@menu
3201* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3202* Continuing and Stepping:: Resuming execution
c906108c 3203* Signals:: Signals
c906108c 3204* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3205@end menu
3206
6d2ebf8b 3207@node Breakpoints
79a6e687 3208@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3209
3210@cindex breakpoints
3211A @dfn{breakpoint} makes your program stop whenever a certain point in
3212the program is reached. For each breakpoint, you can add conditions to
3213control in finer detail whether your program stops. You can set
3214breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3215Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3216should stop by line number, function name or exact address in the
3217program.
3218
09d4efe1
EZ
3219On some systems, you can set breakpoints in shared libraries before
3220the executable is run. There is a minor limitation on HP-UX systems:
3221you must wait until the executable is run in order to set breakpoints
3222in shared library routines that are not called directly by the program
3223(for example, routines that are arguments in a @code{pthread_create}
3224call).
c906108c
SS
3225
3226@cindex watchpoints
fd60e0df 3227@cindex data breakpoints
c906108c
SS
3228@cindex memory tracing
3229@cindex breakpoint on memory address
3230@cindex breakpoint on variable modification
3231A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3232when the value of an expression changes. The expression may be a value
0ced0c34 3233of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3234combined by operators, such as @samp{a + b}. This is sometimes called
3235@dfn{data breakpoints}. You must use a different command to set
79a6e687 3236watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3237from that, you can manage a watchpoint like any other breakpoint: you
3238enable, disable, and delete both breakpoints and watchpoints using the
3239same commands.
c906108c
SS
3240
3241You can arrange to have values from your program displayed automatically
3242whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3243Automatic Display}.
c906108c
SS
3244
3245@cindex catchpoints
3246@cindex breakpoint on events
3247A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3248when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3249exception or the loading of a library. As with watchpoints, you use a
3250different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3251Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3252other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3253@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3254
3255@cindex breakpoint numbers
3256@cindex numbers for breakpoints
3257@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3258catchpoint when you create it; these numbers are successive integers
3259starting with one. In many of the commands for controlling various
3260features of breakpoints you use the breakpoint number to say which
3261breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3262@dfn{disabled}; if disabled, it has no effect on your program until you
3263enable it again.
3264
c5394b80
JM
3265@cindex breakpoint ranges
3266@cindex ranges of breakpoints
3267Some @value{GDBN} commands accept a range of breakpoints on which to
3268operate. A breakpoint range is either a single breakpoint number, like
3269@samp{5}, or two such numbers, in increasing order, separated by a
3270hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 3271all breakpoints in that range are operated on.
c5394b80 3272
c906108c
SS
3273@menu
3274* Set Breaks:: Setting breakpoints
3275* Set Watchpoints:: Setting watchpoints
3276* Set Catchpoints:: Setting catchpoints
3277* Delete Breaks:: Deleting breakpoints
3278* Disabling:: Disabling breakpoints
3279* Conditions:: Break conditions
3280* Break Commands:: Breakpoint command lists
6149aea9 3281* Save Breakpoints:: How to save breakpoints in a file
d4f3574e 3282* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3283* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3284@end menu
3285
6d2ebf8b 3286@node Set Breaks
79a6e687 3287@subsection Setting Breakpoints
c906108c 3288
5d161b24 3289@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3290@c consider in particular declaration with/without initialization.
3291@c
3292@c FIXME 2 is there stuff on this already? break at fun start, already init?
3293
3294@kindex break
41afff9a
EZ
3295@kindex b @r{(@code{break})}
3296@vindex $bpnum@r{, convenience variable}
c906108c
SS
3297@cindex latest breakpoint
3298Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3299@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3300number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3301Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3302convenience variables.
3303
c906108c 3304@table @code
2a25a5ba
EZ
3305@item break @var{location}
3306Set a breakpoint at the given @var{location}, which can specify a
3307function name, a line number, or an address of an instruction.
3308(@xref{Specify Location}, for a list of all the possible ways to
3309specify a @var{location}.) The breakpoint will stop your program just
3310before it executes any of the code in the specified @var{location}.
3311
c906108c 3312When using source languages that permit overloading of symbols, such as
2a25a5ba 3313C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3314@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3315that situation.
c906108c 3316
45ac276d 3317It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3318only if a specific thread (@pxref{Thread-Specific Breakpoints})
3319or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3320
c906108c
SS
3321@item break
3322When called without any arguments, @code{break} sets a breakpoint at
3323the next instruction to be executed in the selected stack frame
3324(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3325innermost, this makes your program stop as soon as control
3326returns to that frame. This is similar to the effect of a
3327@code{finish} command in the frame inside the selected frame---except
3328that @code{finish} does not leave an active breakpoint. If you use
3329@code{break} without an argument in the innermost frame, @value{GDBN} stops
3330the next time it reaches the current location; this may be useful
3331inside loops.
3332
3333@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3334least one instruction has been executed. If it did not do this, you
3335would be unable to proceed past a breakpoint without first disabling the
3336breakpoint. This rule applies whether or not the breakpoint already
3337existed when your program stopped.
3338
3339@item break @dots{} if @var{cond}
3340Set a breakpoint with condition @var{cond}; evaluate the expression
3341@var{cond} each time the breakpoint is reached, and stop only if the
3342value is nonzero---that is, if @var{cond} evaluates as true.
3343@samp{@dots{}} stands for one of the possible arguments described
3344above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3345,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3346
3347@kindex tbreak
3348@item tbreak @var{args}
3349Set a breakpoint enabled only for one stop. @var{args} are the
3350same as for the @code{break} command, and the breakpoint is set in the same
3351way, but the breakpoint is automatically deleted after the first time your
79a6e687 3352program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3353
c906108c 3354@kindex hbreak
ba04e063 3355@cindex hardware breakpoints
c906108c 3356@item hbreak @var{args}
d4f3574e
SS
3357Set a hardware-assisted breakpoint. @var{args} are the same as for the
3358@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3359breakpoint requires hardware support and some target hardware may not
3360have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3361debugging, so you can set a breakpoint at an instruction without
3362changing the instruction. This can be used with the new trap-generation
09d4efe1 3363provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3364will generate traps when a program accesses some data or instruction
3365address that is assigned to the debug registers. However the hardware
3366breakpoint registers can take a limited number of breakpoints. For
3367example, on the DSU, only two data breakpoints can be set at a time, and
3368@value{GDBN} will reject this command if more than two are used. Delete
3369or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3370(@pxref{Disabling, ,Disabling Breakpoints}).
3371@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3372For remote targets, you can restrict the number of hardware
3373breakpoints @value{GDBN} will use, see @ref{set remote
3374hardware-breakpoint-limit}.
501eef12 3375
c906108c
SS
3376@kindex thbreak
3377@item thbreak @var{args}
3378Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3379are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3380the same way. However, like the @code{tbreak} command,
c906108c
SS
3381the breakpoint is automatically deleted after the
3382first time your program stops there. Also, like the @code{hbreak}
5d161b24 3383command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3384may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3385See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3386
3387@kindex rbreak
3388@cindex regular expression
8bd10a10 3389@cindex breakpoints at functions matching a regexp
c45da7e6 3390@cindex set breakpoints in many functions
c906108c 3391@item rbreak @var{regex}
c906108c 3392Set breakpoints on all functions matching the regular expression
11cf8741
JM
3393@var{regex}. This command sets an unconditional breakpoint on all
3394matches, printing a list of all breakpoints it set. Once these
3395breakpoints are set, they are treated just like the breakpoints set with
3396the @code{break} command. You can delete them, disable them, or make
3397them conditional the same way as any other breakpoint.
3398
3399The syntax of the regular expression is the standard one used with tools
3400like @file{grep}. Note that this is different from the syntax used by
3401shells, so for instance @code{foo*} matches all functions that include
3402an @code{fo} followed by zero or more @code{o}s. There is an implicit
3403@code{.*} leading and trailing the regular expression you supply, so to
3404match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3405
f7dc1244 3406@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3407When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3408breakpoints on overloaded functions that are not members of any special
3409classes.
c906108c 3410
f7dc1244
EZ
3411@cindex set breakpoints on all functions
3412The @code{rbreak} command can be used to set breakpoints in
3413@strong{all} the functions in a program, like this:
3414
3415@smallexample
3416(@value{GDBP}) rbreak .
3417@end smallexample
3418
8bd10a10
CM
3419@item rbreak @var{file}:@var{regex}
3420If @code{rbreak} is called with a filename qualification, it limits
3421the search for functions matching the given regular expression to the
3422specified @var{file}. This can be used, for example, to set breakpoints on
3423every function in a given file:
3424
3425@smallexample
3426(@value{GDBP}) rbreak file.c:.
3427@end smallexample
3428
3429The colon separating the filename qualifier from the regex may
3430optionally be surrounded by spaces.
3431
c906108c
SS
3432@kindex info breakpoints
3433@cindex @code{$_} and @code{info breakpoints}
3434@item info breakpoints @r{[}@var{n}@r{]}
3435@itemx info break @r{[}@var{n}@r{]}
c906108c 3436Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734
EZ
3437not deleted. Optional argument @var{n} means print information only
3438about the specified breakpoint (or watchpoint or catchpoint). For
3439each breakpoint, following columns are printed:
c906108c
SS
3440
3441@table @emph
3442@item Breakpoint Numbers
3443@item Type
3444Breakpoint, watchpoint, or catchpoint.
3445@item Disposition
3446Whether the breakpoint is marked to be disabled or deleted when hit.
3447@item Enabled or Disabled
3448Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3449that are not enabled.
c906108c 3450@item Address
fe6fbf8b 3451Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3452pending breakpoint whose address is not yet known, this field will
3453contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3454library that has the symbol or line referred by breakpoint is loaded.
3455See below for details. A breakpoint with several locations will
3b784c4f 3456have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3457@item What
3458Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3459line number. For a pending breakpoint, the original string passed to
3460the breakpoint command will be listed as it cannot be resolved until
3461the appropriate shared library is loaded in the future.
c906108c
SS
3462@end table
3463
3464@noindent
3465If a breakpoint is conditional, @code{info break} shows the condition on
3466the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
3467are listed after that. A pending breakpoint is allowed to have a condition
3468specified for it. The condition is not parsed for validity until a shared
3469library is loaded that allows the pending breakpoint to resolve to a
3470valid location.
c906108c
SS
3471
3472@noindent
3473@code{info break} with a breakpoint
3474number @var{n} as argument lists only that breakpoint. The
3475convenience variable @code{$_} and the default examining-address for
3476the @code{x} command are set to the address of the last breakpoint
79a6e687 3477listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3478
3479@noindent
3480@code{info break} displays a count of the number of times the breakpoint
3481has been hit. This is especially useful in conjunction with the
3482@code{ignore} command. You can ignore a large number of breakpoint
3483hits, look at the breakpoint info to see how many times the breakpoint
3484was hit, and then run again, ignoring one less than that number. This
3485will get you quickly to the last hit of that breakpoint.
3486@end table
3487
3488@value{GDBN} allows you to set any number of breakpoints at the same place in
3489your program. There is nothing silly or meaningless about this. When
3490the breakpoints are conditional, this is even useful
79a6e687 3491(@pxref{Conditions, ,Break Conditions}).
c906108c 3492
2e9132cc
EZ
3493@cindex multiple locations, breakpoints
3494@cindex breakpoints, multiple locations
fcda367b 3495It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3496in your program. Examples of this situation are:
3497
3498@itemize @bullet
fe6fbf8b
VP
3499@item
3500For a C@t{++} constructor, the @value{NGCC} compiler generates several
3501instances of the function body, used in different cases.
3502
3503@item
3504For a C@t{++} template function, a given line in the function can
3505correspond to any number of instantiations.
3506
3507@item
3508For an inlined function, a given source line can correspond to
3509several places where that function is inlined.
fe6fbf8b
VP
3510@end itemize
3511
3512In all those cases, @value{GDBN} will insert a breakpoint at all
2e9132cc
EZ
3513the relevant locations@footnote{
3514As of this writing, multiple-location breakpoints work only if there's
3515line number information for all the locations. This means that they
3516will generally not work in system libraries, unless you have debug
3517info with line numbers for them.}.
fe6fbf8b 3518
3b784c4f
EZ
3519A breakpoint with multiple locations is displayed in the breakpoint
3520table using several rows---one header row, followed by one row for
3521each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3522address column. The rows for individual locations contain the actual
3523addresses for locations, and show the functions to which those
3524locations belong. The number column for a location is of the form
fe6fbf8b
VP
3525@var{breakpoint-number}.@var{location-number}.
3526
3527For example:
3b784c4f 3528
fe6fbf8b
VP
3529@smallexample
3530Num Type Disp Enb Address What
35311 breakpoint keep y <MULTIPLE>
3532 stop only if i==1
3533 breakpoint already hit 1 time
35341.1 y 0x080486a2 in void foo<int>() at t.cc:8
35351.2 y 0x080486ca in void foo<double>() at t.cc:8
3536@end smallexample
3537
3538Each location can be individually enabled or disabled by passing
3539@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3540@code{enable} and @code{disable} commands. Note that you cannot
3541delete the individual locations from the list, you can only delete the
16bfc218 3542entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3543the @kbd{delete @var{num}} command, where @var{num} is the number of
3544the parent breakpoint, 1 in the above example). Disabling or enabling
3545the parent breakpoint (@pxref{Disabling}) affects all of the locations
3546that belong to that breakpoint.
fe6fbf8b 3547
2650777c 3548@cindex pending breakpoints
fe6fbf8b 3549It's quite common to have a breakpoint inside a shared library.
3b784c4f 3550Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3551and possibly repeatedly, as the program is executed. To support
3552this use case, @value{GDBN} updates breakpoint locations whenever
3553any shared library is loaded or unloaded. Typically, you would
fcda367b 3554set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3555debugging session, when the library is not loaded, and when the
3556symbols from the library are not available. When you try to set
3557breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3558a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3559is not yet resolved.
3560
3561After the program is run, whenever a new shared library is loaded,
3562@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3563shared library contains the symbol or line referred to by some
3564pending breakpoint, that breakpoint is resolved and becomes an
3565ordinary breakpoint. When a library is unloaded, all breakpoints
3566that refer to its symbols or source lines become pending again.
3567
3568This logic works for breakpoints with multiple locations, too. For
3569example, if you have a breakpoint in a C@t{++} template function, and
3570a newly loaded shared library has an instantiation of that template,
3571a new location is added to the list of locations for the breakpoint.
3572
3573Except for having unresolved address, pending breakpoints do not
3574differ from regular breakpoints. You can set conditions or commands,
3575enable and disable them and perform other breakpoint operations.
3576
3577@value{GDBN} provides some additional commands for controlling what
3578happens when the @samp{break} command cannot resolve breakpoint
3579address specification to an address:
dd79a6cf
JJ
3580
3581@kindex set breakpoint pending
3582@kindex show breakpoint pending
3583@table @code
3584@item set breakpoint pending auto
3585This is the default behavior. When @value{GDBN} cannot find the breakpoint
3586location, it queries you whether a pending breakpoint should be created.
3587
3588@item set breakpoint pending on
3589This indicates that an unrecognized breakpoint location should automatically
3590result in a pending breakpoint being created.
3591
3592@item set breakpoint pending off
3593This indicates that pending breakpoints are not to be created. Any
3594unrecognized breakpoint location results in an error. This setting does
3595not affect any pending breakpoints previously created.
3596
3597@item show breakpoint pending
3598Show the current behavior setting for creating pending breakpoints.
3599@end table
2650777c 3600
fe6fbf8b
VP
3601The settings above only affect the @code{break} command and its
3602variants. Once breakpoint is set, it will be automatically updated
3603as shared libraries are loaded and unloaded.
2650777c 3604
765dc015
VP
3605@cindex automatic hardware breakpoints
3606For some targets, @value{GDBN} can automatically decide if hardware or
3607software breakpoints should be used, depending on whether the
3608breakpoint address is read-only or read-write. This applies to
3609breakpoints set with the @code{break} command as well as to internal
3610breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3611breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3612breakpoints.
3613
3614You can control this automatic behaviour with the following commands::
3615
3616@kindex set breakpoint auto-hw
3617@kindex show breakpoint auto-hw
3618@table @code
3619@item set breakpoint auto-hw on
3620This is the default behavior. When @value{GDBN} sets a breakpoint, it
3621will try to use the target memory map to decide if software or hardware
3622breakpoint must be used.
3623
3624@item set breakpoint auto-hw off
3625This indicates @value{GDBN} should not automatically select breakpoint
3626type. If the target provides a memory map, @value{GDBN} will warn when
3627trying to set software breakpoint at a read-only address.
3628@end table
3629
74960c60
VP
3630@value{GDBN} normally implements breakpoints by replacing the program code
3631at the breakpoint address with a special instruction, which, when
3632executed, given control to the debugger. By default, the program
3633code is so modified only when the program is resumed. As soon as
3634the program stops, @value{GDBN} restores the original instructions. This
3635behaviour guards against leaving breakpoints inserted in the
3636target should gdb abrubptly disconnect. However, with slow remote
3637targets, inserting and removing breakpoint can reduce the performance.
3638This behavior can be controlled with the following commands::
3639
3640@kindex set breakpoint always-inserted
3641@kindex show breakpoint always-inserted
3642@table @code
3643@item set breakpoint always-inserted off
33e5cbd6
PA
3644All breakpoints, including newly added by the user, are inserted in
3645the target only when the target is resumed. All breakpoints are
3646removed from the target when it stops.
74960c60
VP
3647
3648@item set breakpoint always-inserted on
3649Causes all breakpoints to be inserted in the target at all times. If
3650the user adds a new breakpoint, or changes an existing breakpoint, the
3651breakpoints in the target are updated immediately. A breakpoint is
3652removed from the target only when breakpoint itself is removed.
33e5cbd6
PA
3653
3654@cindex non-stop mode, and @code{breakpoint always-inserted}
3655@item set breakpoint always-inserted auto
3656This is the default mode. If @value{GDBN} is controlling the inferior
3657in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3658@code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3659controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3660@code{breakpoint always-inserted} mode is off.
74960c60 3661@end table
765dc015 3662
c906108c
SS
3663@cindex negative breakpoint numbers
3664@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3665@value{GDBN} itself sometimes sets breakpoints in your program for
3666special purposes, such as proper handling of @code{longjmp} (in C
3667programs). These internal breakpoints are assigned negative numbers,
3668starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3669You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3670@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3671
3672
6d2ebf8b 3673@node Set Watchpoints
79a6e687 3674@subsection Setting Watchpoints
c906108c
SS
3675
3676@cindex setting watchpoints
c906108c
SS
3677You can use a watchpoint to stop execution whenever the value of an
3678expression changes, without having to predict a particular place where
fd60e0df
EZ
3679this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3680The expression may be as simple as the value of a single variable, or
3681as complex as many variables combined by operators. Examples include:
3682
3683@itemize @bullet
3684@item
3685A reference to the value of a single variable.
3686
3687@item
3688An address cast to an appropriate data type. For example,
3689@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3690address (assuming an @code{int} occupies 4 bytes).
3691
3692@item
3693An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3694expression can use any operators valid in the program's native
3695language (@pxref{Languages}).
3696@end itemize
c906108c 3697
fa4727a6
DJ
3698You can set a watchpoint on an expression even if the expression can
3699not be evaluated yet. For instance, you can set a watchpoint on
3700@samp{*global_ptr} before @samp{global_ptr} is initialized.
3701@value{GDBN} will stop when your program sets @samp{global_ptr} and
3702the expression produces a valid value. If the expression becomes
3703valid in some other way than changing a variable (e.g.@: if the memory
3704pointed to by @samp{*global_ptr} becomes readable as the result of a
3705@code{malloc} call), @value{GDBN} may not stop until the next time
3706the expression changes.
3707
82f2d802
EZ
3708@cindex software watchpoints
3709@cindex hardware watchpoints
c906108c 3710Depending on your system, watchpoints may be implemented in software or
2df3850c 3711hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3712program and testing the variable's value each time, which is hundreds of
3713times slower than normal execution. (But this may still be worth it, to
3714catch errors where you have no clue what part of your program is the
3715culprit.)
3716
37e4754d 3717On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
82f2d802
EZ
3718x86-based targets, @value{GDBN} includes support for hardware
3719watchpoints, which do not slow down the running of your program.
c906108c
SS
3720
3721@table @code
3722@kindex watch
06a64a0b 3723@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]}
fd60e0df
EZ
3724Set a watchpoint for an expression. @value{GDBN} will break when the
3725expression @var{expr} is written into by the program and its value
3726changes. The simplest (and the most popular) use of this command is
3727to watch the value of a single variable:
3728
3729@smallexample
3730(@value{GDBP}) watch foo
3731@end smallexample
c906108c 3732
d8b2a693
JB
3733If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3734clause, @value{GDBN} breaks only when the thread identified by
3735@var{threadnum} changes the value of @var{expr}. If any other threads
3736change the value of @var{expr}, @value{GDBN} will not break. Note
3737that watchpoints restricted to a single thread in this way only work
3738with Hardware Watchpoints.
3739
06a64a0b
TT
3740Ordinarily a watchpoint respects the scope of variables in @var{expr}
3741(see below). The @code{-location} argument tells @value{GDBN} to
3742instead watch the memory referred to by @var{expr}. In this case,
3743@value{GDBN} will evaluate @var{expr}, take the address of the result,
3744and watch the memory at that address. The type of the result is used
3745to determine the size of the watched memory. If the expression's
3746result does not have an address, then @value{GDBN} will print an
3747error.
3748
c906108c 3749@kindex rwatch
06a64a0b 3750@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]}
09d4efe1
EZ
3751Set a watchpoint that will break when the value of @var{expr} is read
3752by the program.
c906108c
SS
3753
3754@kindex awatch
06a64a0b 3755@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]}
09d4efe1
EZ
3756Set a watchpoint that will break when @var{expr} is either read from
3757or written into by the program.
c906108c 3758
45ac1734 3759@kindex info watchpoints @r{[}@var{n}@r{]}
c906108c 3760@item info watchpoints
d77f58be
SS
3761This command prints a list of watchpoints, using the same format as
3762@code{info break} (@pxref{Set Breaks}).
c906108c
SS
3763@end table
3764
65d79d4b
SDJ
3765If you watch for a change in a numerically entered address you need to
3766dereference it, as the address itself is just a constant number which will
3767never change. @value{GDBN} refuses to create a watchpoint that watches
3768a never-changing value:
3769
3770@smallexample
3771(@value{GDBP}) watch 0x600850
3772Cannot watch constant value 0x600850.
3773(@value{GDBP}) watch *(int *) 0x600850
3774Watchpoint 1: *(int *) 6293584
3775@end smallexample
3776
c906108c
SS
3777@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3778watchpoints execute very quickly, and the debugger reports a change in
3779value at the exact instruction where the change occurs. If @value{GDBN}
3780cannot set a hardware watchpoint, it sets a software watchpoint, which
3781executes more slowly and reports the change in value at the next
82f2d802
EZ
3782@emph{statement}, not the instruction, after the change occurs.
3783
82f2d802
EZ
3784@cindex use only software watchpoints
3785You can force @value{GDBN} to use only software watchpoints with the
3786@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3787zero, @value{GDBN} will never try to use hardware watchpoints, even if
3788the underlying system supports them. (Note that hardware-assisted
3789watchpoints that were set @emph{before} setting
3790@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 3791mechanism of watching expression values.)
c906108c 3792
9c16f35a
EZ
3793@table @code
3794@item set can-use-hw-watchpoints
3795@kindex set can-use-hw-watchpoints
3796Set whether or not to use hardware watchpoints.
3797
3798@item show can-use-hw-watchpoints
3799@kindex show can-use-hw-watchpoints
3800Show the current mode of using hardware watchpoints.
3801@end table
3802
3803For remote targets, you can restrict the number of hardware
3804watchpoints @value{GDBN} will use, see @ref{set remote
3805hardware-breakpoint-limit}.
3806
c906108c
SS
3807When you issue the @code{watch} command, @value{GDBN} reports
3808
474c8240 3809@smallexample
c906108c 3810Hardware watchpoint @var{num}: @var{expr}
474c8240 3811@end smallexample
c906108c
SS
3812
3813@noindent
3814if it was able to set a hardware watchpoint.
3815
7be570e7
JM
3816Currently, the @code{awatch} and @code{rwatch} commands can only set
3817hardware watchpoints, because accesses to data that don't change the
3818value of the watched expression cannot be detected without examining
3819every instruction as it is being executed, and @value{GDBN} does not do
3820that currently. If @value{GDBN} finds that it is unable to set a
3821hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3822will print a message like this:
3823
3824@smallexample
3825Expression cannot be implemented with read/access watchpoint.
3826@end smallexample
3827
3828Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3829data type of the watched expression is wider than what a hardware
3830watchpoint on the target machine can handle. For example, some systems
3831can only watch regions that are up to 4 bytes wide; on such systems you
3832cannot set hardware watchpoints for an expression that yields a
3833double-precision floating-point number (which is typically 8 bytes
3834wide). As a work-around, it might be possible to break the large region
3835into a series of smaller ones and watch them with separate watchpoints.
3836
3837If you set too many hardware watchpoints, @value{GDBN} might be unable
3838to insert all of them when you resume the execution of your program.
3839Since the precise number of active watchpoints is unknown until such
3840time as the program is about to be resumed, @value{GDBN} might not be
3841able to warn you about this when you set the watchpoints, and the
3842warning will be printed only when the program is resumed:
3843
3844@smallexample
3845Hardware watchpoint @var{num}: Could not insert watchpoint
3846@end smallexample
3847
3848@noindent
3849If this happens, delete or disable some of the watchpoints.
3850
fd60e0df
EZ
3851Watching complex expressions that reference many variables can also
3852exhaust the resources available for hardware-assisted watchpoints.
3853That's because @value{GDBN} needs to watch every variable in the
3854expression with separately allocated resources.
3855
c906108c 3856If you call a function interactively using @code{print} or @code{call},
2df3850c 3857any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3858kind of breakpoint or the call completes.
3859
7be570e7
JM
3860@value{GDBN} automatically deletes watchpoints that watch local
3861(automatic) variables, or expressions that involve such variables, when
3862they go out of scope, that is, when the execution leaves the block in
3863which these variables were defined. In particular, when the program
3864being debugged terminates, @emph{all} local variables go out of scope,
3865and so only watchpoints that watch global variables remain set. If you
3866rerun the program, you will need to set all such watchpoints again. One
3867way of doing that would be to set a code breakpoint at the entry to the
3868@code{main} function and when it breaks, set all the watchpoints.
3869
c906108c
SS
3870@cindex watchpoints and threads
3871@cindex threads and watchpoints
d983da9c
DJ
3872In multi-threaded programs, watchpoints will detect changes to the
3873watched expression from every thread.
3874
3875@quotation
3876@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
3877have only limited usefulness. If @value{GDBN} creates a software
3878watchpoint, it can only watch the value of an expression @emph{in a
3879single thread}. If you are confident that the expression can only
3880change due to the current thread's activity (and if you are also
3881confident that no other thread can become current), then you can use
3882software watchpoints as usual. However, @value{GDBN} may not notice
3883when a non-current thread's activity changes the expression. (Hardware
3884watchpoints, in contrast, watch an expression in all threads.)
c906108c 3885@end quotation
c906108c 3886
501eef12
AC
3887@xref{set remote hardware-watchpoint-limit}.
3888
6d2ebf8b 3889@node Set Catchpoints
79a6e687 3890@subsection Setting Catchpoints
d4f3574e 3891@cindex catchpoints, setting
c906108c
SS
3892@cindex exception handlers
3893@cindex event handling
3894
3895You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3896kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3897shared library. Use the @code{catch} command to set a catchpoint.
3898
3899@table @code
3900@kindex catch
3901@item catch @var{event}
3902Stop when @var{event} occurs. @var{event} can be any of the following:
3903@table @code
3904@item throw
4644b6e3 3905@cindex stop on C@t{++} exceptions
b37052ae 3906The throwing of a C@t{++} exception.
c906108c
SS
3907
3908@item catch
b37052ae 3909The catching of a C@t{++} exception.
c906108c 3910
8936fcda
JB
3911@item exception
3912@cindex Ada exception catching
3913@cindex catch Ada exceptions
3914An Ada exception being raised. If an exception name is specified
3915at the end of the command (eg @code{catch exception Program_Error}),
3916the debugger will stop only when this specific exception is raised.
3917Otherwise, the debugger stops execution when any Ada exception is raised.
3918
87f67dba
JB
3919When inserting an exception catchpoint on a user-defined exception whose
3920name is identical to one of the exceptions defined by the language, the
3921fully qualified name must be used as the exception name. Otherwise,
3922@value{GDBN} will assume that it should stop on the pre-defined exception
3923rather than the user-defined one. For instance, assuming an exception
3924called @code{Constraint_Error} is defined in package @code{Pck}, then
3925the command to use to catch such exceptions is @kbd{catch exception
3926Pck.Constraint_Error}.
3927
8936fcda
JB
3928@item exception unhandled
3929An exception that was raised but is not handled by the program.
3930
3931@item assert
3932A failed Ada assertion.
3933
c906108c 3934@item exec
4644b6e3 3935@cindex break on fork/exec
5ee187d7
DJ
3936A call to @code{exec}. This is currently only available for HP-UX
3937and @sc{gnu}/Linux.
c906108c 3938
a96d9b2e 3939@item syscall
ee8e71d4 3940@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
a96d9b2e
SDJ
3941@cindex break on a system call.
3942A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
3943syscall is a mechanism for application programs to request a service
3944from the operating system (OS) or one of the OS system services.
3945@value{GDBN} can catch some or all of the syscalls issued by the
3946debuggee, and show the related information for each syscall. If no
3947argument is specified, calls to and returns from all system calls
3948will be caught.
3949
3950@var{name} can be any system call name that is valid for the
3951underlying OS. Just what syscalls are valid depends on the OS. On
3952GNU and Unix systems, you can find the full list of valid syscall
3953names on @file{/usr/include/asm/unistd.h}.
3954
3955@c For MS-Windows, the syscall names and the corresponding numbers
3956@c can be found, e.g., on this URL:
3957@c http://www.metasploit.com/users/opcode/syscalls.html
3958@c but we don't support Windows syscalls yet.
3959
3960Normally, @value{GDBN} knows in advance which syscalls are valid for
3961each OS, so you can use the @value{GDBN} command-line completion
3962facilities (@pxref{Completion,, command completion}) to list the
3963available choices.
3964
3965You may also specify the system call numerically. A syscall's
3966number is the value passed to the OS's syscall dispatcher to
3967identify the requested service. When you specify the syscall by its
3968name, @value{GDBN} uses its database of syscalls to convert the name
3969into the corresponding numeric code, but using the number directly
3970may be useful if @value{GDBN}'s database does not have the complete
3971list of syscalls on your system (e.g., because @value{GDBN} lags
3972behind the OS upgrades).
3973
3974The example below illustrates how this command works if you don't provide
3975arguments to it:
3976
3977@smallexample
3978(@value{GDBP}) catch syscall
3979Catchpoint 1 (syscall)
3980(@value{GDBP}) r
3981Starting program: /tmp/catch-syscall
3982
3983Catchpoint 1 (call to syscall 'close'), \
3984 0xffffe424 in __kernel_vsyscall ()
3985(@value{GDBP}) c
3986Continuing.
3987
3988Catchpoint 1 (returned from syscall 'close'), \
3989 0xffffe424 in __kernel_vsyscall ()
3990(@value{GDBP})
3991@end smallexample
3992
3993Here is an example of catching a system call by name:
3994
3995@smallexample
3996(@value{GDBP}) catch syscall chroot
3997Catchpoint 1 (syscall 'chroot' [61])
3998(@value{GDBP}) r
3999Starting program: /tmp/catch-syscall
4000
4001Catchpoint 1 (call to syscall 'chroot'), \
4002 0xffffe424 in __kernel_vsyscall ()
4003(@value{GDBP}) c
4004Continuing.
4005
4006Catchpoint 1 (returned from syscall 'chroot'), \
4007 0xffffe424 in __kernel_vsyscall ()
4008(@value{GDBP})
4009@end smallexample
4010
4011An example of specifying a system call numerically. In the case
4012below, the syscall number has a corresponding entry in the XML
4013file, so @value{GDBN} finds its name and prints it:
4014
4015@smallexample
4016(@value{GDBP}) catch syscall 252
4017Catchpoint 1 (syscall(s) 'exit_group')
4018(@value{GDBP}) r
4019Starting program: /tmp/catch-syscall
4020
4021Catchpoint 1 (call to syscall 'exit_group'), \
4022 0xffffe424 in __kernel_vsyscall ()
4023(@value{GDBP}) c
4024Continuing.
4025
4026Program exited normally.
4027(@value{GDBP})
4028@end smallexample
4029
4030However, there can be situations when there is no corresponding name
4031in XML file for that syscall number. In this case, @value{GDBN} prints
4032a warning message saying that it was not able to find the syscall name,
4033but the catchpoint will be set anyway. See the example below:
4034
4035@smallexample
4036(@value{GDBP}) catch syscall 764
4037warning: The number '764' does not represent a known syscall.
4038Catchpoint 2 (syscall 764)
4039(@value{GDBP})
4040@end smallexample
4041
4042If you configure @value{GDBN} using the @samp{--without-expat} option,
4043it will not be able to display syscall names. Also, if your
4044architecture does not have an XML file describing its system calls,
4045you will not be able to see the syscall names. It is important to
4046notice that these two features are used for accessing the syscall
4047name database. In either case, you will see a warning like this:
4048
4049@smallexample
4050(@value{GDBP}) catch syscall
4051warning: Could not open "syscalls/i386-linux.xml"
4052warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4053GDB will not be able to display syscall names.
4054Catchpoint 1 (syscall)
4055(@value{GDBP})
4056@end smallexample
4057
4058Of course, the file name will change depending on your architecture and system.
4059
4060Still using the example above, you can also try to catch a syscall by its
4061number. In this case, you would see something like:
4062
4063@smallexample
4064(@value{GDBP}) catch syscall 252
4065Catchpoint 1 (syscall(s) 252)
4066@end smallexample
4067
4068Again, in this case @value{GDBN} would not be able to display syscall's names.
4069
c906108c 4070@item fork
5ee187d7
DJ
4071A call to @code{fork}. This is currently only available for HP-UX
4072and @sc{gnu}/Linux.
c906108c
SS
4073
4074@item vfork
5ee187d7
DJ
4075A call to @code{vfork}. This is currently only available for HP-UX
4076and @sc{gnu}/Linux.
c906108c 4077
c906108c
SS
4078@end table
4079
4080@item tcatch @var{event}
4081Set a catchpoint that is enabled only for one stop. The catchpoint is
4082automatically deleted after the first time the event is caught.
4083
4084@end table
4085
4086Use the @code{info break} command to list the current catchpoints.
4087
b37052ae 4088There are currently some limitations to C@t{++} exception handling
c906108c
SS
4089(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4090
4091@itemize @bullet
4092@item
4093If you call a function interactively, @value{GDBN} normally returns
4094control to you when the function has finished executing. If the call
4095raises an exception, however, the call may bypass the mechanism that
4096returns control to you and cause your program either to abort or to
4097simply continue running until it hits a breakpoint, catches a signal
4098that @value{GDBN} is listening for, or exits. This is the case even if
4099you set a catchpoint for the exception; catchpoints on exceptions are
4100disabled within interactive calls.
4101
4102@item
4103You cannot raise an exception interactively.
4104
4105@item
4106You cannot install an exception handler interactively.
4107@end itemize
4108
4109@cindex raise exceptions
4110Sometimes @code{catch} is not the best way to debug exception handling:
4111if you need to know exactly where an exception is raised, it is better to
4112stop @emph{before} the exception handler is called, since that way you
4113can see the stack before any unwinding takes place. If you set a
4114breakpoint in an exception handler instead, it may not be easy to find
4115out where the exception was raised.
4116
4117To stop just before an exception handler is called, you need some
b37052ae 4118knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
4119raised by calling a library function named @code{__raise_exception}
4120which has the following ANSI C interface:
4121
474c8240 4122@smallexample
c906108c 4123 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
4124 @var{id} is the exception identifier. */
4125 void __raise_exception (void **addr, void *id);
474c8240 4126@end smallexample
c906108c
SS
4127
4128@noindent
4129To make the debugger catch all exceptions before any stack
4130unwinding takes place, set a breakpoint on @code{__raise_exception}
79a6e687 4131(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
c906108c 4132
79a6e687 4133With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
c906108c
SS
4134that depends on the value of @var{id}, you can stop your program when
4135a specific exception is raised. You can use multiple conditional
4136breakpoints to stop your program when any of a number of exceptions are
4137raised.
4138
4139
6d2ebf8b 4140@node Delete Breaks
79a6e687 4141@subsection Deleting Breakpoints
c906108c
SS
4142
4143@cindex clearing breakpoints, watchpoints, catchpoints
4144@cindex deleting breakpoints, watchpoints, catchpoints
4145It is often necessary to eliminate a breakpoint, watchpoint, or
4146catchpoint once it has done its job and you no longer want your program
4147to stop there. This is called @dfn{deleting} the breakpoint. A
4148breakpoint that has been deleted no longer exists; it is forgotten.
4149
4150With the @code{clear} command you can delete breakpoints according to
4151where they are in your program. With the @code{delete} command you can
4152delete individual breakpoints, watchpoints, or catchpoints by specifying
4153their breakpoint numbers.
4154
4155It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4156automatically ignores breakpoints on the first instruction to be executed
4157when you continue execution without changing the execution address.
4158
4159@table @code
4160@kindex clear
4161@item clear
4162Delete any breakpoints at the next instruction to be executed in the
79a6e687 4163selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4164the innermost frame is selected, this is a good way to delete a
4165breakpoint where your program just stopped.
4166
2a25a5ba
EZ
4167@item clear @var{location}
4168Delete any breakpoints set at the specified @var{location}.
4169@xref{Specify Location}, for the various forms of @var{location}; the
4170most useful ones are listed below:
4171
4172@table @code
c906108c
SS
4173@item clear @var{function}
4174@itemx clear @var{filename}:@var{function}
09d4efe1 4175Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4176
4177@item clear @var{linenum}
4178@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4179Delete any breakpoints set at or within the code of the specified
4180@var{linenum} of the specified @var{filename}.
2a25a5ba 4181@end table
c906108c
SS
4182
4183@cindex delete breakpoints
4184@kindex delete
41afff9a 4185@kindex d @r{(@code{delete})}
c5394b80
JM
4186@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4187Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4188ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
4189breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4190confirm off}). You can abbreviate this command as @code{d}.
4191@end table
4192
6d2ebf8b 4193@node Disabling
79a6e687 4194@subsection Disabling Breakpoints
c906108c 4195
4644b6e3 4196@cindex enable/disable a breakpoint
c906108c
SS
4197Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4198prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4199it had been deleted, but remembers the information on the breakpoint so
4200that you can @dfn{enable} it again later.
4201
4202You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4203the @code{enable} and @code{disable} commands, optionally specifying
4204one or more breakpoint numbers as arguments. Use @code{info break} to
4205print a list of all breakpoints, watchpoints, and catchpoints if you
4206do not know which numbers to use.
c906108c 4207
3b784c4f
EZ
4208Disabling and enabling a breakpoint that has multiple locations
4209affects all of its locations.
4210
c906108c
SS
4211A breakpoint, watchpoint, or catchpoint can have any of four different
4212states of enablement:
4213
4214@itemize @bullet
4215@item
4216Enabled. The breakpoint stops your program. A breakpoint set
4217with the @code{break} command starts out in this state.
4218@item
4219Disabled. The breakpoint has no effect on your program.
4220@item
4221Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4222disabled.
c906108c
SS
4223@item
4224Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4225immediately after it does so it is deleted permanently. A breakpoint
4226set with the @code{tbreak} command starts out in this state.
c906108c
SS
4227@end itemize
4228
4229You can use the following commands to enable or disable breakpoints,
4230watchpoints, and catchpoints:
4231
4232@table @code
c906108c 4233@kindex disable
41afff9a 4234@kindex dis @r{(@code{disable})}
c5394b80 4235@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4236Disable the specified breakpoints---or all breakpoints, if none are
4237listed. A disabled breakpoint has no effect but is not forgotten. All
4238options such as ignore-counts, conditions and commands are remembered in
4239case the breakpoint is enabled again later. You may abbreviate
4240@code{disable} as @code{dis}.
4241
c906108c 4242@kindex enable
c5394b80 4243@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4244Enable the specified breakpoints (or all defined breakpoints). They
4245become effective once again in stopping your program.
4246
c5394b80 4247@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
4248Enable the specified breakpoints temporarily. @value{GDBN} disables any
4249of these breakpoints immediately after stopping your program.
4250
c5394b80 4251@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
4252Enable the specified breakpoints to work once, then die. @value{GDBN}
4253deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4254Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4255@end table
4256
d4f3574e
SS
4257@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4258@c confusing: tbreak is also initially enabled.
c906108c 4259Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 4260,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
4261subsequently, they become disabled or enabled only when you use one of
4262the commands above. (The command @code{until} can set and delete a
4263breakpoint of its own, but it does not change the state of your other
4264breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 4265Stepping}.)
c906108c 4266
6d2ebf8b 4267@node Conditions
79a6e687 4268@subsection Break Conditions
c906108c
SS
4269@cindex conditional breakpoints
4270@cindex breakpoint conditions
4271
4272@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 4273@c in particular for a watchpoint?
c906108c
SS
4274The simplest sort of breakpoint breaks every time your program reaches a
4275specified place. You can also specify a @dfn{condition} for a
4276breakpoint. A condition is just a Boolean expression in your
4277programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4278a condition evaluates the expression each time your program reaches it,
4279and your program stops only if the condition is @emph{true}.
4280
4281This is the converse of using assertions for program validation; in that
4282situation, you want to stop when the assertion is violated---that is,
4283when the condition is false. In C, if you want to test an assertion expressed
4284by the condition @var{assert}, you should set the condition
4285@samp{! @var{assert}} on the appropriate breakpoint.
4286
4287Conditions are also accepted for watchpoints; you may not need them,
4288since a watchpoint is inspecting the value of an expression anyhow---but
4289it might be simpler, say, to just set a watchpoint on a variable name,
4290and specify a condition that tests whether the new value is an interesting
4291one.
4292
4293Break conditions can have side effects, and may even call functions in
4294your program. This can be useful, for example, to activate functions
4295that log program progress, or to use your own print functions to
99e008fe 4296format special data structures. The effects are completely predictable
c906108c
SS
4297unless there is another enabled breakpoint at the same address. (In
4298that case, @value{GDBN} might see the other breakpoint first and stop your
4299program without checking the condition of this one.) Note that
d4f3574e
SS
4300breakpoint commands are usually more convenient and flexible than break
4301conditions for the
c906108c 4302purpose of performing side effects when a breakpoint is reached
79a6e687 4303(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c
SS
4304
4305Break conditions can be specified when a breakpoint is set, by using
4306@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 4307Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 4308with the @code{condition} command.
53a5351d 4309
c906108c
SS
4310You can also use the @code{if} keyword with the @code{watch} command.
4311The @code{catch} command does not recognize the @code{if} keyword;
4312@code{condition} is the only way to impose a further condition on a
4313catchpoint.
c906108c
SS
4314
4315@table @code
4316@kindex condition
4317@item condition @var{bnum} @var{expression}
4318Specify @var{expression} as the break condition for breakpoint,
4319watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4320breakpoint @var{bnum} stops your program only if the value of
4321@var{expression} is true (nonzero, in C). When you use
4322@code{condition}, @value{GDBN} checks @var{expression} immediately for
4323syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
4324referents in the context of your breakpoint. If @var{expression} uses
4325symbols not referenced in the context of the breakpoint, @value{GDBN}
4326prints an error message:
4327
474c8240 4328@smallexample
d4f3574e 4329No symbol "foo" in current context.
474c8240 4330@end smallexample
d4f3574e
SS
4331
4332@noindent
c906108c
SS
4333@value{GDBN} does
4334not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
4335command (or a command that sets a breakpoint with a condition, like
4336@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
4337
4338@item condition @var{bnum}
4339Remove the condition from breakpoint number @var{bnum}. It becomes
4340an ordinary unconditional breakpoint.
4341@end table
4342
4343@cindex ignore count (of breakpoint)
4344A special case of a breakpoint condition is to stop only when the
4345breakpoint has been reached a certain number of times. This is so
4346useful that there is a special way to do it, using the @dfn{ignore
4347count} of the breakpoint. Every breakpoint has an ignore count, which
4348is an integer. Most of the time, the ignore count is zero, and
4349therefore has no effect. But if your program reaches a breakpoint whose
4350ignore count is positive, then instead of stopping, it just decrements
4351the ignore count by one and continues. As a result, if the ignore count
4352value is @var{n}, the breakpoint does not stop the next @var{n} times
4353your program reaches it.
4354
4355@table @code
4356@kindex ignore
4357@item ignore @var{bnum} @var{count}
4358Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4359The next @var{count} times the breakpoint is reached, your program's
4360execution does not stop; other than to decrement the ignore count, @value{GDBN}
4361takes no action.
4362
4363To make the breakpoint stop the next time it is reached, specify
4364a count of zero.
4365
4366When you use @code{continue} to resume execution of your program from a
4367breakpoint, you can specify an ignore count directly as an argument to
4368@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 4369Stepping,,Continuing and Stepping}.
c906108c
SS
4370
4371If a breakpoint has a positive ignore count and a condition, the
4372condition is not checked. Once the ignore count reaches zero,
4373@value{GDBN} resumes checking the condition.
4374
4375You could achieve the effect of the ignore count with a condition such
4376as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4377is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 4378Variables}.
c906108c
SS
4379@end table
4380
4381Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4382
4383
6d2ebf8b 4384@node Break Commands
79a6e687 4385@subsection Breakpoint Command Lists
c906108c
SS
4386
4387@cindex breakpoint commands
4388You can give any breakpoint (or watchpoint or catchpoint) a series of
4389commands to execute when your program stops due to that breakpoint. For
4390example, you might want to print the values of certain expressions, or
4391enable other breakpoints.
4392
4393@table @code
4394@kindex commands
ca91424e 4395@kindex end@r{ (breakpoint commands)}
95a42b64 4396@item commands @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4397@itemx @dots{} @var{command-list} @dots{}
4398@itemx end
95a42b64 4399Specify a list of commands for the given breakpoints. The commands
c906108c
SS
4400themselves appear on the following lines. Type a line containing just
4401@code{end} to terminate the commands.
4402
4403To remove all commands from a breakpoint, type @code{commands} and
4404follow it immediately with @code{end}; that is, give no commands.
4405
95a42b64
TT
4406With no argument, @code{commands} refers to the last breakpoint,
4407watchpoint, or catchpoint set (not to the breakpoint most recently
4408encountered). If the most recent breakpoints were set with a single
4409command, then the @code{commands} will apply to all the breakpoints
4410set by that command. This applies to breakpoints set by
86b17b60
PA
4411@code{rbreak}, and also applies when a single @code{break} command
4412creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4413Expressions}).
c906108c
SS
4414@end table
4415
4416Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4417disabled within a @var{command-list}.
4418
4419You can use breakpoint commands to start your program up again. Simply
4420use the @code{continue} command, or @code{step}, or any other command
4421that resumes execution.
4422
4423Any other commands in the command list, after a command that resumes
4424execution, are ignored. This is because any time you resume execution
4425(even with a simple @code{next} or @code{step}), you may encounter
4426another breakpoint---which could have its own command list, leading to
4427ambiguities about which list to execute.
4428
4429@kindex silent
4430If the first command you specify in a command list is @code{silent}, the
4431usual message about stopping at a breakpoint is not printed. This may
4432be desirable for breakpoints that are to print a specific message and
4433then continue. If none of the remaining commands print anything, you
4434see no sign that the breakpoint was reached. @code{silent} is
4435meaningful only at the beginning of a breakpoint command list.
4436
4437The commands @code{echo}, @code{output}, and @code{printf} allow you to
4438print precisely controlled output, and are often useful in silent
79a6e687 4439breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
4440
4441For example, here is how you could use breakpoint commands to print the
4442value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4443
474c8240 4444@smallexample
c906108c
SS
4445break foo if x>0
4446commands
4447silent
4448printf "x is %d\n",x
4449cont
4450end
474c8240 4451@end smallexample
c906108c
SS
4452
4453One application for breakpoint commands is to compensate for one bug so
4454you can test for another. Put a breakpoint just after the erroneous line
4455of code, give it a condition to detect the case in which something
4456erroneous has been done, and give it commands to assign correct values
4457to any variables that need them. End with the @code{continue} command
4458so that your program does not stop, and start with the @code{silent}
4459command so that no output is produced. Here is an example:
4460
474c8240 4461@smallexample
c906108c
SS
4462break 403
4463commands
4464silent
4465set x = y + 4
4466cont
4467end
474c8240 4468@end smallexample
c906108c 4469
6149aea9
PA
4470@node Save Breakpoints
4471@subsection How to save breakpoints to a file
4472
4473To save breakpoint definitions to a file use the @w{@code{save
4474breakpoints}} command.
4475
4476@table @code
4477@kindex save breakpoints
4478@cindex save breakpoints to a file for future sessions
4479@item save breakpoints [@var{filename}]
4480This command saves all current breakpoint definitions together with
4481their commands and ignore counts, into a file @file{@var{filename}}
4482suitable for use in a later debugging session. This includes all
4483types of breakpoints (breakpoints, watchpoints, catchpoints,
4484tracepoints). To read the saved breakpoint definitions, use the
4485@code{source} command (@pxref{Command Files}). Note that watchpoints
4486with expressions involving local variables may fail to be recreated
4487because it may not be possible to access the context where the
4488watchpoint is valid anymore. Because the saved breakpoint definitions
4489are simply a sequence of @value{GDBN} commands that recreate the
4490breakpoints, you can edit the file in your favorite editing program,
4491and remove the breakpoint definitions you're not interested in, or
4492that can no longer be recreated.
4493@end table
4494
c906108c 4495@c @ifclear BARETARGET
6d2ebf8b 4496@node Error in Breakpoints
d4f3574e 4497@subsection ``Cannot insert breakpoints''
c906108c 4498
fa3a767f
PA
4499If you request too many active hardware-assisted breakpoints and
4500watchpoints, you will see this error message:
d4f3574e
SS
4501
4502@c FIXME: the precise wording of this message may change; the relevant
4503@c source change is not committed yet (Sep 3, 1999).
4504@smallexample
4505Stopped; cannot insert breakpoints.
4506You may have requested too many hardware breakpoints and watchpoints.
4507@end smallexample
4508
4509@noindent
4510This message is printed when you attempt to resume the program, since
4511only then @value{GDBN} knows exactly how many hardware breakpoints and
4512watchpoints it needs to insert.
4513
4514When this message is printed, you need to disable or remove some of the
4515hardware-assisted breakpoints and watchpoints, and then continue.
4516
79a6e687 4517@node Breakpoint-related Warnings
1485d690
KB
4518@subsection ``Breakpoint address adjusted...''
4519@cindex breakpoint address adjusted
4520
4521Some processor architectures place constraints on the addresses at
4522which breakpoints may be placed. For architectures thus constrained,
4523@value{GDBN} will attempt to adjust the breakpoint's address to comply
4524with the constraints dictated by the architecture.
4525
4526One example of such an architecture is the Fujitsu FR-V. The FR-V is
4527a VLIW architecture in which a number of RISC-like instructions may be
4528bundled together for parallel execution. The FR-V architecture
4529constrains the location of a breakpoint instruction within such a
4530bundle to the instruction with the lowest address. @value{GDBN}
4531honors this constraint by adjusting a breakpoint's address to the
4532first in the bundle.
4533
4534It is not uncommon for optimized code to have bundles which contain
4535instructions from different source statements, thus it may happen that
4536a breakpoint's address will be adjusted from one source statement to
4537another. Since this adjustment may significantly alter @value{GDBN}'s
4538breakpoint related behavior from what the user expects, a warning is
4539printed when the breakpoint is first set and also when the breakpoint
4540is hit.
4541
4542A warning like the one below is printed when setting a breakpoint
4543that's been subject to address adjustment:
4544
4545@smallexample
4546warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4547@end smallexample
4548
4549Such warnings are printed both for user settable and @value{GDBN}'s
4550internal breakpoints. If you see one of these warnings, you should
4551verify that a breakpoint set at the adjusted address will have the
4552desired affect. If not, the breakpoint in question may be removed and
b383017d 4553other breakpoints may be set which will have the desired behavior.
1485d690
KB
4554E.g., it may be sufficient to place the breakpoint at a later
4555instruction. A conditional breakpoint may also be useful in some
4556cases to prevent the breakpoint from triggering too often.
4557
4558@value{GDBN} will also issue a warning when stopping at one of these
4559adjusted breakpoints:
4560
4561@smallexample
4562warning: Breakpoint 1 address previously adjusted from 0x00010414
4563to 0x00010410.
4564@end smallexample
4565
4566When this warning is encountered, it may be too late to take remedial
4567action except in cases where the breakpoint is hit earlier or more
4568frequently than expected.
d4f3574e 4569
6d2ebf8b 4570@node Continuing and Stepping
79a6e687 4571@section Continuing and Stepping
c906108c
SS
4572
4573@cindex stepping
4574@cindex continuing
4575@cindex resuming execution
4576@dfn{Continuing} means resuming program execution until your program
4577completes normally. In contrast, @dfn{stepping} means executing just
4578one more ``step'' of your program, where ``step'' may mean either one
4579line of source code, or one machine instruction (depending on what
7a292a7a
SS
4580particular command you use). Either when continuing or when stepping,
4581your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
4582it stops due to a signal, you may want to use @code{handle}, or use
4583@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
4584
4585@table @code
4586@kindex continue
41afff9a
EZ
4587@kindex c @r{(@code{continue})}
4588@kindex fg @r{(resume foreground execution)}
c906108c
SS
4589@item continue @r{[}@var{ignore-count}@r{]}
4590@itemx c @r{[}@var{ignore-count}@r{]}
4591@itemx fg @r{[}@var{ignore-count}@r{]}
4592Resume program execution, at the address where your program last stopped;
4593any breakpoints set at that address are bypassed. The optional argument
4594@var{ignore-count} allows you to specify a further number of times to
4595ignore a breakpoint at this location; its effect is like that of
79a6e687 4596@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
4597
4598The argument @var{ignore-count} is meaningful only when your program
4599stopped due to a breakpoint. At other times, the argument to
4600@code{continue} is ignored.
4601
d4f3574e
SS
4602The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4603debugged program is deemed to be the foreground program) are provided
4604purely for convenience, and have exactly the same behavior as
4605@code{continue}.
c906108c
SS
4606@end table
4607
4608To resume execution at a different place, you can use @code{return}
79a6e687 4609(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 4610calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 4611Different Address}) to go to an arbitrary location in your program.
c906108c
SS
4612
4613A typical technique for using stepping is to set a breakpoint
79a6e687 4614(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
4615beginning of the function or the section of your program where a problem
4616is believed to lie, run your program until it stops at that breakpoint,
4617and then step through the suspect area, examining the variables that are
4618interesting, until you see the problem happen.
4619
4620@table @code
4621@kindex step
41afff9a 4622@kindex s @r{(@code{step})}
c906108c
SS
4623@item step
4624Continue running your program until control reaches a different source
4625line, then stop it and return control to @value{GDBN}. This command is
4626abbreviated @code{s}.
4627
4628@quotation
4629@c "without debugging information" is imprecise; actually "without line
4630@c numbers in the debugging information". (gcc -g1 has debugging info but
4631@c not line numbers). But it seems complex to try to make that
4632@c distinction here.
4633@emph{Warning:} If you use the @code{step} command while control is
4634within a function that was compiled without debugging information,
4635execution proceeds until control reaches a function that does have
4636debugging information. Likewise, it will not step into a function which
4637is compiled without debugging information. To step through functions
4638without debugging information, use the @code{stepi} command, described
4639below.
4640@end quotation
4641
4a92d011
EZ
4642The @code{step} command only stops at the first instruction of a source
4643line. This prevents the multiple stops that could otherwise occur in
4644@code{switch} statements, @code{for} loops, etc. @code{step} continues
4645to stop if a function that has debugging information is called within
4646the line. In other words, @code{step} @emph{steps inside} any functions
4647called within the line.
c906108c 4648
d4f3574e
SS
4649Also, the @code{step} command only enters a function if there is line
4650number information for the function. Otherwise it acts like the
5d161b24 4651@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 4652on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 4653was any debugging information about the routine.
c906108c
SS
4654
4655@item step @var{count}
4656Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
4657breakpoint is reached, or a signal not related to stepping occurs before
4658@var{count} steps, stepping stops right away.
c906108c
SS
4659
4660@kindex next
41afff9a 4661@kindex n @r{(@code{next})}
c906108c
SS
4662@item next @r{[}@var{count}@r{]}
4663Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
4664This is similar to @code{step}, but function calls that appear within
4665the line of code are executed without stopping. Execution stops when
4666control reaches a different line of code at the original stack level
4667that was executing when you gave the @code{next} command. This command
4668is abbreviated @code{n}.
c906108c
SS
4669
4670An argument @var{count} is a repeat count, as for @code{step}.
4671
4672
4673@c FIX ME!! Do we delete this, or is there a way it fits in with
4674@c the following paragraph? --- Vctoria
4675@c
4676@c @code{next} within a function that lacks debugging information acts like
4677@c @code{step}, but any function calls appearing within the code of the
4678@c function are executed without stopping.
4679
d4f3574e
SS
4680The @code{next} command only stops at the first instruction of a
4681source line. This prevents multiple stops that could otherwise occur in
4a92d011 4682@code{switch} statements, @code{for} loops, etc.
c906108c 4683
b90a5f51
CF
4684@kindex set step-mode
4685@item set step-mode
4686@cindex functions without line info, and stepping
4687@cindex stepping into functions with no line info
4688@itemx set step-mode on
4a92d011 4689The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
4690stop at the first instruction of a function which contains no debug line
4691information rather than stepping over it.
4692
4a92d011
EZ
4693This is useful in cases where you may be interested in inspecting the
4694machine instructions of a function which has no symbolic info and do not
4695want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
4696
4697@item set step-mode off
4a92d011 4698Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
4699debug information. This is the default.
4700
9c16f35a
EZ
4701@item show step-mode
4702Show whether @value{GDBN} will stop in or step over functions without
4703source line debug information.
4704
c906108c 4705@kindex finish
8dfa32fc 4706@kindex fin @r{(@code{finish})}
c906108c
SS
4707@item finish
4708Continue running until just after function in the selected stack frame
8dfa32fc
JB
4709returns. Print the returned value (if any). This command can be
4710abbreviated as @code{fin}.
c906108c
SS
4711
4712Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 4713,Returning from a Function}).
c906108c
SS
4714
4715@kindex until
41afff9a 4716@kindex u @r{(@code{until})}
09d4efe1 4717@cindex run until specified location
c906108c
SS
4718@item until
4719@itemx u
4720Continue running until a source line past the current line, in the
4721current stack frame, is reached. This command is used to avoid single
4722stepping through a loop more than once. It is like the @code{next}
4723command, except that when @code{until} encounters a jump, it
4724automatically continues execution until the program counter is greater
4725than the address of the jump.
4726
4727This means that when you reach the end of a loop after single stepping
4728though it, @code{until} makes your program continue execution until it
4729exits the loop. In contrast, a @code{next} command at the end of a loop
4730simply steps back to the beginning of the loop, which forces you to step
4731through the next iteration.
4732
4733@code{until} always stops your program if it attempts to exit the current
4734stack frame.
4735
4736@code{until} may produce somewhat counterintuitive results if the order
4737of machine code does not match the order of the source lines. For
4738example, in the following excerpt from a debugging session, the @code{f}
4739(@code{frame}) command shows that execution is stopped at line
4740@code{206}; yet when we use @code{until}, we get to line @code{195}:
4741
474c8240 4742@smallexample
c906108c
SS
4743(@value{GDBP}) f
4744#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4745206 expand_input();
4746(@value{GDBP}) until
4747195 for ( ; argc > 0; NEXTARG) @{
474c8240 4748@end smallexample
c906108c
SS
4749
4750This happened because, for execution efficiency, the compiler had
4751generated code for the loop closure test at the end, rather than the
4752start, of the loop---even though the test in a C @code{for}-loop is
4753written before the body of the loop. The @code{until} command appeared
4754to step back to the beginning of the loop when it advanced to this
4755expression; however, it has not really gone to an earlier
4756statement---not in terms of the actual machine code.
4757
4758@code{until} with no argument works by means of single
4759instruction stepping, and hence is slower than @code{until} with an
4760argument.
4761
4762@item until @var{location}
4763@itemx u @var{location}
4764Continue running your program until either the specified location is
4765reached, or the current stack frame returns. @var{location} is any of
2a25a5ba
EZ
4766the forms described in @ref{Specify Location}.
4767This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
4768hence is quicker than @code{until} without an argument. The specified
4769location is actually reached only if it is in the current frame. This
4770implies that @code{until} can be used to skip over recursive function
4771invocations. For instance in the code below, if the current location is
4772line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 4773line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
4774invocations have returned.
4775
4776@smallexample
477794 int factorial (int value)
477895 @{
477996 if (value > 1) @{
478097 value *= factorial (value - 1);
478198 @}
478299 return (value);
4783100 @}
4784@end smallexample
4785
4786
4787@kindex advance @var{location}
4788@itemx advance @var{location}
09d4efe1 4789Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
4790required, which should be of one of the forms described in
4791@ref{Specify Location}.
4792Execution will also stop upon exit from the current stack
c60eb6f1
EZ
4793frame. This command is similar to @code{until}, but @code{advance} will
4794not skip over recursive function calls, and the target location doesn't
4795have to be in the same frame as the current one.
4796
c906108c
SS
4797
4798@kindex stepi
41afff9a 4799@kindex si @r{(@code{stepi})}
c906108c 4800@item stepi
96a2c332 4801@itemx stepi @var{arg}
c906108c
SS
4802@itemx si
4803Execute one machine instruction, then stop and return to the debugger.
4804
4805It is often useful to do @samp{display/i $pc} when stepping by machine
4806instructions. This makes @value{GDBN} automatically display the next
4807instruction to be executed, each time your program stops. @xref{Auto
79a6e687 4808Display,, Automatic Display}.
c906108c
SS
4809
4810An argument is a repeat count, as in @code{step}.
4811
4812@need 750
4813@kindex nexti
41afff9a 4814@kindex ni @r{(@code{nexti})}
c906108c 4815@item nexti
96a2c332 4816@itemx nexti @var{arg}
c906108c
SS
4817@itemx ni
4818Execute one machine instruction, but if it is a function call,
4819proceed until the function returns.
4820
4821An argument is a repeat count, as in @code{next}.
4822@end table
4823
6d2ebf8b 4824@node Signals
c906108c
SS
4825@section Signals
4826@cindex signals
4827
4828A signal is an asynchronous event that can happen in a program. The
4829operating system defines the possible kinds of signals, and gives each
4830kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 4831signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
4832@code{SIGSEGV} is the signal a program gets from referencing a place in
4833memory far away from all the areas in use; @code{SIGALRM} occurs when
4834the alarm clock timer goes off (which happens only if your program has
4835requested an alarm).
4836
4837@cindex fatal signals
4838Some signals, including @code{SIGALRM}, are a normal part of the
4839functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 4840errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
4841program has not specified in advance some other way to handle the signal.
4842@code{SIGINT} does not indicate an error in your program, but it is normally
4843fatal so it can carry out the purpose of the interrupt: to kill the program.
4844
4845@value{GDBN} has the ability to detect any occurrence of a signal in your
4846program. You can tell @value{GDBN} in advance what to do for each kind of
4847signal.
4848
4849@cindex handling signals
24f93129
EZ
4850Normally, @value{GDBN} is set up to let the non-erroneous signals like
4851@code{SIGALRM} be silently passed to your program
4852(so as not to interfere with their role in the program's functioning)
c906108c
SS
4853but to stop your program immediately whenever an error signal happens.
4854You can change these settings with the @code{handle} command.
4855
4856@table @code
4857@kindex info signals
09d4efe1 4858@kindex info handle
c906108c 4859@item info signals
96a2c332 4860@itemx info handle
c906108c
SS
4861Print a table of all the kinds of signals and how @value{GDBN} has been told to
4862handle each one. You can use this to see the signal numbers of all
4863the defined types of signals.
4864
45ac1734
EZ
4865@item info signals @var{sig}
4866Similar, but print information only about the specified signal number.
4867
d4f3574e 4868@code{info handle} is an alias for @code{info signals}.
c906108c
SS
4869
4870@kindex handle
45ac1734 4871@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
4872Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4873can be the number of a signal or its name (with or without the
24f93129 4874@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 4875@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
4876known signals. Optional arguments @var{keywords}, described below,
4877say what change to make.
c906108c
SS
4878@end table
4879
4880@c @group
4881The keywords allowed by the @code{handle} command can be abbreviated.
4882Their full names are:
4883
4884@table @code
4885@item nostop
4886@value{GDBN} should not stop your program when this signal happens. It may
4887still print a message telling you that the signal has come in.
4888
4889@item stop
4890@value{GDBN} should stop your program when this signal happens. This implies
4891the @code{print} keyword as well.
4892
4893@item print
4894@value{GDBN} should print a message when this signal happens.
4895
4896@item noprint
4897@value{GDBN} should not mention the occurrence of the signal at all. This
4898implies the @code{nostop} keyword as well.
4899
4900@item pass
5ece1a18 4901@itemx noignore
c906108c
SS
4902@value{GDBN} should allow your program to see this signal; your program
4903can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 4904and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
4905
4906@item nopass
5ece1a18 4907@itemx ignore
c906108c 4908@value{GDBN} should not allow your program to see this signal.
5ece1a18 4909@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
4910@end table
4911@c @end group
4912
d4f3574e
SS
4913When a signal stops your program, the signal is not visible to the
4914program until you
c906108c
SS
4915continue. Your program sees the signal then, if @code{pass} is in
4916effect for the signal in question @emph{at that time}. In other words,
4917after @value{GDBN} reports a signal, you can use the @code{handle}
4918command with @code{pass} or @code{nopass} to control whether your
4919program sees that signal when you continue.
4920
24f93129
EZ
4921The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4922non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4923@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4924erroneous signals.
4925
c906108c
SS
4926You can also use the @code{signal} command to prevent your program from
4927seeing a signal, or cause it to see a signal it normally would not see,
4928or to give it any signal at any time. For example, if your program stopped
4929due to some sort of memory reference error, you might store correct
4930values into the erroneous variables and continue, hoping to see more
4931execution; but your program would probably terminate immediately as
4932a result of the fatal signal once it saw the signal. To prevent this,
4933you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 4934Program a Signal}.
c906108c 4935
4aa995e1
PA
4936@cindex extra signal information
4937@anchor{extra signal information}
4938
4939On some targets, @value{GDBN} can inspect extra signal information
4940associated with the intercepted signal, before it is actually
4941delivered to the program being debugged. This information is exported
4942by the convenience variable @code{$_siginfo}, and consists of data
4943that is passed by the kernel to the signal handler at the time of the
4944receipt of a signal. The data type of the information itself is
4945target dependent. You can see the data type using the @code{ptype
4946$_siginfo} command. On Unix systems, it typically corresponds to the
4947standard @code{siginfo_t} type, as defined in the @file{signal.h}
4948system header.
4949
4950Here's an example, on a @sc{gnu}/Linux system, printing the stray
4951referenced address that raised a segmentation fault.
4952
4953@smallexample
4954@group
4955(@value{GDBP}) continue
4956Program received signal SIGSEGV, Segmentation fault.
49570x0000000000400766 in main ()
495869 *(int *)p = 0;
4959(@value{GDBP}) ptype $_siginfo
4960type = struct @{
4961 int si_signo;
4962 int si_errno;
4963 int si_code;
4964 union @{
4965 int _pad[28];
4966 struct @{...@} _kill;
4967 struct @{...@} _timer;
4968 struct @{...@} _rt;
4969 struct @{...@} _sigchld;
4970 struct @{...@} _sigfault;
4971 struct @{...@} _sigpoll;
4972 @} _sifields;
4973@}
4974(@value{GDBP}) ptype $_siginfo._sifields._sigfault
4975type = struct @{
4976 void *si_addr;
4977@}
4978(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
4979$1 = (void *) 0x7ffff7ff7000
4980@end group
4981@end smallexample
4982
4983Depending on target support, @code{$_siginfo} may also be writable.
4984
6d2ebf8b 4985@node Thread Stops
79a6e687 4986@section Stopping and Starting Multi-thread Programs
c906108c 4987
0606b73b
SL
4988@cindex stopped threads
4989@cindex threads, stopped
4990
4991@cindex continuing threads
4992@cindex threads, continuing
4993
4994@value{GDBN} supports debugging programs with multiple threads
4995(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
4996are two modes of controlling execution of your program within the
4997debugger. In the default mode, referred to as @dfn{all-stop mode},
4998when any thread in your program stops (for example, at a breakpoint
4999or while being stepped), all other threads in the program are also stopped by
5000@value{GDBN}. On some targets, @value{GDBN} also supports
5001@dfn{non-stop mode}, in which other threads can continue to run freely while
5002you examine the stopped thread in the debugger.
5003
5004@menu
5005* All-Stop Mode:: All threads stop when GDB takes control
5006* Non-Stop Mode:: Other threads continue to execute
5007* Background Execution:: Running your program asynchronously
5008* Thread-Specific Breakpoints:: Controlling breakpoints
5009* Interrupted System Calls:: GDB may interfere with system calls
d914c394 5010* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
5011@end menu
5012
5013@node All-Stop Mode
5014@subsection All-Stop Mode
5015
5016@cindex all-stop mode
5017
5018In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5019@emph{all} threads of execution stop, not just the current thread. This
5020allows you to examine the overall state of the program, including
5021switching between threads, without worrying that things may change
5022underfoot.
5023
5024Conversely, whenever you restart the program, @emph{all} threads start
5025executing. @emph{This is true even when single-stepping} with commands
5026like @code{step} or @code{next}.
5027
5028In particular, @value{GDBN} cannot single-step all threads in lockstep.
5029Since thread scheduling is up to your debugging target's operating
5030system (not controlled by @value{GDBN}), other threads may
5031execute more than one statement while the current thread completes a
5032single step. Moreover, in general other threads stop in the middle of a
5033statement, rather than at a clean statement boundary, when the program
5034stops.
5035
5036You might even find your program stopped in another thread after
5037continuing or even single-stepping. This happens whenever some other
5038thread runs into a breakpoint, a signal, or an exception before the
5039first thread completes whatever you requested.
5040
5041@cindex automatic thread selection
5042@cindex switching threads automatically
5043@cindex threads, automatic switching
5044Whenever @value{GDBN} stops your program, due to a breakpoint or a
5045signal, it automatically selects the thread where that breakpoint or
5046signal happened. @value{GDBN} alerts you to the context switch with a
5047message such as @samp{[Switching to Thread @var{n}]} to identify the
5048thread.
5049
5050On some OSes, you can modify @value{GDBN}'s default behavior by
5051locking the OS scheduler to allow only a single thread to run.
5052
5053@table @code
5054@item set scheduler-locking @var{mode}
5055@cindex scheduler locking mode
5056@cindex lock scheduler
5057Set the scheduler locking mode. If it is @code{off}, then there is no
5058locking and any thread may run at any time. If @code{on}, then only the
5059current thread may run when the inferior is resumed. The @code{step}
5060mode optimizes for single-stepping; it prevents other threads
5061from preempting the current thread while you are stepping, so that
5062the focus of debugging does not change unexpectedly.
5063Other threads only rarely (or never) get a chance to run
5064when you step. They are more likely to run when you @samp{next} over a
5065function call, and they are completely free to run when you use commands
5066like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5067thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5068the current thread away from the thread that you are debugging.
5069
5070@item show scheduler-locking
5071Display the current scheduler locking mode.
5072@end table
5073
d4db2f36
PA
5074@cindex resume threads of multiple processes simultaneously
5075By default, when you issue one of the execution commands such as
5076@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5077threads of the current inferior to run. For example, if @value{GDBN}
5078is attached to two inferiors, each with two threads, the
5079@code{continue} command resumes only the two threads of the current
5080inferior. This is useful, for example, when you debug a program that
5081forks and you want to hold the parent stopped (so that, for instance,
5082it doesn't run to exit), while you debug the child. In other
5083situations, you may not be interested in inspecting the current state
5084of any of the processes @value{GDBN} is attached to, and you may want
5085to resume them all until some breakpoint is hit. In the latter case,
5086you can instruct @value{GDBN} to allow all threads of all the
5087inferiors to run with the @w{@code{set schedule-multiple}} command.
5088
5089@table @code
5090@kindex set schedule-multiple
5091@item set schedule-multiple
5092Set the mode for allowing threads of multiple processes to be resumed
5093when an execution command is issued. When @code{on}, all threads of
5094all processes are allowed to run. When @code{off}, only the threads
5095of the current process are resumed. The default is @code{off}. The
5096@code{scheduler-locking} mode takes precedence when set to @code{on},
5097or while you are stepping and set to @code{step}.
5098
5099@item show schedule-multiple
5100Display the current mode for resuming the execution of threads of
5101multiple processes.
5102@end table
5103
0606b73b
SL
5104@node Non-Stop Mode
5105@subsection Non-Stop Mode
5106
5107@cindex non-stop mode
5108
5109@c This section is really only a place-holder, and needs to be expanded
5110@c with more details.
5111
5112For some multi-threaded targets, @value{GDBN} supports an optional
5113mode of operation in which you can examine stopped program threads in
5114the debugger while other threads continue to execute freely. This
5115minimizes intrusion when debugging live systems, such as programs
5116where some threads have real-time constraints or must continue to
5117respond to external events. This is referred to as @dfn{non-stop} mode.
5118
5119In non-stop mode, when a thread stops to report a debugging event,
5120@emph{only} that thread is stopped; @value{GDBN} does not stop other
5121threads as well, in contrast to the all-stop mode behavior. Additionally,
5122execution commands such as @code{continue} and @code{step} apply by default
5123only to the current thread in non-stop mode, rather than all threads as
5124in all-stop mode. This allows you to control threads explicitly in
5125ways that are not possible in all-stop mode --- for example, stepping
5126one thread while allowing others to run freely, stepping
5127one thread while holding all others stopped, or stepping several threads
5128independently and simultaneously.
5129
5130To enter non-stop mode, use this sequence of commands before you run
5131or attach to your program:
5132
0606b73b
SL
5133@smallexample
5134# Enable the async interface.
c6ebd6cf 5135set target-async 1
0606b73b 5136
0606b73b
SL
5137# If using the CLI, pagination breaks non-stop.
5138set pagination off
5139
5140# Finally, turn it on!
5141set non-stop on
5142@end smallexample
5143
5144You can use these commands to manipulate the non-stop mode setting:
5145
5146@table @code
5147@kindex set non-stop
5148@item set non-stop on
5149Enable selection of non-stop mode.
5150@item set non-stop off
5151Disable selection of non-stop mode.
5152@kindex show non-stop
5153@item show non-stop
5154Show the current non-stop enablement setting.
5155@end table
5156
5157Note these commands only reflect whether non-stop mode is enabled,
5158not whether the currently-executing program is being run in non-stop mode.
5159In particular, the @code{set non-stop} preference is only consulted when
5160@value{GDBN} starts or connects to the target program, and it is generally
5161not possible to switch modes once debugging has started. Furthermore,
5162since not all targets support non-stop mode, even when you have enabled
5163non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5164default.
5165
5166In non-stop mode, all execution commands apply only to the current thread
5167by default. That is, @code{continue} only continues one thread.
5168To continue all threads, issue @code{continue -a} or @code{c -a}.
5169
5170You can use @value{GDBN}'s background execution commands
5171(@pxref{Background Execution}) to run some threads in the background
5172while you continue to examine or step others from @value{GDBN}.
5173The MI execution commands (@pxref{GDB/MI Program Execution}) are
5174always executed asynchronously in non-stop mode.
5175
5176Suspending execution is done with the @code{interrupt} command when
5177running in the background, or @kbd{Ctrl-c} during foreground execution.
5178In all-stop mode, this stops the whole process;
5179but in non-stop mode the interrupt applies only to the current thread.
5180To stop the whole program, use @code{interrupt -a}.
5181
5182Other execution commands do not currently support the @code{-a} option.
5183
5184In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5185that thread current, as it does in all-stop mode. This is because the
5186thread stop notifications are asynchronous with respect to @value{GDBN}'s
5187command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5188changed to a different thread just as you entered a command to operate on the
5189previously current thread.
5190
5191@node Background Execution
5192@subsection Background Execution
5193
5194@cindex foreground execution
5195@cindex background execution
5196@cindex asynchronous execution
5197@cindex execution, foreground, background and asynchronous
5198
5199@value{GDBN}'s execution commands have two variants: the normal
5200foreground (synchronous) behavior, and a background
5201(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5202the program to report that some thread has stopped before prompting for
5203another command. In background execution, @value{GDBN} immediately gives
5204a command prompt so that you can issue other commands while your program runs.
5205
32fc0df9
PA
5206You need to explicitly enable asynchronous mode before you can use
5207background execution commands. You can use these commands to
5208manipulate the asynchronous mode setting:
5209
5210@table @code
5211@kindex set target-async
5212@item set target-async on
5213Enable asynchronous mode.
5214@item set target-async off
5215Disable asynchronous mode.
5216@kindex show target-async
5217@item show target-async
5218Show the current target-async setting.
5219@end table
5220
5221If the target doesn't support async mode, @value{GDBN} issues an error
5222message if you attempt to use the background execution commands.
5223
0606b73b
SL
5224To specify background execution, add a @code{&} to the command. For example,
5225the background form of the @code{continue} command is @code{continue&}, or
5226just @code{c&}. The execution commands that accept background execution
5227are:
5228
5229@table @code
5230@kindex run&
5231@item run
5232@xref{Starting, , Starting your Program}.
5233
5234@item attach
5235@kindex attach&
5236@xref{Attach, , Debugging an Already-running Process}.
5237
5238@item step
5239@kindex step&
5240@xref{Continuing and Stepping, step}.
5241
5242@item stepi
5243@kindex stepi&
5244@xref{Continuing and Stepping, stepi}.
5245
5246@item next
5247@kindex next&
5248@xref{Continuing and Stepping, next}.
5249
7ce58dd2
DE
5250@item nexti
5251@kindex nexti&
5252@xref{Continuing and Stepping, nexti}.
5253
0606b73b
SL
5254@item continue
5255@kindex continue&
5256@xref{Continuing and Stepping, continue}.
5257
5258@item finish
5259@kindex finish&
5260@xref{Continuing and Stepping, finish}.
5261
5262@item until
5263@kindex until&
5264@xref{Continuing and Stepping, until}.
5265
5266@end table
5267
5268Background execution is especially useful in conjunction with non-stop
5269mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5270However, you can also use these commands in the normal all-stop mode with
5271the restriction that you cannot issue another execution command until the
5272previous one finishes. Examples of commands that are valid in all-stop
5273mode while the program is running include @code{help} and @code{info break}.
5274
5275You can interrupt your program while it is running in the background by
5276using the @code{interrupt} command.
5277
5278@table @code
5279@kindex interrupt
5280@item interrupt
5281@itemx interrupt -a
5282
5283Suspend execution of the running program. In all-stop mode,
5284@code{interrupt} stops the whole process, but in non-stop mode, it stops
5285only the current thread. To stop the whole program in non-stop mode,
5286use @code{interrupt -a}.
5287@end table
5288
0606b73b
SL
5289@node Thread-Specific Breakpoints
5290@subsection Thread-Specific Breakpoints
5291
c906108c 5292When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 5293Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
5294breakpoints on all threads, or on a particular thread.
5295
5296@table @code
5297@cindex breakpoints and threads
5298@cindex thread breakpoints
5299@kindex break @dots{} thread @var{threadno}
5300@item break @var{linespec} thread @var{threadno}
5301@itemx break @var{linespec} thread @var{threadno} if @dots{}
5302@var{linespec} specifies source lines; there are several ways of
2a25a5ba
EZ
5303writing them (@pxref{Specify Location}), but the effect is always to
5304specify some source line.
c906108c
SS
5305
5306Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5307to specify that you only want @value{GDBN} to stop the program when a
5308particular thread reaches this breakpoint. @var{threadno} is one of the
5309numeric thread identifiers assigned by @value{GDBN}, shown in the first
5310column of the @samp{info threads} display.
5311
5312If you do not specify @samp{thread @var{threadno}} when you set a
5313breakpoint, the breakpoint applies to @emph{all} threads of your
5314program.
5315
5316You can use the @code{thread} qualifier on conditional breakpoints as
b6199126
DJ
5317well; in this case, place @samp{thread @var{threadno}} before or
5318after the breakpoint condition, like this:
c906108c
SS
5319
5320@smallexample
2df3850c 5321(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
5322@end smallexample
5323
5324@end table
5325
0606b73b
SL
5326@node Interrupted System Calls
5327@subsection Interrupted System Calls
c906108c 5328
36d86913
MC
5329@cindex thread breakpoints and system calls
5330@cindex system calls and thread breakpoints
5331@cindex premature return from system calls
0606b73b
SL
5332There is an unfortunate side effect when using @value{GDBN} to debug
5333multi-threaded programs. If one thread stops for a
36d86913
MC
5334breakpoint, or for some other reason, and another thread is blocked in a
5335system call, then the system call may return prematurely. This is a
5336consequence of the interaction between multiple threads and the signals
5337that @value{GDBN} uses to implement breakpoints and other events that
5338stop execution.
5339
5340To handle this problem, your program should check the return value of
5341each system call and react appropriately. This is good programming
5342style anyways.
5343
5344For example, do not write code like this:
5345
5346@smallexample
5347 sleep (10);
5348@end smallexample
5349
5350The call to @code{sleep} will return early if a different thread stops
5351at a breakpoint or for some other reason.
5352
5353Instead, write this:
5354
5355@smallexample
5356 int unslept = 10;
5357 while (unslept > 0)
5358 unslept = sleep (unslept);
5359@end smallexample
5360
5361A system call is allowed to return early, so the system is still
5362conforming to its specification. But @value{GDBN} does cause your
5363multi-threaded program to behave differently than it would without
5364@value{GDBN}.
5365
5366Also, @value{GDBN} uses internal breakpoints in the thread library to
5367monitor certain events such as thread creation and thread destruction.
5368When such an event happens, a system call in another thread may return
5369prematurely, even though your program does not appear to stop.
5370
d914c394
SS
5371@node Observer Mode
5372@subsection Observer Mode
5373
5374If you want to build on non-stop mode and observe program behavior
5375without any chance of disruption by @value{GDBN}, you can set
5376variables to disable all of the debugger's attempts to modify state,
5377whether by writing memory, inserting breakpoints, etc. These operate
5378at a low level, intercepting operations from all commands.
5379
5380When all of these are set to @code{off}, then @value{GDBN} is said to
5381be @dfn{observer mode}. As a convenience, the variable
5382@code{observer} can be set to disable these, plus enable non-stop
5383mode.
5384
5385Note that @value{GDBN} will not prevent you from making nonsensical
5386combinations of these settings. For instance, if you have enabled
5387@code{may-insert-breakpoints} but disabled @code{may-write-memory},
5388then breakpoints that work by writing trap instructions into the code
5389stream will still not be able to be placed.
5390
5391@table @code
5392
5393@kindex observer
5394@item set observer on
5395@itemx set observer off
5396When set to @code{on}, this disables all the permission variables
5397below (except for @code{insert-fast-tracepoints}), plus enables
5398non-stop debugging. Setting this to @code{off} switches back to
5399normal debugging, though remaining in non-stop mode.
5400
5401@item show observer
5402Show whether observer mode is on or off.
5403
5404@kindex may-write-registers
5405@item set may-write-registers on
5406@itemx set may-write-registers off
5407This controls whether @value{GDBN} will attempt to alter the values of
5408registers, such as with assignment expressions in @code{print}, or the
5409@code{jump} command. It defaults to @code{on}.
5410
5411@item show may-write-registers
5412Show the current permission to write registers.
5413
5414@kindex may-write-memory
5415@item set may-write-memory on
5416@itemx set may-write-memory off
5417This controls whether @value{GDBN} will attempt to alter the contents
5418of memory, such as with assignment expressions in @code{print}. It
5419defaults to @code{on}.
5420
5421@item show may-write-memory
5422Show the current permission to write memory.
5423
5424@kindex may-insert-breakpoints
5425@item set may-insert-breakpoints on
5426@itemx set may-insert-breakpoints off
5427This controls whether @value{GDBN} will attempt to insert breakpoints.
5428This affects all breakpoints, including internal breakpoints defined
5429by @value{GDBN}. It defaults to @code{on}.
5430
5431@item show may-insert-breakpoints
5432Show the current permission to insert breakpoints.
5433
5434@kindex may-insert-tracepoints
5435@item set may-insert-tracepoints on
5436@itemx set may-insert-tracepoints off
5437This controls whether @value{GDBN} will attempt to insert (regular)
5438tracepoints at the beginning of a tracing experiment. It affects only
5439non-fast tracepoints, fast tracepoints being under the control of
5440@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
5441
5442@item show may-insert-tracepoints
5443Show the current permission to insert tracepoints.
5444
5445@kindex may-insert-fast-tracepoints
5446@item set may-insert-fast-tracepoints on
5447@itemx set may-insert-fast-tracepoints off
5448This controls whether @value{GDBN} will attempt to insert fast
5449tracepoints at the beginning of a tracing experiment. It affects only
5450fast tracepoints, regular (non-fast) tracepoints being under the
5451control of @code{may-insert-tracepoints}. It defaults to @code{on}.
5452
5453@item show may-insert-fast-tracepoints
5454Show the current permission to insert fast tracepoints.
5455
5456@kindex may-interrupt
5457@item set may-interrupt on
5458@itemx set may-interrupt off
5459This controls whether @value{GDBN} will attempt to interrupt or stop
5460program execution. When this variable is @code{off}, the
5461@code{interrupt} command will have no effect, nor will
5462@kbd{Ctrl-c}. It defaults to @code{on}.
5463
5464@item show may-interrupt
5465Show the current permission to interrupt or stop the program.
5466
5467@end table
c906108c 5468
bacec72f
MS
5469@node Reverse Execution
5470@chapter Running programs backward
5471@cindex reverse execution
5472@cindex running programs backward
5473
5474When you are debugging a program, it is not unusual to realize that
5475you have gone too far, and some event of interest has already happened.
5476If the target environment supports it, @value{GDBN} can allow you to
5477``rewind'' the program by running it backward.
5478
5479A target environment that supports reverse execution should be able
5480to ``undo'' the changes in machine state that have taken place as the
5481program was executing normally. Variables, registers etc.@: should
5482revert to their previous values. Obviously this requires a great
5483deal of sophistication on the part of the target environment; not
5484all target environments can support reverse execution.
5485
5486When a program is executed in reverse, the instructions that
5487have most recently been executed are ``un-executed'', in reverse
5488order. The program counter runs backward, following the previous
5489thread of execution in reverse. As each instruction is ``un-executed'',
5490the values of memory and/or registers that were changed by that
5491instruction are reverted to their previous states. After executing
5492a piece of source code in reverse, all side effects of that code
5493should be ``undone'', and all variables should be returned to their
5494prior values@footnote{
5495Note that some side effects are easier to undo than others. For instance,
5496memory and registers are relatively easy, but device I/O is hard. Some
5497targets may be able undo things like device I/O, and some may not.
5498
5499The contract between @value{GDBN} and the reverse executing target
5500requires only that the target do something reasonable when
5501@value{GDBN} tells it to execute backwards, and then report the
5502results back to @value{GDBN}. Whatever the target reports back to
5503@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
5504assumes that the memory and registers that the target reports are in a
5505consistant state, but @value{GDBN} accepts whatever it is given.
5506}.
5507
5508If you are debugging in a target environment that supports
5509reverse execution, @value{GDBN} provides the following commands.
5510
5511@table @code
5512@kindex reverse-continue
5513@kindex rc @r{(@code{reverse-continue})}
5514@item reverse-continue @r{[}@var{ignore-count}@r{]}
5515@itemx rc @r{[}@var{ignore-count}@r{]}
5516Beginning at the point where your program last stopped, start executing
5517in reverse. Reverse execution will stop for breakpoints and synchronous
5518exceptions (signals), just like normal execution. Behavior of
5519asynchronous signals depends on the target environment.
5520
5521@kindex reverse-step
5522@kindex rs @r{(@code{step})}
5523@item reverse-step @r{[}@var{count}@r{]}
5524Run the program backward until control reaches the start of a
5525different source line; then stop it, and return control to @value{GDBN}.
5526
5527Like the @code{step} command, @code{reverse-step} will only stop
5528at the beginning of a source line. It ``un-executes'' the previously
5529executed source line. If the previous source line included calls to
5530debuggable functions, @code{reverse-step} will step (backward) into
5531the called function, stopping at the beginning of the @emph{last}
5532statement in the called function (typically a return statement).
5533
5534Also, as with the @code{step} command, if non-debuggable functions are
5535called, @code{reverse-step} will run thru them backward without stopping.
5536
5537@kindex reverse-stepi
5538@kindex rsi @r{(@code{reverse-stepi})}
5539@item reverse-stepi @r{[}@var{count}@r{]}
5540Reverse-execute one machine instruction. Note that the instruction
5541to be reverse-executed is @emph{not} the one pointed to by the program
5542counter, but the instruction executed prior to that one. For instance,
5543if the last instruction was a jump, @code{reverse-stepi} will take you
5544back from the destination of the jump to the jump instruction itself.
5545
5546@kindex reverse-next
5547@kindex rn @r{(@code{reverse-next})}
5548@item reverse-next @r{[}@var{count}@r{]}
5549Run backward to the beginning of the previous line executed in
5550the current (innermost) stack frame. If the line contains function
5551calls, they will be ``un-executed'' without stopping. Starting from
5552the first line of a function, @code{reverse-next} will take you back
5553to the caller of that function, @emph{before} the function was called,
5554just as the normal @code{next} command would take you from the last
5555line of a function back to its return to its caller
16af530a 5556@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
5557
5558@kindex reverse-nexti
5559@kindex rni @r{(@code{reverse-nexti})}
5560@item reverse-nexti @r{[}@var{count}@r{]}
5561Like @code{nexti}, @code{reverse-nexti} executes a single instruction
5562in reverse, except that called functions are ``un-executed'' atomically.
5563That is, if the previously executed instruction was a return from
540aa8e7 5564another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
5565in reverse until the call to that function (from the current stack
5566frame) is reached.
5567
5568@kindex reverse-finish
5569@item reverse-finish
5570Just as the @code{finish} command takes you to the point where the
5571current function returns, @code{reverse-finish} takes you to the point
5572where it was called. Instead of ending up at the end of the current
5573function invocation, you end up at the beginning.
5574
5575@kindex set exec-direction
5576@item set exec-direction
5577Set the direction of target execution.
5578@itemx set exec-direction reverse
5579@cindex execute forward or backward in time
5580@value{GDBN} will perform all execution commands in reverse, until the
5581exec-direction mode is changed to ``forward''. Affected commands include
5582@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
5583command cannot be used in reverse mode.
5584@item set exec-direction forward
5585@value{GDBN} will perform all execution commands in the normal fashion.
5586This is the default.
5587@end table
5588
c906108c 5589
a2311334
EZ
5590@node Process Record and Replay
5591@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
5592@cindex process record and replay
5593@cindex recording inferior's execution and replaying it
5594
8e05493c
EZ
5595On some platforms, @value{GDBN} provides a special @dfn{process record
5596and replay} target that can record a log of the process execution, and
5597replay it later with both forward and reverse execution commands.
a2311334
EZ
5598
5599@cindex replay mode
5600When this target is in use, if the execution log includes the record
5601for the next instruction, @value{GDBN} will debug in @dfn{replay
5602mode}. In the replay mode, the inferior does not really execute code
5603instructions. Instead, all the events that normally happen during
5604code execution are taken from the execution log. While code is not
5605really executed in replay mode, the values of registers (including the
5606program counter register) and the memory of the inferior are still
8e05493c
EZ
5607changed as they normally would. Their contents are taken from the
5608execution log.
a2311334
EZ
5609
5610@cindex record mode
5611If the record for the next instruction is not in the execution log,
5612@value{GDBN} will debug in @dfn{record mode}. In this mode, the
5613inferior executes normally, and @value{GDBN} records the execution log
5614for future replay.
5615
8e05493c
EZ
5616The process record and replay target supports reverse execution
5617(@pxref{Reverse Execution}), even if the platform on which the
5618inferior runs does not. However, the reverse execution is limited in
5619this case by the range of the instructions recorded in the execution
5620log. In other words, reverse execution on platforms that don't
5621support it directly can only be done in the replay mode.
5622
5623When debugging in the reverse direction, @value{GDBN} will work in
5624replay mode as long as the execution log includes the record for the
5625previous instruction; otherwise, it will work in record mode, if the
5626platform supports reverse execution, or stop if not.
5627
a2311334
EZ
5628For architecture environments that support process record and replay,
5629@value{GDBN} provides the following commands:
53cc454a
HZ
5630
5631@table @code
5632@kindex target record
5633@kindex record
5634@kindex rec
5635@item target record
a2311334
EZ
5636This command starts the process record and replay target. The process
5637record and replay target can only debug a process that is already
5638running. Therefore, you need first to start the process with the
5639@kbd{run} or @kbd{start} commands, and then start the recording with
5640the @kbd{target record} command.
5641
5642Both @code{record} and @code{rec} are aliases of @code{target record}.
5643
5644@cindex displaced stepping, and process record and replay
5645Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
5646will be automatically disabled when process record and replay target
5647is started. That's because the process record and replay target
5648doesn't support displaced stepping.
5649
5650@cindex non-stop mode, and process record and replay
5651@cindex asynchronous execution, and process record and replay
5652If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
5653the asynchronous execution mode (@pxref{Background Execution}), the
5654process record and replay target cannot be started because it doesn't
5655support these two modes.
53cc454a
HZ
5656
5657@kindex record stop
5658@kindex rec s
5659@item record stop
a2311334
EZ
5660Stop the process record and replay target. When process record and
5661replay target stops, the entire execution log will be deleted and the
5662inferior will either be terminated, or will remain in its final state.
53cc454a 5663
a2311334
EZ
5664When you stop the process record and replay target in record mode (at
5665the end of the execution log), the inferior will be stopped at the
5666next instruction that would have been recorded. In other words, if
5667you record for a while and then stop recording, the inferior process
5668will be left in the same state as if the recording never happened.
53cc454a 5669
a2311334
EZ
5670On the other hand, if the process record and replay target is stopped
5671while in replay mode (that is, not at the end of the execution log,
5672but at some earlier point), the inferior process will become ``live''
5673at that earlier state, and it will then be possible to continue the
5674usual ``live'' debugging of the process from that state.
53cc454a 5675
a2311334
EZ
5676When the inferior process exits, or @value{GDBN} detaches from it,
5677process record and replay target will automatically stop itself.
53cc454a 5678
24e933df
HZ
5679@kindex record save
5680@item record save @var{filename}
5681Save the execution log to a file @file{@var{filename}}.
5682Default filename is @file{gdb_record.@var{process_id}}, where
5683@var{process_id} is the process ID of the inferior.
5684
5685@kindex record restore
5686@item record restore @var{filename}
5687Restore the execution log from a file @file{@var{filename}}.
5688File must have been created with @code{record save}.
5689
53cc454a
HZ
5690@kindex set record insn-number-max
5691@item set record insn-number-max @var{limit}
5692Set the limit of instructions to be recorded. Default value is 200000.
5693
a2311334
EZ
5694If @var{limit} is a positive number, then @value{GDBN} will start
5695deleting instructions from the log once the number of the record
5696instructions becomes greater than @var{limit}. For every new recorded
5697instruction, @value{GDBN} will delete the earliest recorded
5698instruction to keep the number of recorded instructions at the limit.
5699(Since deleting recorded instructions loses information, @value{GDBN}
5700lets you control what happens when the limit is reached, by means of
5701the @code{stop-at-limit} option, described below.)
53cc454a 5702
a2311334
EZ
5703If @var{limit} is zero, @value{GDBN} will never delete recorded
5704instructions from the execution log. The number of recorded
5705instructions is unlimited in this case.
53cc454a
HZ
5706
5707@kindex show record insn-number-max
5708@item show record insn-number-max
a2311334 5709Show the limit of instructions to be recorded.
53cc454a
HZ
5710
5711@kindex set record stop-at-limit
a2311334
EZ
5712@item set record stop-at-limit
5713Control the behavior when the number of recorded instructions reaches
5714the limit. If ON (the default), @value{GDBN} will stop when the limit
5715is reached for the first time and ask you whether you want to stop the
5716inferior or continue running it and recording the execution log. If
5717you decide to continue recording, each new recorded instruction will
5718cause the oldest one to be deleted.
53cc454a 5719
a2311334
EZ
5720If this option is OFF, @value{GDBN} will automatically delete the
5721oldest record to make room for each new one, without asking.
53cc454a
HZ
5722
5723@kindex show record stop-at-limit
5724@item show record stop-at-limit
a2311334 5725Show the current setting of @code{stop-at-limit}.
53cc454a 5726
bb08c432
HZ
5727@kindex set record memory-query
5728@item set record memory-query
5729Control the behavior when @value{GDBN} is unable to record memory
5730changes caused by an instruction. If ON, @value{GDBN} will query
5731whether to stop the inferior in that case.
5732
5733If this option is OFF (the default), @value{GDBN} will automatically
5734ignore the effect of such instructions on memory. Later, when
5735@value{GDBN} replays this execution log, it will mark the log of this
5736instruction as not accessible, and it will not affect the replay
5737results.
5738
5739@kindex show record memory-query
5740@item show record memory-query
5741Show the current setting of @code{memory-query}.
5742
29153c24
MS
5743@kindex info record
5744@item info record
5745Show various statistics about the state of process record and its
5746in-memory execution log buffer, including:
5747
5748@itemize @bullet
5749@item
5750Whether in record mode or replay mode.
5751@item
5752Lowest recorded instruction number (counting from when the current execution log started recording instructions).
5753@item
5754Highest recorded instruction number.
5755@item
5756Current instruction about to be replayed (if in replay mode).
5757@item
5758Number of instructions contained in the execution log.
5759@item
5760Maximum number of instructions that may be contained in the execution log.
5761@end itemize
53cc454a
HZ
5762
5763@kindex record delete
5764@kindex rec del
5765@item record delete
a2311334 5766When record target runs in replay mode (``in the past''), delete the
53cc454a 5767subsequent execution log and begin to record a new execution log starting
a2311334 5768from the current address. This means you will abandon the previously
53cc454a
HZ
5769recorded ``future'' and begin recording a new ``future''.
5770@end table
5771
5772
6d2ebf8b 5773@node Stack
c906108c
SS
5774@chapter Examining the Stack
5775
5776When your program has stopped, the first thing you need to know is where it
5777stopped and how it got there.
5778
5779@cindex call stack
5d161b24
DB
5780Each time your program performs a function call, information about the call
5781is generated.
5782That information includes the location of the call in your program,
5783the arguments of the call,
c906108c 5784and the local variables of the function being called.
5d161b24 5785The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
5786The stack frames are allocated in a region of memory called the @dfn{call
5787stack}.
5788
5789When your program stops, the @value{GDBN} commands for examining the
5790stack allow you to see all of this information.
5791
5792@cindex selected frame
5793One of the stack frames is @dfn{selected} by @value{GDBN} and many
5794@value{GDBN} commands refer implicitly to the selected frame. In
5795particular, whenever you ask @value{GDBN} for the value of a variable in
5796your program, the value is found in the selected frame. There are
5797special @value{GDBN} commands to select whichever frame you are
79a6e687 5798interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
5799
5800When your program stops, @value{GDBN} automatically selects the
5d161b24 5801currently executing frame and describes it briefly, similar to the
79a6e687 5802@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
5803
5804@menu
5805* Frames:: Stack frames
5806* Backtrace:: Backtraces
5807* Selection:: Selecting a frame
5808* Frame Info:: Information on a frame
c906108c
SS
5809
5810@end menu
5811
6d2ebf8b 5812@node Frames
79a6e687 5813@section Stack Frames
c906108c 5814
d4f3574e 5815@cindex frame, definition
c906108c
SS
5816@cindex stack frame
5817The call stack is divided up into contiguous pieces called @dfn{stack
5818frames}, or @dfn{frames} for short; each frame is the data associated
5819with one call to one function. The frame contains the arguments given
5820to the function, the function's local variables, and the address at
5821which the function is executing.
5822
5823@cindex initial frame
5824@cindex outermost frame
5825@cindex innermost frame
5826When your program is started, the stack has only one frame, that of the
5827function @code{main}. This is called the @dfn{initial} frame or the
5828@dfn{outermost} frame. Each time a function is called, a new frame is
5829made. Each time a function returns, the frame for that function invocation
5830is eliminated. If a function is recursive, there can be many frames for
5831the same function. The frame for the function in which execution is
5832actually occurring is called the @dfn{innermost} frame. This is the most
5833recently created of all the stack frames that still exist.
5834
5835@cindex frame pointer
5836Inside your program, stack frames are identified by their addresses. A
5837stack frame consists of many bytes, each of which has its own address; each
5838kind of computer has a convention for choosing one byte whose
5839address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
5840in a register called the @dfn{frame pointer register}
5841(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
5842
5843@cindex frame number
5844@value{GDBN} assigns numbers to all existing stack frames, starting with
5845zero for the innermost frame, one for the frame that called it,
5846and so on upward. These numbers do not really exist in your program;
5847they are assigned by @value{GDBN} to give you a way of designating stack
5848frames in @value{GDBN} commands.
5849
6d2ebf8b
SS
5850@c The -fomit-frame-pointer below perennially causes hbox overflow
5851@c underflow problems.
c906108c
SS
5852@cindex frameless execution
5853Some compilers provide a way to compile functions so that they operate
e22ea452 5854without stack frames. (For example, the @value{NGCC} option
474c8240 5855@smallexample
6d2ebf8b 5856@samp{-fomit-frame-pointer}
474c8240 5857@end smallexample
6d2ebf8b 5858generates functions without a frame.)
c906108c
SS
5859This is occasionally done with heavily used library functions to save
5860the frame setup time. @value{GDBN} has limited facilities for dealing
5861with these function invocations. If the innermost function invocation
5862has no stack frame, @value{GDBN} nevertheless regards it as though
5863it had a separate frame, which is numbered zero as usual, allowing
5864correct tracing of the function call chain. However, @value{GDBN} has
5865no provision for frameless functions elsewhere in the stack.
5866
5867@table @code
d4f3574e 5868@kindex frame@r{, command}
41afff9a 5869@cindex current stack frame
c906108c 5870@item frame @var{args}
5d161b24 5871The @code{frame} command allows you to move from one stack frame to another,
c906108c 5872and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
5873address of the frame or the stack frame number. Without an argument,
5874@code{frame} prints the current stack frame.
c906108c
SS
5875
5876@kindex select-frame
41afff9a 5877@cindex selecting frame silently
c906108c
SS
5878@item select-frame
5879The @code{select-frame} command allows you to move from one stack frame
5880to another without printing the frame. This is the silent version of
5881@code{frame}.
5882@end table
5883
6d2ebf8b 5884@node Backtrace
c906108c
SS
5885@section Backtraces
5886
09d4efe1
EZ
5887@cindex traceback
5888@cindex call stack traces
c906108c
SS
5889A backtrace is a summary of how your program got where it is. It shows one
5890line per frame, for many frames, starting with the currently executing
5891frame (frame zero), followed by its caller (frame one), and on up the
5892stack.
5893
5894@table @code
5895@kindex backtrace
41afff9a 5896@kindex bt @r{(@code{backtrace})}
c906108c
SS
5897@item backtrace
5898@itemx bt
5899Print a backtrace of the entire stack: one line per frame for all
5900frames in the stack.
5901
5902You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 5903character, normally @kbd{Ctrl-c}.
c906108c
SS
5904
5905@item backtrace @var{n}
5906@itemx bt @var{n}
5907Similar, but print only the innermost @var{n} frames.
5908
5909@item backtrace -@var{n}
5910@itemx bt -@var{n}
5911Similar, but print only the outermost @var{n} frames.
0f061b69
NR
5912
5913@item backtrace full
0f061b69 5914@itemx bt full
dd74f6ae
NR
5915@itemx bt full @var{n}
5916@itemx bt full -@var{n}
e7109c7e 5917Print the values of the local variables also. @var{n} specifies the
286ba84d 5918number of frames to print, as described above.
c906108c
SS
5919@end table
5920
5921@kindex where
5922@kindex info stack
c906108c
SS
5923The names @code{where} and @code{info stack} (abbreviated @code{info s})
5924are additional aliases for @code{backtrace}.
5925
839c27b7
EZ
5926@cindex multiple threads, backtrace
5927In a multi-threaded program, @value{GDBN} by default shows the
5928backtrace only for the current thread. To display the backtrace for
5929several or all of the threads, use the command @code{thread apply}
5930(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
5931apply all backtrace}, @value{GDBN} will display the backtrace for all
5932the threads; this is handy when you debug a core dump of a
5933multi-threaded program.
5934
c906108c
SS
5935Each line in the backtrace shows the frame number and the function name.
5936The program counter value is also shown---unless you use @code{set
5937print address off}. The backtrace also shows the source file name and
5938line number, as well as the arguments to the function. The program
5939counter value is omitted if it is at the beginning of the code for that
5940line number.
5941
5942Here is an example of a backtrace. It was made with the command
5943@samp{bt 3}, so it shows the innermost three frames.
5944
5945@smallexample
5946@group
5d161b24 5947#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 5948 at builtin.c:993
4f5376b2 5949#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
5950#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
5951 at macro.c:71
5952(More stack frames follow...)
5953@end group
5954@end smallexample
5955
5956@noindent
5957The display for frame zero does not begin with a program counter
5958value, indicating that your program has stopped at the beginning of the
5959code for line @code{993} of @code{builtin.c}.
5960
4f5376b2
JB
5961@noindent
5962The value of parameter @code{data} in frame 1 has been replaced by
5963@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
5964only if it is a scalar (integer, pointer, enumeration, etc). See command
5965@kbd{set print frame-arguments} in @ref{Print Settings} for more details
5966on how to configure the way function parameter values are printed.
5967
18999be5
EZ
5968@cindex value optimized out, in backtrace
5969@cindex function call arguments, optimized out
5970If your program was compiled with optimizations, some compilers will
5971optimize away arguments passed to functions if those arguments are
5972never used after the call. Such optimizations generate code that
5973passes arguments through registers, but doesn't store those arguments
5974in the stack frame. @value{GDBN} has no way of displaying such
5975arguments in stack frames other than the innermost one. Here's what
5976such a backtrace might look like:
5977
5978@smallexample
5979@group
5980#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5981 at builtin.c:993
5982#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
5983#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
5984 at macro.c:71
5985(More stack frames follow...)
5986@end group
5987@end smallexample
5988
5989@noindent
5990The values of arguments that were not saved in their stack frames are
5991shown as @samp{<value optimized out>}.
5992
5993If you need to display the values of such optimized-out arguments,
5994either deduce that from other variables whose values depend on the one
5995you are interested in, or recompile without optimizations.
5996
a8f24a35
EZ
5997@cindex backtrace beyond @code{main} function
5998@cindex program entry point
5999@cindex startup code, and backtrace
25d29d70
AC
6000Most programs have a standard user entry point---a place where system
6001libraries and startup code transition into user code. For C this is
d416eeec
EZ
6002@code{main}@footnote{
6003Note that embedded programs (the so-called ``free-standing''
6004environment) are not required to have a @code{main} function as the
6005entry point. They could even have multiple entry points.}.
6006When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
6007it will terminate the backtrace, to avoid tracing into highly
6008system-specific (and generally uninteresting) code.
6009
6010If you need to examine the startup code, or limit the number of levels
6011in a backtrace, you can change this behavior:
95f90d25
DJ
6012
6013@table @code
25d29d70
AC
6014@item set backtrace past-main
6015@itemx set backtrace past-main on
4644b6e3 6016@kindex set backtrace
25d29d70
AC
6017Backtraces will continue past the user entry point.
6018
6019@item set backtrace past-main off
95f90d25
DJ
6020Backtraces will stop when they encounter the user entry point. This is the
6021default.
6022
25d29d70 6023@item show backtrace past-main
4644b6e3 6024@kindex show backtrace
25d29d70
AC
6025Display the current user entry point backtrace policy.
6026
2315ffec
RC
6027@item set backtrace past-entry
6028@itemx set backtrace past-entry on
a8f24a35 6029Backtraces will continue past the internal entry point of an application.
2315ffec
RC
6030This entry point is encoded by the linker when the application is built,
6031and is likely before the user entry point @code{main} (or equivalent) is called.
6032
6033@item set backtrace past-entry off
d3e8051b 6034Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
6035application. This is the default.
6036
6037@item show backtrace past-entry
6038Display the current internal entry point backtrace policy.
6039
25d29d70
AC
6040@item set backtrace limit @var{n}
6041@itemx set backtrace limit 0
6042@cindex backtrace limit
6043Limit the backtrace to @var{n} levels. A value of zero means
6044unlimited.
95f90d25 6045
25d29d70
AC
6046@item show backtrace limit
6047Display the current limit on backtrace levels.
95f90d25
DJ
6048@end table
6049
6d2ebf8b 6050@node Selection
79a6e687 6051@section Selecting a Frame
c906108c
SS
6052
6053Most commands for examining the stack and other data in your program work on
6054whichever stack frame is selected at the moment. Here are the commands for
6055selecting a stack frame; all of them finish by printing a brief description
6056of the stack frame just selected.
6057
6058@table @code
d4f3574e 6059@kindex frame@r{, selecting}
41afff9a 6060@kindex f @r{(@code{frame})}
c906108c
SS
6061@item frame @var{n}
6062@itemx f @var{n}
6063Select frame number @var{n}. Recall that frame zero is the innermost
6064(currently executing) frame, frame one is the frame that called the
6065innermost one, and so on. The highest-numbered frame is the one for
6066@code{main}.
6067
6068@item frame @var{addr}
6069@itemx f @var{addr}
6070Select the frame at address @var{addr}. This is useful mainly if the
6071chaining of stack frames has been damaged by a bug, making it
6072impossible for @value{GDBN} to assign numbers properly to all frames. In
6073addition, this can be useful when your program has multiple stacks and
6074switches between them.
6075
c906108c
SS
6076On the SPARC architecture, @code{frame} needs two addresses to
6077select an arbitrary frame: a frame pointer and a stack pointer.
6078
6079On the MIPS and Alpha architecture, it needs two addresses: a stack
6080pointer and a program counter.
6081
6082On the 29k architecture, it needs three addresses: a register stack
6083pointer, a program counter, and a memory stack pointer.
c906108c
SS
6084
6085@kindex up
6086@item up @var{n}
6087Move @var{n} frames up the stack. For positive numbers @var{n}, this
6088advances toward the outermost frame, to higher frame numbers, to frames
6089that have existed longer. @var{n} defaults to one.
6090
6091@kindex down
41afff9a 6092@kindex do @r{(@code{down})}
c906108c
SS
6093@item down @var{n}
6094Move @var{n} frames down the stack. For positive numbers @var{n}, this
6095advances toward the innermost frame, to lower frame numbers, to frames
6096that were created more recently. @var{n} defaults to one. You may
6097abbreviate @code{down} as @code{do}.
6098@end table
6099
6100All of these commands end by printing two lines of output describing the
6101frame. The first line shows the frame number, the function name, the
6102arguments, and the source file and line number of execution in that
5d161b24 6103frame. The second line shows the text of that source line.
c906108c
SS
6104
6105@need 1000
6106For example:
6107
6108@smallexample
6109@group
6110(@value{GDBP}) up
6111#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6112 at env.c:10
611310 read_input_file (argv[i]);
6114@end group
6115@end smallexample
6116
6117After such a printout, the @code{list} command with no arguments
6118prints ten lines centered on the point of execution in the frame.
87885426
FN
6119You can also edit the program at the point of execution with your favorite
6120editing program by typing @code{edit}.
79a6e687 6121@xref{List, ,Printing Source Lines},
87885426 6122for details.
c906108c
SS
6123
6124@table @code
6125@kindex down-silently
6126@kindex up-silently
6127@item up-silently @var{n}
6128@itemx down-silently @var{n}
6129These two commands are variants of @code{up} and @code{down},
6130respectively; they differ in that they do their work silently, without
6131causing display of the new frame. They are intended primarily for use
6132in @value{GDBN} command scripts, where the output might be unnecessary and
6133distracting.
6134@end table
6135
6d2ebf8b 6136@node Frame Info
79a6e687 6137@section Information About a Frame
c906108c
SS
6138
6139There are several other commands to print information about the selected
6140stack frame.
6141
6142@table @code
6143@item frame
6144@itemx f
6145When used without any argument, this command does not change which
6146frame is selected, but prints a brief description of the currently
6147selected stack frame. It can be abbreviated @code{f}. With an
6148argument, this command is used to select a stack frame.
79a6e687 6149@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6150
6151@kindex info frame
41afff9a 6152@kindex info f @r{(@code{info frame})}
c906108c
SS
6153@item info frame
6154@itemx info f
6155This command prints a verbose description of the selected stack frame,
6156including:
6157
6158@itemize @bullet
5d161b24
DB
6159@item
6160the address of the frame
c906108c
SS
6161@item
6162the address of the next frame down (called by this frame)
6163@item
6164the address of the next frame up (caller of this frame)
6165@item
6166the language in which the source code corresponding to this frame is written
6167@item
6168the address of the frame's arguments
6169@item
d4f3574e
SS
6170the address of the frame's local variables
6171@item
c906108c
SS
6172the program counter saved in it (the address of execution in the caller frame)
6173@item
6174which registers were saved in the frame
6175@end itemize
6176
6177@noindent The verbose description is useful when
6178something has gone wrong that has made the stack format fail to fit
6179the usual conventions.
6180
6181@item info frame @var{addr}
6182@itemx info f @var{addr}
6183Print a verbose description of the frame at address @var{addr}, without
6184selecting that frame. The selected frame remains unchanged by this
6185command. This requires the same kind of address (more than one for some
6186architectures) that you specify in the @code{frame} command.
79a6e687 6187@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6188
6189@kindex info args
6190@item info args
6191Print the arguments of the selected frame, each on a separate line.
6192
6193@item info locals
6194@kindex info locals
6195Print the local variables of the selected frame, each on a separate
6196line. These are all variables (declared either static or automatic)
6197accessible at the point of execution of the selected frame.
6198
c906108c 6199@kindex info catch
d4f3574e
SS
6200@cindex catch exceptions, list active handlers
6201@cindex exception handlers, how to list
c906108c
SS
6202@item info catch
6203Print a list of all the exception handlers that are active in the
6204current stack frame at the current point of execution. To see other
6205exception handlers, visit the associated frame (using the @code{up},
6206@code{down}, or @code{frame} commands); then type @code{info catch}.
79a6e687 6207@xref{Set Catchpoints, , Setting Catchpoints}.
53a5351d 6208
c906108c
SS
6209@end table
6210
c906108c 6211
6d2ebf8b 6212@node Source
c906108c
SS
6213@chapter Examining Source Files
6214
6215@value{GDBN} can print parts of your program's source, since the debugging
6216information recorded in the program tells @value{GDBN} what source files were
6217used to build it. When your program stops, @value{GDBN} spontaneously prints
6218the line where it stopped. Likewise, when you select a stack frame
79a6e687 6219(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
6220execution in that frame has stopped. You can print other portions of
6221source files by explicit command.
6222
7a292a7a 6223If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 6224prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 6225@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
6226
6227@menu
6228* List:: Printing source lines
2a25a5ba 6229* Specify Location:: How to specify code locations
87885426 6230* Edit:: Editing source files
c906108c 6231* Search:: Searching source files
c906108c
SS
6232* Source Path:: Specifying source directories
6233* Machine Code:: Source and machine code
6234@end menu
6235
6d2ebf8b 6236@node List
79a6e687 6237@section Printing Source Lines
c906108c
SS
6238
6239@kindex list
41afff9a 6240@kindex l @r{(@code{list})}
c906108c 6241To print lines from a source file, use the @code{list} command
5d161b24 6242(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
6243There are several ways to specify what part of the file you want to
6244print; see @ref{Specify Location}, for the full list.
c906108c
SS
6245
6246Here are the forms of the @code{list} command most commonly used:
6247
6248@table @code
6249@item list @var{linenum}
6250Print lines centered around line number @var{linenum} in the
6251current source file.
6252
6253@item list @var{function}
6254Print lines centered around the beginning of function
6255@var{function}.
6256
6257@item list
6258Print more lines. If the last lines printed were printed with a
6259@code{list} command, this prints lines following the last lines
6260printed; however, if the last line printed was a solitary line printed
6261as part of displaying a stack frame (@pxref{Stack, ,Examining the
6262Stack}), this prints lines centered around that line.
6263
6264@item list -
6265Print lines just before the lines last printed.
6266@end table
6267
9c16f35a 6268@cindex @code{list}, how many lines to display
c906108c
SS
6269By default, @value{GDBN} prints ten source lines with any of these forms of
6270the @code{list} command. You can change this using @code{set listsize}:
6271
6272@table @code
6273@kindex set listsize
6274@item set listsize @var{count}
6275Make the @code{list} command display @var{count} source lines (unless
6276the @code{list} argument explicitly specifies some other number).
6277
6278@kindex show listsize
6279@item show listsize
6280Display the number of lines that @code{list} prints.
6281@end table
6282
6283Repeating a @code{list} command with @key{RET} discards the argument,
6284so it is equivalent to typing just @code{list}. This is more useful
6285than listing the same lines again. An exception is made for an
6286argument of @samp{-}; that argument is preserved in repetition so that
6287each repetition moves up in the source file.
6288
c906108c
SS
6289In general, the @code{list} command expects you to supply zero, one or two
6290@dfn{linespecs}. Linespecs specify source lines; there are several ways
2a25a5ba
EZ
6291of writing them (@pxref{Specify Location}), but the effect is always
6292to specify some source line.
6293
c906108c
SS
6294Here is a complete description of the possible arguments for @code{list}:
6295
6296@table @code
6297@item list @var{linespec}
6298Print lines centered around the line specified by @var{linespec}.
6299
6300@item list @var{first},@var{last}
6301Print lines from @var{first} to @var{last}. Both arguments are
2a25a5ba
EZ
6302linespecs. When a @code{list} command has two linespecs, and the
6303source file of the second linespec is omitted, this refers to
6304the same source file as the first linespec.
c906108c
SS
6305
6306@item list ,@var{last}
6307Print lines ending with @var{last}.
6308
6309@item list @var{first},
6310Print lines starting with @var{first}.
6311
6312@item list +
6313Print lines just after the lines last printed.
6314
6315@item list -
6316Print lines just before the lines last printed.
6317
6318@item list
6319As described in the preceding table.
6320@end table
6321
2a25a5ba
EZ
6322@node Specify Location
6323@section Specifying a Location
6324@cindex specifying location
6325@cindex linespec
c906108c 6326
2a25a5ba
EZ
6327Several @value{GDBN} commands accept arguments that specify a location
6328of your program's code. Since @value{GDBN} is a source-level
6329debugger, a location usually specifies some line in the source code;
6330for that reason, locations are also known as @dfn{linespecs}.
c906108c 6331
2a25a5ba
EZ
6332Here are all the different ways of specifying a code location that
6333@value{GDBN} understands:
c906108c 6334
2a25a5ba
EZ
6335@table @code
6336@item @var{linenum}
6337Specifies the line number @var{linenum} of the current source file.
c906108c 6338
2a25a5ba
EZ
6339@item -@var{offset}
6340@itemx +@var{offset}
6341Specifies the line @var{offset} lines before or after the @dfn{current
6342line}. For the @code{list} command, the current line is the last one
6343printed; for the breakpoint commands, this is the line at which
6344execution stopped in the currently selected @dfn{stack frame}
6345(@pxref{Frames, ,Frames}, for a description of stack frames.) When
6346used as the second of the two linespecs in a @code{list} command,
6347this specifies the line @var{offset} lines up or down from the first
6348linespec.
6349
6350@item @var{filename}:@var{linenum}
6351Specifies the line @var{linenum} in the source file @var{filename}.
c906108c
SS
6352
6353@item @var{function}
6354Specifies the line that begins the body of the function @var{function}.
2a25a5ba 6355For example, in C, this is the line with the open brace.
c906108c
SS
6356
6357@item @var{filename}:@var{function}
2a25a5ba
EZ
6358Specifies the line that begins the body of the function @var{function}
6359in the file @var{filename}. You only need the file name with a
6360function name to avoid ambiguity when there are identically named
6361functions in different source files.
c906108c 6362
0f5238ed
TT
6363@item @var{label}
6364Specifies the line at which the label named @var{label} appears.
6365@value{GDBN} searches for the label in the function corresponding to
6366the currently selected stack frame. If there is no current selected
6367stack frame (for instance, if the inferior is not running), then
6368@value{GDBN} will not search for a label.
6369
c906108c 6370@item *@var{address}
2a25a5ba
EZ
6371Specifies the program address @var{address}. For line-oriented
6372commands, such as @code{list} and @code{edit}, this specifies a source
6373line that contains @var{address}. For @code{break} and other
6374breakpoint oriented commands, this can be used to set breakpoints in
6375parts of your program which do not have debugging information or
6376source files.
6377
6378Here @var{address} may be any expression valid in the current working
6379language (@pxref{Languages, working language}) that specifies a code
5fa54e5d
EZ
6380address. In addition, as a convenience, @value{GDBN} extends the
6381semantics of expressions used in locations to cover the situations
6382that frequently happen during debugging. Here are the various forms
6383of @var{address}:
2a25a5ba
EZ
6384
6385@table @code
6386@item @var{expression}
6387Any expression valid in the current working language.
6388
6389@item @var{funcaddr}
6390An address of a function or procedure derived from its name. In C,
6391C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
6392simply the function's name @var{function} (and actually a special case
6393of a valid expression). In Pascal and Modula-2, this is
6394@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
6395(although the Pascal form also works).
6396
6397This form specifies the address of the function's first instruction,
6398before the stack frame and arguments have been set up.
6399
6400@item '@var{filename}'::@var{funcaddr}
6401Like @var{funcaddr} above, but also specifies the name of the source
6402file explicitly. This is useful if the name of the function does not
6403specify the function unambiguously, e.g., if there are several
6404functions with identical names in different source files.
c906108c
SS
6405@end table
6406
2a25a5ba
EZ
6407@end table
6408
6409
87885426 6410@node Edit
79a6e687 6411@section Editing Source Files
87885426
FN
6412@cindex editing source files
6413
6414@kindex edit
6415@kindex e @r{(@code{edit})}
6416To edit the lines in a source file, use the @code{edit} command.
6417The editing program of your choice
6418is invoked with the current line set to
6419the active line in the program.
6420Alternatively, there are several ways to specify what part of the file you
2a25a5ba 6421want to print if you want to see other parts of the program:
87885426
FN
6422
6423@table @code
2a25a5ba
EZ
6424@item edit @var{location}
6425Edit the source file specified by @code{location}. Editing starts at
6426that @var{location}, e.g., at the specified source line of the
6427specified file. @xref{Specify Location}, for all the possible forms
6428of the @var{location} argument; here are the forms of the @code{edit}
6429command most commonly used:
87885426 6430
2a25a5ba 6431@table @code
87885426
FN
6432@item edit @var{number}
6433Edit the current source file with @var{number} as the active line number.
6434
6435@item edit @var{function}
6436Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 6437@end table
87885426 6438
87885426
FN
6439@end table
6440
79a6e687 6441@subsection Choosing your Editor
87885426
FN
6442You can customize @value{GDBN} to use any editor you want
6443@footnote{
6444The only restriction is that your editor (say @code{ex}), recognizes the
6445following command-line syntax:
10998722 6446@smallexample
87885426 6447ex +@var{number} file
10998722 6448@end smallexample
15387254
EZ
6449The optional numeric value +@var{number} specifies the number of the line in
6450the file where to start editing.}.
6451By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
6452by setting the environment variable @code{EDITOR} before using
6453@value{GDBN}. For example, to configure @value{GDBN} to use the
6454@code{vi} editor, you could use these commands with the @code{sh} shell:
6455@smallexample
87885426
FN
6456EDITOR=/usr/bin/vi
6457export EDITOR
15387254 6458gdb @dots{}
10998722 6459@end smallexample
87885426 6460or in the @code{csh} shell,
10998722 6461@smallexample
87885426 6462setenv EDITOR /usr/bin/vi
15387254 6463gdb @dots{}
10998722 6464@end smallexample
87885426 6465
6d2ebf8b 6466@node Search
79a6e687 6467@section Searching Source Files
15387254 6468@cindex searching source files
c906108c
SS
6469
6470There are two commands for searching through the current source file for a
6471regular expression.
6472
6473@table @code
6474@kindex search
6475@kindex forward-search
6476@item forward-search @var{regexp}
6477@itemx search @var{regexp}
6478The command @samp{forward-search @var{regexp}} checks each line,
6479starting with the one following the last line listed, for a match for
5d161b24 6480@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
6481synonym @samp{search @var{regexp}} or abbreviate the command name as
6482@code{fo}.
6483
09d4efe1 6484@kindex reverse-search
c906108c
SS
6485@item reverse-search @var{regexp}
6486The command @samp{reverse-search @var{regexp}} checks each line, starting
6487with the one before the last line listed and going backward, for a match
6488for @var{regexp}. It lists the line that is found. You can abbreviate
6489this command as @code{rev}.
6490@end table
c906108c 6491
6d2ebf8b 6492@node Source Path
79a6e687 6493@section Specifying Source Directories
c906108c
SS
6494
6495@cindex source path
6496@cindex directories for source files
6497Executable programs sometimes do not record the directories of the source
6498files from which they were compiled, just the names. Even when they do,
6499the directories could be moved between the compilation and your debugging
6500session. @value{GDBN} has a list of directories to search for source files;
6501this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
6502it tries all the directories in the list, in the order they are present
0b66e38c
EZ
6503in the list, until it finds a file with the desired name.
6504
6505For example, suppose an executable references the file
6506@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
6507@file{/mnt/cross}. The file is first looked up literally; if this
6508fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
6509fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
6510message is printed. @value{GDBN} does not look up the parts of the
6511source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
6512Likewise, the subdirectories of the source path are not searched: if
6513the source path is @file{/mnt/cross}, and the binary refers to
6514@file{foo.c}, @value{GDBN} would not find it under
6515@file{/mnt/cross/usr/src/foo-1.0/lib}.
6516
6517Plain file names, relative file names with leading directories, file
6518names containing dots, etc.@: are all treated as described above; for
6519instance, if the source path is @file{/mnt/cross}, and the source file
6520is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
6521@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
6522that---@file{/mnt/cross/foo.c}.
6523
6524Note that the executable search path is @emph{not} used to locate the
cd852561 6525source files.
c906108c
SS
6526
6527Whenever you reset or rearrange the source path, @value{GDBN} clears out
6528any information it has cached about where source files are found and where
6529each line is in the file.
6530
6531@kindex directory
6532@kindex dir
d4f3574e
SS
6533When you start @value{GDBN}, its source path includes only @samp{cdir}
6534and @samp{cwd}, in that order.
c906108c
SS
6535To add other directories, use the @code{directory} command.
6536
4b505b12
AS
6537The search path is used to find both program source files and @value{GDBN}
6538script files (read using the @samp{-command} option and @samp{source} command).
6539
30daae6c
JB
6540In addition to the source path, @value{GDBN} provides a set of commands
6541that manage a list of source path substitution rules. A @dfn{substitution
6542rule} specifies how to rewrite source directories stored in the program's
6543debug information in case the sources were moved to a different
6544directory between compilation and debugging. A rule is made of
6545two strings, the first specifying what needs to be rewritten in
6546the path, and the second specifying how it should be rewritten.
6547In @ref{set substitute-path}, we name these two parts @var{from} and
6548@var{to} respectively. @value{GDBN} does a simple string replacement
6549of @var{from} with @var{to} at the start of the directory part of the
6550source file name, and uses that result instead of the original file
6551name to look up the sources.
6552
6553Using the previous example, suppose the @file{foo-1.0} tree has been
6554moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 6555@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
6556@file{/mnt/cross}. The first lookup will then be
6557@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
6558of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
6559substitution rule, use the @code{set substitute-path} command
6560(@pxref{set substitute-path}).
6561
6562To avoid unexpected substitution results, a rule is applied only if the
6563@var{from} part of the directory name ends at a directory separator.
6564For instance, a rule substituting @file{/usr/source} into
6565@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
6566not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 6567is applied only at the beginning of the directory name, this rule will
30daae6c
JB
6568not be applied to @file{/root/usr/source/baz.c} either.
6569
6570In many cases, you can achieve the same result using the @code{directory}
6571command. However, @code{set substitute-path} can be more efficient in
6572the case where the sources are organized in a complex tree with multiple
6573subdirectories. With the @code{directory} command, you need to add each
6574subdirectory of your project. If you moved the entire tree while
6575preserving its internal organization, then @code{set substitute-path}
6576allows you to direct the debugger to all the sources with one single
6577command.
6578
6579@code{set substitute-path} is also more than just a shortcut command.
6580The source path is only used if the file at the original location no
6581longer exists. On the other hand, @code{set substitute-path} modifies
6582the debugger behavior to look at the rewritten location instead. So, if
6583for any reason a source file that is not relevant to your executable is
6584located at the original location, a substitution rule is the only
3f94c067 6585method available to point @value{GDBN} at the new location.
30daae6c 6586
29b0e8a2
JM
6587@cindex @samp{--with-relocated-sources}
6588@cindex default source path substitution
6589You can configure a default source path substitution rule by
6590configuring @value{GDBN} with the
6591@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
6592should be the name of a directory under @value{GDBN}'s configured
6593prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
6594directory names in debug information under @var{dir} will be adjusted
6595automatically if the installed @value{GDBN} is moved to a new
6596location. This is useful if @value{GDBN}, libraries or executables
6597with debug information and corresponding source code are being moved
6598together.
6599
c906108c
SS
6600@table @code
6601@item directory @var{dirname} @dots{}
6602@item dir @var{dirname} @dots{}
6603Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
6604directory names may be given to this command, separated by @samp{:}
6605(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
6606part of absolute file names) or
c906108c
SS
6607whitespace. You may specify a directory that is already in the source
6608path; this moves it forward, so @value{GDBN} searches it sooner.
6609
6610@kindex cdir
6611@kindex cwd
41afff9a 6612@vindex $cdir@r{, convenience variable}
d3e8051b 6613@vindex $cwd@r{, convenience variable}
c906108c
SS
6614@cindex compilation directory
6615@cindex current directory
6616@cindex working directory
6617@cindex directory, current
6618@cindex directory, compilation
6619You can use the string @samp{$cdir} to refer to the compilation
6620directory (if one is recorded), and @samp{$cwd} to refer to the current
6621working directory. @samp{$cwd} is not the same as @samp{.}---the former
6622tracks the current working directory as it changes during your @value{GDBN}
6623session, while the latter is immediately expanded to the current
6624directory at the time you add an entry to the source path.
6625
6626@item directory
cd852561 6627Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
6628
6629@c RET-repeat for @code{directory} is explicitly disabled, but since
6630@c repeating it would be a no-op we do not say that. (thanks to RMS)
6631
99e7ae30
DE
6632@item set directories @var{path-list}
6633@kindex set directories
6634Set the source path to @var{path-list}.
6635@samp{$cdir:$cwd} are added if missing.
6636
c906108c
SS
6637@item show directories
6638@kindex show directories
6639Print the source path: show which directories it contains.
30daae6c
JB
6640
6641@anchor{set substitute-path}
6642@item set substitute-path @var{from} @var{to}
6643@kindex set substitute-path
6644Define a source path substitution rule, and add it at the end of the
6645current list of existing substitution rules. If a rule with the same
6646@var{from} was already defined, then the old rule is also deleted.
6647
6648For example, if the file @file{/foo/bar/baz.c} was moved to
6649@file{/mnt/cross/baz.c}, then the command
6650
6651@smallexample
6652(@value{GDBP}) set substitute-path /usr/src /mnt/cross
6653@end smallexample
6654
6655@noindent
6656will tell @value{GDBN} to replace @samp{/usr/src} with
6657@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
6658@file{baz.c} even though it was moved.
6659
6660In the case when more than one substitution rule have been defined,
6661the rules are evaluated one by one in the order where they have been
6662defined. The first one matching, if any, is selected to perform
6663the substitution.
6664
6665For instance, if we had entered the following commands:
6666
6667@smallexample
6668(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
6669(@value{GDBP}) set substitute-path /usr/src /mnt/src
6670@end smallexample
6671
6672@noindent
6673@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
6674@file{/mnt/include/defs.h} by using the first rule. However, it would
6675use the second rule to rewrite @file{/usr/src/lib/foo.c} into
6676@file{/mnt/src/lib/foo.c}.
6677
6678
6679@item unset substitute-path [path]
6680@kindex unset substitute-path
6681If a path is specified, search the current list of substitution rules
6682for a rule that would rewrite that path. Delete that rule if found.
6683A warning is emitted by the debugger if no rule could be found.
6684
6685If no path is specified, then all substitution rules are deleted.
6686
6687@item show substitute-path [path]
6688@kindex show substitute-path
6689If a path is specified, then print the source path substitution rule
6690which would rewrite that path, if any.
6691
6692If no path is specified, then print all existing source path substitution
6693rules.
6694
c906108c
SS
6695@end table
6696
6697If your source path is cluttered with directories that are no longer of
6698interest, @value{GDBN} may sometimes cause confusion by finding the wrong
6699versions of source. You can correct the situation as follows:
6700
6701@enumerate
6702@item
cd852561 6703Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
6704
6705@item
6706Use @code{directory} with suitable arguments to reinstall the
6707directories you want in the source path. You can add all the
6708directories in one command.
6709@end enumerate
6710
6d2ebf8b 6711@node Machine Code
79a6e687 6712@section Source and Machine Code
15387254 6713@cindex source line and its code address
c906108c
SS
6714
6715You can use the command @code{info line} to map source lines to program
6716addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
6717a range of addresses as machine instructions. You can use the command
6718@code{set disassemble-next-line} to set whether to disassemble next
6719source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 6720mode, the @code{info line} command causes the arrow to point to the
5d161b24 6721line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
6722well as hex.
6723
6724@table @code
6725@kindex info line
6726@item info line @var{linespec}
6727Print the starting and ending addresses of the compiled code for
6728source line @var{linespec}. You can specify source lines in any of
2a25a5ba 6729the ways documented in @ref{Specify Location}.
c906108c
SS
6730@end table
6731
6732For example, we can use @code{info line} to discover the location of
6733the object code for the first line of function
6734@code{m4_changequote}:
6735
d4f3574e
SS
6736@c FIXME: I think this example should also show the addresses in
6737@c symbolic form, as they usually would be displayed.
c906108c 6738@smallexample
96a2c332 6739(@value{GDBP}) info line m4_changequote
c906108c
SS
6740Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
6741@end smallexample
6742
6743@noindent
15387254 6744@cindex code address and its source line
c906108c
SS
6745We can also inquire (using @code{*@var{addr}} as the form for
6746@var{linespec}) what source line covers a particular address:
6747@smallexample
6748(@value{GDBP}) info line *0x63ff
6749Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
6750@end smallexample
6751
6752@cindex @code{$_} and @code{info line}
15387254 6753@cindex @code{x} command, default address
41afff9a 6754@kindex x@r{(examine), and} info line
c906108c
SS
6755After @code{info line}, the default address for the @code{x} command
6756is changed to the starting address of the line, so that @samp{x/i} is
6757sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 6758,Examining Memory}). Also, this address is saved as the value of the
c906108c 6759convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 6760Variables}).
c906108c
SS
6761
6762@table @code
6763@kindex disassemble
6764@cindex assembly instructions
6765@cindex instructions, assembly
6766@cindex machine instructions
6767@cindex listing machine instructions
6768@item disassemble
d14508fe 6769@itemx disassemble /m
9b117ef3 6770@itemx disassemble /r
c906108c 6771This specialized command dumps a range of memory as machine
d14508fe 6772instructions. It can also print mixed source+disassembly by specifying
9b117ef3
HZ
6773the @code{/m} modifier and print the raw instructions in hex as well as
6774in symbolic form by specifying the @code{/r}.
d14508fe 6775The default memory range is the function surrounding the
c906108c
SS
6776program counter of the selected frame. A single argument to this
6777command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
6778surrounding this value. When two arguments are given, they should
6779be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
6780arguments specify a range of addresses to dump, in one of two forms:
6781
6782@table @code
6783@item @var{start},@var{end}
6784the addresses from @var{start} (inclusive) to @var{end} (exclusive)
6785@item @var{start},+@var{length}
6786the addresses from @var{start} (inclusive) to
6787@code{@var{start}+@var{length}} (exclusive).
6788@end table
6789
6790@noindent
6791When 2 arguments are specified, the name of the function is also
6792printed (since there could be several functions in the given range).
21a0512e
PP
6793
6794The argument(s) can be any expression yielding a numeric value, such as
6795@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
6796
6797If the range of memory being disassembled contains current program counter,
6798the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
6799@end table
6800
c906108c
SS
6801The following example shows the disassembly of a range of addresses of
6802HP PA-RISC 2.0 code:
6803
6804@smallexample
21a0512e 6805(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 6806Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
6807 0x32c4 <main+204>: addil 0,dp
6808 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
6809 0x32cc <main+212>: ldil 0x3000,r31
6810 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
6811 0x32d4 <main+220>: ldo 0(r31),rp
6812 0x32d8 <main+224>: addil -0x800,dp
6813 0x32dc <main+228>: ldo 0x588(r1),r26
6814 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
6815End of assembler dump.
6816@end smallexample
c906108c 6817
2b28d209
PP
6818Here is an example showing mixed source+assembly for Intel x86, when the
6819program is stopped just after function prologue:
d14508fe
DE
6820
6821@smallexample
6822(@value{GDBP}) disas /m main
6823Dump of assembler code for function main:
68245 @{
9c419145
PP
6825 0x08048330 <+0>: push %ebp
6826 0x08048331 <+1>: mov %esp,%ebp
6827 0x08048333 <+3>: sub $0x8,%esp
6828 0x08048336 <+6>: and $0xfffffff0,%esp
6829 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
6830
68316 printf ("Hello.\n");
9c419145
PP
6832=> 0x0804833c <+12>: movl $0x8048440,(%esp)
6833 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
6834
68357 return 0;
68368 @}
9c419145
PP
6837 0x08048348 <+24>: mov $0x0,%eax
6838 0x0804834d <+29>: leave
6839 0x0804834e <+30>: ret
d14508fe
DE
6840
6841End of assembler dump.
6842@end smallexample
6843
53a71c06
CR
6844Here is another example showing raw instructions in hex for AMD x86-64,
6845
6846@smallexample
6847(gdb) disas /r 0x400281,+10
6848Dump of assembler code from 0x400281 to 0x40028b:
6849 0x0000000000400281: 38 36 cmp %dh,(%rsi)
6850 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
6851 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
6852 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
6853End of assembler dump.
6854@end smallexample
6855
c906108c
SS
6856Some architectures have more than one commonly-used set of instruction
6857mnemonics or other syntax.
6858
76d17f34
EZ
6859For programs that were dynamically linked and use shared libraries,
6860instructions that call functions or branch to locations in the shared
6861libraries might show a seemingly bogus location---it's actually a
6862location of the relocation table. On some architectures, @value{GDBN}
6863might be able to resolve these to actual function names.
6864
c906108c 6865@table @code
d4f3574e 6866@kindex set disassembly-flavor
d4f3574e
SS
6867@cindex Intel disassembly flavor
6868@cindex AT&T disassembly flavor
6869@item set disassembly-flavor @var{instruction-set}
c906108c
SS
6870Select the instruction set to use when disassembling the
6871program via the @code{disassemble} or @code{x/i} commands.
6872
6873Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
6874can set @var{instruction-set} to either @code{intel} or @code{att}.
6875The default is @code{att}, the AT&T flavor used by default by Unix
6876assemblers for x86-based targets.
9c16f35a
EZ
6877
6878@kindex show disassembly-flavor
6879@item show disassembly-flavor
6880Show the current setting of the disassembly flavor.
c906108c
SS
6881@end table
6882
91440f57
HZ
6883@table @code
6884@kindex set disassemble-next-line
6885@kindex show disassemble-next-line
6886@item set disassemble-next-line
6887@itemx show disassemble-next-line
32ae1842
EZ
6888Control whether or not @value{GDBN} will disassemble the next source
6889line or instruction when execution stops. If ON, @value{GDBN} will
6890display disassembly of the next source line when execution of the
6891program being debugged stops. This is @emph{in addition} to
6892displaying the source line itself, which @value{GDBN} always does if
6893possible. If the next source line cannot be displayed for some reason
6894(e.g., if @value{GDBN} cannot find the source file, or there's no line
6895info in the debug info), @value{GDBN} will display disassembly of the
6896next @emph{instruction} instead of showing the next source line. If
6897AUTO, @value{GDBN} will display disassembly of next instruction only
6898if the source line cannot be displayed. This setting causes
6899@value{GDBN} to display some feedback when you step through a function
6900with no line info or whose source file is unavailable. The default is
6901OFF, which means never display the disassembly of the next line or
6902instruction.
91440f57
HZ
6903@end table
6904
c906108c 6905
6d2ebf8b 6906@node Data
c906108c
SS
6907@chapter Examining Data
6908
6909@cindex printing data
6910@cindex examining data
6911@kindex print
6912@kindex inspect
6913@c "inspect" is not quite a synonym if you are using Epoch, which we do not
6914@c document because it is nonstandard... Under Epoch it displays in a
6915@c different window or something like that.
6916The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
6917command (abbreviated @code{p}), or its synonym @code{inspect}. It
6918evaluates and prints the value of an expression of the language your
6919program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
6920Different Languages}). It may also print the expression using a
6921Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
6922
6923@table @code
d4f3574e
SS
6924@item print @var{expr}
6925@itemx print /@var{f} @var{expr}
6926@var{expr} is an expression (in the source language). By default the
6927value of @var{expr} is printed in a format appropriate to its data type;
c906108c 6928you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 6929@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 6930Formats}.
c906108c
SS
6931
6932@item print
6933@itemx print /@var{f}
15387254 6934@cindex reprint the last value
d4f3574e 6935If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 6936@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
6937conveniently inspect the same value in an alternative format.
6938@end table
6939
6940A more low-level way of examining data is with the @code{x} command.
6941It examines data in memory at a specified address and prints it in a
79a6e687 6942specified format. @xref{Memory, ,Examining Memory}.
c906108c 6943
7a292a7a 6944If you are interested in information about types, or about how the
d4f3574e
SS
6945fields of a struct or a class are declared, use the @code{ptype @var{exp}}
6946command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 6947Table}.
c906108c
SS
6948
6949@menu
6950* Expressions:: Expressions
6ba66d6a 6951* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
6952* Variables:: Program variables
6953* Arrays:: Artificial arrays
6954* Output Formats:: Output formats
6955* Memory:: Examining memory
6956* Auto Display:: Automatic display
6957* Print Settings:: Print settings
4c374409 6958* Pretty Printing:: Python pretty printing
c906108c
SS
6959* Value History:: Value history
6960* Convenience Vars:: Convenience variables
6961* Registers:: Registers
c906108c 6962* Floating Point Hardware:: Floating point hardware
53c69bd7 6963* Vector Unit:: Vector Unit
721c2651 6964* OS Information:: Auxiliary data provided by operating system
29e57380 6965* Memory Region Attributes:: Memory region attributes
16d9dec6 6966* Dump/Restore Files:: Copy between memory and a file
384ee23f 6967* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
6968* Character Sets:: Debugging programs that use a different
6969 character set than GDB does
09d4efe1 6970* Caching Remote Data:: Data caching for remote targets
08388c79 6971* Searching Memory:: Searching memory for a sequence of bytes
c906108c
SS
6972@end menu
6973
6d2ebf8b 6974@node Expressions
c906108c
SS
6975@section Expressions
6976
6977@cindex expressions
6978@code{print} and many other @value{GDBN} commands accept an expression and
6979compute its value. Any kind of constant, variable or operator defined
6980by the programming language you are using is valid in an expression in
e2e0bcd1
JB
6981@value{GDBN}. This includes conditional expressions, function calls,
6982casts, and string constants. It also includes preprocessor macros, if
6983you compiled your program to include this information; see
6984@ref{Compilation}.
c906108c 6985
15387254 6986@cindex arrays in expressions
d4f3574e
SS
6987@value{GDBN} supports array constants in expressions input by
6988the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
6989you can use the command @code{print @{1, 2, 3@}} to create an array
6990of three integers. If you pass an array to a function or assign it
6991to a program variable, @value{GDBN} copies the array to memory that
6992is @code{malloc}ed in the target program.
c906108c 6993
c906108c
SS
6994Because C is so widespread, most of the expressions shown in examples in
6995this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
6996Languages}, for information on how to use expressions in other
6997languages.
6998
6999In this section, we discuss operators that you can use in @value{GDBN}
7000expressions regardless of your programming language.
7001
15387254 7002@cindex casts, in expressions
c906108c
SS
7003Casts are supported in all languages, not just in C, because it is so
7004useful to cast a number into a pointer in order to examine a structure
7005at that address in memory.
7006@c FIXME: casts supported---Mod2 true?
c906108c
SS
7007
7008@value{GDBN} supports these operators, in addition to those common
7009to programming languages:
7010
7011@table @code
7012@item @@
7013@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 7014@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
7015
7016@item ::
7017@samp{::} allows you to specify a variable in terms of the file or
79a6e687 7018function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
7019
7020@cindex @{@var{type}@}
7021@cindex type casting memory
7022@cindex memory, viewing as typed object
7023@cindex casts, to view memory
7024@item @{@var{type}@} @var{addr}
7025Refers to an object of type @var{type} stored at address @var{addr} in
7026memory. @var{addr} may be any expression whose value is an integer or
7027pointer (but parentheses are required around binary operators, just as in
7028a cast). This construct is allowed regardless of what kind of data is
7029normally supposed to reside at @var{addr}.
7030@end table
7031
6ba66d6a
JB
7032@node Ambiguous Expressions
7033@section Ambiguous Expressions
7034@cindex ambiguous expressions
7035
7036Expressions can sometimes contain some ambiguous elements. For instance,
7037some programming languages (notably Ada, C@t{++} and Objective-C) permit
7038a single function name to be defined several times, for application in
7039different contexts. This is called @dfn{overloading}. Another example
7040involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
7041templates and is typically instantiated several times, resulting in
7042the same function name being defined in different contexts.
7043
7044In some cases and depending on the language, it is possible to adjust
7045the expression to remove the ambiguity. For instance in C@t{++}, you
7046can specify the signature of the function you want to break on, as in
7047@kbd{break @var{function}(@var{types})}. In Ada, using the fully
7048qualified name of your function often makes the expression unambiguous
7049as well.
7050
7051When an ambiguity that needs to be resolved is detected, the debugger
7052has the capability to display a menu of numbered choices for each
7053possibility, and then waits for the selection with the prompt @samp{>}.
7054The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
7055aborts the current command. If the command in which the expression was
7056used allows more than one choice to be selected, the next option in the
7057menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
7058choices.
7059
7060For example, the following session excerpt shows an attempt to set a
7061breakpoint at the overloaded symbol @code{String::after}.
7062We choose three particular definitions of that function name:
7063
7064@c FIXME! This is likely to change to show arg type lists, at least
7065@smallexample
7066@group
7067(@value{GDBP}) b String::after
7068[0] cancel
7069[1] all
7070[2] file:String.cc; line number:867
7071[3] file:String.cc; line number:860
7072[4] file:String.cc; line number:875
7073[5] file:String.cc; line number:853
7074[6] file:String.cc; line number:846
7075[7] file:String.cc; line number:735
7076> 2 4 6
7077Breakpoint 1 at 0xb26c: file String.cc, line 867.
7078Breakpoint 2 at 0xb344: file String.cc, line 875.
7079Breakpoint 3 at 0xafcc: file String.cc, line 846.
7080Multiple breakpoints were set.
7081Use the "delete" command to delete unwanted
7082 breakpoints.
7083(@value{GDBP})
7084@end group
7085@end smallexample
7086
7087@table @code
7088@kindex set multiple-symbols
7089@item set multiple-symbols @var{mode}
7090@cindex multiple-symbols menu
7091
7092This option allows you to adjust the debugger behavior when an expression
7093is ambiguous.
7094
7095By default, @var{mode} is set to @code{all}. If the command with which
7096the expression is used allows more than one choice, then @value{GDBN}
7097automatically selects all possible choices. For instance, inserting
7098a breakpoint on a function using an ambiguous name results in a breakpoint
7099inserted on each possible match. However, if a unique choice must be made,
7100then @value{GDBN} uses the menu to help you disambiguate the expression.
7101For instance, printing the address of an overloaded function will result
7102in the use of the menu.
7103
7104When @var{mode} is set to @code{ask}, the debugger always uses the menu
7105when an ambiguity is detected.
7106
7107Finally, when @var{mode} is set to @code{cancel}, the debugger reports
7108an error due to the ambiguity and the command is aborted.
7109
7110@kindex show multiple-symbols
7111@item show multiple-symbols
7112Show the current value of the @code{multiple-symbols} setting.
7113@end table
7114
6d2ebf8b 7115@node Variables
79a6e687 7116@section Program Variables
c906108c
SS
7117
7118The most common kind of expression to use is the name of a variable
7119in your program.
7120
7121Variables in expressions are understood in the selected stack frame
79a6e687 7122(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
7123
7124@itemize @bullet
7125@item
7126global (or file-static)
7127@end itemize
7128
5d161b24 7129@noindent or
c906108c
SS
7130
7131@itemize @bullet
7132@item
7133visible according to the scope rules of the
7134programming language from the point of execution in that frame
5d161b24 7135@end itemize
c906108c
SS
7136
7137@noindent This means that in the function
7138
474c8240 7139@smallexample
c906108c
SS
7140foo (a)
7141 int a;
7142@{
7143 bar (a);
7144 @{
7145 int b = test ();
7146 bar (b);
7147 @}
7148@}
474c8240 7149@end smallexample
c906108c
SS
7150
7151@noindent
7152you can examine and use the variable @code{a} whenever your program is
7153executing within the function @code{foo}, but you can only use or
7154examine the variable @code{b} while your program is executing inside
7155the block where @code{b} is declared.
7156
7157@cindex variable name conflict
7158There is an exception: you can refer to a variable or function whose
7159scope is a single source file even if the current execution point is not
7160in this file. But it is possible to have more than one such variable or
7161function with the same name (in different source files). If that
7162happens, referring to that name has unpredictable effects. If you wish,
7163you can specify a static variable in a particular function or file,
15387254 7164using the colon-colon (@code{::}) notation:
c906108c 7165
d4f3574e 7166@cindex colon-colon, context for variables/functions
12c27660 7167@ifnotinfo
c906108c 7168@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 7169@cindex @code{::}, context for variables/functions
12c27660 7170@end ifnotinfo
474c8240 7171@smallexample
c906108c
SS
7172@var{file}::@var{variable}
7173@var{function}::@var{variable}
474c8240 7174@end smallexample
c906108c
SS
7175
7176@noindent
7177Here @var{file} or @var{function} is the name of the context for the
7178static @var{variable}. In the case of file names, you can use quotes to
7179make sure @value{GDBN} parses the file name as a single word---for example,
7180to print a global value of @code{x} defined in @file{f2.c}:
7181
474c8240 7182@smallexample
c906108c 7183(@value{GDBP}) p 'f2.c'::x
474c8240 7184@end smallexample
c906108c 7185
b37052ae 7186@cindex C@t{++} scope resolution
c906108c 7187This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 7188use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
7189scope resolution operator in @value{GDBN} expressions.
7190@c FIXME: Um, so what happens in one of those rare cases where it's in
7191@c conflict?? --mew
c906108c
SS
7192
7193@cindex wrong values
7194@cindex variable values, wrong
15387254
EZ
7195@cindex function entry/exit, wrong values of variables
7196@cindex optimized code, wrong values of variables
c906108c
SS
7197@quotation
7198@emph{Warning:} Occasionally, a local variable may appear to have the
7199wrong value at certain points in a function---just after entry to a new
7200scope, and just before exit.
7201@end quotation
7202You may see this problem when you are stepping by machine instructions.
7203This is because, on most machines, it takes more than one instruction to
7204set up a stack frame (including local variable definitions); if you are
7205stepping by machine instructions, variables may appear to have the wrong
7206values until the stack frame is completely built. On exit, it usually
7207also takes more than one machine instruction to destroy a stack frame;
7208after you begin stepping through that group of instructions, local
7209variable definitions may be gone.
7210
7211This may also happen when the compiler does significant optimizations.
7212To be sure of always seeing accurate values, turn off all optimization
7213when compiling.
7214
d4f3574e
SS
7215@cindex ``No symbol "foo" in current context''
7216Another possible effect of compiler optimizations is to optimize
7217unused variables out of existence, or assign variables to registers (as
7218opposed to memory addresses). Depending on the support for such cases
7219offered by the debug info format used by the compiler, @value{GDBN}
7220might not be able to display values for such local variables. If that
7221happens, @value{GDBN} will print a message like this:
7222
474c8240 7223@smallexample
d4f3574e 7224No symbol "foo" in current context.
474c8240 7225@end smallexample
d4f3574e
SS
7226
7227To solve such problems, either recompile without optimizations, or use a
7228different debug info format, if the compiler supports several such
15387254 7229formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
7230usually supports the @option{-gstabs+} option. @option{-gstabs+}
7231produces debug info in a format that is superior to formats such as
7232COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
7233an effective form for debug info. @xref{Debugging Options,,Options
ce9341a1
BW
7234for Debugging Your Program or GCC, gcc.info, Using the @sc{gnu}
7235Compiler Collection (GCC)}.
79a6e687 7236@xref{C, ,C and C@t{++}}, for more information about debug info formats
15387254 7237that are best suited to C@t{++} programs.
d4f3574e 7238
ab1adacd
EZ
7239If you ask to print an object whose contents are unknown to
7240@value{GDBN}, e.g., because its data type is not completely specified
7241by the debug information, @value{GDBN} will say @samp{<incomplete
7242type>}. @xref{Symbols, incomplete type}, for more about this.
7243
3a60f64e
JK
7244Strings are identified as arrays of @code{char} values without specified
7245signedness. Arrays of either @code{signed char} or @code{unsigned char} get
7246printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
7247@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
7248defines literal string type @code{"char"} as @code{char} without a sign.
7249For program code
7250
7251@smallexample
7252char var0[] = "A";
7253signed char var1[] = "A";
7254@end smallexample
7255
7256You get during debugging
7257@smallexample
7258(gdb) print var0
7259$1 = "A"
7260(gdb) print var1
7261$2 = @{65 'A', 0 '\0'@}
7262@end smallexample
7263
6d2ebf8b 7264@node Arrays
79a6e687 7265@section Artificial Arrays
c906108c
SS
7266
7267@cindex artificial array
15387254 7268@cindex arrays
41afff9a 7269@kindex @@@r{, referencing memory as an array}
c906108c
SS
7270It is often useful to print out several successive objects of the
7271same type in memory; a section of an array, or an array of
7272dynamically determined size for which only a pointer exists in the
7273program.
7274
7275You can do this by referring to a contiguous span of memory as an
7276@dfn{artificial array}, using the binary operator @samp{@@}. The left
7277operand of @samp{@@} should be the first element of the desired array
7278and be an individual object. The right operand should be the desired length
7279of the array. The result is an array value whose elements are all of
7280the type of the left argument. The first element is actually the left
7281argument; the second element comes from bytes of memory immediately
7282following those that hold the first element, and so on. Here is an
7283example. If a program says
7284
474c8240 7285@smallexample
c906108c 7286int *array = (int *) malloc (len * sizeof (int));
474c8240 7287@end smallexample
c906108c
SS
7288
7289@noindent
7290you can print the contents of @code{array} with
7291
474c8240 7292@smallexample
c906108c 7293p *array@@len
474c8240 7294@end smallexample
c906108c
SS
7295
7296The left operand of @samp{@@} must reside in memory. Array values made
7297with @samp{@@} in this way behave just like other arrays in terms of
7298subscripting, and are coerced to pointers when used in expressions.
7299Artificial arrays most often appear in expressions via the value history
79a6e687 7300(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
7301
7302Another way to create an artificial array is to use a cast.
7303This re-interprets a value as if it were an array.
7304The value need not be in memory:
474c8240 7305@smallexample
c906108c
SS
7306(@value{GDBP}) p/x (short[2])0x12345678
7307$1 = @{0x1234, 0x5678@}
474c8240 7308@end smallexample
c906108c
SS
7309
7310As a convenience, if you leave the array length out (as in
c3f6f71d 7311@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 7312the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 7313@smallexample
c906108c
SS
7314(@value{GDBP}) p/x (short[])0x12345678
7315$2 = @{0x1234, 0x5678@}
474c8240 7316@end smallexample
c906108c
SS
7317
7318Sometimes the artificial array mechanism is not quite enough; in
7319moderately complex data structures, the elements of interest may not
7320actually be adjacent---for example, if you are interested in the values
7321of pointers in an array. One useful work-around in this situation is
7322to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 7323Variables}) as a counter in an expression that prints the first
c906108c
SS
7324interesting value, and then repeat that expression via @key{RET}. For
7325instance, suppose you have an array @code{dtab} of pointers to
7326structures, and you are interested in the values of a field @code{fv}
7327in each structure. Here is an example of what you might type:
7328
474c8240 7329@smallexample
c906108c
SS
7330set $i = 0
7331p dtab[$i++]->fv
7332@key{RET}
7333@key{RET}
7334@dots{}
474c8240 7335@end smallexample
c906108c 7336
6d2ebf8b 7337@node Output Formats
79a6e687 7338@section Output Formats
c906108c
SS
7339
7340@cindex formatted output
7341@cindex output formats
7342By default, @value{GDBN} prints a value according to its data type. Sometimes
7343this is not what you want. For example, you might want to print a number
7344in hex, or a pointer in decimal. Or you might want to view data in memory
7345at a certain address as a character string or as an instruction. To do
7346these things, specify an @dfn{output format} when you print a value.
7347
7348The simplest use of output formats is to say how to print a value
7349already computed. This is done by starting the arguments of the
7350@code{print} command with a slash and a format letter. The format
7351letters supported are:
7352
7353@table @code
7354@item x
7355Regard the bits of the value as an integer, and print the integer in
7356hexadecimal.
7357
7358@item d
7359Print as integer in signed decimal.
7360
7361@item u
7362Print as integer in unsigned decimal.
7363
7364@item o
7365Print as integer in octal.
7366
7367@item t
7368Print as integer in binary. The letter @samp{t} stands for ``two''.
7369@footnote{@samp{b} cannot be used because these format letters are also
7370used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 7371see @ref{Memory,,Examining Memory}.}
c906108c
SS
7372
7373@item a
7374@cindex unknown address, locating
3d67e040 7375@cindex locate address
c906108c
SS
7376Print as an address, both absolute in hexadecimal and as an offset from
7377the nearest preceding symbol. You can use this format used to discover
7378where (in what function) an unknown address is located:
7379
474c8240 7380@smallexample
c906108c
SS
7381(@value{GDBP}) p/a 0x54320
7382$3 = 0x54320 <_initialize_vx+396>
474c8240 7383@end smallexample
c906108c 7384
3d67e040
EZ
7385@noindent
7386The command @code{info symbol 0x54320} yields similar results.
7387@xref{Symbols, info symbol}.
7388
c906108c 7389@item c
51274035
EZ
7390Regard as an integer and print it as a character constant. This
7391prints both the numerical value and its character representation. The
7392character representation is replaced with the octal escape @samp{\nnn}
7393for characters outside the 7-bit @sc{ascii} range.
c906108c 7394
ea37ba09
DJ
7395Without this format, @value{GDBN} displays @code{char},
7396@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
7397constants. Single-byte members of vectors are displayed as integer
7398data.
7399
c906108c
SS
7400@item f
7401Regard the bits of the value as a floating point number and print
7402using typical floating point syntax.
ea37ba09
DJ
7403
7404@item s
7405@cindex printing strings
7406@cindex printing byte arrays
7407Regard as a string, if possible. With this format, pointers to single-byte
7408data are displayed as null-terminated strings and arrays of single-byte data
7409are displayed as fixed-length strings. Other values are displayed in their
7410natural types.
7411
7412Without this format, @value{GDBN} displays pointers to and arrays of
7413@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
7414strings. Single-byte members of a vector are displayed as an integer
7415array.
a6bac58e
TT
7416
7417@item r
7418@cindex raw printing
7419Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
7420use a Python-based pretty-printer, if one is available (@pxref{Pretty
7421Printing}). This typically results in a higher-level display of the
7422value's contents. The @samp{r} format bypasses any Python
7423pretty-printer which might exist.
c906108c
SS
7424@end table
7425
7426For example, to print the program counter in hex (@pxref{Registers}), type
7427
474c8240 7428@smallexample
c906108c 7429p/x $pc
474c8240 7430@end smallexample
c906108c
SS
7431
7432@noindent
7433Note that no space is required before the slash; this is because command
7434names in @value{GDBN} cannot contain a slash.
7435
7436To reprint the last value in the value history with a different format,
7437you can use the @code{print} command with just a format and no
7438expression. For example, @samp{p/x} reprints the last value in hex.
7439
6d2ebf8b 7440@node Memory
79a6e687 7441@section Examining Memory
c906108c
SS
7442
7443You can use the command @code{x} (for ``examine'') to examine memory in
7444any of several formats, independently of your program's data types.
7445
7446@cindex examining memory
7447@table @code
41afff9a 7448@kindex x @r{(examine memory)}
c906108c
SS
7449@item x/@var{nfu} @var{addr}
7450@itemx x @var{addr}
7451@itemx x
7452Use the @code{x} command to examine memory.
7453@end table
7454
7455@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
7456much memory to display and how to format it; @var{addr} is an
7457expression giving the address where you want to start displaying memory.
7458If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
7459Several commands set convenient defaults for @var{addr}.
7460
7461@table @r
7462@item @var{n}, the repeat count
7463The repeat count is a decimal integer; the default is 1. It specifies
7464how much memory (counting by units @var{u}) to display.
7465@c This really is **decimal**; unaffected by 'set radix' as of GDB
7466@c 4.1.2.
7467
7468@item @var{f}, the display format
51274035
EZ
7469The display format is one of the formats used by @code{print}
7470(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
7471@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
7472The default is @samp{x} (hexadecimal) initially. The default changes
7473each time you use either @code{x} or @code{print}.
c906108c
SS
7474
7475@item @var{u}, the unit size
7476The unit size is any of
7477
7478@table @code
7479@item b
7480Bytes.
7481@item h
7482Halfwords (two bytes).
7483@item w
7484Words (four bytes). This is the initial default.
7485@item g
7486Giant words (eight bytes).
7487@end table
7488
7489Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
7490default unit the next time you use @code{x}. For the @samp{i} format,
7491the unit size is ignored and is normally not written. For the @samp{s} format,
7492the unit size defaults to @samp{b}, unless it is explicitly given.
7493Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
749432-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
7495Note that the results depend on the programming language of the
7496current compilation unit. If the language is C, the @samp{s}
7497modifier will use the UTF-16 encoding while @samp{w} will use
7498UTF-32. The encoding is set by the programming language and cannot
7499be altered.
c906108c
SS
7500
7501@item @var{addr}, starting display address
7502@var{addr} is the address where you want @value{GDBN} to begin displaying
7503memory. The expression need not have a pointer value (though it may);
7504it is always interpreted as an integer address of a byte of memory.
7505@xref{Expressions, ,Expressions}, for more information on expressions. The default for
7506@var{addr} is usually just after the last address examined---but several
7507other commands also set the default address: @code{info breakpoints} (to
7508the address of the last breakpoint listed), @code{info line} (to the
7509starting address of a line), and @code{print} (if you use it to display
7510a value from memory).
7511@end table
7512
7513For example, @samp{x/3uh 0x54320} is a request to display three halfwords
7514(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
7515starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
7516words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 7517@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
7518
7519Since the letters indicating unit sizes are all distinct from the
7520letters specifying output formats, you do not have to remember whether
7521unit size or format comes first; either order works. The output
7522specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
7523(However, the count @var{n} must come first; @samp{wx4} does not work.)
7524
7525Even though the unit size @var{u} is ignored for the formats @samp{s}
7526and @samp{i}, you might still want to use a count @var{n}; for example,
7527@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
7528including any operands. For convenience, especially when used with
7529the @code{display} command, the @samp{i} format also prints branch delay
7530slot instructions, if any, beyond the count specified, which immediately
7531follow the last instruction that is within the count. The command
7532@code{disassemble} gives an alternative way of inspecting machine
7533instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
7534
7535All the defaults for the arguments to @code{x} are designed to make it
7536easy to continue scanning memory with minimal specifications each time
7537you use @code{x}. For example, after you have inspected three machine
7538instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
7539with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
7540the repeat count @var{n} is used again; the other arguments default as
7541for successive uses of @code{x}.
7542
2b28d209
PP
7543When examining machine instructions, the instruction at current program
7544counter is shown with a @code{=>} marker. For example:
7545
7546@smallexample
7547(@value{GDBP}) x/5i $pc-6
7548 0x804837f <main+11>: mov %esp,%ebp
7549 0x8048381 <main+13>: push %ecx
7550 0x8048382 <main+14>: sub $0x4,%esp
7551=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
7552 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
7553@end smallexample
7554
c906108c
SS
7555@cindex @code{$_}, @code{$__}, and value history
7556The addresses and contents printed by the @code{x} command are not saved
7557in the value history because there is often too much of them and they
7558would get in the way. Instead, @value{GDBN} makes these values available for
7559subsequent use in expressions as values of the convenience variables
7560@code{$_} and @code{$__}. After an @code{x} command, the last address
7561examined is available for use in expressions in the convenience variable
7562@code{$_}. The contents of that address, as examined, are available in
7563the convenience variable @code{$__}.
7564
7565If the @code{x} command has a repeat count, the address and contents saved
7566are from the last memory unit printed; this is not the same as the last
7567address printed if several units were printed on the last line of output.
7568
09d4efe1
EZ
7569@cindex remote memory comparison
7570@cindex verify remote memory image
7571When you are debugging a program running on a remote target machine
ea35711c 7572(@pxref{Remote Debugging}), you may wish to verify the program's image in the
09d4efe1
EZ
7573remote machine's memory against the executable file you downloaded to
7574the target. The @code{compare-sections} command is provided for such
7575situations.
7576
7577@table @code
7578@kindex compare-sections
7579@item compare-sections @r{[}@var{section-name}@r{]}
7580Compare the data of a loadable section @var{section-name} in the
7581executable file of the program being debugged with the same section in
7582the remote machine's memory, and report any mismatches. With no
7583arguments, compares all loadable sections. This command's
7584availability depends on the target's support for the @code{"qCRC"}
7585remote request.
7586@end table
7587
6d2ebf8b 7588@node Auto Display
79a6e687 7589@section Automatic Display
c906108c
SS
7590@cindex automatic display
7591@cindex display of expressions
7592
7593If you find that you want to print the value of an expression frequently
7594(to see how it changes), you might want to add it to the @dfn{automatic
7595display list} so that @value{GDBN} prints its value each time your program stops.
7596Each expression added to the list is given a number to identify it;
7597to remove an expression from the list, you specify that number.
7598The automatic display looks like this:
7599
474c8240 7600@smallexample
c906108c
SS
76012: foo = 38
76023: bar[5] = (struct hack *) 0x3804
474c8240 7603@end smallexample
c906108c
SS
7604
7605@noindent
7606This display shows item numbers, expressions and their current values. As with
7607displays you request manually using @code{x} or @code{print}, you can
7608specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
7609whether to use @code{print} or @code{x} depending your format
7610specification---it uses @code{x} if you specify either the @samp{i}
7611or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
7612
7613@table @code
7614@kindex display
d4f3574e
SS
7615@item display @var{expr}
7616Add the expression @var{expr} to the list of expressions to display
c906108c
SS
7617each time your program stops. @xref{Expressions, ,Expressions}.
7618
7619@code{display} does not repeat if you press @key{RET} again after using it.
7620
d4f3574e 7621@item display/@var{fmt} @var{expr}
c906108c 7622For @var{fmt} specifying only a display format and not a size or
d4f3574e 7623count, add the expression @var{expr} to the auto-display list but
c906108c 7624arrange to display it each time in the specified format @var{fmt}.
79a6e687 7625@xref{Output Formats,,Output Formats}.
c906108c
SS
7626
7627@item display/@var{fmt} @var{addr}
7628For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
7629number of units, add the expression @var{addr} as a memory address to
7630be examined each time your program stops. Examining means in effect
79a6e687 7631doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
7632@end table
7633
7634For example, @samp{display/i $pc} can be helpful, to see the machine
7635instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 7636is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
7637
7638@table @code
7639@kindex delete display
7640@kindex undisplay
7641@item undisplay @var{dnums}@dots{}
7642@itemx delete display @var{dnums}@dots{}
7643Remove item numbers @var{dnums} from the list of expressions to display.
7644
7645@code{undisplay} does not repeat if you press @key{RET} after using it.
7646(Otherwise you would just get the error @samp{No display number @dots{}}.)
7647
7648@kindex disable display
7649@item disable display @var{dnums}@dots{}
7650Disable the display of item numbers @var{dnums}. A disabled display
7651item is not printed automatically, but is not forgotten. It may be
7652enabled again later.
7653
7654@kindex enable display
7655@item enable display @var{dnums}@dots{}
7656Enable display of item numbers @var{dnums}. It becomes effective once
7657again in auto display of its expression, until you specify otherwise.
7658
7659@item display
7660Display the current values of the expressions on the list, just as is
7661done when your program stops.
7662
7663@kindex info display
7664@item info display
7665Print the list of expressions previously set up to display
7666automatically, each one with its item number, but without showing the
7667values. This includes disabled expressions, which are marked as such.
7668It also includes expressions which would not be displayed right now
7669because they refer to automatic variables not currently available.
7670@end table
7671
15387254 7672@cindex display disabled out of scope
c906108c
SS
7673If a display expression refers to local variables, then it does not make
7674sense outside the lexical context for which it was set up. Such an
7675expression is disabled when execution enters a context where one of its
7676variables is not defined. For example, if you give the command
7677@code{display last_char} while inside a function with an argument
7678@code{last_char}, @value{GDBN} displays this argument while your program
7679continues to stop inside that function. When it stops elsewhere---where
7680there is no variable @code{last_char}---the display is disabled
7681automatically. The next time your program stops where @code{last_char}
7682is meaningful, you can enable the display expression once again.
7683
6d2ebf8b 7684@node Print Settings
79a6e687 7685@section Print Settings
c906108c
SS
7686
7687@cindex format options
7688@cindex print settings
7689@value{GDBN} provides the following ways to control how arrays, structures,
7690and symbols are printed.
7691
7692@noindent
7693These settings are useful for debugging programs in any language:
7694
7695@table @code
4644b6e3 7696@kindex set print
c906108c
SS
7697@item set print address
7698@itemx set print address on
4644b6e3 7699@cindex print/don't print memory addresses
c906108c
SS
7700@value{GDBN} prints memory addresses showing the location of stack
7701traces, structure values, pointer values, breakpoints, and so forth,
7702even when it also displays the contents of those addresses. The default
7703is @code{on}. For example, this is what a stack frame display looks like with
7704@code{set print address on}:
7705
7706@smallexample
7707@group
7708(@value{GDBP}) f
7709#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
7710 at input.c:530
7711530 if (lquote != def_lquote)
7712@end group
7713@end smallexample
7714
7715@item set print address off
7716Do not print addresses when displaying their contents. For example,
7717this is the same stack frame displayed with @code{set print address off}:
7718
7719@smallexample
7720@group
7721(@value{GDBP}) set print addr off
7722(@value{GDBP}) f
7723#0 set_quotes (lq="<<", rq=">>") at input.c:530
7724530 if (lquote != def_lquote)
7725@end group
7726@end smallexample
7727
7728You can use @samp{set print address off} to eliminate all machine
7729dependent displays from the @value{GDBN} interface. For example, with
7730@code{print address off}, you should get the same text for backtraces on
7731all machines---whether or not they involve pointer arguments.
7732
4644b6e3 7733@kindex show print
c906108c
SS
7734@item show print address
7735Show whether or not addresses are to be printed.
7736@end table
7737
7738When @value{GDBN} prints a symbolic address, it normally prints the
7739closest earlier symbol plus an offset. If that symbol does not uniquely
7740identify the address (for example, it is a name whose scope is a single
7741source file), you may need to clarify. One way to do this is with
7742@code{info line}, for example @samp{info line *0x4537}. Alternately,
7743you can set @value{GDBN} to print the source file and line number when
7744it prints a symbolic address:
7745
7746@table @code
c906108c 7747@item set print symbol-filename on
9c16f35a
EZ
7748@cindex source file and line of a symbol
7749@cindex symbol, source file and line
c906108c
SS
7750Tell @value{GDBN} to print the source file name and line number of a
7751symbol in the symbolic form of an address.
7752
7753@item set print symbol-filename off
7754Do not print source file name and line number of a symbol. This is the
7755default.
7756
c906108c
SS
7757@item show print symbol-filename
7758Show whether or not @value{GDBN} will print the source file name and
7759line number of a symbol in the symbolic form of an address.
7760@end table
7761
7762Another situation where it is helpful to show symbol filenames and line
7763numbers is when disassembling code; @value{GDBN} shows you the line
7764number and source file that corresponds to each instruction.
7765
7766Also, you may wish to see the symbolic form only if the address being
7767printed is reasonably close to the closest earlier symbol:
7768
7769@table @code
c906108c 7770@item set print max-symbolic-offset @var{max-offset}
4644b6e3 7771@cindex maximum value for offset of closest symbol
c906108c
SS
7772Tell @value{GDBN} to only display the symbolic form of an address if the
7773offset between the closest earlier symbol and the address is less than
5d161b24 7774@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
7775to always print the symbolic form of an address if any symbol precedes it.
7776
c906108c
SS
7777@item show print max-symbolic-offset
7778Ask how large the maximum offset is that @value{GDBN} prints in a
7779symbolic address.
7780@end table
7781
7782@cindex wild pointer, interpreting
7783@cindex pointer, finding referent
7784If you have a pointer and you are not sure where it points, try
7785@samp{set print symbol-filename on}. Then you can determine the name
7786and source file location of the variable where it points, using
7787@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
7788For example, here @value{GDBN} shows that a variable @code{ptt} points
7789at another variable @code{t}, defined in @file{hi2.c}:
7790
474c8240 7791@smallexample
c906108c
SS
7792(@value{GDBP}) set print symbol-filename on
7793(@value{GDBP}) p/a ptt
7794$4 = 0xe008 <t in hi2.c>
474c8240 7795@end smallexample
c906108c
SS
7796
7797@quotation
7798@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
7799does not show the symbol name and filename of the referent, even with
7800the appropriate @code{set print} options turned on.
7801@end quotation
7802
7803Other settings control how different kinds of objects are printed:
7804
7805@table @code
c906108c
SS
7806@item set print array
7807@itemx set print array on
4644b6e3 7808@cindex pretty print arrays
c906108c
SS
7809Pretty print arrays. This format is more convenient to read,
7810but uses more space. The default is off.
7811
7812@item set print array off
7813Return to compressed format for arrays.
7814
c906108c
SS
7815@item show print array
7816Show whether compressed or pretty format is selected for displaying
7817arrays.
7818
3c9c013a
JB
7819@cindex print array indexes
7820@item set print array-indexes
7821@itemx set print array-indexes on
7822Print the index of each element when displaying arrays. May be more
7823convenient to locate a given element in the array or quickly find the
7824index of a given element in that printed array. The default is off.
7825
7826@item set print array-indexes off
7827Stop printing element indexes when displaying arrays.
7828
7829@item show print array-indexes
7830Show whether the index of each element is printed when displaying
7831arrays.
7832
c906108c 7833@item set print elements @var{number-of-elements}
4644b6e3 7834@cindex number of array elements to print
9c16f35a 7835@cindex limit on number of printed array elements
c906108c
SS
7836Set a limit on how many elements of an array @value{GDBN} will print.
7837If @value{GDBN} is printing a large array, it stops printing after it has
7838printed the number of elements set by the @code{set print elements} command.
7839This limit also applies to the display of strings.
d4f3574e 7840When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
7841Setting @var{number-of-elements} to zero means that the printing is unlimited.
7842
c906108c
SS
7843@item show print elements
7844Display the number of elements of a large array that @value{GDBN} will print.
7845If the number is 0, then the printing is unlimited.
7846
b4740add 7847@item set print frame-arguments @var{value}
a0381d3a 7848@kindex set print frame-arguments
b4740add
JB
7849@cindex printing frame argument values
7850@cindex print all frame argument values
7851@cindex print frame argument values for scalars only
7852@cindex do not print frame argument values
7853This command allows to control how the values of arguments are printed
7854when the debugger prints a frame (@pxref{Frames}). The possible
7855values are:
7856
7857@table @code
7858@item all
4f5376b2 7859The values of all arguments are printed.
b4740add
JB
7860
7861@item scalars
7862Print the value of an argument only if it is a scalar. The value of more
7863complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
7864by @code{@dots{}}. This is the default. Here is an example where
7865only scalar arguments are shown:
b4740add
JB
7866
7867@smallexample
7868#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
7869 at frame-args.c:23
7870@end smallexample
7871
7872@item none
7873None of the argument values are printed. Instead, the value of each argument
7874is replaced by @code{@dots{}}. In this case, the example above now becomes:
7875
7876@smallexample
7877#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
7878 at frame-args.c:23
7879@end smallexample
7880@end table
7881
4f5376b2
JB
7882By default, only scalar arguments are printed. This command can be used
7883to configure the debugger to print the value of all arguments, regardless
7884of their type. However, it is often advantageous to not print the value
7885of more complex parameters. For instance, it reduces the amount of
7886information printed in each frame, making the backtrace more readable.
7887Also, it improves performance when displaying Ada frames, because
7888the computation of large arguments can sometimes be CPU-intensive,
7889especially in large applications. Setting @code{print frame-arguments}
7890to @code{scalars} (the default) or @code{none} avoids this computation,
7891thus speeding up the display of each Ada frame.
b4740add
JB
7892
7893@item show print frame-arguments
7894Show how the value of arguments should be displayed when printing a frame.
7895
9c16f35a
EZ
7896@item set print repeats
7897@cindex repeated array elements
7898Set the threshold for suppressing display of repeated array
d3e8051b 7899elements. When the number of consecutive identical elements of an
9c16f35a
EZ
7900array exceeds the threshold, @value{GDBN} prints the string
7901@code{"<repeats @var{n} times>"}, where @var{n} is the number of
7902identical repetitions, instead of displaying the identical elements
7903themselves. Setting the threshold to zero will cause all elements to
7904be individually printed. The default threshold is 10.
7905
7906@item show print repeats
7907Display the current threshold for printing repeated identical
7908elements.
7909
c906108c 7910@item set print null-stop
4644b6e3 7911@cindex @sc{null} elements in arrays
c906108c 7912Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 7913@sc{null} is encountered. This is useful when large arrays actually
c906108c 7914contain only short strings.
d4f3574e 7915The default is off.
c906108c 7916
9c16f35a
EZ
7917@item show print null-stop
7918Show whether @value{GDBN} stops printing an array on the first
7919@sc{null} character.
7920
c906108c 7921@item set print pretty on
9c16f35a
EZ
7922@cindex print structures in indented form
7923@cindex indentation in structure display
5d161b24 7924Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
7925per line, like this:
7926
7927@smallexample
7928@group
7929$1 = @{
7930 next = 0x0,
7931 flags = @{
7932 sweet = 1,
7933 sour = 1
7934 @},
7935 meat = 0x54 "Pork"
7936@}
7937@end group
7938@end smallexample
7939
7940@item set print pretty off
7941Cause @value{GDBN} to print structures in a compact format, like this:
7942
7943@smallexample
7944@group
7945$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
7946meat = 0x54 "Pork"@}
7947@end group
7948@end smallexample
7949
7950@noindent
7951This is the default format.
7952
c906108c
SS
7953@item show print pretty
7954Show which format @value{GDBN} is using to print structures.
7955
c906108c 7956@item set print sevenbit-strings on
4644b6e3
EZ
7957@cindex eight-bit characters in strings
7958@cindex octal escapes in strings
c906108c
SS
7959Print using only seven-bit characters; if this option is set,
7960@value{GDBN} displays any eight-bit characters (in strings or
7961character values) using the notation @code{\}@var{nnn}. This setting is
7962best if you are working in English (@sc{ascii}) and you use the
7963high-order bit of characters as a marker or ``meta'' bit.
7964
7965@item set print sevenbit-strings off
7966Print full eight-bit characters. This allows the use of more
7967international character sets, and is the default.
7968
c906108c
SS
7969@item show print sevenbit-strings
7970Show whether or not @value{GDBN} is printing only seven-bit characters.
7971
c906108c 7972@item set print union on
4644b6e3 7973@cindex unions in structures, printing
9c16f35a
EZ
7974Tell @value{GDBN} to print unions which are contained in structures
7975and other unions. This is the default setting.
c906108c
SS
7976
7977@item set print union off
9c16f35a
EZ
7978Tell @value{GDBN} not to print unions which are contained in
7979structures and other unions. @value{GDBN} will print @code{"@{...@}"}
7980instead.
c906108c 7981
c906108c
SS
7982@item show print union
7983Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 7984structures and other unions.
c906108c
SS
7985
7986For example, given the declarations
7987
7988@smallexample
7989typedef enum @{Tree, Bug@} Species;
7990typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 7991typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
7992 Bug_forms;
7993
7994struct thing @{
7995 Species it;
7996 union @{
7997 Tree_forms tree;
7998 Bug_forms bug;
7999 @} form;
8000@};
8001
8002struct thing foo = @{Tree, @{Acorn@}@};
8003@end smallexample
8004
8005@noindent
8006with @code{set print union on} in effect @samp{p foo} would print
8007
8008@smallexample
8009$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
8010@end smallexample
8011
8012@noindent
8013and with @code{set print union off} in effect it would print
8014
8015@smallexample
8016$1 = @{it = Tree, form = @{...@}@}
8017@end smallexample
9c16f35a
EZ
8018
8019@noindent
8020@code{set print union} affects programs written in C-like languages
8021and in Pascal.
c906108c
SS
8022@end table
8023
c906108c
SS
8024@need 1000
8025@noindent
b37052ae 8026These settings are of interest when debugging C@t{++} programs:
c906108c
SS
8027
8028@table @code
4644b6e3 8029@cindex demangling C@t{++} names
c906108c
SS
8030@item set print demangle
8031@itemx set print demangle on
b37052ae 8032Print C@t{++} names in their source form rather than in the encoded
c906108c 8033(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 8034linkage. The default is on.
c906108c 8035
c906108c 8036@item show print demangle
b37052ae 8037Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 8038
c906108c
SS
8039@item set print asm-demangle
8040@itemx set print asm-demangle on
b37052ae 8041Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
8042in assembler code printouts such as instruction disassemblies.
8043The default is off.
8044
c906108c 8045@item show print asm-demangle
b37052ae 8046Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
8047or demangled form.
8048
b37052ae
EZ
8049@cindex C@t{++} symbol decoding style
8050@cindex symbol decoding style, C@t{++}
a8f24a35 8051@kindex set demangle-style
c906108c
SS
8052@item set demangle-style @var{style}
8053Choose among several encoding schemes used by different compilers to
b37052ae 8054represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
8055
8056@table @code
8057@item auto
8058Allow @value{GDBN} to choose a decoding style by inspecting your program.
8059
8060@item gnu
b37052ae 8061Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 8062This is the default.
c906108c
SS
8063
8064@item hp
b37052ae 8065Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
8066
8067@item lucid
b37052ae 8068Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
8069
8070@item arm
b37052ae 8071Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
8072@strong{Warning:} this setting alone is not sufficient to allow
8073debugging @code{cfront}-generated executables. @value{GDBN} would
8074require further enhancement to permit that.
8075
8076@end table
8077If you omit @var{style}, you will see a list of possible formats.
8078
c906108c 8079@item show demangle-style
b37052ae 8080Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 8081
c906108c
SS
8082@item set print object
8083@itemx set print object on
4644b6e3 8084@cindex derived type of an object, printing
9c16f35a 8085@cindex display derived types
c906108c
SS
8086When displaying a pointer to an object, identify the @emph{actual}
8087(derived) type of the object rather than the @emph{declared} type, using
8088the virtual function table.
8089
8090@item set print object off
8091Display only the declared type of objects, without reference to the
8092virtual function table. This is the default setting.
8093
c906108c
SS
8094@item show print object
8095Show whether actual, or declared, object types are displayed.
8096
c906108c
SS
8097@item set print static-members
8098@itemx set print static-members on
4644b6e3 8099@cindex static members of C@t{++} objects
b37052ae 8100Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
8101
8102@item set print static-members off
b37052ae 8103Do not print static members when displaying a C@t{++} object.
c906108c 8104
c906108c 8105@item show print static-members
9c16f35a
EZ
8106Show whether C@t{++} static members are printed or not.
8107
8108@item set print pascal_static-members
8109@itemx set print pascal_static-members on
d3e8051b
EZ
8110@cindex static members of Pascal objects
8111@cindex Pascal objects, static members display
9c16f35a
EZ
8112Print static members when displaying a Pascal object. The default is on.
8113
8114@item set print pascal_static-members off
8115Do not print static members when displaying a Pascal object.
8116
8117@item show print pascal_static-members
8118Show whether Pascal static members are printed or not.
c906108c
SS
8119
8120@c These don't work with HP ANSI C++ yet.
c906108c
SS
8121@item set print vtbl
8122@itemx set print vtbl on
4644b6e3 8123@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
8124@cindex virtual functions (C@t{++}) display
8125@cindex VTBL display
b37052ae 8126Pretty print C@t{++} virtual function tables. The default is off.
c906108c 8127(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8128ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8129
8130@item set print vtbl off
b37052ae 8131Do not pretty print C@t{++} virtual function tables.
c906108c 8132
c906108c 8133@item show print vtbl
b37052ae 8134Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 8135@end table
c906108c 8136
4c374409
JK
8137@node Pretty Printing
8138@section Pretty Printing
8139
8140@value{GDBN} provides a mechanism to allow pretty-printing of values using
8141Python code. It greatly simplifies the display of complex objects. This
8142mechanism works for both MI and the CLI.
8143
7b51bc51
DE
8144@menu
8145* Pretty-Printer Introduction:: Introduction to pretty-printers
8146* Pretty-Printer Example:: An example pretty-printer
8147* Pretty-Printer Commands:: Pretty-printer commands
8148@end menu
8149
8150@node Pretty-Printer Introduction
8151@subsection Pretty-Printer Introduction
8152
8153When @value{GDBN} prints a value, it first sees if there is a pretty-printer
8154registered for the value. If there is then @value{GDBN} invokes the
8155pretty-printer to print the value. Otherwise the value is printed normally.
8156
8157Pretty-printers are normally named. This makes them easy to manage.
8158The @samp{info pretty-printer} command will list all the installed
8159pretty-printers with their names.
8160If a pretty-printer can handle multiple data types, then its
8161@dfn{subprinters} are the printers for the individual data types.
8162Each such subprinter has its own name.
8163The format of the name is @var{printer-name}:@var{subprinter-name}.
8164
8165Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
8166Typically they are automatically loaded and registered when the corresponding
8167debug information is loaded, thus making them available without having to
8168do anything special.
8169
8170There are three places where a pretty-printer can be registered.
8171
8172@itemize @bullet
8173@item
8174Pretty-printers registered globally are available when debugging
8175all inferiors.
8176
8177@item
8178Pretty-printers registered with a program space are available only
8179when debugging that program.
8180@xref{Progspaces In Python}, for more details on program spaces in Python.
8181
8182@item
8183Pretty-printers registered with an objfile are loaded and unloaded
8184with the corresponding objfile (e.g., shared library).
8185@xref{Objfiles In Python}, for more details on objfiles in Python.
8186@end itemize
8187
8188@xref{Selecting Pretty-Printers}, for further information on how
8189pretty-printers are selected,
8190
8191@xref{Writing a Pretty-Printer}, for implementing pretty printers
8192for new types.
8193
8194@node Pretty-Printer Example
8195@subsection Pretty-Printer Example
8196
8197Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
8198
8199@smallexample
8200(@value{GDBP}) print s
8201$1 = @{
8202 static npos = 4294967295,
8203 _M_dataplus = @{
8204 <std::allocator<char>> = @{
8205 <__gnu_cxx::new_allocator<char>> = @{
8206 <No data fields>@}, <No data fields>
8207 @},
8208 members of std::basic_string<char, std::char_traits<char>,
8209 std::allocator<char> >::_Alloc_hider:
8210 _M_p = 0x804a014 "abcd"
8211 @}
8212@}
8213@end smallexample
8214
8215With a pretty-printer for @code{std::string} only the contents are printed:
8216
8217@smallexample
8218(@value{GDBP}) print s
8219$2 = "abcd"
8220@end smallexample
8221
7b51bc51
DE
8222@node Pretty-Printer Commands
8223@subsection Pretty-Printer Commands
8224@cindex pretty-printer commands
8225
8226@table @code
8227@kindex info pretty-printer
8228@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
8229Print the list of installed pretty-printers.
8230This includes disabled pretty-printers, which are marked as such.
8231
8232@var{object-regexp} is a regular expression matching the objects
8233whose pretty-printers to list.
8234Objects can be @code{global}, the program space's file
8235(@pxref{Progspaces In Python}),
8236and the object files within that program space (@pxref{Objfiles In Python}).
8237@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
8238looks up a printer from these three objects.
8239
8240@var{name-regexp} is a regular expression matching the name of the printers
8241to list.
8242
8243@kindex disable pretty-printer
8244@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
8245Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
8246A disabled pretty-printer is not forgotten, it may be enabled again later.
8247
8248@kindex enable pretty-printer
8249@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
8250Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
8251@end table
8252
8253Example:
8254
8255Suppose we have three pretty-printers installed: one from library1.so
8256named @code{foo} that prints objects of type @code{foo}, and
8257another from library2.so named @code{bar} that prints two types of objects,
8258@code{bar1} and @code{bar2}.
8259
8260@smallexample
8261(gdb) info pretty-printer
8262library1.so:
8263 foo
8264library2.so:
8265 bar
8266 bar1
8267 bar2
8268(gdb) info pretty-printer library2
8269library2.so:
8270 bar
8271 bar1
8272 bar2
8273(gdb) disable pretty-printer library1
82741 printer disabled
82752 of 3 printers enabled
8276(gdb) info pretty-printer
8277library1.so:
8278 foo [disabled]
8279library2.so:
8280 bar
8281 bar1
8282 bar2
8283(gdb) disable pretty-printer library2 bar:bar1
82841 printer disabled
82851 of 3 printers enabled
8286(gdb) info pretty-printer library2
8287library1.so:
8288 foo [disabled]
8289library2.so:
8290 bar
8291 bar1 [disabled]
8292 bar2
8293(gdb) disable pretty-printer library2 bar
82941 printer disabled
82950 of 3 printers enabled
8296(gdb) info pretty-printer library2
8297library1.so:
8298 foo [disabled]
8299library2.so:
8300 bar [disabled]
8301 bar1 [disabled]
8302 bar2
8303@end smallexample
8304
8305Note that for @code{bar} the entire printer can be disabled,
8306as can each individual subprinter.
4c374409 8307
6d2ebf8b 8308@node Value History
79a6e687 8309@section Value History
c906108c
SS
8310
8311@cindex value history
9c16f35a 8312@cindex history of values printed by @value{GDBN}
5d161b24
DB
8313Values printed by the @code{print} command are saved in the @value{GDBN}
8314@dfn{value history}. This allows you to refer to them in other expressions.
8315Values are kept until the symbol table is re-read or discarded
8316(for example with the @code{file} or @code{symbol-file} commands).
8317When the symbol table changes, the value history is discarded,
8318since the values may contain pointers back to the types defined in the
c906108c
SS
8319symbol table.
8320
8321@cindex @code{$}
8322@cindex @code{$$}
8323@cindex history number
8324The values printed are given @dfn{history numbers} by which you can
8325refer to them. These are successive integers starting with one.
8326@code{print} shows you the history number assigned to a value by
8327printing @samp{$@var{num} = } before the value; here @var{num} is the
8328history number.
8329
8330To refer to any previous value, use @samp{$} followed by the value's
8331history number. The way @code{print} labels its output is designed to
8332remind you of this. Just @code{$} refers to the most recent value in
8333the history, and @code{$$} refers to the value before that.
8334@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
8335is the value just prior to @code{$$}, @code{$$1} is equivalent to
8336@code{$$}, and @code{$$0} is equivalent to @code{$}.
8337
8338For example, suppose you have just printed a pointer to a structure and
8339want to see the contents of the structure. It suffices to type
8340
474c8240 8341@smallexample
c906108c 8342p *$
474c8240 8343@end smallexample
c906108c
SS
8344
8345If you have a chain of structures where the component @code{next} points
8346to the next one, you can print the contents of the next one with this:
8347
474c8240 8348@smallexample
c906108c 8349p *$.next
474c8240 8350@end smallexample
c906108c
SS
8351
8352@noindent
8353You can print successive links in the chain by repeating this
8354command---which you can do by just typing @key{RET}.
8355
8356Note that the history records values, not expressions. If the value of
8357@code{x} is 4 and you type these commands:
8358
474c8240 8359@smallexample
c906108c
SS
8360print x
8361set x=5
474c8240 8362@end smallexample
c906108c
SS
8363
8364@noindent
8365then the value recorded in the value history by the @code{print} command
8366remains 4 even though the value of @code{x} has changed.
8367
8368@table @code
8369@kindex show values
8370@item show values
8371Print the last ten values in the value history, with their item numbers.
8372This is like @samp{p@ $$9} repeated ten times, except that @code{show
8373values} does not change the history.
8374
8375@item show values @var{n}
8376Print ten history values centered on history item number @var{n}.
8377
8378@item show values +
8379Print ten history values just after the values last printed. If no more
8380values are available, @code{show values +} produces no display.
8381@end table
8382
8383Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
8384same effect as @samp{show values +}.
8385
6d2ebf8b 8386@node Convenience Vars
79a6e687 8387@section Convenience Variables
c906108c
SS
8388
8389@cindex convenience variables
9c16f35a 8390@cindex user-defined variables
c906108c
SS
8391@value{GDBN} provides @dfn{convenience variables} that you can use within
8392@value{GDBN} to hold on to a value and refer to it later. These variables
8393exist entirely within @value{GDBN}; they are not part of your program, and
8394setting a convenience variable has no direct effect on further execution
8395of your program. That is why you can use them freely.
8396
8397Convenience variables are prefixed with @samp{$}. Any name preceded by
8398@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 8399the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 8400(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 8401by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
8402
8403You can save a value in a convenience variable with an assignment
8404expression, just as you would set a variable in your program.
8405For example:
8406
474c8240 8407@smallexample
c906108c 8408set $foo = *object_ptr
474c8240 8409@end smallexample
c906108c
SS
8410
8411@noindent
8412would save in @code{$foo} the value contained in the object pointed to by
8413@code{object_ptr}.
8414
8415Using a convenience variable for the first time creates it, but its
8416value is @code{void} until you assign a new value. You can alter the
8417value with another assignment at any time.
8418
8419Convenience variables have no fixed types. You can assign a convenience
8420variable any type of value, including structures and arrays, even if
8421that variable already has a value of a different type. The convenience
8422variable, when used as an expression, has the type of its current value.
8423
8424@table @code
8425@kindex show convenience
9c16f35a 8426@cindex show all user variables
c906108c
SS
8427@item show convenience
8428Print a list of convenience variables used so far, and their values.
d4f3574e 8429Abbreviated @code{show conv}.
53e5f3cf
AS
8430
8431@kindex init-if-undefined
8432@cindex convenience variables, initializing
8433@item init-if-undefined $@var{variable} = @var{expression}
8434Set a convenience variable if it has not already been set. This is useful
8435for user-defined commands that keep some state. It is similar, in concept,
8436to using local static variables with initializers in C (except that
8437convenience variables are global). It can also be used to allow users to
8438override default values used in a command script.
8439
8440If the variable is already defined then the expression is not evaluated so
8441any side-effects do not occur.
c906108c
SS
8442@end table
8443
8444One of the ways to use a convenience variable is as a counter to be
8445incremented or a pointer to be advanced. For example, to print
8446a field from successive elements of an array of structures:
8447
474c8240 8448@smallexample
c906108c
SS
8449set $i = 0
8450print bar[$i++]->contents
474c8240 8451@end smallexample
c906108c 8452
d4f3574e
SS
8453@noindent
8454Repeat that command by typing @key{RET}.
c906108c
SS
8455
8456Some convenience variables are created automatically by @value{GDBN} and given
8457values likely to be useful.
8458
8459@table @code
41afff9a 8460@vindex $_@r{, convenience variable}
c906108c
SS
8461@item $_
8462The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 8463the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
8464commands which provide a default address for @code{x} to examine also
8465set @code{$_} to that address; these commands include @code{info line}
8466and @code{info breakpoint}. The type of @code{$_} is @code{void *}
8467except when set by the @code{x} command, in which case it is a pointer
8468to the type of @code{$__}.
8469
41afff9a 8470@vindex $__@r{, convenience variable}
c906108c
SS
8471@item $__
8472The variable @code{$__} is automatically set by the @code{x} command
8473to the value found in the last address examined. Its type is chosen
8474to match the format in which the data was printed.
8475
8476@item $_exitcode
41afff9a 8477@vindex $_exitcode@r{, convenience variable}
c906108c
SS
8478The variable @code{$_exitcode} is automatically set to the exit code when
8479the program being debugged terminates.
4aa995e1 8480
0fb4aa4b
PA
8481@item $_sdata
8482@vindex $_sdata@r{, inspect, convenience variable}
8483The variable @code{$_sdata} contains extra collected static tracepoint
8484data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
8485@code{$_sdata} could be empty, if not inspecting a trace buffer, or
8486if extra static tracepoint data has not been collected.
8487
4aa995e1
PA
8488@item $_siginfo
8489@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
8490The variable @code{$_siginfo} contains extra signal information
8491(@pxref{extra signal information}). Note that @code{$_siginfo}
8492could be empty, if the application has not yet received any signals.
8493For example, it will be empty before you execute the @code{run} command.
711e434b
PM
8494
8495@item $_tlb
8496@vindex $_tlb@r{, convenience variable}
8497The variable @code{$_tlb} is automatically set when debugging
8498applications running on MS-Windows in native mode or connected to
8499gdbserver that supports the @code{qGetTIBAddr} request.
8500@xref{General Query Packets}.
8501This variable contains the address of the thread information block.
8502
c906108c
SS
8503@end table
8504
53a5351d
JM
8505On HP-UX systems, if you refer to a function or variable name that
8506begins with a dollar sign, @value{GDBN} searches for a user or system
8507name first, before it searches for a convenience variable.
c906108c 8508
bc3b79fd
TJB
8509@cindex convenience functions
8510@value{GDBN} also supplies some @dfn{convenience functions}. These
8511have a syntax similar to convenience variables. A convenience
8512function can be used in an expression just like an ordinary function;
8513however, a convenience function is implemented internally to
8514@value{GDBN}.
8515
8516@table @code
8517@item help function
8518@kindex help function
8519@cindex show all convenience functions
8520Print a list of all convenience functions.
8521@end table
8522
6d2ebf8b 8523@node Registers
c906108c
SS
8524@section Registers
8525
8526@cindex registers
8527You can refer to machine register contents, in expressions, as variables
8528with names starting with @samp{$}. The names of registers are different
8529for each machine; use @code{info registers} to see the names used on
8530your machine.
8531
8532@table @code
8533@kindex info registers
8534@item info registers
8535Print the names and values of all registers except floating-point
c85508ee 8536and vector registers (in the selected stack frame).
c906108c
SS
8537
8538@kindex info all-registers
8539@cindex floating point registers
8540@item info all-registers
8541Print the names and values of all registers, including floating-point
c85508ee 8542and vector registers (in the selected stack frame).
c906108c
SS
8543
8544@item info registers @var{regname} @dots{}
8545Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
8546As discussed in detail below, register values are normally relative to
8547the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
8548the machine you are using, with or without the initial @samp{$}.
8549@end table
8550
e09f16f9
EZ
8551@cindex stack pointer register
8552@cindex program counter register
8553@cindex process status register
8554@cindex frame pointer register
8555@cindex standard registers
c906108c
SS
8556@value{GDBN} has four ``standard'' register names that are available (in
8557expressions) on most machines---whenever they do not conflict with an
8558architecture's canonical mnemonics for registers. The register names
8559@code{$pc} and @code{$sp} are used for the program counter register and
8560the stack pointer. @code{$fp} is used for a register that contains a
8561pointer to the current stack frame, and @code{$ps} is used for a
8562register that contains the processor status. For example,
8563you could print the program counter in hex with
8564
474c8240 8565@smallexample
c906108c 8566p/x $pc
474c8240 8567@end smallexample
c906108c
SS
8568
8569@noindent
8570or print the instruction to be executed next with
8571
474c8240 8572@smallexample
c906108c 8573x/i $pc
474c8240 8574@end smallexample
c906108c
SS
8575
8576@noindent
8577or add four to the stack pointer@footnote{This is a way of removing
8578one word from the stack, on machines where stacks grow downward in
8579memory (most machines, nowadays). This assumes that the innermost
8580stack frame is selected; setting @code{$sp} is not allowed when other
8581stack frames are selected. To pop entire frames off the stack,
8582regardless of machine architecture, use @code{return};
79a6e687 8583see @ref{Returning, ,Returning from a Function}.} with
c906108c 8584
474c8240 8585@smallexample
c906108c 8586set $sp += 4
474c8240 8587@end smallexample
c906108c
SS
8588
8589Whenever possible, these four standard register names are available on
8590your machine even though the machine has different canonical mnemonics,
8591so long as there is no conflict. The @code{info registers} command
8592shows the canonical names. For example, on the SPARC, @code{info
8593registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
8594can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
8595is an alias for the @sc{eflags} register.
c906108c
SS
8596
8597@value{GDBN} always considers the contents of an ordinary register as an
8598integer when the register is examined in this way. Some machines have
8599special registers which can hold nothing but floating point; these
8600registers are considered to have floating point values. There is no way
8601to refer to the contents of an ordinary register as floating point value
8602(although you can @emph{print} it as a floating point value with
8603@samp{print/f $@var{regname}}).
8604
8605Some registers have distinct ``raw'' and ``virtual'' data formats. This
8606means that the data format in which the register contents are saved by
8607the operating system is not the same one that your program normally
8608sees. For example, the registers of the 68881 floating point
8609coprocessor are always saved in ``extended'' (raw) format, but all C
8610programs expect to work with ``double'' (virtual) format. In such
5d161b24 8611cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
8612that makes sense for your program), but the @code{info registers} command
8613prints the data in both formats.
8614
36b80e65
EZ
8615@cindex SSE registers (x86)
8616@cindex MMX registers (x86)
8617Some machines have special registers whose contents can be interpreted
8618in several different ways. For example, modern x86-based machines
8619have SSE and MMX registers that can hold several values packed
8620together in several different formats. @value{GDBN} refers to such
8621registers in @code{struct} notation:
8622
8623@smallexample
8624(@value{GDBP}) print $xmm1
8625$1 = @{
8626 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
8627 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
8628 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
8629 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
8630 v4_int32 = @{0, 20657912, 11, 13@},
8631 v2_int64 = @{88725056443645952, 55834574859@},
8632 uint128 = 0x0000000d0000000b013b36f800000000
8633@}
8634@end smallexample
8635
8636@noindent
8637To set values of such registers, you need to tell @value{GDBN} which
8638view of the register you wish to change, as if you were assigning
8639value to a @code{struct} member:
8640
8641@smallexample
8642 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
8643@end smallexample
8644
c906108c 8645Normally, register values are relative to the selected stack frame
79a6e687 8646(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
8647value that the register would contain if all stack frames farther in
8648were exited and their saved registers restored. In order to see the
8649true contents of hardware registers, you must select the innermost
8650frame (with @samp{frame 0}).
8651
8652However, @value{GDBN} must deduce where registers are saved, from the machine
8653code generated by your compiler. If some registers are not saved, or if
8654@value{GDBN} is unable to locate the saved registers, the selected stack
8655frame makes no difference.
8656
6d2ebf8b 8657@node Floating Point Hardware
79a6e687 8658@section Floating Point Hardware
c906108c
SS
8659@cindex floating point
8660
8661Depending on the configuration, @value{GDBN} may be able to give
8662you more information about the status of the floating point hardware.
8663
8664@table @code
8665@kindex info float
8666@item info float
8667Display hardware-dependent information about the floating
8668point unit. The exact contents and layout vary depending on the
8669floating point chip. Currently, @samp{info float} is supported on
8670the ARM and x86 machines.
8671@end table
c906108c 8672
e76f1f2e
AC
8673@node Vector Unit
8674@section Vector Unit
8675@cindex vector unit
8676
8677Depending on the configuration, @value{GDBN} may be able to give you
8678more information about the status of the vector unit.
8679
8680@table @code
8681@kindex info vector
8682@item info vector
8683Display information about the vector unit. The exact contents and
8684layout vary depending on the hardware.
8685@end table
8686
721c2651 8687@node OS Information
79a6e687 8688@section Operating System Auxiliary Information
721c2651
EZ
8689@cindex OS information
8690
8691@value{GDBN} provides interfaces to useful OS facilities that can help
8692you debug your program.
8693
8694@cindex @code{ptrace} system call
8695@cindex @code{struct user} contents
8696When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
8697machines), it interfaces with the inferior via the @code{ptrace}
8698system call. The operating system creates a special sata structure,
8699called @code{struct user}, for this interface. You can use the
8700command @code{info udot} to display the contents of this data
8701structure.
8702
8703@table @code
8704@item info udot
8705@kindex info udot
8706Display the contents of the @code{struct user} maintained by the OS
8707kernel for the program being debugged. @value{GDBN} displays the
8708contents of @code{struct user} as a list of hex numbers, similar to
8709the @code{examine} command.
8710@end table
8711
b383017d
RM
8712@cindex auxiliary vector
8713@cindex vector, auxiliary
b383017d
RM
8714Some operating systems supply an @dfn{auxiliary vector} to programs at
8715startup. This is akin to the arguments and environment that you
8716specify for a program, but contains a system-dependent variety of
8717binary values that tell system libraries important details about the
8718hardware, operating system, and process. Each value's purpose is
8719identified by an integer tag; the meanings are well-known but system-specific.
8720Depending on the configuration and operating system facilities,
9c16f35a
EZ
8721@value{GDBN} may be able to show you this information. For remote
8722targets, this functionality may further depend on the remote stub's
427c3a89
DJ
8723support of the @samp{qXfer:auxv:read} packet, see
8724@ref{qXfer auxiliary vector read}.
b383017d
RM
8725
8726@table @code
8727@kindex info auxv
8728@item info auxv
8729Display the auxiliary vector of the inferior, which can be either a
e4937fc1 8730live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
8731numerically, and also shows names and text descriptions for recognized
8732tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 8733pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
8734most appropriate form for a recognized tag, and in hexadecimal for
8735an unrecognized tag.
8736@end table
8737
07e059b5
VP
8738On some targets, @value{GDBN} can access operating-system-specific information
8739and display it to user, without interpretation. For remote targets,
8740this functionality depends on the remote stub's support of the
8741@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
8742
8743@table @code
a61408f8
SS
8744@kindex info os
8745@item info os
8746List the types of OS information available for the target. If the
8747target does not return a list of possible types, this command will
8748report an error.
8749
07e059b5
VP
8750@kindex info os processes
8751@item info os processes
8752Display the list of processes on the target. For each process,
8753@value{GDBN} prints the process identifier, the name of the user, and
8754the command corresponding to the process.
8755@end table
721c2651 8756
29e57380 8757@node Memory Region Attributes
79a6e687 8758@section Memory Region Attributes
29e57380
C
8759@cindex memory region attributes
8760
b383017d 8761@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
8762required by regions of your target's memory. @value{GDBN} uses
8763attributes to determine whether to allow certain types of memory
8764accesses; whether to use specific width accesses; and whether to cache
8765target memory. By default the description of memory regions is
8766fetched from the target (if the current target supports this), but the
8767user can override the fetched regions.
29e57380
C
8768
8769Defined memory regions can be individually enabled and disabled. When a
8770memory region is disabled, @value{GDBN} uses the default attributes when
8771accessing memory in that region. Similarly, if no memory regions have
8772been defined, @value{GDBN} uses the default attributes when accessing
8773all memory.
8774
b383017d 8775When a memory region is defined, it is given a number to identify it;
29e57380
C
8776to enable, disable, or remove a memory region, you specify that number.
8777
8778@table @code
8779@kindex mem
bfac230e 8780@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
8781Define a memory region bounded by @var{lower} and @var{upper} with
8782attributes @var{attributes}@dots{}, and add it to the list of regions
8783monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 8784case: it is treated as the target's maximum memory address.
bfac230e 8785(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 8786
fd79ecee
DJ
8787@item mem auto
8788Discard any user changes to the memory regions and use target-supplied
8789regions, if available, or no regions if the target does not support.
8790
29e57380
C
8791@kindex delete mem
8792@item delete mem @var{nums}@dots{}
09d4efe1
EZ
8793Remove memory regions @var{nums}@dots{} from the list of regions
8794monitored by @value{GDBN}.
29e57380
C
8795
8796@kindex disable mem
8797@item disable mem @var{nums}@dots{}
09d4efe1 8798Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 8799A disabled memory region is not forgotten.
29e57380
C
8800It may be enabled again later.
8801
8802@kindex enable mem
8803@item enable mem @var{nums}@dots{}
09d4efe1 8804Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
8805
8806@kindex info mem
8807@item info mem
8808Print a table of all defined memory regions, with the following columns
09d4efe1 8809for each region:
29e57380
C
8810
8811@table @emph
8812@item Memory Region Number
8813@item Enabled or Disabled.
b383017d 8814Enabled memory regions are marked with @samp{y}.
29e57380
C
8815Disabled memory regions are marked with @samp{n}.
8816
8817@item Lo Address
8818The address defining the inclusive lower bound of the memory region.
8819
8820@item Hi Address
8821The address defining the exclusive upper bound of the memory region.
8822
8823@item Attributes
8824The list of attributes set for this memory region.
8825@end table
8826@end table
8827
8828
8829@subsection Attributes
8830
b383017d 8831@subsubsection Memory Access Mode
29e57380
C
8832The access mode attributes set whether @value{GDBN} may make read or
8833write accesses to a memory region.
8834
8835While these attributes prevent @value{GDBN} from performing invalid
8836memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 8837etc.@: from accessing memory.
29e57380
C
8838
8839@table @code
8840@item ro
8841Memory is read only.
8842@item wo
8843Memory is write only.
8844@item rw
6ca652b0 8845Memory is read/write. This is the default.
29e57380
C
8846@end table
8847
8848@subsubsection Memory Access Size
d3e8051b 8849The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
8850accesses in the memory region. Often memory mapped device registers
8851require specific sized accesses. If no access size attribute is
8852specified, @value{GDBN} may use accesses of any size.
8853
8854@table @code
8855@item 8
8856Use 8 bit memory accesses.
8857@item 16
8858Use 16 bit memory accesses.
8859@item 32
8860Use 32 bit memory accesses.
8861@item 64
8862Use 64 bit memory accesses.
8863@end table
8864
8865@c @subsubsection Hardware/Software Breakpoints
8866@c The hardware/software breakpoint attributes set whether @value{GDBN}
8867@c will use hardware or software breakpoints for the internal breakpoints
8868@c used by the step, next, finish, until, etc. commands.
8869@c
8870@c @table @code
8871@c @item hwbreak
b383017d 8872@c Always use hardware breakpoints
29e57380
C
8873@c @item swbreak (default)
8874@c @end table
8875
8876@subsubsection Data Cache
8877The data cache attributes set whether @value{GDBN} will cache target
8878memory. While this generally improves performance by reducing debug
8879protocol overhead, it can lead to incorrect results because @value{GDBN}
8880does not know about volatile variables or memory mapped device
8881registers.
8882
8883@table @code
8884@item cache
b383017d 8885Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
8886@item nocache
8887Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
8888@end table
8889
4b5752d0
VP
8890@subsection Memory Access Checking
8891@value{GDBN} can be instructed to refuse accesses to memory that is
8892not explicitly described. This can be useful if accessing such
8893regions has undesired effects for a specific target, or to provide
8894better error checking. The following commands control this behaviour.
8895
8896@table @code
8897@kindex set mem inaccessible-by-default
8898@item set mem inaccessible-by-default [on|off]
8899If @code{on} is specified, make @value{GDBN} treat memory not
8900explicitly described by the memory ranges as non-existent and refuse accesses
8901to such memory. The checks are only performed if there's at least one
8902memory range defined. If @code{off} is specified, make @value{GDBN}
8903treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 8904The default value is @code{on}.
4b5752d0
VP
8905@kindex show mem inaccessible-by-default
8906@item show mem inaccessible-by-default
8907Show the current handling of accesses to unknown memory.
8908@end table
8909
8910
29e57380 8911@c @subsubsection Memory Write Verification
b383017d 8912@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
8913@c will re-reads data after each write to verify the write was successful.
8914@c
8915@c @table @code
8916@c @item verify
8917@c @item noverify (default)
8918@c @end table
8919
16d9dec6 8920@node Dump/Restore Files
79a6e687 8921@section Copy Between Memory and a File
16d9dec6
MS
8922@cindex dump/restore files
8923@cindex append data to a file
8924@cindex dump data to a file
8925@cindex restore data from a file
16d9dec6 8926
df5215a6
JB
8927You can use the commands @code{dump}, @code{append}, and
8928@code{restore} to copy data between target memory and a file. The
8929@code{dump} and @code{append} commands write data to a file, and the
8930@code{restore} command reads data from a file back into the inferior's
8931memory. Files may be in binary, Motorola S-record, Intel hex, or
8932Tektronix Hex format; however, @value{GDBN} can only append to binary
8933files.
8934
8935@table @code
8936
8937@kindex dump
8938@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
8939@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
8940Dump the contents of memory from @var{start_addr} to @var{end_addr},
8941or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 8942
df5215a6 8943The @var{format} parameter may be any one of:
16d9dec6 8944@table @code
df5215a6
JB
8945@item binary
8946Raw binary form.
8947@item ihex
8948Intel hex format.
8949@item srec
8950Motorola S-record format.
8951@item tekhex
8952Tektronix Hex format.
8953@end table
8954
8955@value{GDBN} uses the same definitions of these formats as the
8956@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
8957@var{format} is omitted, @value{GDBN} dumps the data in raw binary
8958form.
8959
8960@kindex append
8961@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
8962@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
8963Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 8964or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
8965(@value{GDBN} can only append data to files in raw binary form.)
8966
8967@kindex restore
8968@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
8969Restore the contents of file @var{filename} into memory. The
8970@code{restore} command can automatically recognize any known @sc{bfd}
8971file format, except for raw binary. To restore a raw binary file you
8972must specify the optional keyword @code{binary} after the filename.
16d9dec6 8973
b383017d 8974If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
8975contained in the file. Binary files always start at address zero, so
8976they will be restored at address @var{bias}. Other bfd files have
8977a built-in location; they will be restored at offset @var{bias}
8978from that location.
8979
8980If @var{start} and/or @var{end} are non-zero, then only data between
8981file offset @var{start} and file offset @var{end} will be restored.
b383017d 8982These offsets are relative to the addresses in the file, before
16d9dec6
MS
8983the @var{bias} argument is applied.
8984
8985@end table
8986
384ee23f
EZ
8987@node Core File Generation
8988@section How to Produce a Core File from Your Program
8989@cindex dump core from inferior
8990
8991A @dfn{core file} or @dfn{core dump} is a file that records the memory
8992image of a running process and its process status (register values
8993etc.). Its primary use is post-mortem debugging of a program that
8994crashed while it ran outside a debugger. A program that crashes
8995automatically produces a core file, unless this feature is disabled by
8996the user. @xref{Files}, for information on invoking @value{GDBN} in
8997the post-mortem debugging mode.
8998
8999Occasionally, you may wish to produce a core file of the program you
9000are debugging in order to preserve a snapshot of its state.
9001@value{GDBN} has a special command for that.
9002
9003@table @code
9004@kindex gcore
9005@kindex generate-core-file
9006@item generate-core-file [@var{file}]
9007@itemx gcore [@var{file}]
9008Produce a core dump of the inferior process. The optional argument
9009@var{file} specifies the file name where to put the core dump. If not
9010specified, the file name defaults to @file{core.@var{pid}}, where
9011@var{pid} is the inferior process ID.
9012
9013Note that this command is implemented only for some systems (as of
9014this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
9015@end table
9016
a0eb71c5
KB
9017@node Character Sets
9018@section Character Sets
9019@cindex character sets
9020@cindex charset
9021@cindex translating between character sets
9022@cindex host character set
9023@cindex target character set
9024
9025If the program you are debugging uses a different character set to
9026represent characters and strings than the one @value{GDBN} uses itself,
9027@value{GDBN} can automatically translate between the character sets for
9028you. The character set @value{GDBN} uses we call the @dfn{host
9029character set}; the one the inferior program uses we call the
9030@dfn{target character set}.
9031
9032For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
9033uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 9034remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
9035running on an IBM mainframe, which uses the @sc{ebcdic} character set,
9036then the host character set is Latin-1, and the target character set is
9037@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 9038target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
9039@sc{ebcdic} and Latin 1 as you print character or string values, or use
9040character and string literals in expressions.
9041
9042@value{GDBN} has no way to automatically recognize which character set
9043the inferior program uses; you must tell it, using the @code{set
9044target-charset} command, described below.
9045
9046Here are the commands for controlling @value{GDBN}'s character set
9047support:
9048
9049@table @code
9050@item set target-charset @var{charset}
9051@kindex set target-charset
10af6951
EZ
9052Set the current target character set to @var{charset}. To display the
9053list of supported target character sets, type
9054@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 9055
a0eb71c5
KB
9056@item set host-charset @var{charset}
9057@kindex set host-charset
9058Set the current host character set to @var{charset}.
9059
9060By default, @value{GDBN} uses a host character set appropriate to the
9061system it is running on; you can override that default using the
732f6a93
TT
9062@code{set host-charset} command. On some systems, @value{GDBN} cannot
9063automatically determine the appropriate host character set. In this
9064case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
9065
9066@value{GDBN} can only use certain character sets as its host character
c1b6b909 9067set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 9068@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
9069
9070@item set charset @var{charset}
9071@kindex set charset
e33d66ec 9072Set the current host and target character sets to @var{charset}. As
10af6951
EZ
9073above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
9074@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
9075for both host and target.
9076
a0eb71c5 9077@item show charset
a0eb71c5 9078@kindex show charset
10af6951 9079Show the names of the current host and target character sets.
e33d66ec 9080
10af6951 9081@item show host-charset
a0eb71c5 9082@kindex show host-charset
10af6951 9083Show the name of the current host character set.
e33d66ec 9084
10af6951 9085@item show target-charset
a0eb71c5 9086@kindex show target-charset
10af6951 9087Show the name of the current target character set.
a0eb71c5 9088
10af6951
EZ
9089@item set target-wide-charset @var{charset}
9090@kindex set target-wide-charset
9091Set the current target's wide character set to @var{charset}. This is
9092the character set used by the target's @code{wchar_t} type. To
9093display the list of supported wide character sets, type
9094@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
9095
9096@item show target-wide-charset
9097@kindex show target-wide-charset
9098Show the name of the current target's wide character set.
a0eb71c5
KB
9099@end table
9100
a0eb71c5
KB
9101Here is an example of @value{GDBN}'s character set support in action.
9102Assume that the following source code has been placed in the file
9103@file{charset-test.c}:
9104
9105@smallexample
9106#include <stdio.h>
9107
9108char ascii_hello[]
9109 = @{72, 101, 108, 108, 111, 44, 32, 119,
9110 111, 114, 108, 100, 33, 10, 0@};
9111char ibm1047_hello[]
9112 = @{200, 133, 147, 147, 150, 107, 64, 166,
9113 150, 153, 147, 132, 90, 37, 0@};
9114
9115main ()
9116@{
9117 printf ("Hello, world!\n");
9118@}
10998722 9119@end smallexample
a0eb71c5
KB
9120
9121In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
9122containing the string @samp{Hello, world!} followed by a newline,
9123encoded in the @sc{ascii} and @sc{ibm1047} character sets.
9124
9125We compile the program, and invoke the debugger on it:
9126
9127@smallexample
9128$ gcc -g charset-test.c -o charset-test
9129$ gdb -nw charset-test
9130GNU gdb 2001-12-19-cvs
9131Copyright 2001 Free Software Foundation, Inc.
9132@dots{}
f7dc1244 9133(@value{GDBP})
10998722 9134@end smallexample
a0eb71c5
KB
9135
9136We can use the @code{show charset} command to see what character sets
9137@value{GDBN} is currently using to interpret and display characters and
9138strings:
9139
9140@smallexample
f7dc1244 9141(@value{GDBP}) show charset
e33d66ec 9142The current host and target character set is `ISO-8859-1'.
f7dc1244 9143(@value{GDBP})
10998722 9144@end smallexample
a0eb71c5
KB
9145
9146For the sake of printing this manual, let's use @sc{ascii} as our
9147initial character set:
9148@smallexample
f7dc1244
EZ
9149(@value{GDBP}) set charset ASCII
9150(@value{GDBP}) show charset
e33d66ec 9151The current host and target character set is `ASCII'.
f7dc1244 9152(@value{GDBP})
10998722 9153@end smallexample
a0eb71c5
KB
9154
9155Let's assume that @sc{ascii} is indeed the correct character set for our
9156host system --- in other words, let's assume that if @value{GDBN} prints
9157characters using the @sc{ascii} character set, our terminal will display
9158them properly. Since our current target character set is also
9159@sc{ascii}, the contents of @code{ascii_hello} print legibly:
9160
9161@smallexample
f7dc1244 9162(@value{GDBP}) print ascii_hello
a0eb71c5 9163$1 = 0x401698 "Hello, world!\n"
f7dc1244 9164(@value{GDBP}) print ascii_hello[0]
a0eb71c5 9165$2 = 72 'H'
f7dc1244 9166(@value{GDBP})
10998722 9167@end smallexample
a0eb71c5
KB
9168
9169@value{GDBN} uses the target character set for character and string
9170literals you use in expressions:
9171
9172@smallexample
f7dc1244 9173(@value{GDBP}) print '+'
a0eb71c5 9174$3 = 43 '+'
f7dc1244 9175(@value{GDBP})
10998722 9176@end smallexample
a0eb71c5
KB
9177
9178The @sc{ascii} character set uses the number 43 to encode the @samp{+}
9179character.
9180
9181@value{GDBN} relies on the user to tell it which character set the
9182target program uses. If we print @code{ibm1047_hello} while our target
9183character set is still @sc{ascii}, we get jibberish:
9184
9185@smallexample
f7dc1244 9186(@value{GDBP}) print ibm1047_hello
a0eb71c5 9187$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 9188(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 9189$5 = 200 '\310'
f7dc1244 9190(@value{GDBP})
10998722 9191@end smallexample
a0eb71c5 9192
e33d66ec 9193If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
9194@value{GDBN} tells us the character sets it supports:
9195
9196@smallexample
f7dc1244 9197(@value{GDBP}) set target-charset
b383017d 9198ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 9199(@value{GDBP}) set target-charset
10998722 9200@end smallexample
a0eb71c5
KB
9201
9202We can select @sc{ibm1047} as our target character set, and examine the
9203program's strings again. Now the @sc{ascii} string is wrong, but
9204@value{GDBN} translates the contents of @code{ibm1047_hello} from the
9205target character set, @sc{ibm1047}, to the host character set,
9206@sc{ascii}, and they display correctly:
9207
9208@smallexample
f7dc1244
EZ
9209(@value{GDBP}) set target-charset IBM1047
9210(@value{GDBP}) show charset
e33d66ec
EZ
9211The current host character set is `ASCII'.
9212The current target character set is `IBM1047'.
f7dc1244 9213(@value{GDBP}) print ascii_hello
a0eb71c5 9214$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 9215(@value{GDBP}) print ascii_hello[0]
a0eb71c5 9216$7 = 72 '\110'
f7dc1244 9217(@value{GDBP}) print ibm1047_hello
a0eb71c5 9218$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 9219(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 9220$9 = 200 'H'
f7dc1244 9221(@value{GDBP})
10998722 9222@end smallexample
a0eb71c5
KB
9223
9224As above, @value{GDBN} uses the target character set for character and
9225string literals you use in expressions:
9226
9227@smallexample
f7dc1244 9228(@value{GDBP}) print '+'
a0eb71c5 9229$10 = 78 '+'
f7dc1244 9230(@value{GDBP})
10998722 9231@end smallexample
a0eb71c5 9232
e33d66ec 9233The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
9234character.
9235
09d4efe1
EZ
9236@node Caching Remote Data
9237@section Caching Data of Remote Targets
9238@cindex caching data of remote targets
9239
4e5d721f 9240@value{GDBN} caches data exchanged between the debugger and a
ea35711c 9241remote target (@pxref{Remote Debugging}). Such caching generally improves
09d4efe1 9242performance, because it reduces the overhead of the remote protocol by
4e5d721f
DE
9243bundling memory reads and writes into large chunks. Unfortunately, simply
9244caching everything would lead to incorrect results, since @value{GDBN}
9245does not necessarily know anything about volatile values, memory-mapped I/O
29b090c0
DE
9246addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
9247memory can be changed @emph{while} a gdb command is executing.
9248Therefore, by default, @value{GDBN} only caches data
9249known to be on the stack@footnote{In non-stop mode, it is moderately
9250rare for a running thread to modify the stack of a stopped thread
9251in a way that would interfere with a backtrace, and caching of
9252stack reads provides a significant speed up of remote backtraces.}.
9253Other regions of memory can be explicitly marked as
4e5d721f 9254cacheable; see @pxref{Memory Region Attributes}.
09d4efe1
EZ
9255
9256@table @code
9257@kindex set remotecache
9258@item set remotecache on
9259@itemx set remotecache off
4e5d721f
DE
9260This option no longer does anything; it exists for compatibility
9261with old scripts.
09d4efe1
EZ
9262
9263@kindex show remotecache
9264@item show remotecache
4e5d721f
DE
9265Show the current state of the obsolete remotecache flag.
9266
9267@kindex set stack-cache
9268@item set stack-cache on
9269@itemx set stack-cache off
9270Enable or disable caching of stack accesses. When @code{ON}, use
9271caching. By default, this option is @code{ON}.
9272
9273@kindex show stack-cache
9274@item show stack-cache
9275Show the current state of data caching for memory accesses.
09d4efe1
EZ
9276
9277@kindex info dcache
4e5d721f 9278@item info dcache @r{[}line@r{]}
09d4efe1 9279Print the information about the data cache performance. The
4e5d721f
DE
9280information displayed includes the dcache width and depth, and for
9281each cache line, its number, address, and how many times it was
9282referenced. This command is useful for debugging the data cache
9283operation.
9284
9285If a line number is specified, the contents of that line will be
9286printed in hex.
09d4efe1
EZ
9287@end table
9288
08388c79
DE
9289@node Searching Memory
9290@section Search Memory
9291@cindex searching memory
9292
9293Memory can be searched for a particular sequence of bytes with the
9294@code{find} command.
9295
9296@table @code
9297@kindex find
9298@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
9299@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
9300Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
9301etc. The search begins at address @var{start_addr} and continues for either
9302@var{len} bytes or through to @var{end_addr} inclusive.
9303@end table
9304
9305@var{s} and @var{n} are optional parameters.
9306They may be specified in either order, apart or together.
9307
9308@table @r
9309@item @var{s}, search query size
9310The size of each search query value.
9311
9312@table @code
9313@item b
9314bytes
9315@item h
9316halfwords (two bytes)
9317@item w
9318words (four bytes)
9319@item g
9320giant words (eight bytes)
9321@end table
9322
9323All values are interpreted in the current language.
9324This means, for example, that if the current source language is C/C@t{++}
9325then searching for the string ``hello'' includes the trailing '\0'.
9326
9327If the value size is not specified, it is taken from the
9328value's type in the current language.
9329This is useful when one wants to specify the search
9330pattern as a mixture of types.
9331Note that this means, for example, that in the case of C-like languages
9332a search for an untyped 0x42 will search for @samp{(int) 0x42}
9333which is typically four bytes.
9334
9335@item @var{n}, maximum number of finds
9336The maximum number of matches to print. The default is to print all finds.
9337@end table
9338
9339You can use strings as search values. Quote them with double-quotes
9340 (@code{"}).
9341The string value is copied into the search pattern byte by byte,
9342regardless of the endianness of the target and the size specification.
9343
9344The address of each match found is printed as well as a count of the
9345number of matches found.
9346
9347The address of the last value found is stored in convenience variable
9348@samp{$_}.
9349A count of the number of matches is stored in @samp{$numfound}.
9350
9351For example, if stopped at the @code{printf} in this function:
9352
9353@smallexample
9354void
9355hello ()
9356@{
9357 static char hello[] = "hello-hello";
9358 static struct @{ char c; short s; int i; @}
9359 __attribute__ ((packed)) mixed
9360 = @{ 'c', 0x1234, 0x87654321 @};
9361 printf ("%s\n", hello);
9362@}
9363@end smallexample
9364
9365@noindent
9366you get during debugging:
9367
9368@smallexample
9369(gdb) find &hello[0], +sizeof(hello), "hello"
93700x804956d <hello.1620+6>
93711 pattern found
9372(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
93730x8049567 <hello.1620>
93740x804956d <hello.1620+6>
93752 patterns found
9376(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
93770x8049567 <hello.1620>
93781 pattern found
9379(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
93800x8049560 <mixed.1625>
93811 pattern found
9382(gdb) print $numfound
9383$1 = 1
9384(gdb) print $_
9385$2 = (void *) 0x8049560
9386@end smallexample
a0eb71c5 9387
edb3359d
DJ
9388@node Optimized Code
9389@chapter Debugging Optimized Code
9390@cindex optimized code, debugging
9391@cindex debugging optimized code
9392
9393Almost all compilers support optimization. With optimization
9394disabled, the compiler generates assembly code that corresponds
9395directly to your source code, in a simplistic way. As the compiler
9396applies more powerful optimizations, the generated assembly code
9397diverges from your original source code. With help from debugging
9398information generated by the compiler, @value{GDBN} can map from
9399the running program back to constructs from your original source.
9400
9401@value{GDBN} is more accurate with optimization disabled. If you
9402can recompile without optimization, it is easier to follow the
9403progress of your program during debugging. But, there are many cases
9404where you may need to debug an optimized version.
9405
9406When you debug a program compiled with @samp{-g -O}, remember that the
9407optimizer has rearranged your code; the debugger shows you what is
9408really there. Do not be too surprised when the execution path does not
9409exactly match your source file! An extreme example: if you define a
9410variable, but never use it, @value{GDBN} never sees that
9411variable---because the compiler optimizes it out of existence.
9412
9413Some things do not work as well with @samp{-g -O} as with just
9414@samp{-g}, particularly on machines with instruction scheduling. If in
9415doubt, recompile with @samp{-g} alone, and if this fixes the problem,
9416please report it to us as a bug (including a test case!).
9417@xref{Variables}, for more information about debugging optimized code.
9418
9419@menu
9420* Inline Functions:: How @value{GDBN} presents inlining
9421@end menu
9422
9423@node Inline Functions
9424@section Inline Functions
9425@cindex inline functions, debugging
9426
9427@dfn{Inlining} is an optimization that inserts a copy of the function
9428body directly at each call site, instead of jumping to a shared
9429routine. @value{GDBN} displays inlined functions just like
9430non-inlined functions. They appear in backtraces. You can view their
9431arguments and local variables, step into them with @code{step}, skip
9432them with @code{next}, and escape from them with @code{finish}.
9433You can check whether a function was inlined by using the
9434@code{info frame} command.
9435
9436For @value{GDBN} to support inlined functions, the compiler must
9437record information about inlining in the debug information ---
9438@value{NGCC} using the @sc{dwarf 2} format does this, and several
9439other compilers do also. @value{GDBN} only supports inlined functions
9440when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
9441do not emit two required attributes (@samp{DW_AT_call_file} and
9442@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
9443function calls with earlier versions of @value{NGCC}. It instead
9444displays the arguments and local variables of inlined functions as
9445local variables in the caller.
9446
9447The body of an inlined function is directly included at its call site;
9448unlike a non-inlined function, there are no instructions devoted to
9449the call. @value{GDBN} still pretends that the call site and the
9450start of the inlined function are different instructions. Stepping to
9451the call site shows the call site, and then stepping again shows
9452the first line of the inlined function, even though no additional
9453instructions are executed.
9454
9455This makes source-level debugging much clearer; you can see both the
9456context of the call and then the effect of the call. Only stepping by
9457a single instruction using @code{stepi} or @code{nexti} does not do
9458this; single instruction steps always show the inlined body.
9459
9460There are some ways that @value{GDBN} does not pretend that inlined
9461function calls are the same as normal calls:
9462
9463@itemize @bullet
9464@item
9465You cannot set breakpoints on inlined functions. @value{GDBN}
9466either reports that there is no symbol with that name, or else sets the
9467breakpoint only on non-inlined copies of the function. This limitation
9468will be removed in a future version of @value{GDBN}; until then,
9469set a breakpoint by line number on the first line of the inlined
9470function instead.
9471
9472@item
9473Setting breakpoints at the call site of an inlined function may not
9474work, because the call site does not contain any code. @value{GDBN}
9475may incorrectly move the breakpoint to the next line of the enclosing
9476function, after the call. This limitation will be removed in a future
9477version of @value{GDBN}; until then, set a breakpoint on an earlier line
9478or inside the inlined function instead.
9479
9480@item
9481@value{GDBN} cannot locate the return value of inlined calls after
9482using the @code{finish} command. This is a limitation of compiler-generated
9483debugging information; after @code{finish}, you can step to the next line
9484and print a variable where your program stored the return value.
9485
9486@end itemize
9487
9488
e2e0bcd1
JB
9489@node Macros
9490@chapter C Preprocessor Macros
9491
49efadf5 9492Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
9493``preprocessor macros'' which expand into strings of tokens.
9494@value{GDBN} can evaluate expressions containing macro invocations, show
9495the result of macro expansion, and show a macro's definition, including
9496where it was defined.
9497
9498You may need to compile your program specially to provide @value{GDBN}
9499with information about preprocessor macros. Most compilers do not
9500include macros in their debugging information, even when you compile
9501with the @option{-g} flag. @xref{Compilation}.
9502
9503A program may define a macro at one point, remove that definition later,
9504and then provide a different definition after that. Thus, at different
9505points in the program, a macro may have different definitions, or have
9506no definition at all. If there is a current stack frame, @value{GDBN}
9507uses the macros in scope at that frame's source code line. Otherwise,
9508@value{GDBN} uses the macros in scope at the current listing location;
9509see @ref{List}.
9510
e2e0bcd1
JB
9511Whenever @value{GDBN} evaluates an expression, it always expands any
9512macro invocations present in the expression. @value{GDBN} also provides
9513the following commands for working with macros explicitly.
9514
9515@table @code
9516
9517@kindex macro expand
9518@cindex macro expansion, showing the results of preprocessor
9519@cindex preprocessor macro expansion, showing the results of
9520@cindex expanding preprocessor macros
9521@item macro expand @var{expression}
9522@itemx macro exp @var{expression}
9523Show the results of expanding all preprocessor macro invocations in
9524@var{expression}. Since @value{GDBN} simply expands macros, but does
9525not parse the result, @var{expression} need not be a valid expression;
9526it can be any string of tokens.
9527
09d4efe1 9528@kindex macro exp1
e2e0bcd1
JB
9529@item macro expand-once @var{expression}
9530@itemx macro exp1 @var{expression}
4644b6e3 9531@cindex expand macro once
e2e0bcd1
JB
9532@i{(This command is not yet implemented.)} Show the results of
9533expanding those preprocessor macro invocations that appear explicitly in
9534@var{expression}. Macro invocations appearing in that expansion are
9535left unchanged. This command allows you to see the effect of a
9536particular macro more clearly, without being confused by further
9537expansions. Since @value{GDBN} simply expands macros, but does not
9538parse the result, @var{expression} need not be a valid expression; it
9539can be any string of tokens.
9540
475b0867 9541@kindex info macro
e2e0bcd1
JB
9542@cindex macro definition, showing
9543@cindex definition, showing a macro's
475b0867 9544@item info macro @var{macro}
e2e0bcd1 9545Show the definition of the macro named @var{macro}, and describe the
484086b7 9546source location or compiler command-line where that definition was established.
e2e0bcd1
JB
9547
9548@kindex macro define
9549@cindex user-defined macros
9550@cindex defining macros interactively
9551@cindex macros, user-defined
9552@item macro define @var{macro} @var{replacement-list}
9553@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
9554Introduce a definition for a preprocessor macro named @var{macro},
9555invocations of which are replaced by the tokens given in
9556@var{replacement-list}. The first form of this command defines an
9557``object-like'' macro, which takes no arguments; the second form
9558defines a ``function-like'' macro, which takes the arguments given in
9559@var{arglist}.
9560
9561A definition introduced by this command is in scope in every
9562expression evaluated in @value{GDBN}, until it is removed with the
9563@code{macro undef} command, described below. The definition overrides
9564all definitions for @var{macro} present in the program being debugged,
9565as well as any previous user-supplied definition.
e2e0bcd1
JB
9566
9567@kindex macro undef
9568@item macro undef @var{macro}
d7d9f01e
TT
9569Remove any user-supplied definition for the macro named @var{macro}.
9570This command only affects definitions provided with the @code{macro
9571define} command, described above; it cannot remove definitions present
9572in the program being debugged.
e2e0bcd1 9573
09d4efe1
EZ
9574@kindex macro list
9575@item macro list
d7d9f01e 9576List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
9577@end table
9578
9579@cindex macros, example of debugging with
9580Here is a transcript showing the above commands in action. First, we
9581show our source files:
9582
9583@smallexample
9584$ cat sample.c
9585#include <stdio.h>
9586#include "sample.h"
9587
9588#define M 42
9589#define ADD(x) (M + x)
9590
9591main ()
9592@{
9593#define N 28
9594 printf ("Hello, world!\n");
9595#undef N
9596 printf ("We're so creative.\n");
9597#define N 1729
9598 printf ("Goodbye, world!\n");
9599@}
9600$ cat sample.h
9601#define Q <
9602$
9603@end smallexample
9604
9605Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
9606We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
9607compiler includes information about preprocessor macros in the debugging
9608information.
9609
9610@smallexample
9611$ gcc -gdwarf-2 -g3 sample.c -o sample
9612$
9613@end smallexample
9614
9615Now, we start @value{GDBN} on our sample program:
9616
9617@smallexample
9618$ gdb -nw sample
9619GNU gdb 2002-05-06-cvs
9620Copyright 2002 Free Software Foundation, Inc.
9621GDB is free software, @dots{}
f7dc1244 9622(@value{GDBP})
e2e0bcd1
JB
9623@end smallexample
9624
9625We can expand macros and examine their definitions, even when the
9626program is not running. @value{GDBN} uses the current listing position
9627to decide which macro definitions are in scope:
9628
9629@smallexample
f7dc1244 9630(@value{GDBP}) list main
e2e0bcd1
JB
96313
96324 #define M 42
96335 #define ADD(x) (M + x)
96346
96357 main ()
96368 @{
96379 #define N 28
963810 printf ("Hello, world!\n");
963911 #undef N
964012 printf ("We're so creative.\n");
f7dc1244 9641(@value{GDBP}) info macro ADD
e2e0bcd1
JB
9642Defined at /home/jimb/gdb/macros/play/sample.c:5
9643#define ADD(x) (M + x)
f7dc1244 9644(@value{GDBP}) info macro Q
e2e0bcd1
JB
9645Defined at /home/jimb/gdb/macros/play/sample.h:1
9646 included at /home/jimb/gdb/macros/play/sample.c:2
9647#define Q <
f7dc1244 9648(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 9649expands to: (42 + 1)
f7dc1244 9650(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 9651expands to: once (M + 1)
f7dc1244 9652(@value{GDBP})
e2e0bcd1
JB
9653@end smallexample
9654
d7d9f01e 9655In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
9656the macro invocation explicit in the original text --- the invocation of
9657@code{ADD} --- but does not expand the invocation of the macro @code{M},
9658which was introduced by @code{ADD}.
9659
3f94c067
BW
9660Once the program is running, @value{GDBN} uses the macro definitions in
9661force at the source line of the current stack frame:
e2e0bcd1
JB
9662
9663@smallexample
f7dc1244 9664(@value{GDBP}) break main
e2e0bcd1 9665Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 9666(@value{GDBP}) run
b383017d 9667Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
9668
9669Breakpoint 1, main () at sample.c:10
967010 printf ("Hello, world!\n");
f7dc1244 9671(@value{GDBP})
e2e0bcd1
JB
9672@end smallexample
9673
9674At line 10, the definition of the macro @code{N} at line 9 is in force:
9675
9676@smallexample
f7dc1244 9677(@value{GDBP}) info macro N
e2e0bcd1
JB
9678Defined at /home/jimb/gdb/macros/play/sample.c:9
9679#define N 28
f7dc1244 9680(@value{GDBP}) macro expand N Q M
e2e0bcd1 9681expands to: 28 < 42
f7dc1244 9682(@value{GDBP}) print N Q M
e2e0bcd1 9683$1 = 1
f7dc1244 9684(@value{GDBP})
e2e0bcd1
JB
9685@end smallexample
9686
9687As we step over directives that remove @code{N}'s definition, and then
9688give it a new definition, @value{GDBN} finds the definition (or lack
9689thereof) in force at each point:
9690
9691@smallexample
f7dc1244 9692(@value{GDBP}) next
e2e0bcd1
JB
9693Hello, world!
969412 printf ("We're so creative.\n");
f7dc1244 9695(@value{GDBP}) info macro N
e2e0bcd1
JB
9696The symbol `N' has no definition as a C/C++ preprocessor macro
9697at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 9698(@value{GDBP}) next
e2e0bcd1
JB
9699We're so creative.
970014 printf ("Goodbye, world!\n");
f7dc1244 9701(@value{GDBP}) info macro N
e2e0bcd1
JB
9702Defined at /home/jimb/gdb/macros/play/sample.c:13
9703#define N 1729
f7dc1244 9704(@value{GDBP}) macro expand N Q M
e2e0bcd1 9705expands to: 1729 < 42
f7dc1244 9706(@value{GDBP}) print N Q M
e2e0bcd1 9707$2 = 0
f7dc1244 9708(@value{GDBP})
e2e0bcd1
JB
9709@end smallexample
9710
484086b7
JK
9711In addition to source files, macros can be defined on the compilation command
9712line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
9713such a way, @value{GDBN} displays the location of their definition as line zero
9714of the source file submitted to the compiler.
9715
9716@smallexample
9717(@value{GDBP}) info macro __STDC__
9718Defined at /home/jimb/gdb/macros/play/sample.c:0
9719-D__STDC__=1
9720(@value{GDBP})
9721@end smallexample
9722
e2e0bcd1 9723
b37052ae
EZ
9724@node Tracepoints
9725@chapter Tracepoints
9726@c This chapter is based on the documentation written by Michael
9727@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
9728
9729@cindex tracepoints
9730In some applications, it is not feasible for the debugger to interrupt
9731the program's execution long enough for the developer to learn
9732anything helpful about its behavior. If the program's correctness
9733depends on its real-time behavior, delays introduced by a debugger
9734might cause the program to change its behavior drastically, or perhaps
9735fail, even when the code itself is correct. It is useful to be able
9736to observe the program's behavior without interrupting it.
9737
9738Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
9739specify locations in the program, called @dfn{tracepoints}, and
9740arbitrary expressions to evaluate when those tracepoints are reached.
9741Later, using the @code{tfind} command, you can examine the values
9742those expressions had when the program hit the tracepoints. The
9743expressions may also denote objects in memory---structures or arrays,
9744for example---whose values @value{GDBN} should record; while visiting
9745a particular tracepoint, you may inspect those objects as if they were
9746in memory at that moment. However, because @value{GDBN} records these
9747values without interacting with you, it can do so quickly and
9748unobtrusively, hopefully not disturbing the program's behavior.
9749
9750The tracepoint facility is currently available only for remote
9d29849a
JB
9751targets. @xref{Targets}. In addition, your remote target must know
9752how to collect trace data. This functionality is implemented in the
9753remote stub; however, none of the stubs distributed with @value{GDBN}
9754support tracepoints as of this writing. The format of the remote
9755packets used to implement tracepoints are described in @ref{Tracepoint
9756Packets}.
b37052ae 9757
00bf0b85
SS
9758It is also possible to get trace data from a file, in a manner reminiscent
9759of corefiles; you specify the filename, and use @code{tfind} to search
9760through the file. @xref{Trace Files}, for more details.
9761
b37052ae
EZ
9762This chapter describes the tracepoint commands and features.
9763
9764@menu
b383017d
RM
9765* Set Tracepoints::
9766* Analyze Collected Data::
9767* Tracepoint Variables::
00bf0b85 9768* Trace Files::
b37052ae
EZ
9769@end menu
9770
9771@node Set Tracepoints
9772@section Commands to Set Tracepoints
9773
9774Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
9775tracepoints can be set. A tracepoint is actually a special type of
9776breakpoint (@pxref{Set Breaks}), so you can manipulate it using
9777standard breakpoint commands. For instance, as with breakpoints,
9778tracepoint numbers are successive integers starting from one, and many
9779of the commands associated with tracepoints take the tracepoint number
9780as their argument, to identify which tracepoint to work on.
b37052ae
EZ
9781
9782For each tracepoint, you can specify, in advance, some arbitrary set
9783of data that you want the target to collect in the trace buffer when
9784it hits that tracepoint. The collected data can include registers,
9785local variables, or global data. Later, you can use @value{GDBN}
9786commands to examine the values these data had at the time the
9787tracepoint was hit.
9788
7d13fe92
SS
9789Tracepoints do not support every breakpoint feature. Ignore counts on
9790tracepoints have no effect, and tracepoints cannot run @value{GDBN}
9791commands when they are hit. Tracepoints may not be thread-specific
9792either.
1042e4c0 9793
7a697b8d
SS
9794@cindex fast tracepoints
9795Some targets may support @dfn{fast tracepoints}, which are inserted in
9796a different way (such as with a jump instead of a trap), that is
9797faster but possibly restricted in where they may be installed.
9798
0fb4aa4b
PA
9799@cindex static tracepoints
9800@cindex markers, static tracepoints
9801@cindex probing markers, static tracepoints
9802Regular and fast tracepoints are dynamic tracing facilities, meaning
9803that they can be used to insert tracepoints at (almost) any location
9804in the target. Some targets may also support controlling @dfn{static
9805tracepoints} from @value{GDBN}. With static tracing, a set of
9806instrumentation points, also known as @dfn{markers}, are embedded in
9807the target program, and can be activated or deactivated by name or
9808address. These are usually placed at locations which facilitate
9809investigating what the target is actually doing. @value{GDBN}'s
9810support for static tracing includes being able to list instrumentation
9811points, and attach them with @value{GDBN} defined high level
9812tracepoints that expose the whole range of convenience of
9813@value{GDBN}'s tracepoints support. Namelly, support for collecting
9814registers values and values of global or local (to the instrumentation
9815point) variables; tracepoint conditions and trace state variables.
9816The act of installing a @value{GDBN} static tracepoint on an
9817instrumentation point, or marker, is referred to as @dfn{probing} a
9818static tracepoint marker.
9819
fa593d66
PA
9820@code{gdbserver} supports tracepoints on some target systems.
9821@xref{Server,,Tracepoints support in @code{gdbserver}}.
9822
b37052ae
EZ
9823This section describes commands to set tracepoints and associated
9824conditions and actions.
9825
9826@menu
b383017d
RM
9827* Create and Delete Tracepoints::
9828* Enable and Disable Tracepoints::
9829* Tracepoint Passcounts::
782b2b07 9830* Tracepoint Conditions::
f61e138d 9831* Trace State Variables::
b383017d
RM
9832* Tracepoint Actions::
9833* Listing Tracepoints::
0fb4aa4b 9834* Listing Static Tracepoint Markers::
79a6e687 9835* Starting and Stopping Trace Experiments::
c9429232 9836* Tracepoint Restrictions::
b37052ae
EZ
9837@end menu
9838
9839@node Create and Delete Tracepoints
9840@subsection Create and Delete Tracepoints
9841
9842@table @code
9843@cindex set tracepoint
9844@kindex trace
1042e4c0 9845@item trace @var{location}
b37052ae 9846The @code{trace} command is very similar to the @code{break} command.
1042e4c0
SS
9847Its argument @var{location} can be a source line, a function name, or
9848an address in the target program. @xref{Specify Location}. The
9849@code{trace} command defines a tracepoint, which is a point in the
9850target program where the debugger will briefly stop, collect some
9851data, and then allow the program to continue. Setting a tracepoint or
9852changing its actions doesn't take effect until the next @code{tstart}
9853command, and once a trace experiment is running, further changes will
9854not have any effect until the next trace experiment starts.
b37052ae
EZ
9855
9856Here are some examples of using the @code{trace} command:
9857
9858@smallexample
9859(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
9860
9861(@value{GDBP}) @b{trace +2} // 2 lines forward
9862
9863(@value{GDBP}) @b{trace my_function} // first source line of function
9864
9865(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
9866
9867(@value{GDBP}) @b{trace *0x2117c4} // an address
9868@end smallexample
9869
9870@noindent
9871You can abbreviate @code{trace} as @code{tr}.
9872
782b2b07
SS
9873@item trace @var{location} if @var{cond}
9874Set a tracepoint with condition @var{cond}; evaluate the expression
9875@var{cond} each time the tracepoint is reached, and collect data only
9876if the value is nonzero---that is, if @var{cond} evaluates as true.
9877@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
9878information on tracepoint conditions.
9879
7a697b8d
SS
9880@item ftrace @var{location} [ if @var{cond} ]
9881@cindex set fast tracepoint
74c761c1 9882@cindex fast tracepoints, setting
7a697b8d
SS
9883@kindex ftrace
9884The @code{ftrace} command sets a fast tracepoint. For targets that
9885support them, fast tracepoints will use a more efficient but possibly
9886less general technique to trigger data collection, such as a jump
9887instruction instead of a trap, or some sort of hardware support. It
9888may not be possible to create a fast tracepoint at the desired
9889location, in which case the command will exit with an explanatory
9890message.
9891
9892@value{GDBN} handles arguments to @code{ftrace} exactly as for
9893@code{trace}.
9894
0fb4aa4b 9895@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
9896@cindex set static tracepoint
9897@cindex static tracepoints, setting
9898@cindex probe static tracepoint marker
0fb4aa4b
PA
9899@kindex strace
9900The @code{strace} command sets a static tracepoint. For targets that
9901support it, setting a static tracepoint probes a static
9902instrumentation point, or marker, found at @var{location}. It may not
9903be possible to set a static tracepoint at the desired location, in
9904which case the command will exit with an explanatory message.
9905
9906@value{GDBN} handles arguments to @code{strace} exactly as for
9907@code{trace}, with the addition that the user can also specify
9908@code{-m @var{marker}} as @var{location}. This probes the marker
9909identified by the @var{marker} string identifier. This identifier
9910depends on the static tracepoint backend library your program is
9911using. You can find all the marker identifiers in the @samp{ID} field
9912of the @code{info static-tracepoint-markers} command output.
9913@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
9914Markers}. For example, in the following small program using the UST
9915tracing engine:
9916
9917@smallexample
9918main ()
9919@{
9920 trace_mark(ust, bar33, "str %s", "FOOBAZ");
9921@}
9922@end smallexample
9923
9924@noindent
9925the marker id is composed of joining the first two arguments to the
9926@code{trace_mark} call with a slash, which translates to:
9927
9928@smallexample
9929(@value{GDBP}) info static-tracepoint-markers
9930Cnt Enb ID Address What
99311 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
9932 Data: "str %s"
9933[etc...]
9934@end smallexample
9935
9936@noindent
9937so you may probe the marker above with:
9938
9939@smallexample
9940(@value{GDBP}) strace -m ust/bar33
9941@end smallexample
9942
9943Static tracepoints accept an extra collect action --- @code{collect
9944$_sdata}. This collects arbitrary user data passed in the probe point
9945call to the tracing library. In the UST example above, you'll see
9946that the third argument to @code{trace_mark} is a printf-like format
9947string. The user data is then the result of running that formating
9948string against the following arguments. Note that @code{info
9949static-tracepoint-markers} command output lists that format string in
9950the @samp{Data:} field.
9951
9952You can inspect this data when analyzing the trace buffer, by printing
9953the $_sdata variable like any other variable available to
9954@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
9955
b37052ae
EZ
9956@vindex $tpnum
9957@cindex last tracepoint number
9958@cindex recent tracepoint number
9959@cindex tracepoint number
9960The convenience variable @code{$tpnum} records the tracepoint number
9961of the most recently set tracepoint.
9962
9963@kindex delete tracepoint
9964@cindex tracepoint deletion
9965@item delete tracepoint @r{[}@var{num}@r{]}
9966Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
9967default is to delete all tracepoints. Note that the regular
9968@code{delete} command can remove tracepoints also.
b37052ae
EZ
9969
9970Examples:
9971
9972@smallexample
9973(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
9974
9975(@value{GDBP}) @b{delete trace} // remove all tracepoints
9976@end smallexample
9977
9978@noindent
9979You can abbreviate this command as @code{del tr}.
9980@end table
9981
9982@node Enable and Disable Tracepoints
9983@subsection Enable and Disable Tracepoints
9984
1042e4c0
SS
9985These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
9986
b37052ae
EZ
9987@table @code
9988@kindex disable tracepoint
9989@item disable tracepoint @r{[}@var{num}@r{]}
9990Disable tracepoint @var{num}, or all tracepoints if no argument
9991@var{num} is given. A disabled tracepoint will have no effect during
9992the next trace experiment, but it is not forgotten. You can re-enable
9993a disabled tracepoint using the @code{enable tracepoint} command.
9994
9995@kindex enable tracepoint
9996@item enable tracepoint @r{[}@var{num}@r{]}
9997Enable tracepoint @var{num}, or all tracepoints. The enabled
9998tracepoints will become effective the next time a trace experiment is
9999run.
10000@end table
10001
10002@node Tracepoint Passcounts
10003@subsection Tracepoint Passcounts
10004
10005@table @code
10006@kindex passcount
10007@cindex tracepoint pass count
10008@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
10009Set the @dfn{passcount} of a tracepoint. The passcount is a way to
10010automatically stop a trace experiment. If a tracepoint's passcount is
10011@var{n}, then the trace experiment will be automatically stopped on
10012the @var{n}'th time that tracepoint is hit. If the tracepoint number
10013@var{num} is not specified, the @code{passcount} command sets the
10014passcount of the most recently defined tracepoint. If no passcount is
10015given, the trace experiment will run until stopped explicitly by the
10016user.
10017
10018Examples:
10019
10020@smallexample
b383017d 10021(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 10022@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
10023
10024(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 10025@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
10026(@value{GDBP}) @b{trace foo}
10027(@value{GDBP}) @b{pass 3}
10028(@value{GDBP}) @b{trace bar}
10029(@value{GDBP}) @b{pass 2}
10030(@value{GDBP}) @b{trace baz}
10031(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
10032@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
10033@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
10034@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
10035@end smallexample
10036@end table
10037
782b2b07
SS
10038@node Tracepoint Conditions
10039@subsection Tracepoint Conditions
10040@cindex conditional tracepoints
10041@cindex tracepoint conditions
10042
10043The simplest sort of tracepoint collects data every time your program
10044reaches a specified place. You can also specify a @dfn{condition} for
10045a tracepoint. A condition is just a Boolean expression in your
10046programming language (@pxref{Expressions, ,Expressions}). A
10047tracepoint with a condition evaluates the expression each time your
10048program reaches it, and data collection happens only if the condition
10049is true.
10050
10051Tracepoint conditions can be specified when a tracepoint is set, by
10052using @samp{if} in the arguments to the @code{trace} command.
10053@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
10054also be set or changed at any time with the @code{condition} command,
10055just as with breakpoints.
10056
10057Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
10058the conditional expression itself. Instead, @value{GDBN} encodes the
10059expression into an agent expression (@pxref{Agent Expressions}
10060suitable for execution on the target, independently of @value{GDBN}.
10061Global variables become raw memory locations, locals become stack
10062accesses, and so forth.
10063
10064For instance, suppose you have a function that is usually called
10065frequently, but should not be called after an error has occurred. You
10066could use the following tracepoint command to collect data about calls
10067of that function that happen while the error code is propagating
10068through the program; an unconditional tracepoint could end up
10069collecting thousands of useless trace frames that you would have to
10070search through.
10071
10072@smallexample
10073(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
10074@end smallexample
10075
f61e138d
SS
10076@node Trace State Variables
10077@subsection Trace State Variables
10078@cindex trace state variables
10079
10080A @dfn{trace state variable} is a special type of variable that is
10081created and managed by target-side code. The syntax is the same as
10082that for GDB's convenience variables (a string prefixed with ``$''),
10083but they are stored on the target. They must be created explicitly,
10084using a @code{tvariable} command. They are always 64-bit signed
10085integers.
10086
10087Trace state variables are remembered by @value{GDBN}, and downloaded
10088to the target along with tracepoint information when the trace
10089experiment starts. There are no intrinsic limits on the number of
10090trace state variables, beyond memory limitations of the target.
10091
10092@cindex convenience variables, and trace state variables
10093Although trace state variables are managed by the target, you can use
10094them in print commands and expressions as if they were convenience
10095variables; @value{GDBN} will get the current value from the target
10096while the trace experiment is running. Trace state variables share
10097the same namespace as other ``$'' variables, which means that you
10098cannot have trace state variables with names like @code{$23} or
10099@code{$pc}, nor can you have a trace state variable and a convenience
10100variable with the same name.
10101
10102@table @code
10103
10104@item tvariable $@var{name} [ = @var{expression} ]
10105@kindex tvariable
10106The @code{tvariable} command creates a new trace state variable named
10107@code{$@var{name}}, and optionally gives it an initial value of
10108@var{expression}. @var{expression} is evaluated when this command is
10109entered; the result will be converted to an integer if possible,
10110otherwise @value{GDBN} will report an error. A subsequent
10111@code{tvariable} command specifying the same name does not create a
10112variable, but instead assigns the supplied initial value to the
10113existing variable of that name, overwriting any previous initial
10114value. The default initial value is 0.
10115
10116@item info tvariables
10117@kindex info tvariables
10118List all the trace state variables along with their initial values.
10119Their current values may also be displayed, if the trace experiment is
10120currently running.
10121
10122@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
10123@kindex delete tvariable
10124Delete the given trace state variables, or all of them if no arguments
10125are specified.
10126
10127@end table
10128
b37052ae
EZ
10129@node Tracepoint Actions
10130@subsection Tracepoint Action Lists
10131
10132@table @code
10133@kindex actions
10134@cindex tracepoint actions
10135@item actions @r{[}@var{num}@r{]}
10136This command will prompt for a list of actions to be taken when the
10137tracepoint is hit. If the tracepoint number @var{num} is not
10138specified, this command sets the actions for the one that was most
10139recently defined (so that you can define a tracepoint and then say
10140@code{actions} without bothering about its number). You specify the
10141actions themselves on the following lines, one action at a time, and
10142terminate the actions list with a line containing just @code{end}. So
7d13fe92 10143far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
10144@code{while-stepping}.
10145
5a9351ae
SS
10146@code{actions} is actually equivalent to @code{commands} (@pxref{Break
10147Commands, ,Breakpoint Command Lists}), except that only the defined
10148actions are allowed; any other @value{GDBN} command is rejected.
10149
b37052ae
EZ
10150@cindex remove actions from a tracepoint
10151To remove all actions from a tracepoint, type @samp{actions @var{num}}
10152and follow it immediately with @samp{end}.
10153
10154@smallexample
10155(@value{GDBP}) @b{collect @var{data}} // collect some data
10156
6826cf00 10157(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 10158
6826cf00 10159(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
10160@end smallexample
10161
10162In the following example, the action list begins with @code{collect}
10163commands indicating the things to be collected when the tracepoint is
10164hit. Then, in order to single-step and collect additional data
10165following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
10166followed by the list of things to be collected after each step in a
10167sequence of single steps. The @code{while-stepping} command is
10168terminated by its own separate @code{end} command. Lastly, the action
10169list is terminated by an @code{end} command.
b37052ae
EZ
10170
10171@smallexample
10172(@value{GDBP}) @b{trace foo}
10173(@value{GDBP}) @b{actions}
10174Enter actions for tracepoint 1, one per line:
10175> collect bar,baz
10176> collect $regs
10177> while-stepping 12
5a9351ae 10178 > collect $pc, arr[i]
b37052ae
EZ
10179 > end
10180end
10181@end smallexample
10182
10183@kindex collect @r{(tracepoints)}
10184@item collect @var{expr1}, @var{expr2}, @dots{}
10185Collect values of the given expressions when the tracepoint is hit.
10186This command accepts a comma-separated list of any valid expressions.
10187In addition to global, static, or local variables, the following
10188special arguments are supported:
10189
10190@table @code
10191@item $regs
0fb4aa4b 10192Collect all registers.
b37052ae
EZ
10193
10194@item $args
0fb4aa4b 10195Collect all function arguments.
b37052ae
EZ
10196
10197@item $locals
0fb4aa4b
PA
10198Collect all local variables.
10199
10200@item $_sdata
10201@vindex $_sdata@r{, collect}
10202Collect static tracepoint marker specific data. Only available for
10203static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
10204Lists}. On the UST static tracepoints library backend, an
10205instrumentation point resembles a @code{printf} function call. The
10206tracing library is able to collect user specified data formatted to a
10207character string using the format provided by the programmer that
10208instrumented the program. Other backends have similar mechanisms.
10209Here's an example of a UST marker call:
10210
10211@smallexample
10212 const char master_name[] = "$your_name";
10213 trace_mark(channel1, marker1, "hello %s", master_name)
10214@end smallexample
10215
10216In this case, collecting @code{$_sdata} collects the string
10217@samp{hello $yourname}. When analyzing the trace buffer, you can
10218inspect @samp{$_sdata} like any other variable available to
10219@value{GDBN}.
b37052ae
EZ
10220@end table
10221
10222You can give several consecutive @code{collect} commands, each one
10223with a single argument, or one @code{collect} command with several
5a9351ae 10224arguments separated by commas; the effect is the same.
b37052ae 10225
f5c37c66
EZ
10226The command @code{info scope} (@pxref{Symbols, info scope}) is
10227particularly useful for figuring out what data to collect.
10228
6da95a67
SS
10229@kindex teval @r{(tracepoints)}
10230@item teval @var{expr1}, @var{expr2}, @dots{}
10231Evaluate the given expressions when the tracepoint is hit. This
10232command accepts a comma-separated list of expressions. The results
10233are discarded, so this is mainly useful for assigning values to trace
10234state variables (@pxref{Trace State Variables}) without adding those
10235values to the trace buffer, as would be the case if the @code{collect}
10236action were used.
10237
b37052ae
EZ
10238@kindex while-stepping @r{(tracepoints)}
10239@item while-stepping @var{n}
c9429232 10240Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 10241collecting new data after each step. The @code{while-stepping}
c9429232
SS
10242command is followed by the list of what to collect while stepping
10243(followed by its own @code{end} command):
b37052ae
EZ
10244
10245@smallexample
10246> while-stepping 12
10247 > collect $regs, myglobal
10248 > end
10249>
10250@end smallexample
10251
10252@noindent
7d13fe92
SS
10253Note that @code{$pc} is not automatically collected by
10254@code{while-stepping}; you need to explicitly collect that register if
10255you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 10256@code{stepping}.
236f1d4d
SS
10257
10258@item set default-collect @var{expr1}, @var{expr2}, @dots{}
10259@kindex set default-collect
10260@cindex default collection action
10261This variable is a list of expressions to collect at each tracepoint
10262hit. It is effectively an additional @code{collect} action prepended
10263to every tracepoint action list. The expressions are parsed
10264individually for each tracepoint, so for instance a variable named
10265@code{xyz} may be interpreted as a global for one tracepoint, and a
10266local for another, as appropriate to the tracepoint's location.
10267
10268@item show default-collect
10269@kindex show default-collect
10270Show the list of expressions that are collected by default at each
10271tracepoint hit.
10272
b37052ae
EZ
10273@end table
10274
10275@node Listing Tracepoints
10276@subsection Listing Tracepoints
10277
10278@table @code
10279@kindex info tracepoints
09d4efe1 10280@kindex info tp
b37052ae
EZ
10281@cindex information about tracepoints
10282@item info tracepoints @r{[}@var{num}@r{]}
1042e4c0
SS
10283Display information about the tracepoint @var{num}. If you don't
10284specify a tracepoint number, displays information about all the
10285tracepoints defined so far. The format is similar to that used for
10286@code{info breakpoints}; in fact, @code{info tracepoints} is the same
10287command, simply restricting itself to tracepoints.
10288
10289A tracepoint's listing may include additional information specific to
10290tracing:
b37052ae
EZ
10291
10292@itemize @bullet
10293@item
b37052ae 10294its passcount as given by the @code{passcount @var{n}} command
b37052ae
EZ
10295@end itemize
10296
10297@smallexample
10298(@value{GDBP}) @b{info trace}
1042e4c0
SS
10299Num Type Disp Enb Address What
103001 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
10301 while-stepping 20
10302 collect globfoo, $regs
10303 end
10304 collect globfoo2
10305 end
1042e4c0 10306 pass count 1200
b37052ae
EZ
10307(@value{GDBP})
10308@end smallexample
10309
10310@noindent
10311This command can be abbreviated @code{info tp}.
10312@end table
10313
0fb4aa4b
PA
10314@node Listing Static Tracepoint Markers
10315@subsection Listing Static Tracepoint Markers
10316
10317@table @code
10318@kindex info static-tracepoint-markers
10319@cindex information about static tracepoint markers
10320@item info static-tracepoint-markers
10321Display information about all static tracepoint markers defined in the
10322program.
10323
10324For each marker, the following columns are printed:
10325
10326@table @emph
10327@item Count
10328An incrementing counter, output to help readability. This is not a
10329stable identifier.
10330@item ID
10331The marker ID, as reported by the target.
10332@item Enabled or Disabled
10333Probed markers are tagged with @samp{y}. @samp{n} identifies marks
10334that are not enabled.
10335@item Address
10336Where the marker is in your program, as a memory address.
10337@item What
10338Where the marker is in the source for your program, as a file and line
10339number. If the debug information included in the program does not
10340allow @value{GDBN} to locate the source of the marker, this column
10341will be left blank.
10342@end table
10343
10344@noindent
10345In addition, the following information may be printed for each marker:
10346
10347@table @emph
10348@item Data
10349User data passed to the tracing library by the marker call. In the
10350UST backend, this is the format string passed as argument to the
10351marker call.
10352@item Static tracepoints probing the marker
10353The list of static tracepoints attached to the marker.
10354@end table
10355
10356@smallexample
10357(@value{GDBP}) info static-tracepoint-markers
10358Cnt ID Enb Address What
103591 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
10360 Data: number1 %d number2 %d
10361 Probed by static tracepoints: #2
103622 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
10363 Data: str %s
10364(@value{GDBP})
10365@end smallexample
10366@end table
10367
79a6e687
BW
10368@node Starting and Stopping Trace Experiments
10369@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
10370
10371@table @code
10372@kindex tstart
10373@cindex start a new trace experiment
10374@cindex collected data discarded
10375@item tstart
10376This command takes no arguments. It starts the trace experiment, and
10377begins collecting data. This has the side effect of discarding all
10378the data collected in the trace buffer during the previous trace
10379experiment.
10380
10381@kindex tstop
10382@cindex stop a running trace experiment
10383@item tstop
10384This command takes no arguments. It ends the trace experiment, and
10385stops collecting data.
10386
68c71a2e 10387@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
10388automatically if any tracepoint's passcount is reached
10389(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
10390
10391@kindex tstatus
10392@cindex status of trace data collection
10393@cindex trace experiment, status of
10394@item tstatus
10395This command displays the status of the current trace data
10396collection.
10397@end table
10398
10399Here is an example of the commands we described so far:
10400
10401@smallexample
10402(@value{GDBP}) @b{trace gdb_c_test}
10403(@value{GDBP}) @b{actions}
10404Enter actions for tracepoint #1, one per line.
10405> collect $regs,$locals,$args
10406> while-stepping 11
10407 > collect $regs
10408 > end
10409> end
10410(@value{GDBP}) @b{tstart}
10411 [time passes @dots{}]
10412(@value{GDBP}) @b{tstop}
10413@end smallexample
10414
d5551862
SS
10415@cindex disconnected tracing
10416You can choose to continue running the trace experiment even if
10417@value{GDBN} disconnects from the target, voluntarily or
10418involuntarily. For commands such as @code{detach}, the debugger will
10419ask what you want to do with the trace. But for unexpected
10420terminations (@value{GDBN} crash, network outage), it would be
10421unfortunate to lose hard-won trace data, so the variable
10422@code{disconnected-tracing} lets you decide whether the trace should
10423continue running without @value{GDBN}.
10424
10425@table @code
10426@item set disconnected-tracing on
10427@itemx set disconnected-tracing off
10428@kindex set disconnected-tracing
10429Choose whether a tracing run should continue to run if @value{GDBN}
10430has disconnected from the target. Note that @code{detach} or
10431@code{quit} will ask you directly what to do about a running trace no
10432matter what this variable's setting, so the variable is mainly useful
10433for handling unexpected situations, such as loss of the network.
10434
10435@item show disconnected-tracing
10436@kindex show disconnected-tracing
10437Show the current choice for disconnected tracing.
10438
10439@end table
10440
10441When you reconnect to the target, the trace experiment may or may not
10442still be running; it might have filled the trace buffer in the
10443meantime, or stopped for one of the other reasons. If it is running,
10444it will continue after reconnection.
10445
10446Upon reconnection, the target will upload information about the
10447tracepoints in effect. @value{GDBN} will then compare that
10448information to the set of tracepoints currently defined, and attempt
10449to match them up, allowing for the possibility that the numbers may
10450have changed due to creation and deletion in the meantime. If one of
10451the target's tracepoints does not match any in @value{GDBN}, the
10452debugger will create a new tracepoint, so that you have a number with
10453which to specify that tracepoint. This matching-up process is
10454necessarily heuristic, and it may result in useless tracepoints being
10455created; you may simply delete them if they are of no use.
b37052ae 10456
4daf5ac0
SS
10457@cindex circular trace buffer
10458If your target agent supports a @dfn{circular trace buffer}, then you
10459can run a trace experiment indefinitely without filling the trace
10460buffer; when space runs out, the agent deletes already-collected trace
10461frames, oldest first, until there is enough room to continue
10462collecting. This is especially useful if your tracepoints are being
10463hit too often, and your trace gets terminated prematurely because the
10464buffer is full. To ask for a circular trace buffer, simply set
10465@samp{circular_trace_buffer} to on. You can set this at any time,
10466including during tracing; if the agent can do it, it will change
10467buffer handling on the fly, otherwise it will not take effect until
10468the next run.
10469
10470@table @code
10471@item set circular-trace-buffer on
10472@itemx set circular-trace-buffer off
10473@kindex set circular-trace-buffer
10474Choose whether a tracing run should use a linear or circular buffer
10475for trace data. A linear buffer will not lose any trace data, but may
10476fill up prematurely, while a circular buffer will discard old trace
10477data, but it will have always room for the latest tracepoint hits.
10478
10479@item show circular-trace-buffer
10480@kindex show circular-trace-buffer
10481Show the current choice for the trace buffer. Note that this may not
10482match the agent's current buffer handling, nor is it guaranteed to
10483match the setting that might have been in effect during a past run,
10484for instance if you are looking at frames from a trace file.
10485
10486@end table
10487
c9429232
SS
10488@node Tracepoint Restrictions
10489@subsection Tracepoint Restrictions
10490
10491@cindex tracepoint restrictions
10492There are a number of restrictions on the use of tracepoints. As
10493described above, tracepoint data gathering occurs on the target
10494without interaction from @value{GDBN}. Thus the full capabilities of
10495the debugger are not available during data gathering, and then at data
10496examination time, you will be limited by only having what was
10497collected. The following items describe some common problems, but it
10498is not exhaustive, and you may run into additional difficulties not
10499mentioned here.
10500
10501@itemize @bullet
10502
10503@item
10504Tracepoint expressions are intended to gather objects (lvalues). Thus
10505the full flexibility of GDB's expression evaluator is not available.
10506You cannot call functions, cast objects to aggregate types, access
10507convenience variables or modify values (except by assignment to trace
10508state variables). Some language features may implicitly call
10509functions (for instance Objective-C fields with accessors), and therefore
10510cannot be collected either.
10511
10512@item
10513Collection of local variables, either individually or in bulk with
10514@code{$locals} or @code{$args}, during @code{while-stepping} may
10515behave erratically. The stepping action may enter a new scope (for
10516instance by stepping into a function), or the location of the variable
10517may change (for instance it is loaded into a register). The
10518tracepoint data recorded uses the location information for the
10519variables that is correct for the tracepoint location. When the
10520tracepoint is created, it is not possible, in general, to determine
10521where the steps of a @code{while-stepping} sequence will advance the
10522program---particularly if a conditional branch is stepped.
10523
10524@item
10525Collection of an incompletely-initialized or partially-destroyed object
10526may result in something that @value{GDBN} cannot display, or displays
10527in a misleading way.
10528
10529@item
10530When @value{GDBN} displays a pointer to character it automatically
10531dereferences the pointer to also display characters of the string
10532being pointed to. However, collecting the pointer during tracing does
10533not automatically collect the string. You need to explicitly
10534dereference the pointer and provide size information if you want to
10535collect not only the pointer, but the memory pointed to. For example,
10536@code{*ptr@@50} can be used to collect the 50 element array pointed to
10537by @code{ptr}.
10538
10539@item
10540It is not possible to collect a complete stack backtrace at a
10541tracepoint. Instead, you may collect the registers and a few hundred
10542bytes from the stack pointer with something like @code{*$esp@@300}
10543(adjust to use the name of the actual stack pointer register on your
10544target architecture, and the amount of stack you wish to capture).
10545Then the @code{backtrace} command will show a partial backtrace when
10546using a trace frame. The number of stack frames that can be examined
10547depends on the sizes of the frames in the collected stack. Note that
10548if you ask for a block so large that it goes past the bottom of the
10549stack, the target agent may report an error trying to read from an
10550invalid address.
10551
af54718e
SS
10552@item
10553If you do not collect registers at a tracepoint, @value{GDBN} can
10554infer that the value of @code{$pc} must be the same as the address of
10555the tracepoint and use that when you are looking at a trace frame
10556for that tracepoint. However, this cannot work if the tracepoint has
10557multiple locations (for instance if it was set in a function that was
10558inlined), or if it has a @code{while-stepping} loop. In those cases
10559@value{GDBN} will warn you that it can't infer @code{$pc}, and default
10560it to zero.
10561
c9429232
SS
10562@end itemize
10563
b37052ae 10564@node Analyze Collected Data
79a6e687 10565@section Using the Collected Data
b37052ae
EZ
10566
10567After the tracepoint experiment ends, you use @value{GDBN} commands
10568for examining the trace data. The basic idea is that each tracepoint
10569collects a trace @dfn{snapshot} every time it is hit and another
10570snapshot every time it single-steps. All these snapshots are
10571consecutively numbered from zero and go into a buffer, and you can
10572examine them later. The way you examine them is to @dfn{focus} on a
10573specific trace snapshot. When the remote stub is focused on a trace
10574snapshot, it will respond to all @value{GDBN} requests for memory and
10575registers by reading from the buffer which belongs to that snapshot,
10576rather than from @emph{real} memory or registers of the program being
10577debugged. This means that @strong{all} @value{GDBN} commands
10578(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
10579behave as if we were currently debugging the program state as it was
10580when the tracepoint occurred. Any requests for data that are not in
10581the buffer will fail.
10582
10583@menu
10584* tfind:: How to select a trace snapshot
10585* tdump:: How to display all data for a snapshot
6149aea9 10586* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
10587@end menu
10588
10589@node tfind
10590@subsection @code{tfind @var{n}}
10591
10592@kindex tfind
10593@cindex select trace snapshot
10594@cindex find trace snapshot
10595The basic command for selecting a trace snapshot from the buffer is
10596@code{tfind @var{n}}, which finds trace snapshot number @var{n},
10597counting from zero. If no argument @var{n} is given, the next
10598snapshot is selected.
10599
10600Here are the various forms of using the @code{tfind} command.
10601
10602@table @code
10603@item tfind start
10604Find the first snapshot in the buffer. This is a synonym for
10605@code{tfind 0} (since 0 is the number of the first snapshot).
10606
10607@item tfind none
10608Stop debugging trace snapshots, resume @emph{live} debugging.
10609
10610@item tfind end
10611Same as @samp{tfind none}.
10612
10613@item tfind
10614No argument means find the next trace snapshot.
10615
10616@item tfind -
10617Find the previous trace snapshot before the current one. This permits
10618retracing earlier steps.
10619
10620@item tfind tracepoint @var{num}
10621Find the next snapshot associated with tracepoint @var{num}. Search
10622proceeds forward from the last examined trace snapshot. If no
10623argument @var{num} is given, it means find the next snapshot collected
10624for the same tracepoint as the current snapshot.
10625
10626@item tfind pc @var{addr}
10627Find the next snapshot associated with the value @var{addr} of the
10628program counter. Search proceeds forward from the last examined trace
10629snapshot. If no argument @var{addr} is given, it means find the next
10630snapshot with the same value of PC as the current snapshot.
10631
10632@item tfind outside @var{addr1}, @var{addr2}
10633Find the next snapshot whose PC is outside the given range of
081dfbf7 10634addresses (exclusive).
b37052ae
EZ
10635
10636@item tfind range @var{addr1}, @var{addr2}
10637Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 10638@var{addr2} (inclusive).
b37052ae
EZ
10639
10640@item tfind line @r{[}@var{file}:@r{]}@var{n}
10641Find the next snapshot associated with the source line @var{n}. If
10642the optional argument @var{file} is given, refer to line @var{n} in
10643that source file. Search proceeds forward from the last examined
10644trace snapshot. If no argument @var{n} is given, it means find the
10645next line other than the one currently being examined; thus saying
10646@code{tfind line} repeatedly can appear to have the same effect as
10647stepping from line to line in a @emph{live} debugging session.
10648@end table
10649
10650The default arguments for the @code{tfind} commands are specifically
10651designed to make it easy to scan through the trace buffer. For
10652instance, @code{tfind} with no argument selects the next trace
10653snapshot, and @code{tfind -} with no argument selects the previous
10654trace snapshot. So, by giving one @code{tfind} command, and then
10655simply hitting @key{RET} repeatedly you can examine all the trace
10656snapshots in order. Or, by saying @code{tfind -} and then hitting
10657@key{RET} repeatedly you can examine the snapshots in reverse order.
10658The @code{tfind line} command with no argument selects the snapshot
10659for the next source line executed. The @code{tfind pc} command with
10660no argument selects the next snapshot with the same program counter
10661(PC) as the current frame. The @code{tfind tracepoint} command with
10662no argument selects the next trace snapshot collected by the same
10663tracepoint as the current one.
10664
10665In addition to letting you scan through the trace buffer manually,
10666these commands make it easy to construct @value{GDBN} scripts that
10667scan through the trace buffer and print out whatever collected data
10668you are interested in. Thus, if we want to examine the PC, FP, and SP
10669registers from each trace frame in the buffer, we can say this:
10670
10671@smallexample
10672(@value{GDBP}) @b{tfind start}
10673(@value{GDBP}) @b{while ($trace_frame != -1)}
10674> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
10675 $trace_frame, $pc, $sp, $fp
10676> tfind
10677> end
10678
10679Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
10680Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
10681Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
10682Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
10683Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
10684Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
10685Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
10686Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
10687Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
10688Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
10689Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
10690@end smallexample
10691
10692Or, if we want to examine the variable @code{X} at each source line in
10693the buffer:
10694
10695@smallexample
10696(@value{GDBP}) @b{tfind start}
10697(@value{GDBP}) @b{while ($trace_frame != -1)}
10698> printf "Frame %d, X == %d\n", $trace_frame, X
10699> tfind line
10700> end
10701
10702Frame 0, X = 1
10703Frame 7, X = 2
10704Frame 13, X = 255
10705@end smallexample
10706
10707@node tdump
10708@subsection @code{tdump}
10709@kindex tdump
10710@cindex dump all data collected at tracepoint
10711@cindex tracepoint data, display
10712
10713This command takes no arguments. It prints all the data collected at
10714the current trace snapshot.
10715
10716@smallexample
10717(@value{GDBP}) @b{trace 444}
10718(@value{GDBP}) @b{actions}
10719Enter actions for tracepoint #2, one per line:
10720> collect $regs, $locals, $args, gdb_long_test
10721> end
10722
10723(@value{GDBP}) @b{tstart}
10724
10725(@value{GDBP}) @b{tfind line 444}
10726#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
10727at gdb_test.c:444
10728444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
10729
10730(@value{GDBP}) @b{tdump}
10731Data collected at tracepoint 2, trace frame 1:
10732d0 0xc4aa0085 -995491707
10733d1 0x18 24
10734d2 0x80 128
10735d3 0x33 51
10736d4 0x71aea3d 119204413
10737d5 0x22 34
10738d6 0xe0 224
10739d7 0x380035 3670069
10740a0 0x19e24a 1696330
10741a1 0x3000668 50333288
10742a2 0x100 256
10743a3 0x322000 3284992
10744a4 0x3000698 50333336
10745a5 0x1ad3cc 1758156
10746fp 0x30bf3c 0x30bf3c
10747sp 0x30bf34 0x30bf34
10748ps 0x0 0
10749pc 0x20b2c8 0x20b2c8
10750fpcontrol 0x0 0
10751fpstatus 0x0 0
10752fpiaddr 0x0 0
10753p = 0x20e5b4 "gdb-test"
10754p1 = (void *) 0x11
10755p2 = (void *) 0x22
10756p3 = (void *) 0x33
10757p4 = (void *) 0x44
10758p5 = (void *) 0x55
10759p6 = (void *) 0x66
10760gdb_long_test = 17 '\021'
10761
10762(@value{GDBP})
10763@end smallexample
10764
af54718e
SS
10765@code{tdump} works by scanning the tracepoint's current collection
10766actions and printing the value of each expression listed. So
10767@code{tdump} can fail, if after a run, you change the tracepoint's
10768actions to mention variables that were not collected during the run.
10769
10770Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
10771uses the collected value of @code{$pc} to distinguish between trace
10772frames that were collected at the tracepoint hit, and frames that were
10773collected while stepping. This allows it to correctly choose whether
10774to display the basic list of collections, or the collections from the
10775body of the while-stepping loop. However, if @code{$pc} was not collected,
10776then @code{tdump} will always attempt to dump using the basic collection
10777list, and may fail if a while-stepping frame does not include all the
10778same data that is collected at the tracepoint hit.
10779@c This is getting pretty arcane, example would be good.
10780
6149aea9
PA
10781@node save tracepoints
10782@subsection @code{save tracepoints @var{filename}}
10783@kindex save tracepoints
b37052ae
EZ
10784@kindex save-tracepoints
10785@cindex save tracepoints for future sessions
10786
10787This command saves all current tracepoint definitions together with
10788their actions and passcounts, into a file @file{@var{filename}}
10789suitable for use in a later debugging session. To read the saved
10790tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
10791Files}). The @w{@code{save-tracepoints}} command is a deprecated
10792alias for @w{@code{save tracepoints}}
b37052ae
EZ
10793
10794@node Tracepoint Variables
10795@section Convenience Variables for Tracepoints
10796@cindex tracepoint variables
10797@cindex convenience variables for tracepoints
10798
10799@table @code
10800@vindex $trace_frame
10801@item (int) $trace_frame
10802The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
10803snapshot is selected.
10804
10805@vindex $tracepoint
10806@item (int) $tracepoint
10807The tracepoint for the current trace snapshot.
10808
10809@vindex $trace_line
10810@item (int) $trace_line
10811The line number for the current trace snapshot.
10812
10813@vindex $trace_file
10814@item (char []) $trace_file
10815The source file for the current trace snapshot.
10816
10817@vindex $trace_func
10818@item (char []) $trace_func
10819The name of the function containing @code{$tracepoint}.
10820@end table
10821
10822Note: @code{$trace_file} is not suitable for use in @code{printf},
10823use @code{output} instead.
10824
10825Here's a simple example of using these convenience variables for
10826stepping through all the trace snapshots and printing some of their
f61e138d
SS
10827data. Note that these are not the same as trace state variables,
10828which are managed by the target.
b37052ae
EZ
10829
10830@smallexample
10831(@value{GDBP}) @b{tfind start}
10832
10833(@value{GDBP}) @b{while $trace_frame != -1}
10834> output $trace_file
10835> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
10836> tfind
10837> end
10838@end smallexample
10839
00bf0b85
SS
10840@node Trace Files
10841@section Using Trace Files
10842@cindex trace files
10843
10844In some situations, the target running a trace experiment may no
10845longer be available; perhaps it crashed, or the hardware was needed
10846for a different activity. To handle these cases, you can arrange to
10847dump the trace data into a file, and later use that file as a source
10848of trace data, via the @code{target tfile} command.
10849
10850@table @code
10851
10852@kindex tsave
10853@item tsave [ -r ] @var{filename}
10854Save the trace data to @var{filename}. By default, this command
10855assumes that @var{filename} refers to the host filesystem, so if
10856necessary @value{GDBN} will copy raw trace data up from the target and
10857then save it. If the target supports it, you can also supply the
10858optional argument @code{-r} (``remote'') to direct the target to save
10859the data directly into @var{filename} in its own filesystem, which may be
10860more efficient if the trace buffer is very large. (Note, however, that
10861@code{target tfile} can only read from files accessible to the host.)
10862
10863@kindex target tfile
10864@kindex tfile
10865@item target tfile @var{filename}
10866Use the file named @var{filename} as a source of trace data. Commands
10867that examine data work as they do with a live target, but it is not
10868possible to run any new trace experiments. @code{tstatus} will report
10869the state of the trace run at the moment the data was saved, as well
10870as the current trace frame you are examining. @var{filename} must be
10871on a filesystem accessible to the host.
10872
10873@end table
10874
df0cd8c5
JB
10875@node Overlays
10876@chapter Debugging Programs That Use Overlays
10877@cindex overlays
10878
10879If your program is too large to fit completely in your target system's
10880memory, you can sometimes use @dfn{overlays} to work around this
10881problem. @value{GDBN} provides some support for debugging programs that
10882use overlays.
10883
10884@menu
10885* How Overlays Work:: A general explanation of overlays.
10886* Overlay Commands:: Managing overlays in @value{GDBN}.
10887* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
10888 mapped by asking the inferior.
10889* Overlay Sample Program:: A sample program using overlays.
10890@end menu
10891
10892@node How Overlays Work
10893@section How Overlays Work
10894@cindex mapped overlays
10895@cindex unmapped overlays
10896@cindex load address, overlay's
10897@cindex mapped address
10898@cindex overlay area
10899
10900Suppose you have a computer whose instruction address space is only 64
10901kilobytes long, but which has much more memory which can be accessed by
10902other means: special instructions, segment registers, or memory
10903management hardware, for example. Suppose further that you want to
10904adapt a program which is larger than 64 kilobytes to run on this system.
10905
10906One solution is to identify modules of your program which are relatively
10907independent, and need not call each other directly; call these modules
10908@dfn{overlays}. Separate the overlays from the main program, and place
10909their machine code in the larger memory. Place your main program in
10910instruction memory, but leave at least enough space there to hold the
10911largest overlay as well.
10912
10913Now, to call a function located in an overlay, you must first copy that
10914overlay's machine code from the large memory into the space set aside
10915for it in the instruction memory, and then jump to its entry point
10916there.
10917
c928edc0
AC
10918@c NB: In the below the mapped area's size is greater or equal to the
10919@c size of all overlays. This is intentional to remind the developer
10920@c that overlays don't necessarily need to be the same size.
10921
474c8240 10922@smallexample
df0cd8c5 10923@group
c928edc0
AC
10924 Data Instruction Larger
10925Address Space Address Space Address Space
10926+-----------+ +-----------+ +-----------+
10927| | | | | |
10928+-----------+ +-----------+ +-----------+<-- overlay 1
10929| program | | main | .----| overlay 1 | load address
10930| variables | | program | | +-----------+
10931| and heap | | | | | |
10932+-----------+ | | | +-----------+<-- overlay 2
10933| | +-----------+ | | | load address
10934+-----------+ | | | .-| overlay 2 |
10935 | | | | | |
10936 mapped --->+-----------+ | | +-----------+
10937 address | | | | | |
10938 | overlay | <-' | | |
10939 | area | <---' +-----------+<-- overlay 3
10940 | | <---. | | load address
10941 +-----------+ `--| overlay 3 |
10942 | | | |
10943 +-----------+ | |
10944 +-----------+
10945 | |
10946 +-----------+
10947
10948 @anchor{A code overlay}A code overlay
df0cd8c5 10949@end group
474c8240 10950@end smallexample
df0cd8c5 10951
c928edc0
AC
10952The diagram (@pxref{A code overlay}) shows a system with separate data
10953and instruction address spaces. To map an overlay, the program copies
10954its code from the larger address space to the instruction address space.
10955Since the overlays shown here all use the same mapped address, only one
10956may be mapped at a time. For a system with a single address space for
10957data and instructions, the diagram would be similar, except that the
10958program variables and heap would share an address space with the main
10959program and the overlay area.
df0cd8c5
JB
10960
10961An overlay loaded into instruction memory and ready for use is called a
10962@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
10963instruction memory. An overlay not present (or only partially present)
10964in instruction memory is called @dfn{unmapped}; its @dfn{load address}
10965is its address in the larger memory. The mapped address is also called
10966the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
10967called the @dfn{load memory address}, or @dfn{LMA}.
10968
10969Unfortunately, overlays are not a completely transparent way to adapt a
10970program to limited instruction memory. They introduce a new set of
10971global constraints you must keep in mind as you design your program:
10972
10973@itemize @bullet
10974
10975@item
10976Before calling or returning to a function in an overlay, your program
10977must make sure that overlay is actually mapped. Otherwise, the call or
10978return will transfer control to the right address, but in the wrong
10979overlay, and your program will probably crash.
10980
10981@item
10982If the process of mapping an overlay is expensive on your system, you
10983will need to choose your overlays carefully to minimize their effect on
10984your program's performance.
10985
10986@item
10987The executable file you load onto your system must contain each
10988overlay's instructions, appearing at the overlay's load address, not its
10989mapped address. However, each overlay's instructions must be relocated
10990and its symbols defined as if the overlay were at its mapped address.
10991You can use GNU linker scripts to specify different load and relocation
10992addresses for pieces of your program; see @ref{Overlay Description,,,
10993ld.info, Using ld: the GNU linker}.
10994
10995@item
10996The procedure for loading executable files onto your system must be able
10997to load their contents into the larger address space as well as the
10998instruction and data spaces.
10999
11000@end itemize
11001
11002The overlay system described above is rather simple, and could be
11003improved in many ways:
11004
11005@itemize @bullet
11006
11007@item
11008If your system has suitable bank switch registers or memory management
11009hardware, you could use those facilities to make an overlay's load area
11010contents simply appear at their mapped address in instruction space.
11011This would probably be faster than copying the overlay to its mapped
11012area in the usual way.
11013
11014@item
11015If your overlays are small enough, you could set aside more than one
11016overlay area, and have more than one overlay mapped at a time.
11017
11018@item
11019You can use overlays to manage data, as well as instructions. In
11020general, data overlays are even less transparent to your design than
11021code overlays: whereas code overlays only require care when you call or
11022return to functions, data overlays require care every time you access
11023the data. Also, if you change the contents of a data overlay, you
11024must copy its contents back out to its load address before you can copy a
11025different data overlay into the same mapped area.
11026
11027@end itemize
11028
11029
11030@node Overlay Commands
11031@section Overlay Commands
11032
11033To use @value{GDBN}'s overlay support, each overlay in your program must
11034correspond to a separate section of the executable file. The section's
11035virtual memory address and load memory address must be the overlay's
11036mapped and load addresses. Identifying overlays with sections allows
11037@value{GDBN} to determine the appropriate address of a function or
11038variable, depending on whether the overlay is mapped or not.
11039
11040@value{GDBN}'s overlay commands all start with the word @code{overlay};
11041you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
11042
11043@table @code
11044@item overlay off
4644b6e3 11045@kindex overlay
df0cd8c5
JB
11046Disable @value{GDBN}'s overlay support. When overlay support is
11047disabled, @value{GDBN} assumes that all functions and variables are
11048always present at their mapped addresses. By default, @value{GDBN}'s
11049overlay support is disabled.
11050
11051@item overlay manual
df0cd8c5
JB
11052@cindex manual overlay debugging
11053Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
11054relies on you to tell it which overlays are mapped, and which are not,
11055using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
11056commands described below.
11057
11058@item overlay map-overlay @var{overlay}
11059@itemx overlay map @var{overlay}
df0cd8c5
JB
11060@cindex map an overlay
11061Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
11062be the name of the object file section containing the overlay. When an
11063overlay is mapped, @value{GDBN} assumes it can find the overlay's
11064functions and variables at their mapped addresses. @value{GDBN} assumes
11065that any other overlays whose mapped ranges overlap that of
11066@var{overlay} are now unmapped.
11067
11068@item overlay unmap-overlay @var{overlay}
11069@itemx overlay unmap @var{overlay}
df0cd8c5
JB
11070@cindex unmap an overlay
11071Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
11072must be the name of the object file section containing the overlay.
11073When an overlay is unmapped, @value{GDBN} assumes it can find the
11074overlay's functions and variables at their load addresses.
11075
11076@item overlay auto
df0cd8c5
JB
11077Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
11078consults a data structure the overlay manager maintains in the inferior
11079to see which overlays are mapped. For details, see @ref{Automatic
11080Overlay Debugging}.
11081
11082@item overlay load-target
11083@itemx overlay load
df0cd8c5
JB
11084@cindex reloading the overlay table
11085Re-read the overlay table from the inferior. Normally, @value{GDBN}
11086re-reads the table @value{GDBN} automatically each time the inferior
11087stops, so this command should only be necessary if you have changed the
11088overlay mapping yourself using @value{GDBN}. This command is only
11089useful when using automatic overlay debugging.
11090
11091@item overlay list-overlays
11092@itemx overlay list
11093@cindex listing mapped overlays
11094Display a list of the overlays currently mapped, along with their mapped
11095addresses, load addresses, and sizes.
11096
11097@end table
11098
11099Normally, when @value{GDBN} prints a code address, it includes the name
11100of the function the address falls in:
11101
474c8240 11102@smallexample
f7dc1244 11103(@value{GDBP}) print main
df0cd8c5 11104$3 = @{int ()@} 0x11a0 <main>
474c8240 11105@end smallexample
df0cd8c5
JB
11106@noindent
11107When overlay debugging is enabled, @value{GDBN} recognizes code in
11108unmapped overlays, and prints the names of unmapped functions with
11109asterisks around them. For example, if @code{foo} is a function in an
11110unmapped overlay, @value{GDBN} prints it this way:
11111
474c8240 11112@smallexample
f7dc1244 11113(@value{GDBP}) overlay list
df0cd8c5 11114No sections are mapped.
f7dc1244 11115(@value{GDBP}) print foo
df0cd8c5 11116$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 11117@end smallexample
df0cd8c5
JB
11118@noindent
11119When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
11120name normally:
11121
474c8240 11122@smallexample
f7dc1244 11123(@value{GDBP}) overlay list
b383017d 11124Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 11125 mapped at 0x1016 - 0x104a
f7dc1244 11126(@value{GDBP}) print foo
df0cd8c5 11127$6 = @{int (int)@} 0x1016 <foo>
474c8240 11128@end smallexample
df0cd8c5
JB
11129
11130When overlay debugging is enabled, @value{GDBN} can find the correct
11131address for functions and variables in an overlay, whether or not the
11132overlay is mapped. This allows most @value{GDBN} commands, like
11133@code{break} and @code{disassemble}, to work normally, even on unmapped
11134code. However, @value{GDBN}'s breakpoint support has some limitations:
11135
11136@itemize @bullet
11137@item
11138@cindex breakpoints in overlays
11139@cindex overlays, setting breakpoints in
11140You can set breakpoints in functions in unmapped overlays, as long as
11141@value{GDBN} can write to the overlay at its load address.
11142@item
11143@value{GDBN} can not set hardware or simulator-based breakpoints in
11144unmapped overlays. However, if you set a breakpoint at the end of your
11145overlay manager (and tell @value{GDBN} which overlays are now mapped, if
11146you are using manual overlay management), @value{GDBN} will re-set its
11147breakpoints properly.
11148@end itemize
11149
11150
11151@node Automatic Overlay Debugging
11152@section Automatic Overlay Debugging
11153@cindex automatic overlay debugging
11154
11155@value{GDBN} can automatically track which overlays are mapped and which
11156are not, given some simple co-operation from the overlay manager in the
11157inferior. If you enable automatic overlay debugging with the
11158@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
11159looks in the inferior's memory for certain variables describing the
11160current state of the overlays.
11161
11162Here are the variables your overlay manager must define to support
11163@value{GDBN}'s automatic overlay debugging:
11164
11165@table @asis
11166
11167@item @code{_ovly_table}:
11168This variable must be an array of the following structures:
11169
474c8240 11170@smallexample
df0cd8c5
JB
11171struct
11172@{
11173 /* The overlay's mapped address. */
11174 unsigned long vma;
11175
11176 /* The size of the overlay, in bytes. */
11177 unsigned long size;
11178
11179 /* The overlay's load address. */
11180 unsigned long lma;
11181
11182 /* Non-zero if the overlay is currently mapped;
11183 zero otherwise. */
11184 unsigned long mapped;
11185@}
474c8240 11186@end smallexample
df0cd8c5
JB
11187
11188@item @code{_novlys}:
11189This variable must be a four-byte signed integer, holding the total
11190number of elements in @code{_ovly_table}.
11191
11192@end table
11193
11194To decide whether a particular overlay is mapped or not, @value{GDBN}
11195looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
11196@code{lma} members equal the VMA and LMA of the overlay's section in the
11197executable file. When @value{GDBN} finds a matching entry, it consults
11198the entry's @code{mapped} member to determine whether the overlay is
11199currently mapped.
11200
81d46470 11201In addition, your overlay manager may define a function called
def71bfa 11202@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
11203will silently set a breakpoint there. If the overlay manager then
11204calls this function whenever it has changed the overlay table, this
11205will enable @value{GDBN} to accurately keep track of which overlays
11206are in program memory, and update any breakpoints that may be set
b383017d 11207in overlays. This will allow breakpoints to work even if the
81d46470
MS
11208overlays are kept in ROM or other non-writable memory while they
11209are not being executed.
df0cd8c5
JB
11210
11211@node Overlay Sample Program
11212@section Overlay Sample Program
11213@cindex overlay example program
11214
11215When linking a program which uses overlays, you must place the overlays
11216at their load addresses, while relocating them to run at their mapped
11217addresses. To do this, you must write a linker script (@pxref{Overlay
11218Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
11219since linker scripts are specific to a particular host system, target
11220architecture, and target memory layout, this manual cannot provide
11221portable sample code demonstrating @value{GDBN}'s overlay support.
11222
11223However, the @value{GDBN} source distribution does contain an overlaid
11224program, with linker scripts for a few systems, as part of its test
11225suite. The program consists of the following files from
11226@file{gdb/testsuite/gdb.base}:
11227
11228@table @file
11229@item overlays.c
11230The main program file.
11231@item ovlymgr.c
11232A simple overlay manager, used by @file{overlays.c}.
11233@item foo.c
11234@itemx bar.c
11235@itemx baz.c
11236@itemx grbx.c
11237Overlay modules, loaded and used by @file{overlays.c}.
11238@item d10v.ld
11239@itemx m32r.ld
11240Linker scripts for linking the test program on the @code{d10v-elf}
11241and @code{m32r-elf} targets.
11242@end table
11243
11244You can build the test program using the @code{d10v-elf} GCC
11245cross-compiler like this:
11246
474c8240 11247@smallexample
df0cd8c5
JB
11248$ d10v-elf-gcc -g -c overlays.c
11249$ d10v-elf-gcc -g -c ovlymgr.c
11250$ d10v-elf-gcc -g -c foo.c
11251$ d10v-elf-gcc -g -c bar.c
11252$ d10v-elf-gcc -g -c baz.c
11253$ d10v-elf-gcc -g -c grbx.c
11254$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
11255 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 11256@end smallexample
df0cd8c5
JB
11257
11258The build process is identical for any other architecture, except that
11259you must substitute the appropriate compiler and linker script for the
11260target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
11261
11262
6d2ebf8b 11263@node Languages
c906108c
SS
11264@chapter Using @value{GDBN} with Different Languages
11265@cindex languages
11266
c906108c
SS
11267Although programming languages generally have common aspects, they are
11268rarely expressed in the same manner. For instance, in ANSI C,
11269dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
11270Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 11271represented (and displayed) differently. Hex numbers in C appear as
c906108c 11272@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
11273
11274@cindex working language
11275Language-specific information is built into @value{GDBN} for some languages,
11276allowing you to express operations like the above in your program's
11277native language, and allowing @value{GDBN} to output values in a manner
11278consistent with the syntax of your program's native language. The
11279language you use to build expressions is called the @dfn{working
11280language}.
11281
11282@menu
11283* Setting:: Switching between source languages
11284* Show:: Displaying the language
c906108c 11285* Checks:: Type and range checks
79a6e687
BW
11286* Supported Languages:: Supported languages
11287* Unsupported Languages:: Unsupported languages
c906108c
SS
11288@end menu
11289
6d2ebf8b 11290@node Setting
79a6e687 11291@section Switching Between Source Languages
c906108c
SS
11292
11293There are two ways to control the working language---either have @value{GDBN}
11294set it automatically, or select it manually yourself. You can use the
11295@code{set language} command for either purpose. On startup, @value{GDBN}
11296defaults to setting the language automatically. The working language is
11297used to determine how expressions you type are interpreted, how values
11298are printed, etc.
11299
11300In addition to the working language, every source file that
11301@value{GDBN} knows about has its own working language. For some object
11302file formats, the compiler might indicate which language a particular
11303source file is in. However, most of the time @value{GDBN} infers the
11304language from the name of the file. The language of a source file
b37052ae 11305controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 11306show each frame appropriately for its own language. There is no way to
d4f3574e
SS
11307set the language of a source file from within @value{GDBN}, but you can
11308set the language associated with a filename extension. @xref{Show, ,
79a6e687 11309Displaying the Language}.
c906108c
SS
11310
11311This is most commonly a problem when you use a program, such
5d161b24 11312as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
11313another language. In that case, make the
11314program use @code{#line} directives in its C output; that way
11315@value{GDBN} will know the correct language of the source code of the original
11316program, and will display that source code, not the generated C code.
11317
11318@menu
11319* Filenames:: Filename extensions and languages.
11320* Manually:: Setting the working language manually
11321* Automatically:: Having @value{GDBN} infer the source language
11322@end menu
11323
6d2ebf8b 11324@node Filenames
79a6e687 11325@subsection List of Filename Extensions and Languages
c906108c
SS
11326
11327If a source file name ends in one of the following extensions, then
11328@value{GDBN} infers that its language is the one indicated.
11329
11330@table @file
e07c999f
PH
11331@item .ada
11332@itemx .ads
11333@itemx .adb
11334@itemx .a
11335Ada source file.
c906108c
SS
11336
11337@item .c
11338C source file
11339
11340@item .C
11341@itemx .cc
11342@itemx .cp
11343@itemx .cpp
11344@itemx .cxx
11345@itemx .c++
b37052ae 11346C@t{++} source file
c906108c 11347
6aecb9c2
JB
11348@item .d
11349D source file
11350
b37303ee
AF
11351@item .m
11352Objective-C source file
11353
c906108c
SS
11354@item .f
11355@itemx .F
11356Fortran source file
11357
c906108c
SS
11358@item .mod
11359Modula-2 source file
c906108c
SS
11360
11361@item .s
11362@itemx .S
11363Assembler source file. This actually behaves almost like C, but
11364@value{GDBN} does not skip over function prologues when stepping.
11365@end table
11366
11367In addition, you may set the language associated with a filename
79a6e687 11368extension. @xref{Show, , Displaying the Language}.
c906108c 11369
6d2ebf8b 11370@node Manually
79a6e687 11371@subsection Setting the Working Language
c906108c
SS
11372
11373If you allow @value{GDBN} to set the language automatically,
11374expressions are interpreted the same way in your debugging session and
11375your program.
11376
11377@kindex set language
11378If you wish, you may set the language manually. To do this, issue the
11379command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 11380a language, such as
c906108c 11381@code{c} or @code{modula-2}.
c906108c
SS
11382For a list of the supported languages, type @samp{set language}.
11383
c906108c
SS
11384Setting the language manually prevents @value{GDBN} from updating the working
11385language automatically. This can lead to confusion if you try
11386to debug a program when the working language is not the same as the
11387source language, when an expression is acceptable to both
11388languages---but means different things. For instance, if the current
11389source file were written in C, and @value{GDBN} was parsing Modula-2, a
11390command such as:
11391
474c8240 11392@smallexample
c906108c 11393print a = b + c
474c8240 11394@end smallexample
c906108c
SS
11395
11396@noindent
11397might not have the effect you intended. In C, this means to add
11398@code{b} and @code{c} and place the result in @code{a}. The result
11399printed would be the value of @code{a}. In Modula-2, this means to compare
11400@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 11401
6d2ebf8b 11402@node Automatically
79a6e687 11403@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
11404
11405To have @value{GDBN} set the working language automatically, use
11406@samp{set language local} or @samp{set language auto}. @value{GDBN}
11407then infers the working language. That is, when your program stops in a
11408frame (usually by encountering a breakpoint), @value{GDBN} sets the
11409working language to the language recorded for the function in that
11410frame. If the language for a frame is unknown (that is, if the function
11411or block corresponding to the frame was defined in a source file that
11412does not have a recognized extension), the current working language is
11413not changed, and @value{GDBN} issues a warning.
11414
11415This may not seem necessary for most programs, which are written
11416entirely in one source language. However, program modules and libraries
11417written in one source language can be used by a main program written in
11418a different source language. Using @samp{set language auto} in this
11419case frees you from having to set the working language manually.
11420
6d2ebf8b 11421@node Show
79a6e687 11422@section Displaying the Language
c906108c
SS
11423
11424The following commands help you find out which language is the
11425working language, and also what language source files were written in.
11426
c906108c
SS
11427@table @code
11428@item show language
9c16f35a 11429@kindex show language
c906108c
SS
11430Display the current working language. This is the
11431language you can use with commands such as @code{print} to
11432build and compute expressions that may involve variables in your program.
11433
11434@item info frame
4644b6e3 11435@kindex info frame@r{, show the source language}
5d161b24 11436Display the source language for this frame. This language becomes the
c906108c 11437working language if you use an identifier from this frame.
79a6e687 11438@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
11439information listed here.
11440
11441@item info source
4644b6e3 11442@kindex info source@r{, show the source language}
c906108c 11443Display the source language of this source file.
5d161b24 11444@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
11445information listed here.
11446@end table
11447
11448In unusual circumstances, you may have source files with extensions
11449not in the standard list. You can then set the extension associated
11450with a language explicitly:
11451
c906108c 11452@table @code
09d4efe1 11453@item set extension-language @var{ext} @var{language}
9c16f35a 11454@kindex set extension-language
09d4efe1
EZ
11455Tell @value{GDBN} that source files with extension @var{ext} are to be
11456assumed as written in the source language @var{language}.
c906108c
SS
11457
11458@item info extensions
9c16f35a 11459@kindex info extensions
c906108c
SS
11460List all the filename extensions and the associated languages.
11461@end table
11462
6d2ebf8b 11463@node Checks
79a6e687 11464@section Type and Range Checking
c906108c
SS
11465
11466@quotation
11467@emph{Warning:} In this release, the @value{GDBN} commands for type and range
11468checking are included, but they do not yet have any effect. This
11469section documents the intended facilities.
11470@end quotation
11471@c FIXME remove warning when type/range code added
11472
11473Some languages are designed to guard you against making seemingly common
11474errors through a series of compile- and run-time checks. These include
11475checking the type of arguments to functions and operators, and making
11476sure mathematical overflows are caught at run time. Checks such as
11477these help to ensure a program's correctness once it has been compiled
11478by eliminating type mismatches, and providing active checks for range
11479errors when your program is running.
11480
11481@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
11482Although @value{GDBN} does not check the statements in your program,
11483it can check expressions entered directly into @value{GDBN} for
11484evaluation via the @code{print} command, for example. As with the
11485working language, @value{GDBN} can also decide whether or not to check
11486automatically based on your program's source language.
79a6e687 11487@xref{Supported Languages, ,Supported Languages}, for the default
9c16f35a 11488settings of supported languages.
c906108c
SS
11489
11490@menu
11491* Type Checking:: An overview of type checking
11492* Range Checking:: An overview of range checking
11493@end menu
11494
11495@cindex type checking
11496@cindex checks, type
6d2ebf8b 11497@node Type Checking
79a6e687 11498@subsection An Overview of Type Checking
c906108c
SS
11499
11500Some languages, such as Modula-2, are strongly typed, meaning that the
11501arguments to operators and functions have to be of the correct type,
11502otherwise an error occurs. These checks prevent type mismatch
11503errors from ever causing any run-time problems. For example,
11504
11505@smallexample
115061 + 2 @result{} 3
11507@exdent but
11508@error{} 1 + 2.3
11509@end smallexample
11510
11511The second example fails because the @code{CARDINAL} 1 is not
11512type-compatible with the @code{REAL} 2.3.
11513
5d161b24
DB
11514For the expressions you use in @value{GDBN} commands, you can tell the
11515@value{GDBN} type checker to skip checking;
11516to treat any mismatches as errors and abandon the expression;
11517or to only issue warnings when type mismatches occur,
c906108c
SS
11518but evaluate the expression anyway. When you choose the last of
11519these, @value{GDBN} evaluates expressions like the second example above, but
11520also issues a warning.
11521
5d161b24
DB
11522Even if you turn type checking off, there may be other reasons
11523related to type that prevent @value{GDBN} from evaluating an expression.
11524For instance, @value{GDBN} does not know how to add an @code{int} and
11525a @code{struct foo}. These particular type errors have nothing to do
11526with the language in use, and usually arise from expressions, such as
c906108c
SS
11527the one described above, which make little sense to evaluate anyway.
11528
11529Each language defines to what degree it is strict about type. For
11530instance, both Modula-2 and C require the arguments to arithmetical
11531operators to be numbers. In C, enumerated types and pointers can be
11532represented as numbers, so that they are valid arguments to mathematical
79a6e687 11533operators. @xref{Supported Languages, ,Supported Languages}, for further
c906108c
SS
11534details on specific languages.
11535
11536@value{GDBN} provides some additional commands for controlling the type checker:
11537
c906108c
SS
11538@kindex set check type
11539@kindex show check type
11540@table @code
11541@item set check type auto
11542Set type checking on or off based on the current working language.
79a6e687 11543@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
11544each language.
11545
11546@item set check type on
11547@itemx set check type off
11548Set type checking on or off, overriding the default setting for the
11549current working language. Issue a warning if the setting does not
11550match the language default. If any type mismatches occur in
d4f3574e 11551evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
11552message and aborts evaluation of the expression.
11553
11554@item set check type warn
11555Cause the type checker to issue warnings, but to always attempt to
11556evaluate the expression. Evaluating the expression may still
11557be impossible for other reasons. For example, @value{GDBN} cannot add
11558numbers and structures.
11559
11560@item show type
5d161b24 11561Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
11562is setting it automatically.
11563@end table
11564
11565@cindex range checking
11566@cindex checks, range
6d2ebf8b 11567@node Range Checking
79a6e687 11568@subsection An Overview of Range Checking
c906108c
SS
11569
11570In some languages (such as Modula-2), it is an error to exceed the
11571bounds of a type; this is enforced with run-time checks. Such range
11572checking is meant to ensure program correctness by making sure
11573computations do not overflow, or indices on an array element access do
11574not exceed the bounds of the array.
11575
11576For expressions you use in @value{GDBN} commands, you can tell
11577@value{GDBN} to treat range errors in one of three ways: ignore them,
11578always treat them as errors and abandon the expression, or issue
11579warnings but evaluate the expression anyway.
11580
11581A range error can result from numerical overflow, from exceeding an
11582array index bound, or when you type a constant that is not a member
11583of any type. Some languages, however, do not treat overflows as an
11584error. In many implementations of C, mathematical overflow causes the
11585result to ``wrap around'' to lower values---for example, if @var{m} is
11586the largest integer value, and @var{s} is the smallest, then
11587
474c8240 11588@smallexample
c906108c 11589@var{m} + 1 @result{} @var{s}
474c8240 11590@end smallexample
c906108c
SS
11591
11592This, too, is specific to individual languages, and in some cases
79a6e687
BW
11593specific to individual compilers or machines. @xref{Supported Languages, ,
11594Supported Languages}, for further details on specific languages.
c906108c
SS
11595
11596@value{GDBN} provides some additional commands for controlling the range checker:
11597
c906108c
SS
11598@kindex set check range
11599@kindex show check range
11600@table @code
11601@item set check range auto
11602Set range checking on or off based on the current working language.
79a6e687 11603@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
11604each language.
11605
11606@item set check range on
11607@itemx set check range off
11608Set range checking on or off, overriding the default setting for the
11609current working language. A warning is issued if the setting does not
c3f6f71d
JM
11610match the language default. If a range error occurs and range checking is on,
11611then a message is printed and evaluation of the expression is aborted.
c906108c
SS
11612
11613@item set check range warn
11614Output messages when the @value{GDBN} range checker detects a range error,
11615but attempt to evaluate the expression anyway. Evaluating the
11616expression may still be impossible for other reasons, such as accessing
11617memory that the process does not own (a typical example from many Unix
11618systems).
11619
11620@item show range
11621Show the current setting of the range checker, and whether or not it is
11622being set automatically by @value{GDBN}.
11623@end table
c906108c 11624
79a6e687
BW
11625@node Supported Languages
11626@section Supported Languages
c906108c 11627
f4b8a18d 11628@value{GDBN} supports C, C@t{++}, D, Objective-C, Fortran, Java, OpenCL C, Pascal,
9c16f35a 11629assembly, Modula-2, and Ada.
cce74817 11630@c This is false ...
c906108c
SS
11631Some @value{GDBN} features may be used in expressions regardless of the
11632language you use: the @value{GDBN} @code{@@} and @code{::} operators,
11633and the @samp{@{type@}addr} construct (@pxref{Expressions,
11634,Expressions}) can be used with the constructs of any supported
11635language.
11636
11637The following sections detail to what degree each source language is
11638supported by @value{GDBN}. These sections are not meant to be language
11639tutorials or references, but serve only as a reference guide to what the
11640@value{GDBN} expression parser accepts, and what input and output
11641formats should look like for different languages. There are many good
11642books written on each of these languages; please look to these for a
11643language reference or tutorial.
11644
c906108c 11645@menu
b37303ee 11646* C:: C and C@t{++}
6aecb9c2 11647* D:: D
b383017d 11648* Objective-C:: Objective-C
f4b8a18d 11649* OpenCL C:: OpenCL C
09d4efe1 11650* Fortran:: Fortran
9c16f35a 11651* Pascal:: Pascal
b37303ee 11652* Modula-2:: Modula-2
e07c999f 11653* Ada:: Ada
c906108c
SS
11654@end menu
11655
6d2ebf8b 11656@node C
b37052ae 11657@subsection C and C@t{++}
7a292a7a 11658
b37052ae
EZ
11659@cindex C and C@t{++}
11660@cindex expressions in C or C@t{++}
c906108c 11661
b37052ae 11662Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
11663to both languages. Whenever this is the case, we discuss those languages
11664together.
11665
41afff9a
EZ
11666@cindex C@t{++}
11667@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
11668@cindex @sc{gnu} C@t{++}
11669The C@t{++} debugging facilities are jointly implemented by the C@t{++}
11670compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
11671effectively, you must compile your C@t{++} programs with a supported
11672C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
11673compiler (@code{aCC}).
11674
0179ffac
DC
11675For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
11676format; if it doesn't work on your system, try the stabs+ debugging
11677format. You can select those formats explicitly with the @code{g++}
11678command-line options @option{-gdwarf-2} and @option{-gstabs+}.
ce9341a1
BW
11679@xref{Debugging Options,,Options for Debugging Your Program or GCC,
11680gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}.
c906108c 11681
c906108c 11682@menu
b37052ae
EZ
11683* C Operators:: C and C@t{++} operators
11684* C Constants:: C and C@t{++} constants
79a6e687 11685* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
11686* C Defaults:: Default settings for C and C@t{++}
11687* C Checks:: C and C@t{++} type and range checks
c906108c 11688* Debugging C:: @value{GDBN} and C
79a6e687 11689* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 11690* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 11691@end menu
c906108c 11692
6d2ebf8b 11693@node C Operators
79a6e687 11694@subsubsection C and C@t{++} Operators
7a292a7a 11695
b37052ae 11696@cindex C and C@t{++} operators
c906108c
SS
11697
11698Operators must be defined on values of specific types. For instance,
11699@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 11700often defined on groups of types.
c906108c 11701
b37052ae 11702For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
11703
11704@itemize @bullet
53a5351d 11705
c906108c 11706@item
c906108c 11707@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 11708specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
11709
11710@item
d4f3574e
SS
11711@emph{Floating-point types} include @code{float}, @code{double}, and
11712@code{long double} (if supported by the target platform).
c906108c
SS
11713
11714@item
53a5351d 11715@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
11716
11717@item
11718@emph{Scalar types} include all of the above.
53a5351d 11719
c906108c
SS
11720@end itemize
11721
11722@noindent
11723The following operators are supported. They are listed here
11724in order of increasing precedence:
11725
11726@table @code
11727@item ,
11728The comma or sequencing operator. Expressions in a comma-separated list
11729are evaluated from left to right, with the result of the entire
11730expression being the last expression evaluated.
11731
11732@item =
11733Assignment. The value of an assignment expression is the value
11734assigned. Defined on scalar types.
11735
11736@item @var{op}=
11737Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
11738and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 11739@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
11740@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
11741@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
11742
11743@item ?:
11744The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
11745of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
11746integral type.
11747
11748@item ||
11749Logical @sc{or}. Defined on integral types.
11750
11751@item &&
11752Logical @sc{and}. Defined on integral types.
11753
11754@item |
11755Bitwise @sc{or}. Defined on integral types.
11756
11757@item ^
11758Bitwise exclusive-@sc{or}. Defined on integral types.
11759
11760@item &
11761Bitwise @sc{and}. Defined on integral types.
11762
11763@item ==@r{, }!=
11764Equality and inequality. Defined on scalar types. The value of these
11765expressions is 0 for false and non-zero for true.
11766
11767@item <@r{, }>@r{, }<=@r{, }>=
11768Less than, greater than, less than or equal, greater than or equal.
11769Defined on scalar types. The value of these expressions is 0 for false
11770and non-zero for true.
11771
11772@item <<@r{, }>>
11773left shift, and right shift. Defined on integral types.
11774
11775@item @@
11776The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
11777
11778@item +@r{, }-
11779Addition and subtraction. Defined on integral types, floating-point types and
11780pointer types.
11781
11782@item *@r{, }/@r{, }%
11783Multiplication, division, and modulus. Multiplication and division are
11784defined on integral and floating-point types. Modulus is defined on
11785integral types.
11786
11787@item ++@r{, }--
11788Increment and decrement. When appearing before a variable, the
11789operation is performed before the variable is used in an expression;
11790when appearing after it, the variable's value is used before the
11791operation takes place.
11792
11793@item *
11794Pointer dereferencing. Defined on pointer types. Same precedence as
11795@code{++}.
11796
11797@item &
11798Address operator. Defined on variables. Same precedence as @code{++}.
11799
b37052ae
EZ
11800For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
11801allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 11802to examine the address
b37052ae 11803where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 11804stored.
c906108c
SS
11805
11806@item -
11807Negative. Defined on integral and floating-point types. Same
11808precedence as @code{++}.
11809
11810@item !
11811Logical negation. Defined on integral types. Same precedence as
11812@code{++}.
11813
11814@item ~
11815Bitwise complement operator. Defined on integral types. Same precedence as
11816@code{++}.
11817
11818
11819@item .@r{, }->
11820Structure member, and pointer-to-structure member. For convenience,
11821@value{GDBN} regards the two as equivalent, choosing whether to dereference a
11822pointer based on the stored type information.
11823Defined on @code{struct} and @code{union} data.
11824
c906108c
SS
11825@item .*@r{, }->*
11826Dereferences of pointers to members.
c906108c
SS
11827
11828@item []
11829Array indexing. @code{@var{a}[@var{i}]} is defined as
11830@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
11831
11832@item ()
11833Function parameter list. Same precedence as @code{->}.
11834
c906108c 11835@item ::
b37052ae 11836C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 11837and @code{class} types.
c906108c
SS
11838
11839@item ::
7a292a7a
SS
11840Doubled colons also represent the @value{GDBN} scope operator
11841(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
11842above.
c906108c
SS
11843@end table
11844
c906108c
SS
11845If an operator is redefined in the user code, @value{GDBN} usually
11846attempts to invoke the redefined version instead of using the operator's
11847predefined meaning.
c906108c 11848
6d2ebf8b 11849@node C Constants
79a6e687 11850@subsubsection C and C@t{++} Constants
c906108c 11851
b37052ae 11852@cindex C and C@t{++} constants
c906108c 11853
b37052ae 11854@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 11855following ways:
c906108c
SS
11856
11857@itemize @bullet
11858@item
11859Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
11860specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
11861by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
11862@samp{l}, specifying that the constant should be treated as a
11863@code{long} value.
11864
11865@item
11866Floating point constants are a sequence of digits, followed by a decimal
11867point, followed by a sequence of digits, and optionally followed by an
11868exponent. An exponent is of the form:
11869@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
11870sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
11871A floating-point constant may also end with a letter @samp{f} or
11872@samp{F}, specifying that the constant should be treated as being of
11873the @code{float} (as opposed to the default @code{double}) type; or with
11874a letter @samp{l} or @samp{L}, which specifies a @code{long double}
11875constant.
c906108c
SS
11876
11877@item
11878Enumerated constants consist of enumerated identifiers, or their
11879integral equivalents.
11880
11881@item
11882Character constants are a single character surrounded by single quotes
11883(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 11884(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
11885be represented by a letter or by @dfn{escape sequences}, which are of
11886the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
11887of the character's ordinal value; or of the form @samp{\@var{x}}, where
11888@samp{@var{x}} is a predefined special character---for example,
11889@samp{\n} for newline.
11890
11891@item
96a2c332
SS
11892String constants are a sequence of character constants surrounded by
11893double quotes (@code{"}). Any valid character constant (as described
11894above) may appear. Double quotes within the string must be preceded by
11895a backslash, so for instance @samp{"a\"b'c"} is a string of five
11896characters.
c906108c
SS
11897
11898@item
11899Pointer constants are an integral value. You can also write pointers
11900to constants using the C operator @samp{&}.
11901
11902@item
11903Array constants are comma-separated lists surrounded by braces @samp{@{}
11904and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
11905integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
11906and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
11907@end itemize
11908
79a6e687
BW
11909@node C Plus Plus Expressions
11910@subsubsection C@t{++} Expressions
b37052ae
EZ
11911
11912@cindex expressions in C@t{++}
11913@value{GDBN} expression handling can interpret most C@t{++} expressions.
11914
0179ffac
DC
11915@cindex debugging C@t{++} programs
11916@cindex C@t{++} compilers
11917@cindex debug formats and C@t{++}
11918@cindex @value{NGCC} and C@t{++}
c906108c 11919@quotation
b37052ae 11920@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
11921proper compiler and the proper debug format. Currently, @value{GDBN}
11922works best when debugging C@t{++} code that is compiled with
11923@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
11924@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
11925stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
11926stabs+ as their default debug format, so you usually don't need to
11927specify a debug format explicitly. Other compilers and/or debug formats
11928are likely to work badly or not at all when using @value{GDBN} to debug
11929C@t{++} code.
c906108c 11930@end quotation
c906108c
SS
11931
11932@enumerate
11933
11934@cindex member functions
11935@item
11936Member function calls are allowed; you can use expressions like
11937
474c8240 11938@smallexample
c906108c 11939count = aml->GetOriginal(x, y)
474c8240 11940@end smallexample
c906108c 11941
41afff9a 11942@vindex this@r{, inside C@t{++} member functions}
b37052ae 11943@cindex namespace in C@t{++}
c906108c
SS
11944@item
11945While a member function is active (in the selected stack frame), your
11946expressions have the same namespace available as the member function;
11947that is, @value{GDBN} allows implicit references to the class instance
b37052ae 11948pointer @code{this} following the same rules as C@t{++}.
c906108c 11949
c906108c 11950@cindex call overloaded functions
d4f3574e 11951@cindex overloaded functions, calling
b37052ae 11952@cindex type conversions in C@t{++}
c906108c
SS
11953@item
11954You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 11955call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
11956perform overload resolution involving user-defined type conversions,
11957calls to constructors, or instantiations of templates that do not exist
11958in the program. It also cannot handle ellipsis argument lists or
11959default arguments.
11960
11961It does perform integral conversions and promotions, floating-point
11962promotions, arithmetic conversions, pointer conversions, conversions of
11963class objects to base classes, and standard conversions such as those of
11964functions or arrays to pointers; it requires an exact match on the
11965number of function arguments.
11966
11967Overload resolution is always performed, unless you have specified
79a6e687
BW
11968@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
11969,@value{GDBN} Features for C@t{++}}.
c906108c 11970
d4f3574e 11971You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
11972explicit function signature to call an overloaded function, as in
11973@smallexample
11974p 'foo(char,int)'('x', 13)
11975@end smallexample
d4f3574e 11976
c906108c 11977The @value{GDBN} command-completion facility can simplify this;
79a6e687 11978see @ref{Completion, ,Command Completion}.
c906108c 11979
c906108c
SS
11980@cindex reference declarations
11981@item
b37052ae
EZ
11982@value{GDBN} understands variables declared as C@t{++} references; you can use
11983them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
11984dereferenced.
11985
11986In the parameter list shown when @value{GDBN} displays a frame, the values of
11987reference variables are not displayed (unlike other variables); this
11988avoids clutter, since references are often used for large structures.
11989The @emph{address} of a reference variable is always shown, unless
11990you have specified @samp{set print address off}.
11991
11992@item
b37052ae 11993@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
11994expressions can use it just as expressions in your program do. Since
11995one scope may be defined in another, you can use @code{::} repeatedly if
11996necessary, for example in an expression like
11997@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 11998resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 11999debugging (@pxref{Variables, ,Program Variables}).
c906108c
SS
12000@end enumerate
12001
b37052ae 12002In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
12003calling virtual functions correctly, printing out virtual bases of
12004objects, calling functions in a base subobject, casting objects, and
12005invoking user-defined operators.
c906108c 12006
6d2ebf8b 12007@node C Defaults
79a6e687 12008@subsubsection C and C@t{++} Defaults
7a292a7a 12009
b37052ae 12010@cindex C and C@t{++} defaults
c906108c 12011
c906108c
SS
12012If you allow @value{GDBN} to set type and range checking automatically, they
12013both default to @code{off} whenever the working language changes to
b37052ae 12014C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 12015selects the working language.
c906108c
SS
12016
12017If you allow @value{GDBN} to set the language automatically, it
12018recognizes source files whose names end with @file{.c}, @file{.C}, or
12019@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 12020these files, it sets the working language to C or C@t{++}.
79a6e687 12021@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
12022for further details.
12023
c906108c
SS
12024@c Type checking is (a) primarily motivated by Modula-2, and (b)
12025@c unimplemented. If (b) changes, it might make sense to let this node
12026@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 12027
6d2ebf8b 12028@node C Checks
79a6e687 12029@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 12030
b37052ae 12031@cindex C and C@t{++} checks
c906108c 12032
b37052ae 12033By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
12034is not used. However, if you turn type checking on, @value{GDBN}
12035considers two variables type equivalent if:
12036
12037@itemize @bullet
12038@item
12039The two variables are structured and have the same structure, union, or
12040enumerated tag.
12041
12042@item
12043The two variables have the same type name, or types that have been
12044declared equivalent through @code{typedef}.
12045
12046@ignore
12047@c leaving this out because neither J Gilmore nor R Pesch understand it.
12048@c FIXME--beers?
12049@item
12050The two @code{struct}, @code{union}, or @code{enum} variables are
12051declared in the same declaration. (Note: this may not be true for all C
12052compilers.)
12053@end ignore
12054@end itemize
12055
12056Range checking, if turned on, is done on mathematical operations. Array
12057indices are not checked, since they are often used to index a pointer
12058that is not itself an array.
c906108c 12059
6d2ebf8b 12060@node Debugging C
c906108c 12061@subsubsection @value{GDBN} and C
c906108c
SS
12062
12063The @code{set print union} and @code{show print union} commands apply to
12064the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
12065inside a @code{struct} or @code{class} is also printed. Otherwise, it
12066appears as @samp{@{...@}}.
c906108c
SS
12067
12068The @code{@@} operator aids in the debugging of dynamic arrays, formed
12069with pointers and a memory allocation function. @xref{Expressions,
12070,Expressions}.
12071
79a6e687
BW
12072@node Debugging C Plus Plus
12073@subsubsection @value{GDBN} Features for C@t{++}
c906108c 12074
b37052ae 12075@cindex commands for C@t{++}
7a292a7a 12076
b37052ae
EZ
12077Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
12078designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
12079
12080@table @code
12081@cindex break in overloaded functions
12082@item @r{breakpoint menus}
12083When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
12084@value{GDBN} has the capability to display a menu of possible breakpoint
12085locations to help you specify which function definition you want.
12086@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 12087
b37052ae 12088@cindex overloading in C@t{++}
c906108c
SS
12089@item rbreak @var{regex}
12090Setting breakpoints using regular expressions is helpful for setting
12091breakpoints on overloaded functions that are not members of any special
12092classes.
79a6e687 12093@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 12094
b37052ae 12095@cindex C@t{++} exception handling
c906108c
SS
12096@item catch throw
12097@itemx catch catch
b37052ae 12098Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 12099Catchpoints, , Setting Catchpoints}.
c906108c
SS
12100
12101@cindex inheritance
12102@item ptype @var{typename}
12103Print inheritance relationships as well as other information for type
12104@var{typename}.
12105@xref{Symbols, ,Examining the Symbol Table}.
12106
b37052ae 12107@cindex C@t{++} symbol display
c906108c
SS
12108@item set print demangle
12109@itemx show print demangle
12110@itemx set print asm-demangle
12111@itemx show print asm-demangle
b37052ae
EZ
12112Control whether C@t{++} symbols display in their source form, both when
12113displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 12114@xref{Print Settings, ,Print Settings}.
c906108c
SS
12115
12116@item set print object
12117@itemx show print object
12118Choose whether to print derived (actual) or declared types of objects.
79a6e687 12119@xref{Print Settings, ,Print Settings}.
c906108c
SS
12120
12121@item set print vtbl
12122@itemx show print vtbl
12123Control the format for printing virtual function tables.
79a6e687 12124@xref{Print Settings, ,Print Settings}.
c906108c 12125(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 12126ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
12127
12128@kindex set overload-resolution
d4f3574e 12129@cindex overloaded functions, overload resolution
c906108c 12130@item set overload-resolution on
b37052ae 12131Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
12132is on. For overloaded functions, @value{GDBN} evaluates the arguments
12133and searches for a function whose signature matches the argument types,
79a6e687
BW
12134using the standard C@t{++} conversion rules (see @ref{C Plus Plus
12135Expressions, ,C@t{++} Expressions}, for details).
12136If it cannot find a match, it emits a message.
c906108c
SS
12137
12138@item set overload-resolution off
b37052ae 12139Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
12140overloaded functions that are not class member functions, @value{GDBN}
12141chooses the first function of the specified name that it finds in the
12142symbol table, whether or not its arguments are of the correct type. For
12143overloaded functions that are class member functions, @value{GDBN}
12144searches for a function whose signature @emph{exactly} matches the
12145argument types.
c906108c 12146
9c16f35a
EZ
12147@kindex show overload-resolution
12148@item show overload-resolution
12149Show the current setting of overload resolution.
12150
c906108c
SS
12151@item @r{Overloaded symbol names}
12152You can specify a particular definition of an overloaded symbol, using
b37052ae 12153the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
12154@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
12155also use the @value{GDBN} command-line word completion facilities to list the
12156available choices, or to finish the type list for you.
79a6e687 12157@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 12158@end table
c906108c 12159
febe4383
TJB
12160@node Decimal Floating Point
12161@subsubsection Decimal Floating Point format
12162@cindex decimal floating point format
12163
12164@value{GDBN} can examine, set and perform computations with numbers in
12165decimal floating point format, which in the C language correspond to the
12166@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
12167specified by the extension to support decimal floating-point arithmetic.
12168
12169There are two encodings in use, depending on the architecture: BID (Binary
12170Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
99e008fe 12171PowerPC. @value{GDBN} will use the appropriate encoding for the configured
febe4383
TJB
12172target.
12173
12174Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
12175to manipulate decimal floating point numbers, it is not possible to convert
12176(using a cast, for example) integers wider than 32-bit to decimal float.
12177
12178In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
12179point computations, error checking in decimal float operations ignores
12180underflow, overflow and divide by zero exceptions.
12181
4acd40f3 12182In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
12183to inspect @code{_Decimal128} values stored in floating point registers.
12184See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 12185
6aecb9c2
JB
12186@node D
12187@subsection D
12188
12189@cindex D
12190@value{GDBN} can be used to debug programs written in D and compiled with
12191GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
12192specific feature --- dynamic arrays.
12193
b37303ee
AF
12194@node Objective-C
12195@subsection Objective-C
12196
12197@cindex Objective-C
12198This section provides information about some commands and command
721c2651
EZ
12199options that are useful for debugging Objective-C code. See also
12200@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
12201few more commands specific to Objective-C support.
b37303ee
AF
12202
12203@menu
b383017d
RM
12204* Method Names in Commands::
12205* The Print Command with Objective-C::
b37303ee
AF
12206@end menu
12207
c8f4133a 12208@node Method Names in Commands
b37303ee
AF
12209@subsubsection Method Names in Commands
12210
12211The following commands have been extended to accept Objective-C method
12212names as line specifications:
12213
12214@kindex clear@r{, and Objective-C}
12215@kindex break@r{, and Objective-C}
12216@kindex info line@r{, and Objective-C}
12217@kindex jump@r{, and Objective-C}
12218@kindex list@r{, and Objective-C}
12219@itemize
12220@item @code{clear}
12221@item @code{break}
12222@item @code{info line}
12223@item @code{jump}
12224@item @code{list}
12225@end itemize
12226
12227A fully qualified Objective-C method name is specified as
12228
12229@smallexample
12230-[@var{Class} @var{methodName}]
12231@end smallexample
12232
c552b3bb
JM
12233where the minus sign is used to indicate an instance method and a
12234plus sign (not shown) is used to indicate a class method. The class
12235name @var{Class} and method name @var{methodName} are enclosed in
12236brackets, similar to the way messages are specified in Objective-C
12237source code. For example, to set a breakpoint at the @code{create}
12238instance method of class @code{Fruit} in the program currently being
12239debugged, enter:
b37303ee
AF
12240
12241@smallexample
12242break -[Fruit create]
12243@end smallexample
12244
12245To list ten program lines around the @code{initialize} class method,
12246enter:
12247
12248@smallexample
12249list +[NSText initialize]
12250@end smallexample
12251
c552b3bb
JM
12252In the current version of @value{GDBN}, the plus or minus sign is
12253required. In future versions of @value{GDBN}, the plus or minus
12254sign will be optional, but you can use it to narrow the search. It
12255is also possible to specify just a method name:
b37303ee
AF
12256
12257@smallexample
12258break create
12259@end smallexample
12260
12261You must specify the complete method name, including any colons. If
12262your program's source files contain more than one @code{create} method,
12263you'll be presented with a numbered list of classes that implement that
12264method. Indicate your choice by number, or type @samp{0} to exit if
12265none apply.
12266
12267As another example, to clear a breakpoint established at the
12268@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
12269
12270@smallexample
12271clear -[NSWindow makeKeyAndOrderFront:]
12272@end smallexample
12273
12274@node The Print Command with Objective-C
12275@subsubsection The Print Command With Objective-C
721c2651 12276@cindex Objective-C, print objects
c552b3bb
JM
12277@kindex print-object
12278@kindex po @r{(@code{print-object})}
b37303ee 12279
c552b3bb 12280The print command has also been extended to accept methods. For example:
b37303ee
AF
12281
12282@smallexample
c552b3bb 12283print -[@var{object} hash]
b37303ee
AF
12284@end smallexample
12285
12286@cindex print an Objective-C object description
c552b3bb
JM
12287@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
12288@noindent
12289will tell @value{GDBN} to send the @code{hash} message to @var{object}
12290and print the result. Also, an additional command has been added,
12291@code{print-object} or @code{po} for short, which is meant to print
12292the description of an object. However, this command may only work
12293with certain Objective-C libraries that have a particular hook
12294function, @code{_NSPrintForDebugger}, defined.
b37303ee 12295
f4b8a18d
KW
12296@node OpenCL C
12297@subsection OpenCL C
12298
12299@cindex OpenCL C
12300This section provides information about @value{GDBN}s OpenCL C support.
12301
12302@menu
12303* OpenCL C Datatypes::
12304* OpenCL C Expressions::
12305* OpenCL C Operators::
12306@end menu
12307
12308@node OpenCL C Datatypes
12309@subsubsection OpenCL C Datatypes
12310
12311@cindex OpenCL C Datatypes
12312@value{GDBN} supports the builtin scalar and vector datatypes specified
12313by OpenCL 1.1. In addition the half- and double-precision floating point
12314data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
12315extensions are also known to @value{GDBN}.
12316
12317@node OpenCL C Expressions
12318@subsubsection OpenCL C Expressions
12319
12320@cindex OpenCL C Expressions
12321@value{GDBN} supports accesses to vector components including the access as
12322lvalue where possible. Since OpenCL C is based on C99 most C expressions
12323supported by @value{GDBN} can be used as well.
12324
12325@node OpenCL C Operators
12326@subsubsection OpenCL C Operators
12327
12328@cindex OpenCL C Operators
12329@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
12330vector data types.
12331
09d4efe1
EZ
12332@node Fortran
12333@subsection Fortran
12334@cindex Fortran-specific support in @value{GDBN}
12335
814e32d7
WZ
12336@value{GDBN} can be used to debug programs written in Fortran, but it
12337currently supports only the features of Fortran 77 language.
12338
12339@cindex trailing underscore, in Fortran symbols
12340Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
12341among them) append an underscore to the names of variables and
12342functions. When you debug programs compiled by those compilers, you
12343will need to refer to variables and functions with a trailing
12344underscore.
12345
12346@menu
12347* Fortran Operators:: Fortran operators and expressions
12348* Fortran Defaults:: Default settings for Fortran
79a6e687 12349* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
12350@end menu
12351
12352@node Fortran Operators
79a6e687 12353@subsubsection Fortran Operators and Expressions
814e32d7
WZ
12354
12355@cindex Fortran operators and expressions
12356
12357Operators must be defined on values of specific types. For instance,
12358@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 12359arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
12360
12361@table @code
12362@item **
99e008fe 12363The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
12364of the second one.
12365
12366@item :
12367The range operator. Normally used in the form of array(low:high) to
12368represent a section of array.
68837c9d
MD
12369
12370@item %
12371The access component operator. Normally used to access elements in derived
12372types. Also suitable for unions. As unions aren't part of regular Fortran,
12373this can only happen when accessing a register that uses a gdbarch-defined
12374union type.
814e32d7
WZ
12375@end table
12376
12377@node Fortran Defaults
12378@subsubsection Fortran Defaults
12379
12380@cindex Fortran Defaults
12381
12382Fortran symbols are usually case-insensitive, so @value{GDBN} by
12383default uses case-insensitive matches for Fortran symbols. You can
12384change that with the @samp{set case-insensitive} command, see
12385@ref{Symbols}, for the details.
12386
79a6e687
BW
12387@node Special Fortran Commands
12388@subsubsection Special Fortran Commands
814e32d7
WZ
12389
12390@cindex Special Fortran commands
12391
db2e3e2e
BW
12392@value{GDBN} has some commands to support Fortran-specific features,
12393such as displaying common blocks.
814e32d7 12394
09d4efe1
EZ
12395@table @code
12396@cindex @code{COMMON} blocks, Fortran
12397@kindex info common
12398@item info common @r{[}@var{common-name}@r{]}
12399This command prints the values contained in the Fortran @code{COMMON}
12400block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 12401all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
12402printed.
12403@end table
12404
9c16f35a
EZ
12405@node Pascal
12406@subsection Pascal
12407
12408@cindex Pascal support in @value{GDBN}, limitations
12409Debugging Pascal programs which use sets, subranges, file variables, or
12410nested functions does not currently work. @value{GDBN} does not support
12411entering expressions, printing values, or similar features using Pascal
12412syntax.
12413
12414The Pascal-specific command @code{set print pascal_static-members}
12415controls whether static members of Pascal objects are displayed.
12416@xref{Print Settings, pascal_static-members}.
12417
09d4efe1 12418@node Modula-2
c906108c 12419@subsection Modula-2
7a292a7a 12420
d4f3574e 12421@cindex Modula-2, @value{GDBN} support
c906108c
SS
12422
12423The extensions made to @value{GDBN} to support Modula-2 only support
12424output from the @sc{gnu} Modula-2 compiler (which is currently being
12425developed). Other Modula-2 compilers are not currently supported, and
12426attempting to debug executables produced by them is most likely
12427to give an error as @value{GDBN} reads in the executable's symbol
12428table.
12429
12430@cindex expressions in Modula-2
12431@menu
12432* M2 Operators:: Built-in operators
12433* Built-In Func/Proc:: Built-in functions and procedures
12434* M2 Constants:: Modula-2 constants
72019c9c 12435* M2 Types:: Modula-2 types
c906108c
SS
12436* M2 Defaults:: Default settings for Modula-2
12437* Deviations:: Deviations from standard Modula-2
12438* M2 Checks:: Modula-2 type and range checks
12439* M2 Scope:: The scope operators @code{::} and @code{.}
12440* GDB/M2:: @value{GDBN} and Modula-2
12441@end menu
12442
6d2ebf8b 12443@node M2 Operators
c906108c
SS
12444@subsubsection Operators
12445@cindex Modula-2 operators
12446
12447Operators must be defined on values of specific types. For instance,
12448@code{+} is defined on numbers, but not on structures. Operators are
12449often defined on groups of types. For the purposes of Modula-2, the
12450following definitions hold:
12451
12452@itemize @bullet
12453
12454@item
12455@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
12456their subranges.
12457
12458@item
12459@emph{Character types} consist of @code{CHAR} and its subranges.
12460
12461@item
12462@emph{Floating-point types} consist of @code{REAL}.
12463
12464@item
12465@emph{Pointer types} consist of anything declared as @code{POINTER TO
12466@var{type}}.
12467
12468@item
12469@emph{Scalar types} consist of all of the above.
12470
12471@item
12472@emph{Set types} consist of @code{SET} and @code{BITSET} types.
12473
12474@item
12475@emph{Boolean types} consist of @code{BOOLEAN}.
12476@end itemize
12477
12478@noindent
12479The following operators are supported, and appear in order of
12480increasing precedence:
12481
12482@table @code
12483@item ,
12484Function argument or array index separator.
12485
12486@item :=
12487Assignment. The value of @var{var} @code{:=} @var{value} is
12488@var{value}.
12489
12490@item <@r{, }>
12491Less than, greater than on integral, floating-point, or enumerated
12492types.
12493
12494@item <=@r{, }>=
96a2c332 12495Less than or equal to, greater than or equal to
c906108c
SS
12496on integral, floating-point and enumerated types, or set inclusion on
12497set types. Same precedence as @code{<}.
12498
12499@item =@r{, }<>@r{, }#
12500Equality and two ways of expressing inequality, valid on scalar types.
12501Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
12502available for inequality, since @code{#} conflicts with the script
12503comment character.
12504
12505@item IN
12506Set membership. Defined on set types and the types of their members.
12507Same precedence as @code{<}.
12508
12509@item OR
12510Boolean disjunction. Defined on boolean types.
12511
12512@item AND@r{, }&
d4f3574e 12513Boolean conjunction. Defined on boolean types.
c906108c
SS
12514
12515@item @@
12516The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
12517
12518@item +@r{, }-
12519Addition and subtraction on integral and floating-point types, or union
12520and difference on set types.
12521
12522@item *
12523Multiplication on integral and floating-point types, or set intersection
12524on set types.
12525
12526@item /
12527Division on floating-point types, or symmetric set difference on set
12528types. Same precedence as @code{*}.
12529
12530@item DIV@r{, }MOD
12531Integer division and remainder. Defined on integral types. Same
12532precedence as @code{*}.
12533
12534@item -
99e008fe 12535Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
12536
12537@item ^
12538Pointer dereferencing. Defined on pointer types.
12539
12540@item NOT
12541Boolean negation. Defined on boolean types. Same precedence as
12542@code{^}.
12543
12544@item .
12545@code{RECORD} field selector. Defined on @code{RECORD} data. Same
12546precedence as @code{^}.
12547
12548@item []
12549Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
12550
12551@item ()
12552Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
12553as @code{^}.
12554
12555@item ::@r{, }.
12556@value{GDBN} and Modula-2 scope operators.
12557@end table
12558
12559@quotation
72019c9c 12560@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
12561treats the use of the operator @code{IN}, or the use of operators
12562@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
12563@code{<=}, and @code{>=} on sets as an error.
12564@end quotation
12565
cb51c4e0 12566
6d2ebf8b 12567@node Built-In Func/Proc
79a6e687 12568@subsubsection Built-in Functions and Procedures
cb51c4e0 12569@cindex Modula-2 built-ins
c906108c
SS
12570
12571Modula-2 also makes available several built-in procedures and functions.
12572In describing these, the following metavariables are used:
12573
12574@table @var
12575
12576@item a
12577represents an @code{ARRAY} variable.
12578
12579@item c
12580represents a @code{CHAR} constant or variable.
12581
12582@item i
12583represents a variable or constant of integral type.
12584
12585@item m
12586represents an identifier that belongs to a set. Generally used in the
12587same function with the metavariable @var{s}. The type of @var{s} should
12588be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
12589
12590@item n
12591represents a variable or constant of integral or floating-point type.
12592
12593@item r
12594represents a variable or constant of floating-point type.
12595
12596@item t
12597represents a type.
12598
12599@item v
12600represents a variable.
12601
12602@item x
12603represents a variable or constant of one of many types. See the
12604explanation of the function for details.
12605@end table
12606
12607All Modula-2 built-in procedures also return a result, described below.
12608
12609@table @code
12610@item ABS(@var{n})
12611Returns the absolute value of @var{n}.
12612
12613@item CAP(@var{c})
12614If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 12615equivalent, otherwise it returns its argument.
c906108c
SS
12616
12617@item CHR(@var{i})
12618Returns the character whose ordinal value is @var{i}.
12619
12620@item DEC(@var{v})
c3f6f71d 12621Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
12622
12623@item DEC(@var{v},@var{i})
12624Decrements the value in the variable @var{v} by @var{i}. Returns the
12625new value.
12626
12627@item EXCL(@var{m},@var{s})
12628Removes the element @var{m} from the set @var{s}. Returns the new
12629set.
12630
12631@item FLOAT(@var{i})
12632Returns the floating point equivalent of the integer @var{i}.
12633
12634@item HIGH(@var{a})
12635Returns the index of the last member of @var{a}.
12636
12637@item INC(@var{v})
c3f6f71d 12638Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
12639
12640@item INC(@var{v},@var{i})
12641Increments the value in the variable @var{v} by @var{i}. Returns the
12642new value.
12643
12644@item INCL(@var{m},@var{s})
12645Adds the element @var{m} to the set @var{s} if it is not already
12646there. Returns the new set.
12647
12648@item MAX(@var{t})
12649Returns the maximum value of the type @var{t}.
12650
12651@item MIN(@var{t})
12652Returns the minimum value of the type @var{t}.
12653
12654@item ODD(@var{i})
12655Returns boolean TRUE if @var{i} is an odd number.
12656
12657@item ORD(@var{x})
12658Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
12659value of a character is its @sc{ascii} value (on machines supporting the
12660@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
12661integral, character and enumerated types.
12662
12663@item SIZE(@var{x})
12664Returns the size of its argument. @var{x} can be a variable or a type.
12665
12666@item TRUNC(@var{r})
12667Returns the integral part of @var{r}.
12668
844781a1
GM
12669@item TSIZE(@var{x})
12670Returns the size of its argument. @var{x} can be a variable or a type.
12671
c906108c
SS
12672@item VAL(@var{t},@var{i})
12673Returns the member of the type @var{t} whose ordinal value is @var{i}.
12674@end table
12675
12676@quotation
12677@emph{Warning:} Sets and their operations are not yet supported, so
12678@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
12679an error.
12680@end quotation
12681
12682@cindex Modula-2 constants
6d2ebf8b 12683@node M2 Constants
c906108c
SS
12684@subsubsection Constants
12685
12686@value{GDBN} allows you to express the constants of Modula-2 in the following
12687ways:
12688
12689@itemize @bullet
12690
12691@item
12692Integer constants are simply a sequence of digits. When used in an
12693expression, a constant is interpreted to be type-compatible with the
12694rest of the expression. Hexadecimal integers are specified by a
12695trailing @samp{H}, and octal integers by a trailing @samp{B}.
12696
12697@item
12698Floating point constants appear as a sequence of digits, followed by a
12699decimal point and another sequence of digits. An optional exponent can
12700then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
12701@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
12702digits of the floating point constant must be valid decimal (base 10)
12703digits.
12704
12705@item
12706Character constants consist of a single character enclosed by a pair of
12707like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 12708also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
12709followed by a @samp{C}.
12710
12711@item
12712String constants consist of a sequence of characters enclosed by a
12713pair of like quotes, either single (@code{'}) or double (@code{"}).
12714Escape sequences in the style of C are also allowed. @xref{C
79a6e687 12715Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
12716sequences.
12717
12718@item
12719Enumerated constants consist of an enumerated identifier.
12720
12721@item
12722Boolean constants consist of the identifiers @code{TRUE} and
12723@code{FALSE}.
12724
12725@item
12726Pointer constants consist of integral values only.
12727
12728@item
12729Set constants are not yet supported.
12730@end itemize
12731
72019c9c
GM
12732@node M2 Types
12733@subsubsection Modula-2 Types
12734@cindex Modula-2 types
12735
12736Currently @value{GDBN} can print the following data types in Modula-2
12737syntax: array types, record types, set types, pointer types, procedure
12738types, enumerated types, subrange types and base types. You can also
12739print the contents of variables declared using these type.
12740This section gives a number of simple source code examples together with
12741sample @value{GDBN} sessions.
12742
12743The first example contains the following section of code:
12744
12745@smallexample
12746VAR
12747 s: SET OF CHAR ;
12748 r: [20..40] ;
12749@end smallexample
12750
12751@noindent
12752and you can request @value{GDBN} to interrogate the type and value of
12753@code{r} and @code{s}.
12754
12755@smallexample
12756(@value{GDBP}) print s
12757@{'A'..'C', 'Z'@}
12758(@value{GDBP}) ptype s
12759SET OF CHAR
12760(@value{GDBP}) print r
1276121
12762(@value{GDBP}) ptype r
12763[20..40]
12764@end smallexample
12765
12766@noindent
12767Likewise if your source code declares @code{s} as:
12768
12769@smallexample
12770VAR
12771 s: SET ['A'..'Z'] ;
12772@end smallexample
12773
12774@noindent
12775then you may query the type of @code{s} by:
12776
12777@smallexample
12778(@value{GDBP}) ptype s
12779type = SET ['A'..'Z']
12780@end smallexample
12781
12782@noindent
12783Note that at present you cannot interactively manipulate set
12784expressions using the debugger.
12785
12786The following example shows how you might declare an array in Modula-2
12787and how you can interact with @value{GDBN} to print its type and contents:
12788
12789@smallexample
12790VAR
12791 s: ARRAY [-10..10] OF CHAR ;
12792@end smallexample
12793
12794@smallexample
12795(@value{GDBP}) ptype s
12796ARRAY [-10..10] OF CHAR
12797@end smallexample
12798
12799Note that the array handling is not yet complete and although the type
12800is printed correctly, expression handling still assumes that all
12801arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 12802above.
72019c9c
GM
12803
12804Here are some more type related Modula-2 examples:
12805
12806@smallexample
12807TYPE
12808 colour = (blue, red, yellow, green) ;
12809 t = [blue..yellow] ;
12810VAR
12811 s: t ;
12812BEGIN
12813 s := blue ;
12814@end smallexample
12815
12816@noindent
12817The @value{GDBN} interaction shows how you can query the data type
12818and value of a variable.
12819
12820@smallexample
12821(@value{GDBP}) print s
12822$1 = blue
12823(@value{GDBP}) ptype t
12824type = [blue..yellow]
12825@end smallexample
12826
12827@noindent
12828In this example a Modula-2 array is declared and its contents
12829displayed. Observe that the contents are written in the same way as
12830their @code{C} counterparts.
12831
12832@smallexample
12833VAR
12834 s: ARRAY [1..5] OF CARDINAL ;
12835BEGIN
12836 s[1] := 1 ;
12837@end smallexample
12838
12839@smallexample
12840(@value{GDBP}) print s
12841$1 = @{1, 0, 0, 0, 0@}
12842(@value{GDBP}) ptype s
12843type = ARRAY [1..5] OF CARDINAL
12844@end smallexample
12845
12846The Modula-2 language interface to @value{GDBN} also understands
12847pointer types as shown in this example:
12848
12849@smallexample
12850VAR
12851 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
12852BEGIN
12853 NEW(s) ;
12854 s^[1] := 1 ;
12855@end smallexample
12856
12857@noindent
12858and you can request that @value{GDBN} describes the type of @code{s}.
12859
12860@smallexample
12861(@value{GDBP}) ptype s
12862type = POINTER TO ARRAY [1..5] OF CARDINAL
12863@end smallexample
12864
12865@value{GDBN} handles compound types as we can see in this example.
12866Here we combine array types, record types, pointer types and subrange
12867types:
12868
12869@smallexample
12870TYPE
12871 foo = RECORD
12872 f1: CARDINAL ;
12873 f2: CHAR ;
12874 f3: myarray ;
12875 END ;
12876
12877 myarray = ARRAY myrange OF CARDINAL ;
12878 myrange = [-2..2] ;
12879VAR
12880 s: POINTER TO ARRAY myrange OF foo ;
12881@end smallexample
12882
12883@noindent
12884and you can ask @value{GDBN} to describe the type of @code{s} as shown
12885below.
12886
12887@smallexample
12888(@value{GDBP}) ptype s
12889type = POINTER TO ARRAY [-2..2] OF foo = RECORD
12890 f1 : CARDINAL;
12891 f2 : CHAR;
12892 f3 : ARRAY [-2..2] OF CARDINAL;
12893END
12894@end smallexample
12895
6d2ebf8b 12896@node M2 Defaults
79a6e687 12897@subsubsection Modula-2 Defaults
c906108c
SS
12898@cindex Modula-2 defaults
12899
12900If type and range checking are set automatically by @value{GDBN}, they
12901both default to @code{on} whenever the working language changes to
d4f3574e 12902Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
12903selected the working language.
12904
12905If you allow @value{GDBN} to set the language automatically, then entering
12906code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
12907working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
12908Infer the Source Language}, for further details.
c906108c 12909
6d2ebf8b 12910@node Deviations
79a6e687 12911@subsubsection Deviations from Standard Modula-2
c906108c
SS
12912@cindex Modula-2, deviations from
12913
12914A few changes have been made to make Modula-2 programs easier to debug.
12915This is done primarily via loosening its type strictness:
12916
12917@itemize @bullet
12918@item
12919Unlike in standard Modula-2, pointer constants can be formed by
12920integers. This allows you to modify pointer variables during
12921debugging. (In standard Modula-2, the actual address contained in a
12922pointer variable is hidden from you; it can only be modified
12923through direct assignment to another pointer variable or expression that
12924returned a pointer.)
12925
12926@item
12927C escape sequences can be used in strings and characters to represent
12928non-printable characters. @value{GDBN} prints out strings with these
12929escape sequences embedded. Single non-printable characters are
12930printed using the @samp{CHR(@var{nnn})} format.
12931
12932@item
12933The assignment operator (@code{:=}) returns the value of its right-hand
12934argument.
12935
12936@item
12937All built-in procedures both modify @emph{and} return their argument.
12938@end itemize
12939
6d2ebf8b 12940@node M2 Checks
79a6e687 12941@subsubsection Modula-2 Type and Range Checks
c906108c
SS
12942@cindex Modula-2 checks
12943
12944@quotation
12945@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
12946range checking.
12947@end quotation
12948@c FIXME remove warning when type/range checks added
12949
12950@value{GDBN} considers two Modula-2 variables type equivalent if:
12951
12952@itemize @bullet
12953@item
12954They are of types that have been declared equivalent via a @code{TYPE
12955@var{t1} = @var{t2}} statement
12956
12957@item
12958They have been declared on the same line. (Note: This is true of the
12959@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
12960@end itemize
12961
12962As long as type checking is enabled, any attempt to combine variables
12963whose types are not equivalent is an error.
12964
12965Range checking is done on all mathematical operations, assignment, array
12966index bounds, and all built-in functions and procedures.
12967
6d2ebf8b 12968@node M2 Scope
79a6e687 12969@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 12970@cindex scope
41afff9a 12971@cindex @code{.}, Modula-2 scope operator
c906108c
SS
12972@cindex colon, doubled as scope operator
12973@ifinfo
41afff9a 12974@vindex colon-colon@r{, in Modula-2}
c906108c
SS
12975@c Info cannot handle :: but TeX can.
12976@end ifinfo
a67ec3f4 12977@ifnotinfo
41afff9a 12978@vindex ::@r{, in Modula-2}
a67ec3f4 12979@end ifnotinfo
c906108c
SS
12980
12981There are a few subtle differences between the Modula-2 scope operator
12982(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
12983similar syntax:
12984
474c8240 12985@smallexample
c906108c
SS
12986
12987@var{module} . @var{id}
12988@var{scope} :: @var{id}
474c8240 12989@end smallexample
c906108c
SS
12990
12991@noindent
12992where @var{scope} is the name of a module or a procedure,
12993@var{module} the name of a module, and @var{id} is any declared
12994identifier within your program, except another module.
12995
12996Using the @code{::} operator makes @value{GDBN} search the scope
12997specified by @var{scope} for the identifier @var{id}. If it is not
12998found in the specified scope, then @value{GDBN} searches all scopes
12999enclosing the one specified by @var{scope}.
13000
13001Using the @code{.} operator makes @value{GDBN} search the current scope for
13002the identifier specified by @var{id} that was imported from the
13003definition module specified by @var{module}. With this operator, it is
13004an error if the identifier @var{id} was not imported from definition
13005module @var{module}, or if @var{id} is not an identifier in
13006@var{module}.
13007
6d2ebf8b 13008@node GDB/M2
c906108c
SS
13009@subsubsection @value{GDBN} and Modula-2
13010
13011Some @value{GDBN} commands have little use when debugging Modula-2 programs.
13012Five subcommands of @code{set print} and @code{show print} apply
b37052ae 13013specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 13014@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 13015apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
13016analogue in Modula-2.
13017
13018The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 13019with any language, is not useful with Modula-2. Its
c906108c 13020intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 13021created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 13022address can be specified by an integral constant, the construct
d4f3574e 13023@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
13024
13025@cindex @code{#} in Modula-2
13026In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
13027interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 13028
e07c999f
PH
13029@node Ada
13030@subsection Ada
13031@cindex Ada
13032
13033The extensions made to @value{GDBN} for Ada only support
13034output from the @sc{gnu} Ada (GNAT) compiler.
13035Other Ada compilers are not currently supported, and
13036attempting to debug executables produced by them is most likely
13037to be difficult.
13038
13039
13040@cindex expressions in Ada
13041@menu
13042* Ada Mode Intro:: General remarks on the Ada syntax
13043 and semantics supported by Ada mode
13044 in @value{GDBN}.
13045* Omissions from Ada:: Restrictions on the Ada expression syntax.
13046* Additions to Ada:: Extensions of the Ada expression syntax.
13047* Stopping Before Main Program:: Debugging the program during elaboration.
20924a55
JB
13048* Ada Tasks:: Listing and setting breakpoints in tasks.
13049* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
13050* Ravenscar Profile:: Tasking Support when using the Ravenscar
13051 Profile
e07c999f
PH
13052* Ada Glitches:: Known peculiarities of Ada mode.
13053@end menu
13054
13055@node Ada Mode Intro
13056@subsubsection Introduction
13057@cindex Ada mode, general
13058
13059The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
13060syntax, with some extensions.
13061The philosophy behind the design of this subset is
13062
13063@itemize @bullet
13064@item
13065That @value{GDBN} should provide basic literals and access to operations for
13066arithmetic, dereferencing, field selection, indexing, and subprogram calls,
13067leaving more sophisticated computations to subprograms written into the
13068program (which therefore may be called from @value{GDBN}).
13069
13070@item
13071That type safety and strict adherence to Ada language restrictions
13072are not particularly important to the @value{GDBN} user.
13073
13074@item
13075That brevity is important to the @value{GDBN} user.
13076@end itemize
13077
f3a2dd1a
JB
13078Thus, for brevity, the debugger acts as if all names declared in
13079user-written packages are directly visible, even if they are not visible
13080according to Ada rules, thus making it unnecessary to fully qualify most
13081names with their packages, regardless of context. Where this causes
13082ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
13083
13084The debugger will start in Ada mode if it detects an Ada main program.
13085As for other languages, it will enter Ada mode when stopped in a program that
13086was translated from an Ada source file.
13087
13088While in Ada mode, you may use `@t{--}' for comments. This is useful
13089mostly for documenting command files. The standard @value{GDBN} comment
13090(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
13091middle (to allow based literals).
13092
13093The debugger supports limited overloading. Given a subprogram call in which
13094the function symbol has multiple definitions, it will use the number of
13095actual parameters and some information about their types to attempt to narrow
13096the set of definitions. It also makes very limited use of context, preferring
13097procedures to functions in the context of the @code{call} command, and
13098functions to procedures elsewhere.
13099
13100@node Omissions from Ada
13101@subsubsection Omissions from Ada
13102@cindex Ada, omissions from
13103
13104Here are the notable omissions from the subset:
13105
13106@itemize @bullet
13107@item
13108Only a subset of the attributes are supported:
13109
13110@itemize @minus
13111@item
13112@t{'First}, @t{'Last}, and @t{'Length}
13113 on array objects (not on types and subtypes).
13114
13115@item
13116@t{'Min} and @t{'Max}.
13117
13118@item
13119@t{'Pos} and @t{'Val}.
13120
13121@item
13122@t{'Tag}.
13123
13124@item
13125@t{'Range} on array objects (not subtypes), but only as the right
13126operand of the membership (@code{in}) operator.
13127
13128@item
13129@t{'Access}, @t{'Unchecked_Access}, and
13130@t{'Unrestricted_Access} (a GNAT extension).
13131
13132@item
13133@t{'Address}.
13134@end itemize
13135
13136@item
13137The names in
13138@code{Characters.Latin_1} are not available and
13139concatenation is not implemented. Thus, escape characters in strings are
13140not currently available.
13141
13142@item
13143Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
13144equality of representations. They will generally work correctly
13145for strings and arrays whose elements have integer or enumeration types.
13146They may not work correctly for arrays whose element
13147types have user-defined equality, for arrays of real values
13148(in particular, IEEE-conformant floating point, because of negative
13149zeroes and NaNs), and for arrays whose elements contain unused bits with
13150indeterminate values.
13151
13152@item
13153The other component-by-component array operations (@code{and}, @code{or},
13154@code{xor}, @code{not}, and relational tests other than equality)
13155are not implemented.
13156
13157@item
860701dc
PH
13158@cindex array aggregates (Ada)
13159@cindex record aggregates (Ada)
13160@cindex aggregates (Ada)
13161There is limited support for array and record aggregates. They are
13162permitted only on the right sides of assignments, as in these examples:
13163
13164@smallexample
077e0a52
JB
13165(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
13166(@value{GDBP}) set An_Array := (1, others => 0)
13167(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
13168(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
13169(@value{GDBP}) set A_Record := (1, "Peter", True);
13170(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
13171@end smallexample
13172
13173Changing a
13174discriminant's value by assigning an aggregate has an
13175undefined effect if that discriminant is used within the record.
13176However, you can first modify discriminants by directly assigning to
13177them (which normally would not be allowed in Ada), and then performing an
13178aggregate assignment. For example, given a variable @code{A_Rec}
13179declared to have a type such as:
13180
13181@smallexample
13182type Rec (Len : Small_Integer := 0) is record
13183 Id : Integer;
13184 Vals : IntArray (1 .. Len);
13185end record;
13186@end smallexample
13187
13188you can assign a value with a different size of @code{Vals} with two
13189assignments:
13190
13191@smallexample
077e0a52
JB
13192(@value{GDBP}) set A_Rec.Len := 4
13193(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
13194@end smallexample
13195
13196As this example also illustrates, @value{GDBN} is very loose about the usual
13197rules concerning aggregates. You may leave out some of the
13198components of an array or record aggregate (such as the @code{Len}
13199component in the assignment to @code{A_Rec} above); they will retain their
13200original values upon assignment. You may freely use dynamic values as
13201indices in component associations. You may even use overlapping or
13202redundant component associations, although which component values are
13203assigned in such cases is not defined.
e07c999f
PH
13204
13205@item
13206Calls to dispatching subprograms are not implemented.
13207
13208@item
13209The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
13210than that of real Ada. It makes only limited use of the context in
13211which a subexpression appears to resolve its meaning, and it is much
13212looser in its rules for allowing type matches. As a result, some
13213function calls will be ambiguous, and the user will be asked to choose
13214the proper resolution.
e07c999f
PH
13215
13216@item
13217The @code{new} operator is not implemented.
13218
13219@item
13220Entry calls are not implemented.
13221
13222@item
13223Aside from printing, arithmetic operations on the native VAX floating-point
13224formats are not supported.
13225
13226@item
13227It is not possible to slice a packed array.
158c7665
PH
13228
13229@item
13230The names @code{True} and @code{False}, when not part of a qualified name,
13231are interpreted as if implicitly prefixed by @code{Standard}, regardless of
13232context.
13233Should your program
13234redefine these names in a package or procedure (at best a dubious practice),
13235you will have to use fully qualified names to access their new definitions.
e07c999f
PH
13236@end itemize
13237
13238@node Additions to Ada
13239@subsubsection Additions to Ada
13240@cindex Ada, deviations from
13241
13242As it does for other languages, @value{GDBN} makes certain generic
13243extensions to Ada (@pxref{Expressions}):
13244
13245@itemize @bullet
13246@item
ae21e955
BW
13247If the expression @var{E} is a variable residing in memory (typically
13248a local variable or array element) and @var{N} is a positive integer,
13249then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
13250@var{N}-1 adjacent variables following it in memory as an array. In
13251Ada, this operator is generally not necessary, since its prime use is
13252in displaying parts of an array, and slicing will usually do this in
13253Ada. However, there are occasional uses when debugging programs in
13254which certain debugging information has been optimized away.
e07c999f
PH
13255
13256@item
ae21e955
BW
13257@code{@var{B}::@var{var}} means ``the variable named @var{var} that
13258appears in function or file @var{B}.'' When @var{B} is a file name,
13259you must typically surround it in single quotes.
e07c999f
PH
13260
13261@item
13262The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
13263@var{type} that appears at address @var{addr}.''
13264
13265@item
13266A name starting with @samp{$} is a convenience variable
13267(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
13268@end itemize
13269
ae21e955
BW
13270In addition, @value{GDBN} provides a few other shortcuts and outright
13271additions specific to Ada:
e07c999f
PH
13272
13273@itemize @bullet
13274@item
13275The assignment statement is allowed as an expression, returning
13276its right-hand operand as its value. Thus, you may enter
13277
13278@smallexample
077e0a52
JB
13279(@value{GDBP}) set x := y + 3
13280(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
13281@end smallexample
13282
13283@item
13284The semicolon is allowed as an ``operator,'' returning as its value
13285the value of its right-hand operand.
13286This allows, for example,
13287complex conditional breaks:
13288
13289@smallexample
077e0a52
JB
13290(@value{GDBP}) break f
13291(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
13292@end smallexample
13293
13294@item
13295Rather than use catenation and symbolic character names to introduce special
13296characters into strings, one may instead use a special bracket notation,
13297which is also used to print strings. A sequence of characters of the form
13298@samp{["@var{XX}"]} within a string or character literal denotes the
13299(single) character whose numeric encoding is @var{XX} in hexadecimal. The
13300sequence of characters @samp{["""]} also denotes a single quotation mark
13301in strings. For example,
13302@smallexample
13303 "One line.["0a"]Next line.["0a"]"
13304@end smallexample
13305@noindent
ae21e955
BW
13306contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
13307after each period.
e07c999f
PH
13308
13309@item
13310The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
13311@t{'Max} is optional (and is ignored in any case). For example, it is valid
13312to write
13313
13314@smallexample
077e0a52 13315(@value{GDBP}) print 'max(x, y)
e07c999f
PH
13316@end smallexample
13317
13318@item
13319When printing arrays, @value{GDBN} uses positional notation when the
13320array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
13321For example, a one-dimensional array of three integers with a lower bound
13322of 3 might print as
e07c999f
PH
13323
13324@smallexample
13325(3 => 10, 17, 1)
13326@end smallexample
13327
13328@noindent
13329That is, in contrast to valid Ada, only the first component has a @code{=>}
13330clause.
13331
13332@item
13333You may abbreviate attributes in expressions with any unique,
13334multi-character subsequence of
13335their names (an exact match gets preference).
13336For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
13337in place of @t{a'length}.
13338
13339@item
13340@cindex quoting Ada internal identifiers
13341Since Ada is case-insensitive, the debugger normally maps identifiers you type
13342to lower case. The GNAT compiler uses upper-case characters for
13343some of its internal identifiers, which are normally of no interest to users.
13344For the rare occasions when you actually have to look at them,
13345enclose them in angle brackets to avoid the lower-case mapping.
13346For example,
13347@smallexample
077e0a52 13348(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
13349@end smallexample
13350
13351@item
13352Printing an object of class-wide type or dereferencing an
13353access-to-class-wide value will display all the components of the object's
13354specific type (as indicated by its run-time tag). Likewise, component
13355selection on such a value will operate on the specific type of the
13356object.
13357
13358@end itemize
13359
13360@node Stopping Before Main Program
13361@subsubsection Stopping at the Very Beginning
13362
13363@cindex breakpointing Ada elaboration code
13364It is sometimes necessary to debug the program during elaboration, and
13365before reaching the main procedure.
13366As defined in the Ada Reference
13367Manual, the elaboration code is invoked from a procedure called
13368@code{adainit}. To run your program up to the beginning of
13369elaboration, simply use the following two commands:
13370@code{tbreak adainit} and @code{run}.
13371
20924a55
JB
13372@node Ada Tasks
13373@subsubsection Extensions for Ada Tasks
13374@cindex Ada, tasking
13375
13376Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
13377@value{GDBN} provides the following task-related commands:
13378
13379@table @code
13380@kindex info tasks
13381@item info tasks
13382This command shows a list of current Ada tasks, as in the following example:
13383
13384
13385@smallexample
13386@iftex
13387@leftskip=0.5cm
13388@end iftex
13389(@value{GDBP}) info tasks
13390 ID TID P-ID Pri State Name
13391 1 8088000 0 15 Child Activation Wait main_task
13392 2 80a4000 1 15 Accept Statement b
13393 3 809a800 1 15 Child Activation Wait a
32cd1edc 13394* 4 80ae800 3 15 Runnable c
20924a55
JB
13395
13396@end smallexample
13397
13398@noindent
13399In this listing, the asterisk before the last task indicates it to be the
13400task currently being inspected.
13401
13402@table @asis
13403@item ID
13404Represents @value{GDBN}'s internal task number.
13405
13406@item TID
13407The Ada task ID.
13408
13409@item P-ID
13410The parent's task ID (@value{GDBN}'s internal task number).
13411
13412@item Pri
13413The base priority of the task.
13414
13415@item State
13416Current state of the task.
13417
13418@table @code
13419@item Unactivated
13420The task has been created but has not been activated. It cannot be
13421executing.
13422
20924a55
JB
13423@item Runnable
13424The task is not blocked for any reason known to Ada. (It may be waiting
13425for a mutex, though.) It is conceptually "executing" in normal mode.
13426
13427@item Terminated
13428The task is terminated, in the sense of ARM 9.3 (5). Any dependents
13429that were waiting on terminate alternatives have been awakened and have
13430terminated themselves.
13431
13432@item Child Activation Wait
13433The task is waiting for created tasks to complete activation.
13434
13435@item Accept Statement
13436The task is waiting on an accept or selective wait statement.
13437
13438@item Waiting on entry call
13439The task is waiting on an entry call.
13440
13441@item Async Select Wait
13442The task is waiting to start the abortable part of an asynchronous
13443select statement.
13444
13445@item Delay Sleep
13446The task is waiting on a select statement with only a delay
13447alternative open.
13448
13449@item Child Termination Wait
13450The task is sleeping having completed a master within itself, and is
13451waiting for the tasks dependent on that master to become terminated or
13452waiting on a terminate Phase.
13453
13454@item Wait Child in Term Alt
13455The task is sleeping waiting for tasks on terminate alternatives to
13456finish terminating.
13457
13458@item Accepting RV with @var{taskno}
13459The task is accepting a rendez-vous with the task @var{taskno}.
13460@end table
13461
13462@item Name
13463Name of the task in the program.
13464
13465@end table
13466
13467@kindex info task @var{taskno}
13468@item info task @var{taskno}
13469This command shows detailled informations on the specified task, as in
13470the following example:
13471@smallexample
13472@iftex
13473@leftskip=0.5cm
13474@end iftex
13475(@value{GDBP}) info tasks
13476 ID TID P-ID Pri State Name
13477 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 13478* 2 807c468 1 15 Runnable task_1
20924a55
JB
13479(@value{GDBP}) info task 2
13480Ada Task: 0x807c468
13481Name: task_1
13482Thread: 0x807f378
13483Parent: 1 (main_task)
13484Base Priority: 15
13485State: Runnable
13486@end smallexample
13487
13488@item task
13489@kindex task@r{ (Ada)}
13490@cindex current Ada task ID
13491This command prints the ID of the current task.
13492
13493@smallexample
13494@iftex
13495@leftskip=0.5cm
13496@end iftex
13497(@value{GDBP}) info tasks
13498 ID TID P-ID Pri State Name
13499 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 13500* 2 807c458 1 15 Runnable t
20924a55
JB
13501(@value{GDBP}) task
13502[Current task is 2]
13503@end smallexample
13504
13505@item task @var{taskno}
13506@cindex Ada task switching
13507This command is like the @code{thread @var{threadno}}
13508command (@pxref{Threads}). It switches the context of debugging
13509from the current task to the given task.
13510
13511@smallexample
13512@iftex
13513@leftskip=0.5cm
13514@end iftex
13515(@value{GDBP}) info tasks
13516 ID TID P-ID Pri State Name
13517 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 13518* 2 807c458 1 15 Runnable t
20924a55
JB
13519(@value{GDBP}) task 1
13520[Switching to task 1]
13521#0 0x8067726 in pthread_cond_wait ()
13522(@value{GDBP}) bt
13523#0 0x8067726 in pthread_cond_wait ()
13524#1 0x8056714 in system.os_interface.pthread_cond_wait ()
13525#2 0x805cb63 in system.task_primitives.operations.sleep ()
13526#3 0x806153e in system.tasking.stages.activate_tasks ()
13527#4 0x804aacc in un () at un.adb:5
13528@end smallexample
13529
45ac276d
JB
13530@item break @var{linespec} task @var{taskno}
13531@itemx break @var{linespec} task @var{taskno} if @dots{}
13532@cindex breakpoints and tasks, in Ada
13533@cindex task breakpoints, in Ada
13534@kindex break @dots{} task @var{taskno}@r{ (Ada)}
13535These commands are like the @code{break @dots{} thread @dots{}}
13536command (@pxref{Thread Stops}).
13537@var{linespec} specifies source lines, as described
13538in @ref{Specify Location}.
13539
13540Use the qualifier @samp{task @var{taskno}} with a breakpoint command
13541to specify that you only want @value{GDBN} to stop the program when a
13542particular Ada task reaches this breakpoint. @var{taskno} is one of the
13543numeric task identifiers assigned by @value{GDBN}, shown in the first
13544column of the @samp{info tasks} display.
13545
13546If you do not specify @samp{task @var{taskno}} when you set a
13547breakpoint, the breakpoint applies to @emph{all} tasks of your
13548program.
13549
13550You can use the @code{task} qualifier on conditional breakpoints as
13551well; in this case, place @samp{task @var{taskno}} before the
13552breakpoint condition (before the @code{if}).
13553
13554For example,
13555
13556@smallexample
13557@iftex
13558@leftskip=0.5cm
13559@end iftex
13560(@value{GDBP}) info tasks
13561 ID TID P-ID Pri State Name
13562 1 140022020 0 15 Child Activation Wait main_task
13563 2 140045060 1 15 Accept/Select Wait t2
13564 3 140044840 1 15 Runnable t1
13565* 4 140056040 1 15 Runnable t3
13566(@value{GDBP}) b 15 task 2
13567Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
13568(@value{GDBP}) cont
13569Continuing.
13570task # 1 running
13571task # 2 running
13572
13573Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1357415 flush;
13575(@value{GDBP}) info tasks
13576 ID TID P-ID Pri State Name
13577 1 140022020 0 15 Child Activation Wait main_task
13578* 2 140045060 1 15 Runnable t2
13579 3 140044840 1 15 Runnable t1
13580 4 140056040 1 15 Delay Sleep t3
13581@end smallexample
20924a55
JB
13582@end table
13583
13584@node Ada Tasks and Core Files
13585@subsubsection Tasking Support when Debugging Core Files
13586@cindex Ada tasking and core file debugging
13587
13588When inspecting a core file, as opposed to debugging a live program,
13589tasking support may be limited or even unavailable, depending on
13590the platform being used.
13591For instance, on x86-linux, the list of tasks is available, but task
13592switching is not supported. On Tru64, however, task switching will work
13593as usual.
13594
13595On certain platforms, including Tru64, the debugger needs to perform some
13596memory writes in order to provide Ada tasking support. When inspecting
13597a core file, this means that the core file must be opened with read-write
13598privileges, using the command @samp{"set write on"} (@pxref{Patching}).
13599Under these circumstances, you should make a backup copy of the core
13600file before inspecting it with @value{GDBN}.
13601
6e1bb179
JB
13602@node Ravenscar Profile
13603@subsubsection Tasking Support when using the Ravenscar Profile
13604@cindex Ravenscar Profile
13605
13606The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
13607specifically designed for systems with safety-critical real-time
13608requirements.
13609
13610@table @code
13611@kindex set ravenscar task-switching on
13612@cindex task switching with program using Ravenscar Profile
13613@item set ravenscar task-switching on
13614Allows task switching when debugging a program that uses the Ravenscar
13615Profile. This is the default.
13616
13617@kindex set ravenscar task-switching off
13618@item set ravenscar task-switching off
13619Turn off task switching when debugging a program that uses the Ravenscar
13620Profile. This is mostly intended to disable the code that adds support
13621for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
13622the Ravenscar runtime is preventing @value{GDBN} from working properly.
13623To be effective, this command should be run before the program is started.
13624
13625@kindex show ravenscar task-switching
13626@item show ravenscar task-switching
13627Show whether it is possible to switch from task to task in a program
13628using the Ravenscar Profile.
13629
13630@end table
13631
e07c999f
PH
13632@node Ada Glitches
13633@subsubsection Known Peculiarities of Ada Mode
13634@cindex Ada, problems
13635
13636Besides the omissions listed previously (@pxref{Omissions from Ada}),
13637we know of several problems with and limitations of Ada mode in
13638@value{GDBN},
13639some of which will be fixed with planned future releases of the debugger
13640and the GNU Ada compiler.
13641
13642@itemize @bullet
13643@item
13644Currently, the debugger
13645has insufficient information to determine whether certain pointers represent
13646pointers to objects or the objects themselves.
13647Thus, the user may have to tack an extra @code{.all} after an expression
13648to get it printed properly.
13649
13650@item
13651Static constants that the compiler chooses not to materialize as objects in
13652storage are invisible to the debugger.
13653
13654@item
13655Named parameter associations in function argument lists are ignored (the
13656argument lists are treated as positional).
13657
13658@item
13659Many useful library packages are currently invisible to the debugger.
13660
13661@item
13662Fixed-point arithmetic, conversions, input, and output is carried out using
13663floating-point arithmetic, and may give results that only approximate those on
13664the host machine.
13665
e07c999f
PH
13666@item
13667The GNAT compiler never generates the prefix @code{Standard} for any of
13668the standard symbols defined by the Ada language. @value{GDBN} knows about
13669this: it will strip the prefix from names when you use it, and will never
13670look for a name you have so qualified among local symbols, nor match against
13671symbols in other packages or subprograms. If you have
13672defined entities anywhere in your program other than parameters and
13673local variables whose simple names match names in @code{Standard},
13674GNAT's lack of qualification here can cause confusion. When this happens,
13675you can usually resolve the confusion
13676by qualifying the problematic names with package
13677@code{Standard} explicitly.
13678@end itemize
13679
95433b34
JB
13680Older versions of the compiler sometimes generate erroneous debugging
13681information, resulting in the debugger incorrectly printing the value
13682of affected entities. In some cases, the debugger is able to work
13683around an issue automatically. In other cases, the debugger is able
13684to work around the issue, but the work-around has to be specifically
13685enabled.
13686
13687@kindex set ada trust-PAD-over-XVS
13688@kindex show ada trust-PAD-over-XVS
13689@table @code
13690
13691@item set ada trust-PAD-over-XVS on
13692Configure GDB to strictly follow the GNAT encoding when computing the
13693value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
13694types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
13695a complete description of the encoding used by the GNAT compiler).
13696This is the default.
13697
13698@item set ada trust-PAD-over-XVS off
13699This is related to the encoding using by the GNAT compiler. If @value{GDBN}
13700sometimes prints the wrong value for certain entities, changing @code{ada
13701trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
13702the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
13703@code{off}, but this incurs a slight performance penalty, so it is
13704recommended to leave this setting to @code{on} unless necessary.
13705
13706@end table
13707
79a6e687
BW
13708@node Unsupported Languages
13709@section Unsupported Languages
4e562065
JB
13710
13711@cindex unsupported languages
13712@cindex minimal language
13713In addition to the other fully-supported programming languages,
13714@value{GDBN} also provides a pseudo-language, called @code{minimal}.
13715It does not represent a real programming language, but provides a set
13716of capabilities close to what the C or assembly languages provide.
13717This should allow most simple operations to be performed while debugging
13718an application that uses a language currently not supported by @value{GDBN}.
13719
13720If the language is set to @code{auto}, @value{GDBN} will automatically
13721select this language if the current frame corresponds to an unsupported
13722language.
13723
6d2ebf8b 13724@node Symbols
c906108c
SS
13725@chapter Examining the Symbol Table
13726
d4f3574e 13727The commands described in this chapter allow you to inquire about the
c906108c
SS
13728symbols (names of variables, functions and types) defined in your
13729program. This information is inherent in the text of your program and
13730does not change as your program executes. @value{GDBN} finds it in your
13731program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
13732(@pxref{File Options, ,Choosing Files}), or by one of the
13733file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
13734
13735@cindex symbol names
13736@cindex names of symbols
13737@cindex quoting names
13738Occasionally, you may need to refer to symbols that contain unusual
13739characters, which @value{GDBN} ordinarily treats as word delimiters. The
13740most frequent case is in referring to static variables in other
79a6e687 13741source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
13742are recorded in object files as debugging symbols, but @value{GDBN} would
13743ordinarily parse a typical file name, like @file{foo.c}, as the three words
13744@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
13745@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
13746
474c8240 13747@smallexample
c906108c 13748p 'foo.c'::x
474c8240 13749@end smallexample
c906108c
SS
13750
13751@noindent
13752looks up the value of @code{x} in the scope of the file @file{foo.c}.
13753
13754@table @code
a8f24a35
EZ
13755@cindex case-insensitive symbol names
13756@cindex case sensitivity in symbol names
13757@kindex set case-sensitive
13758@item set case-sensitive on
13759@itemx set case-sensitive off
13760@itemx set case-sensitive auto
13761Normally, when @value{GDBN} looks up symbols, it matches their names
13762with case sensitivity determined by the current source language.
13763Occasionally, you may wish to control that. The command @code{set
13764case-sensitive} lets you do that by specifying @code{on} for
13765case-sensitive matches or @code{off} for case-insensitive ones. If
13766you specify @code{auto}, case sensitivity is reset to the default
13767suitable for the source language. The default is case-sensitive
13768matches for all languages except for Fortran, for which the default is
13769case-insensitive matches.
13770
9c16f35a
EZ
13771@kindex show case-sensitive
13772@item show case-sensitive
a8f24a35
EZ
13773This command shows the current setting of case sensitivity for symbols
13774lookups.
13775
c906108c 13776@kindex info address
b37052ae 13777@cindex address of a symbol
c906108c
SS
13778@item info address @var{symbol}
13779Describe where the data for @var{symbol} is stored. For a register
13780variable, this says which register it is kept in. For a non-register
13781local variable, this prints the stack-frame offset at which the variable
13782is always stored.
13783
13784Note the contrast with @samp{print &@var{symbol}}, which does not work
13785at all for a register variable, and for a stack local variable prints
13786the exact address of the current instantiation of the variable.
13787
3d67e040 13788@kindex info symbol
b37052ae 13789@cindex symbol from address
9c16f35a 13790@cindex closest symbol and offset for an address
3d67e040
EZ
13791@item info symbol @var{addr}
13792Print the name of a symbol which is stored at the address @var{addr}.
13793If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
13794nearest symbol and an offset from it:
13795
474c8240 13796@smallexample
3d67e040
EZ
13797(@value{GDBP}) info symbol 0x54320
13798_initialize_vx + 396 in section .text
474c8240 13799@end smallexample
3d67e040
EZ
13800
13801@noindent
13802This is the opposite of the @code{info address} command. You can use
13803it to find out the name of a variable or a function given its address.
13804
c14c28ba
PP
13805For dynamically linked executables, the name of executable or shared
13806library containing the symbol is also printed:
13807
13808@smallexample
13809(@value{GDBP}) info symbol 0x400225
13810_start + 5 in section .text of /tmp/a.out
13811(@value{GDBP}) info symbol 0x2aaaac2811cf
13812__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
13813@end smallexample
13814
c906108c 13815@kindex whatis
62f3a2ba
FF
13816@item whatis [@var{arg}]
13817Print the data type of @var{arg}, which can be either an expression or
13818a data type. With no argument, print the data type of @code{$}, the
13819last value in the value history. If @var{arg} is an expression, it is
13820not actually evaluated, and any side-effecting operations (such as
13821assignments or function calls) inside it do not take place. If
13822@var{arg} is a type name, it may be the name of a type or typedef, or
13823for C code it may have the form @samp{class @var{class-name}},
13824@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
13825@samp{enum @var{enum-tag}}.
c906108c
SS
13826@xref{Expressions, ,Expressions}.
13827
c906108c 13828@kindex ptype
62f3a2ba
FF
13829@item ptype [@var{arg}]
13830@code{ptype} accepts the same arguments as @code{whatis}, but prints a
13831detailed description of the type, instead of just the name of the type.
13832@xref{Expressions, ,Expressions}.
c906108c
SS
13833
13834For example, for this variable declaration:
13835
474c8240 13836@smallexample
c906108c 13837struct complex @{double real; double imag;@} v;
474c8240 13838@end smallexample
c906108c
SS
13839
13840@noindent
13841the two commands give this output:
13842
474c8240 13843@smallexample
c906108c
SS
13844@group
13845(@value{GDBP}) whatis v
13846type = struct complex
13847(@value{GDBP}) ptype v
13848type = struct complex @{
13849 double real;
13850 double imag;
13851@}
13852@end group
474c8240 13853@end smallexample
c906108c
SS
13854
13855@noindent
13856As with @code{whatis}, using @code{ptype} without an argument refers to
13857the type of @code{$}, the last value in the value history.
13858
ab1adacd
EZ
13859@cindex incomplete type
13860Sometimes, programs use opaque data types or incomplete specifications
13861of complex data structure. If the debug information included in the
13862program does not allow @value{GDBN} to display a full declaration of
13863the data type, it will say @samp{<incomplete type>}. For example,
13864given these declarations:
13865
13866@smallexample
13867 struct foo;
13868 struct foo *fooptr;
13869@end smallexample
13870
13871@noindent
13872but no definition for @code{struct foo} itself, @value{GDBN} will say:
13873
13874@smallexample
ddb50cd7 13875 (@value{GDBP}) ptype foo
ab1adacd
EZ
13876 $1 = <incomplete type>
13877@end smallexample
13878
13879@noindent
13880``Incomplete type'' is C terminology for data types that are not
13881completely specified.
13882
c906108c
SS
13883@kindex info types
13884@item info types @var{regexp}
13885@itemx info types
09d4efe1
EZ
13886Print a brief description of all types whose names match the regular
13887expression @var{regexp} (or all types in your program, if you supply
13888no argument). Each complete typename is matched as though it were a
13889complete line; thus, @samp{i type value} gives information on all
13890types in your program whose names include the string @code{value}, but
13891@samp{i type ^value$} gives information only on types whose complete
13892name is @code{value}.
c906108c
SS
13893
13894This command differs from @code{ptype} in two ways: first, like
13895@code{whatis}, it does not print a detailed description; second, it
13896lists all source files where a type is defined.
13897
b37052ae
EZ
13898@kindex info scope
13899@cindex local variables
09d4efe1 13900@item info scope @var{location}
b37052ae 13901List all the variables local to a particular scope. This command
09d4efe1
EZ
13902accepts a @var{location} argument---a function name, a source line, or
13903an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
13904to the scope defined by that location. (@xref{Specify Location}, for
13905details about supported forms of @var{location}.) For example:
b37052ae
EZ
13906
13907@smallexample
13908(@value{GDBP}) @b{info scope command_line_handler}
13909Scope for command_line_handler:
13910Symbol rl is an argument at stack/frame offset 8, length 4.
13911Symbol linebuffer is in static storage at address 0x150a18, length 4.
13912Symbol linelength is in static storage at address 0x150a1c, length 4.
13913Symbol p is a local variable in register $esi, length 4.
13914Symbol p1 is a local variable in register $ebx, length 4.
13915Symbol nline is a local variable in register $edx, length 4.
13916Symbol repeat is a local variable at frame offset -8, length 4.
13917@end smallexample
13918
f5c37c66
EZ
13919@noindent
13920This command is especially useful for determining what data to collect
13921during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
13922collect}.
13923
c906108c
SS
13924@kindex info source
13925@item info source
919d772c
JB
13926Show information about the current source file---that is, the source file for
13927the function containing the current point of execution:
13928@itemize @bullet
13929@item
13930the name of the source file, and the directory containing it,
13931@item
13932the directory it was compiled in,
13933@item
13934its length, in lines,
13935@item
13936which programming language it is written in,
13937@item
13938whether the executable includes debugging information for that file, and
13939if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
13940@item
13941whether the debugging information includes information about
13942preprocessor macros.
13943@end itemize
13944
c906108c
SS
13945
13946@kindex info sources
13947@item info sources
13948Print the names of all source files in your program for which there is
13949debugging information, organized into two lists: files whose symbols
13950have already been read, and files whose symbols will be read when needed.
13951
13952@kindex info functions
13953@item info functions
13954Print the names and data types of all defined functions.
13955
13956@item info functions @var{regexp}
13957Print the names and data types of all defined functions
13958whose names contain a match for regular expression @var{regexp}.
13959Thus, @samp{info fun step} finds all functions whose names
13960include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 13961start with @code{step}. If a function name contains characters
c1468174 13962that conflict with the regular expression language (e.g.@:
1c5dfdad 13963@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
13964
13965@kindex info variables
13966@item info variables
0fe7935b 13967Print the names and data types of all variables that are defined
6ca652b0 13968outside of functions (i.e.@: excluding local variables).
c906108c
SS
13969
13970@item info variables @var{regexp}
13971Print the names and data types of all variables (except for local
13972variables) whose names contain a match for regular expression
13973@var{regexp}.
13974
b37303ee 13975@kindex info classes
721c2651 13976@cindex Objective-C, classes and selectors
b37303ee
AF
13977@item info classes
13978@itemx info classes @var{regexp}
13979Display all Objective-C classes in your program, or
13980(with the @var{regexp} argument) all those matching a particular regular
13981expression.
13982
13983@kindex info selectors
13984@item info selectors
13985@itemx info selectors @var{regexp}
13986Display all Objective-C selectors in your program, or
13987(with the @var{regexp} argument) all those matching a particular regular
13988expression.
13989
c906108c
SS
13990@ignore
13991This was never implemented.
13992@kindex info methods
13993@item info methods
13994@itemx info methods @var{regexp}
13995The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
13996methods within C@t{++} program, or (with the @var{regexp} argument) a
13997specific set of methods found in the various C@t{++} classes. Many
13998C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
13999from the @code{ptype} command can be overwhelming and hard to use. The
14000@code{info-methods} command filters the methods, printing only those
14001which match the regular-expression @var{regexp}.
14002@end ignore
14003
c906108c
SS
14004@cindex reloading symbols
14005Some systems allow individual object files that make up your program to
7a292a7a
SS
14006be replaced without stopping and restarting your program. For example,
14007in VxWorks you can simply recompile a defective object file and keep on
14008running. If you are running on one of these systems, you can allow
14009@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
14010
14011@table @code
14012@kindex set symbol-reloading
14013@item set symbol-reloading on
14014Replace symbol definitions for the corresponding source file when an
14015object file with a particular name is seen again.
14016
14017@item set symbol-reloading off
6d2ebf8b
SS
14018Do not replace symbol definitions when encountering object files of the
14019same name more than once. This is the default state; if you are not
14020running on a system that permits automatic relinking of modules, you
14021should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
14022may discard symbols when linking large programs, that may contain
14023several modules (from different directories or libraries) with the same
14024name.
c906108c
SS
14025
14026@kindex show symbol-reloading
14027@item show symbol-reloading
14028Show the current @code{on} or @code{off} setting.
14029@end table
c906108c 14030
9c16f35a 14031@cindex opaque data types
c906108c
SS
14032@kindex set opaque-type-resolution
14033@item set opaque-type-resolution on
14034Tell @value{GDBN} to resolve opaque types. An opaque type is a type
14035declared as a pointer to a @code{struct}, @code{class}, or
14036@code{union}---for example, @code{struct MyType *}---that is used in one
14037source file although the full declaration of @code{struct MyType} is in
14038another source file. The default is on.
14039
14040A change in the setting of this subcommand will not take effect until
14041the next time symbols for a file are loaded.
14042
14043@item set opaque-type-resolution off
14044Tell @value{GDBN} not to resolve opaque types. In this case, the type
14045is printed as follows:
14046@smallexample
14047@{<no data fields>@}
14048@end smallexample
14049
14050@kindex show opaque-type-resolution
14051@item show opaque-type-resolution
14052Show whether opaque types are resolved or not.
c906108c
SS
14053
14054@kindex maint print symbols
14055@cindex symbol dump
14056@kindex maint print psymbols
14057@cindex partial symbol dump
14058@item maint print symbols @var{filename}
14059@itemx maint print psymbols @var{filename}
14060@itemx maint print msymbols @var{filename}
14061Write a dump of debugging symbol data into the file @var{filename}.
14062These commands are used to debug the @value{GDBN} symbol-reading code. Only
14063symbols with debugging data are included. If you use @samp{maint print
14064symbols}, @value{GDBN} includes all the symbols for which it has already
14065collected full details: that is, @var{filename} reflects symbols for
14066only those files whose symbols @value{GDBN} has read. You can use the
14067command @code{info sources} to find out which files these are. If you
14068use @samp{maint print psymbols} instead, the dump shows information about
14069symbols that @value{GDBN} only knows partially---that is, symbols defined in
14070files that @value{GDBN} has skimmed, but not yet read completely. Finally,
14071@samp{maint print msymbols} dumps just the minimal symbol information
14072required for each object file from which @value{GDBN} has read some symbols.
79a6e687 14073@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 14074@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 14075
5e7b2f39
JB
14076@kindex maint info symtabs
14077@kindex maint info psymtabs
44ea7b70
JB
14078@cindex listing @value{GDBN}'s internal symbol tables
14079@cindex symbol tables, listing @value{GDBN}'s internal
14080@cindex full symbol tables, listing @value{GDBN}'s internal
14081@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
14082@item maint info symtabs @r{[} @var{regexp} @r{]}
14083@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
14084
14085List the @code{struct symtab} or @code{struct partial_symtab}
14086structures whose names match @var{regexp}. If @var{regexp} is not
14087given, list them all. The output includes expressions which you can
14088copy into a @value{GDBN} debugging this one to examine a particular
14089structure in more detail. For example:
14090
14091@smallexample
5e7b2f39 14092(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
14093@{ objfile /home/gnu/build/gdb/gdb
14094 ((struct objfile *) 0x82e69d0)
b383017d 14095 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
14096 ((struct partial_symtab *) 0x8474b10)
14097 readin no
14098 fullname (null)
14099 text addresses 0x814d3c8 -- 0x8158074
14100 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
14101 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
14102 dependencies (none)
14103 @}
14104@}
5e7b2f39 14105(@value{GDBP}) maint info symtabs
44ea7b70
JB
14106(@value{GDBP})
14107@end smallexample
14108@noindent
14109We see that there is one partial symbol table whose filename contains
14110the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
14111and we see that @value{GDBN} has not read in any symtabs yet at all.
14112If we set a breakpoint on a function, that will cause @value{GDBN} to
14113read the symtab for the compilation unit containing that function:
14114
14115@smallexample
14116(@value{GDBP}) break dwarf2_psymtab_to_symtab
14117Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
14118line 1574.
5e7b2f39 14119(@value{GDBP}) maint info symtabs
b383017d 14120@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 14121 ((struct objfile *) 0x82e69d0)
b383017d 14122 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
14123 ((struct symtab *) 0x86c1f38)
14124 dirname (null)
14125 fullname (null)
14126 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 14127 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
14128 debugformat DWARF 2
14129 @}
14130@}
b383017d 14131(@value{GDBP})
44ea7b70 14132@end smallexample
c906108c
SS
14133@end table
14134
44ea7b70 14135
6d2ebf8b 14136@node Altering
c906108c
SS
14137@chapter Altering Execution
14138
14139Once you think you have found an error in your program, you might want to
14140find out for certain whether correcting the apparent error would lead to
14141correct results in the rest of the run. You can find the answer by
14142experiment, using the @value{GDBN} features for altering execution of the
14143program.
14144
14145For example, you can store new values into variables or memory
7a292a7a
SS
14146locations, give your program a signal, restart it at a different
14147address, or even return prematurely from a function.
c906108c
SS
14148
14149@menu
14150* Assignment:: Assignment to variables
14151* Jumping:: Continuing at a different address
c906108c 14152* Signaling:: Giving your program a signal
c906108c
SS
14153* Returning:: Returning from a function
14154* Calling:: Calling your program's functions
14155* Patching:: Patching your program
14156@end menu
14157
6d2ebf8b 14158@node Assignment
79a6e687 14159@section Assignment to Variables
c906108c
SS
14160
14161@cindex assignment
14162@cindex setting variables
14163To alter the value of a variable, evaluate an assignment expression.
14164@xref{Expressions, ,Expressions}. For example,
14165
474c8240 14166@smallexample
c906108c 14167print x=4
474c8240 14168@end smallexample
c906108c
SS
14169
14170@noindent
14171stores the value 4 into the variable @code{x}, and then prints the
5d161b24 14172value of the assignment expression (which is 4).
c906108c
SS
14173@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
14174information on operators in supported languages.
c906108c
SS
14175
14176@kindex set variable
14177@cindex variables, setting
14178If you are not interested in seeing the value of the assignment, use the
14179@code{set} command instead of the @code{print} command. @code{set} is
14180really the same as @code{print} except that the expression's value is
14181not printed and is not put in the value history (@pxref{Value History,
79a6e687 14182,Value History}). The expression is evaluated only for its effects.
c906108c 14183
c906108c
SS
14184If the beginning of the argument string of the @code{set} command
14185appears identical to a @code{set} subcommand, use the @code{set
14186variable} command instead of just @code{set}. This command is identical
14187to @code{set} except for its lack of subcommands. For example, if your
14188program has a variable @code{width}, you get an error if you try to set
14189a new value with just @samp{set width=13}, because @value{GDBN} has the
14190command @code{set width}:
14191
474c8240 14192@smallexample
c906108c
SS
14193(@value{GDBP}) whatis width
14194type = double
14195(@value{GDBP}) p width
14196$4 = 13
14197(@value{GDBP}) set width=47
14198Invalid syntax in expression.
474c8240 14199@end smallexample
c906108c
SS
14200
14201@noindent
14202The invalid expression, of course, is @samp{=47}. In
14203order to actually set the program's variable @code{width}, use
14204
474c8240 14205@smallexample
c906108c 14206(@value{GDBP}) set var width=47
474c8240 14207@end smallexample
53a5351d 14208
c906108c
SS
14209Because the @code{set} command has many subcommands that can conflict
14210with the names of program variables, it is a good idea to use the
14211@code{set variable} command instead of just @code{set}. For example, if
14212your program has a variable @code{g}, you run into problems if you try
14213to set a new value with just @samp{set g=4}, because @value{GDBN} has
14214the command @code{set gnutarget}, abbreviated @code{set g}:
14215
474c8240 14216@smallexample
c906108c
SS
14217@group
14218(@value{GDBP}) whatis g
14219type = double
14220(@value{GDBP}) p g
14221$1 = 1
14222(@value{GDBP}) set g=4
2df3850c 14223(@value{GDBP}) p g
c906108c
SS
14224$2 = 1
14225(@value{GDBP}) r
14226The program being debugged has been started already.
14227Start it from the beginning? (y or n) y
14228Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
14229"/home/smith/cc_progs/a.out": can't open to read symbols:
14230 Invalid bfd target.
c906108c
SS
14231(@value{GDBP}) show g
14232The current BFD target is "=4".
14233@end group
474c8240 14234@end smallexample
c906108c
SS
14235
14236@noindent
14237The program variable @code{g} did not change, and you silently set the
14238@code{gnutarget} to an invalid value. In order to set the variable
14239@code{g}, use
14240
474c8240 14241@smallexample
c906108c 14242(@value{GDBP}) set var g=4
474c8240 14243@end smallexample
c906108c
SS
14244
14245@value{GDBN} allows more implicit conversions in assignments than C; you can
14246freely store an integer value into a pointer variable or vice versa,
14247and you can convert any structure to any other structure that is the
14248same length or shorter.
14249@comment FIXME: how do structs align/pad in these conversions?
14250@comment /doc@cygnus.com 18dec1990
14251
14252To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
14253construct to generate a value of specified type at a specified address
14254(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
14255to memory location @code{0x83040} as an integer (which implies a certain size
14256and representation in memory), and
14257
474c8240 14258@smallexample
c906108c 14259set @{int@}0x83040 = 4
474c8240 14260@end smallexample
c906108c
SS
14261
14262@noindent
14263stores the value 4 into that memory location.
14264
6d2ebf8b 14265@node Jumping
79a6e687 14266@section Continuing at a Different Address
c906108c
SS
14267
14268Ordinarily, when you continue your program, you do so at the place where
14269it stopped, with the @code{continue} command. You can instead continue at
14270an address of your own choosing, with the following commands:
14271
14272@table @code
14273@kindex jump
14274@item jump @var{linespec}
2a25a5ba
EZ
14275@itemx jump @var{location}
14276Resume execution at line @var{linespec} or at address given by
14277@var{location}. Execution stops again immediately if there is a
14278breakpoint there. @xref{Specify Location}, for a description of the
14279different forms of @var{linespec} and @var{location}. It is common
14280practice to use the @code{tbreak} command in conjunction with
14281@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
14282
14283The @code{jump} command does not change the current stack frame, or
14284the stack pointer, or the contents of any memory location or any
14285register other than the program counter. If line @var{linespec} is in
14286a different function from the one currently executing, the results may
14287be bizarre if the two functions expect different patterns of arguments or
14288of local variables. For this reason, the @code{jump} command requests
14289confirmation if the specified line is not in the function currently
14290executing. However, even bizarre results are predictable if you are
14291well acquainted with the machine-language code of your program.
c906108c
SS
14292@end table
14293
c906108c 14294@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
14295On many systems, you can get much the same effect as the @code{jump}
14296command by storing a new value into the register @code{$pc}. The
14297difference is that this does not start your program running; it only
14298changes the address of where it @emph{will} run when you continue. For
14299example,
c906108c 14300
474c8240 14301@smallexample
c906108c 14302set $pc = 0x485
474c8240 14303@end smallexample
c906108c
SS
14304
14305@noindent
14306makes the next @code{continue} command or stepping command execute at
14307address @code{0x485}, rather than at the address where your program stopped.
79a6e687 14308@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
14309
14310The most common occasion to use the @code{jump} command is to back
14311up---perhaps with more breakpoints set---over a portion of a program
14312that has already executed, in order to examine its execution in more
14313detail.
14314
c906108c 14315@c @group
6d2ebf8b 14316@node Signaling
79a6e687 14317@section Giving your Program a Signal
9c16f35a 14318@cindex deliver a signal to a program
c906108c
SS
14319
14320@table @code
14321@kindex signal
14322@item signal @var{signal}
14323Resume execution where your program stopped, but immediately give it the
14324signal @var{signal}. @var{signal} can be the name or the number of a
14325signal. For example, on many systems @code{signal 2} and @code{signal
14326SIGINT} are both ways of sending an interrupt signal.
14327
14328Alternatively, if @var{signal} is zero, continue execution without
14329giving a signal. This is useful when your program stopped on account of
14330a signal and would ordinary see the signal when resumed with the
14331@code{continue} command; @samp{signal 0} causes it to resume without a
14332signal.
14333
14334@code{signal} does not repeat when you press @key{RET} a second time
14335after executing the command.
14336@end table
14337@c @end group
14338
14339Invoking the @code{signal} command is not the same as invoking the
14340@code{kill} utility from the shell. Sending a signal with @code{kill}
14341causes @value{GDBN} to decide what to do with the signal depending on
14342the signal handling tables (@pxref{Signals}). The @code{signal} command
14343passes the signal directly to your program.
14344
c906108c 14345
6d2ebf8b 14346@node Returning
79a6e687 14347@section Returning from a Function
c906108c
SS
14348
14349@table @code
14350@cindex returning from a function
14351@kindex return
14352@item return
14353@itemx return @var{expression}
14354You can cancel execution of a function call with the @code{return}
14355command. If you give an
14356@var{expression} argument, its value is used as the function's return
14357value.
14358@end table
14359
14360When you use @code{return}, @value{GDBN} discards the selected stack frame
14361(and all frames within it). You can think of this as making the
14362discarded frame return prematurely. If you wish to specify a value to
14363be returned, give that value as the argument to @code{return}.
14364
14365This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 14366Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
14367innermost remaining frame. That frame becomes selected. The
14368specified value is stored in the registers used for returning values
14369of functions.
14370
14371The @code{return} command does not resume execution; it leaves the
14372program stopped in the state that would exist if the function had just
14373returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 14374and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
14375selected stack frame returns naturally.
14376
61ff14c6
JK
14377@value{GDBN} needs to know how the @var{expression} argument should be set for
14378the inferior. The concrete registers assignment depends on the OS ABI and the
14379type being returned by the selected stack frame. For example it is common for
14380OS ABI to return floating point values in FPU registers while integer values in
14381CPU registers. Still some ABIs return even floating point values in CPU
14382registers. Larger integer widths (such as @code{long long int}) also have
14383specific placement rules. @value{GDBN} already knows the OS ABI from its
14384current target so it needs to find out also the type being returned to make the
14385assignment into the right register(s).
14386
14387Normally, the selected stack frame has debug info. @value{GDBN} will always
14388use the debug info instead of the implicit type of @var{expression} when the
14389debug info is available. For example, if you type @kbd{return -1}, and the
14390function in the current stack frame is declared to return a @code{long long
14391int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
14392into a @code{long long int}:
14393
14394@smallexample
14395Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1439629 return 31;
14397(@value{GDBP}) return -1
14398Make func return now? (y or n) y
14399#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1440043 printf ("result=%lld\n", func ());
14401(@value{GDBP})
14402@end smallexample
14403
14404However, if the selected stack frame does not have a debug info, e.g., if the
14405function was compiled without debug info, @value{GDBN} has to find out the type
14406to return from user. Specifying a different type by mistake may set the value
14407in different inferior registers than the caller code expects. For example,
14408typing @kbd{return -1} with its implicit type @code{int} would set only a part
14409of a @code{long long int} result for a debug info less function (on 32-bit
14410architectures). Therefore the user is required to specify the return type by
14411an appropriate cast explicitly:
14412
14413@smallexample
14414Breakpoint 2, 0x0040050b in func ()
14415(@value{GDBP}) return -1
14416Return value type not available for selected stack frame.
14417Please use an explicit cast of the value to return.
14418(@value{GDBP}) return (long long int) -1
14419Make selected stack frame return now? (y or n) y
14420#0 0x00400526 in main ()
14421(@value{GDBP})
14422@end smallexample
14423
6d2ebf8b 14424@node Calling
79a6e687 14425@section Calling Program Functions
c906108c 14426
f8568604 14427@table @code
c906108c 14428@cindex calling functions
f8568604
EZ
14429@cindex inferior functions, calling
14430@item print @var{expr}
d3e8051b 14431Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
14432@var{expr} may include calls to functions in the program being
14433debugged.
14434
c906108c 14435@kindex call
c906108c
SS
14436@item call @var{expr}
14437Evaluate the expression @var{expr} without displaying @code{void}
14438returned values.
c906108c
SS
14439
14440You can use this variant of the @code{print} command if you want to
f8568604
EZ
14441execute a function from your program that does not return anything
14442(a.k.a.@: @dfn{a void function}), but without cluttering the output
14443with @code{void} returned values that @value{GDBN} will otherwise
14444print. If the result is not void, it is printed and saved in the
14445value history.
14446@end table
14447
9c16f35a
EZ
14448It is possible for the function you call via the @code{print} or
14449@code{call} command to generate a signal (e.g., if there's a bug in
14450the function, or if you passed it incorrect arguments). What happens
14451in that case is controlled by the @code{set unwindonsignal} command.
14452
7cd1089b
PM
14453Similarly, with a C@t{++} program it is possible for the function you
14454call via the @code{print} or @code{call} command to generate an
14455exception that is not handled due to the constraints of the dummy
14456frame. In this case, any exception that is raised in the frame, but has
14457an out-of-frame exception handler will not be found. GDB builds a
14458dummy-frame for the inferior function call, and the unwinder cannot
14459seek for exception handlers outside of this dummy-frame. What happens
14460in that case is controlled by the
14461@code{set unwind-on-terminating-exception} command.
14462
9c16f35a
EZ
14463@table @code
14464@item set unwindonsignal
14465@kindex set unwindonsignal
14466@cindex unwind stack in called functions
14467@cindex call dummy stack unwinding
14468Set unwinding of the stack if a signal is received while in a function
14469that @value{GDBN} called in the program being debugged. If set to on,
14470@value{GDBN} unwinds the stack it created for the call and restores
14471the context to what it was before the call. If set to off (the
14472default), @value{GDBN} stops in the frame where the signal was
14473received.
14474
14475@item show unwindonsignal
14476@kindex show unwindonsignal
14477Show the current setting of stack unwinding in the functions called by
14478@value{GDBN}.
7cd1089b
PM
14479
14480@item set unwind-on-terminating-exception
14481@kindex set unwind-on-terminating-exception
14482@cindex unwind stack in called functions with unhandled exceptions
14483@cindex call dummy stack unwinding on unhandled exception.
14484Set unwinding of the stack if a C@t{++} exception is raised, but left
14485unhandled while in a function that @value{GDBN} called in the program being
14486debugged. If set to on (the default), @value{GDBN} unwinds the stack
14487it created for the call and restores the context to what it was before
14488the call. If set to off, @value{GDBN} the exception is delivered to
14489the default C@t{++} exception handler and the inferior terminated.
14490
14491@item show unwind-on-terminating-exception
14492@kindex show unwind-on-terminating-exception
14493Show the current setting of stack unwinding in the functions called by
14494@value{GDBN}.
14495
9c16f35a
EZ
14496@end table
14497
f8568604
EZ
14498@cindex weak alias functions
14499Sometimes, a function you wish to call is actually a @dfn{weak alias}
14500for another function. In such case, @value{GDBN} might not pick up
14501the type information, including the types of the function arguments,
14502which causes @value{GDBN} to call the inferior function incorrectly.
14503As a result, the called function will function erroneously and may
14504even crash. A solution to that is to use the name of the aliased
14505function instead.
c906108c 14506
6d2ebf8b 14507@node Patching
79a6e687 14508@section Patching Programs
7a292a7a 14509
c906108c
SS
14510@cindex patching binaries
14511@cindex writing into executables
c906108c 14512@cindex writing into corefiles
c906108c 14513
7a292a7a
SS
14514By default, @value{GDBN} opens the file containing your program's
14515executable code (or the corefile) read-only. This prevents accidental
14516alterations to machine code; but it also prevents you from intentionally
14517patching your program's binary.
c906108c
SS
14518
14519If you'd like to be able to patch the binary, you can specify that
14520explicitly with the @code{set write} command. For example, you might
14521want to turn on internal debugging flags, or even to make emergency
14522repairs.
14523
14524@table @code
14525@kindex set write
14526@item set write on
14527@itemx set write off
7a292a7a 14528If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 14529core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
14530off} (the default), @value{GDBN} opens them read-only.
14531
14532If you have already loaded a file, you must load it again (using the
7a292a7a
SS
14533@code{exec-file} or @code{core-file} command) after changing @code{set
14534write}, for your new setting to take effect.
c906108c
SS
14535
14536@item show write
14537@kindex show write
7a292a7a
SS
14538Display whether executable files and core files are opened for writing
14539as well as reading.
c906108c
SS
14540@end table
14541
6d2ebf8b 14542@node GDB Files
c906108c
SS
14543@chapter @value{GDBN} Files
14544
7a292a7a
SS
14545@value{GDBN} needs to know the file name of the program to be debugged,
14546both in order to read its symbol table and in order to start your
14547program. To debug a core dump of a previous run, you must also tell
14548@value{GDBN} the name of the core dump file.
c906108c
SS
14549
14550@menu
14551* Files:: Commands to specify files
5b5d99cf 14552* Separate Debug Files:: Debugging information in separate files
9291a0cd 14553* Index Files:: Index files speed up GDB
c906108c 14554* Symbol Errors:: Errors reading symbol files
b14b1491 14555* Data Files:: GDB data files
c906108c
SS
14556@end menu
14557
6d2ebf8b 14558@node Files
79a6e687 14559@section Commands to Specify Files
c906108c 14560
7a292a7a 14561@cindex symbol table
c906108c 14562@cindex core dump file
7a292a7a
SS
14563
14564You may want to specify executable and core dump file names. The usual
14565way to do this is at start-up time, using the arguments to
14566@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
14567Out of @value{GDBN}}).
c906108c
SS
14568
14569Occasionally it is necessary to change to a different file during a
397ca115
EZ
14570@value{GDBN} session. Or you may run @value{GDBN} and forget to
14571specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
14572via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
14573Program}). In these situations the @value{GDBN} commands to specify
0869d01b 14574new files are useful.
c906108c
SS
14575
14576@table @code
14577@cindex executable file
14578@kindex file
14579@item file @var{filename}
14580Use @var{filename} as the program to be debugged. It is read for its
14581symbols and for the contents of pure memory. It is also the program
14582executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
14583directory and the file is not found in the @value{GDBN} working directory,
14584@value{GDBN} uses the environment variable @code{PATH} as a list of
14585directories to search, just as the shell does when looking for a program
14586to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
14587and your program, using the @code{path} command.
14588
fc8be69e
EZ
14589@cindex unlinked object files
14590@cindex patching object files
14591You can load unlinked object @file{.o} files into @value{GDBN} using
14592the @code{file} command. You will not be able to ``run'' an object
14593file, but you can disassemble functions and inspect variables. Also,
14594if the underlying BFD functionality supports it, you could use
14595@kbd{gdb -write} to patch object files using this technique. Note
14596that @value{GDBN} can neither interpret nor modify relocations in this
14597case, so branches and some initialized variables will appear to go to
14598the wrong place. But this feature is still handy from time to time.
14599
c906108c
SS
14600@item file
14601@code{file} with no argument makes @value{GDBN} discard any information it
14602has on both executable file and the symbol table.
14603
14604@kindex exec-file
14605@item exec-file @r{[} @var{filename} @r{]}
14606Specify that the program to be run (but not the symbol table) is found
14607in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
14608if necessary to locate your program. Omitting @var{filename} means to
14609discard information on the executable file.
14610
14611@kindex symbol-file
14612@item symbol-file @r{[} @var{filename} @r{]}
14613Read symbol table information from file @var{filename}. @code{PATH} is
14614searched when necessary. Use the @code{file} command to get both symbol
14615table and program to run from the same file.
14616
14617@code{symbol-file} with no argument clears out @value{GDBN} information on your
14618program's symbol table.
14619
ae5a43e0
DJ
14620The @code{symbol-file} command causes @value{GDBN} to forget the contents of
14621some breakpoints and auto-display expressions. This is because they may
14622contain pointers to the internal data recording symbols and data types,
14623which are part of the old symbol table data being discarded inside
14624@value{GDBN}.
c906108c
SS
14625
14626@code{symbol-file} does not repeat if you press @key{RET} again after
14627executing it once.
14628
14629When @value{GDBN} is configured for a particular environment, it
14630understands debugging information in whatever format is the standard
14631generated for that environment; you may use either a @sc{gnu} compiler, or
14632other compilers that adhere to the local conventions.
c906108c 14633Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 14634using @code{@value{NGCC}} you can generate debugging information for
c906108c 14635optimized code.
c906108c
SS
14636
14637For most kinds of object files, with the exception of old SVR3 systems
14638using COFF, the @code{symbol-file} command does not normally read the
14639symbol table in full right away. Instead, it scans the symbol table
14640quickly to find which source files and which symbols are present. The
14641details are read later, one source file at a time, as they are needed.
14642
14643The purpose of this two-stage reading strategy is to make @value{GDBN}
14644start up faster. For the most part, it is invisible except for
14645occasional pauses while the symbol table details for a particular source
14646file are being read. (The @code{set verbose} command can turn these
14647pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 14648Warnings and Messages}.)
c906108c 14649
c906108c
SS
14650We have not implemented the two-stage strategy for COFF yet. When the
14651symbol table is stored in COFF format, @code{symbol-file} reads the
14652symbol table data in full right away. Note that ``stabs-in-COFF''
14653still does the two-stage strategy, since the debug info is actually
14654in stabs format.
14655
14656@kindex readnow
14657@cindex reading symbols immediately
14658@cindex symbols, reading immediately
6ac33a4e
TT
14659@item symbol-file @r{[} -readnow @r{]} @var{filename}
14660@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
14661You can override the @value{GDBN} two-stage strategy for reading symbol
14662tables by using the @samp{-readnow} option with any of the commands that
14663load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 14664entire symbol table available.
c906108c 14665
c906108c
SS
14666@c FIXME: for now no mention of directories, since this seems to be in
14667@c flux. 13mar1992 status is that in theory GDB would look either in
14668@c current dir or in same dir as myprog; but issues like competing
14669@c GDB's, or clutter in system dirs, mean that in practice right now
14670@c only current dir is used. FFish says maybe a special GDB hierarchy
14671@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
14672@c files.
14673
c906108c 14674@kindex core-file
09d4efe1 14675@item core-file @r{[}@var{filename}@r{]}
4644b6e3 14676@itemx core
c906108c
SS
14677Specify the whereabouts of a core dump file to be used as the ``contents
14678of memory''. Traditionally, core files contain only some parts of the
14679address space of the process that generated them; @value{GDBN} can access the
14680executable file itself for other parts.
14681
14682@code{core-file} with no argument specifies that no core file is
14683to be used.
14684
14685Note that the core file is ignored when your program is actually running
7a292a7a
SS
14686under @value{GDBN}. So, if you have been running your program and you
14687wish to debug a core file instead, you must kill the subprocess in which
14688the program is running. To do this, use the @code{kill} command
79a6e687 14689(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 14690
c906108c
SS
14691@kindex add-symbol-file
14692@cindex dynamic linking
14693@item add-symbol-file @var{filename} @var{address}
a94ab193 14694@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 14695@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
14696The @code{add-symbol-file} command reads additional symbol table
14697information from the file @var{filename}. You would use this command
14698when @var{filename} has been dynamically loaded (by some other means)
14699into the program that is running. @var{address} should be the memory
14700address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
14701this out for itself. You can additionally specify an arbitrary number
14702of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
14703section name and base address for that section. You can specify any
14704@var{address} as an expression.
c906108c
SS
14705
14706The symbol table of the file @var{filename} is added to the symbol table
14707originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
14708@code{add-symbol-file} command any number of times; the new symbol data
14709thus read keeps adding to the old. To discard all old symbol data
14710instead, use the @code{symbol-file} command without any arguments.
c906108c 14711
17d9d558
JB
14712@cindex relocatable object files, reading symbols from
14713@cindex object files, relocatable, reading symbols from
14714@cindex reading symbols from relocatable object files
14715@cindex symbols, reading from relocatable object files
14716@cindex @file{.o} files, reading symbols from
14717Although @var{filename} is typically a shared library file, an
14718executable file, or some other object file which has been fully
14719relocated for loading into a process, you can also load symbolic
14720information from relocatable @file{.o} files, as long as:
14721
14722@itemize @bullet
14723@item
14724the file's symbolic information refers only to linker symbols defined in
14725that file, not to symbols defined by other object files,
14726@item
14727every section the file's symbolic information refers to has actually
14728been loaded into the inferior, as it appears in the file, and
14729@item
14730you can determine the address at which every section was loaded, and
14731provide these to the @code{add-symbol-file} command.
14732@end itemize
14733
14734@noindent
14735Some embedded operating systems, like Sun Chorus and VxWorks, can load
14736relocatable files into an already running program; such systems
14737typically make the requirements above easy to meet. However, it's
14738important to recognize that many native systems use complex link
49efadf5 14739procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
14740assembly, for example) that make the requirements difficult to meet. In
14741general, one cannot assume that using @code{add-symbol-file} to read a
14742relocatable object file's symbolic information will have the same effect
14743as linking the relocatable object file into the program in the normal
14744way.
14745
c906108c
SS
14746@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
14747
c45da7e6
EZ
14748@kindex add-symbol-file-from-memory
14749@cindex @code{syscall DSO}
14750@cindex load symbols from memory
14751@item add-symbol-file-from-memory @var{address}
14752Load symbols from the given @var{address} in a dynamically loaded
14753object file whose image is mapped directly into the inferior's memory.
14754For example, the Linux kernel maps a @code{syscall DSO} into each
14755process's address space; this DSO provides kernel-specific code for
14756some system calls. The argument can be any expression whose
14757evaluation yields the address of the file's shared object file header.
14758For this command to work, you must have used @code{symbol-file} or
14759@code{exec-file} commands in advance.
14760
09d4efe1
EZ
14761@kindex add-shared-symbol-files
14762@kindex assf
14763@item add-shared-symbol-files @var{library-file}
14764@itemx assf @var{library-file}
14765The @code{add-shared-symbol-files} command can currently be used only
14766in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
14767alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
14768@value{GDBN} automatically looks for shared libraries, however if
14769@value{GDBN} does not find yours, you can invoke
14770@code{add-shared-symbol-files}. It takes one argument: the shared
14771library's file name. @code{assf} is a shorthand alias for
14772@code{add-shared-symbol-files}.
c906108c 14773
c906108c 14774@kindex section
09d4efe1
EZ
14775@item section @var{section} @var{addr}
14776The @code{section} command changes the base address of the named
14777@var{section} of the exec file to @var{addr}. This can be used if the
14778exec file does not contain section addresses, (such as in the
14779@code{a.out} format), or when the addresses specified in the file
14780itself are wrong. Each section must be changed separately. The
14781@code{info files} command, described below, lists all the sections and
14782their addresses.
c906108c
SS
14783
14784@kindex info files
14785@kindex info target
14786@item info files
14787@itemx info target
7a292a7a
SS
14788@code{info files} and @code{info target} are synonymous; both print the
14789current target (@pxref{Targets, ,Specifying a Debugging Target}),
14790including the names of the executable and core dump files currently in
14791use by @value{GDBN}, and the files from which symbols were loaded. The
14792command @code{help target} lists all possible targets rather than
14793current ones.
14794
fe95c787
MS
14795@kindex maint info sections
14796@item maint info sections
14797Another command that can give you extra information about program sections
14798is @code{maint info sections}. In addition to the section information
14799displayed by @code{info files}, this command displays the flags and file
14800offset of each section in the executable and core dump files. In addition,
14801@code{maint info sections} provides the following command options (which
14802may be arbitrarily combined):
14803
14804@table @code
14805@item ALLOBJ
14806Display sections for all loaded object files, including shared libraries.
14807@item @var{sections}
6600abed 14808Display info only for named @var{sections}.
fe95c787
MS
14809@item @var{section-flags}
14810Display info only for sections for which @var{section-flags} are true.
14811The section flags that @value{GDBN} currently knows about are:
14812@table @code
14813@item ALLOC
14814Section will have space allocated in the process when loaded.
14815Set for all sections except those containing debug information.
14816@item LOAD
14817Section will be loaded from the file into the child process memory.
14818Set for pre-initialized code and data, clear for @code{.bss} sections.
14819@item RELOC
14820Section needs to be relocated before loading.
14821@item READONLY
14822Section cannot be modified by the child process.
14823@item CODE
14824Section contains executable code only.
6600abed 14825@item DATA
fe95c787
MS
14826Section contains data only (no executable code).
14827@item ROM
14828Section will reside in ROM.
14829@item CONSTRUCTOR
14830Section contains data for constructor/destructor lists.
14831@item HAS_CONTENTS
14832Section is not empty.
14833@item NEVER_LOAD
14834An instruction to the linker to not output the section.
14835@item COFF_SHARED_LIBRARY
14836A notification to the linker that the section contains
14837COFF shared library information.
14838@item IS_COMMON
14839Section contains common symbols.
14840@end table
14841@end table
6763aef9 14842@kindex set trust-readonly-sections
9c16f35a 14843@cindex read-only sections
6763aef9
MS
14844@item set trust-readonly-sections on
14845Tell @value{GDBN} that readonly sections in your object file
6ca652b0 14846really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
14847In that case, @value{GDBN} can fetch values from these sections
14848out of the object file, rather than from the target program.
14849For some targets (notably embedded ones), this can be a significant
14850enhancement to debugging performance.
14851
14852The default is off.
14853
14854@item set trust-readonly-sections off
15110bc3 14855Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
14856the contents of the section might change while the program is running,
14857and must therefore be fetched from the target when needed.
9c16f35a
EZ
14858
14859@item show trust-readonly-sections
14860Show the current setting of trusting readonly sections.
c906108c
SS
14861@end table
14862
14863All file-specifying commands allow both absolute and relative file names
14864as arguments. @value{GDBN} always converts the file name to an absolute file
14865name and remembers it that way.
14866
c906108c 14867@cindex shared libraries
9cceb671
DJ
14868@anchor{Shared Libraries}
14869@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 14870and IBM RS/6000 AIX shared libraries.
53a5351d 14871
9cceb671
DJ
14872On MS-Windows @value{GDBN} must be linked with the Expat library to support
14873shared libraries. @xref{Expat}.
14874
c906108c
SS
14875@value{GDBN} automatically loads symbol definitions from shared libraries
14876when you use the @code{run} command, or when you examine a core file.
14877(Before you issue the @code{run} command, @value{GDBN} does not understand
14878references to a function in a shared library, however---unless you are
14879debugging a core file).
53a5351d
JM
14880
14881On HP-UX, if the program loads a library explicitly, @value{GDBN}
14882automatically loads the symbols at the time of the @code{shl_load} call.
14883
c906108c
SS
14884@c FIXME: some @value{GDBN} release may permit some refs to undef
14885@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
14886@c FIXME...lib; check this from time to time when updating manual
14887
b7209cb4
FF
14888There are times, however, when you may wish to not automatically load
14889symbol definitions from shared libraries, such as when they are
14890particularly large or there are many of them.
14891
14892To control the automatic loading of shared library symbols, use the
14893commands:
14894
14895@table @code
14896@kindex set auto-solib-add
14897@item set auto-solib-add @var{mode}
14898If @var{mode} is @code{on}, symbols from all shared object libraries
14899will be loaded automatically when the inferior begins execution, you
14900attach to an independently started inferior, or when the dynamic linker
14901informs @value{GDBN} that a new library has been loaded. If @var{mode}
14902is @code{off}, symbols must be loaded manually, using the
14903@code{sharedlibrary} command. The default value is @code{on}.
14904
dcaf7c2c
EZ
14905@cindex memory used for symbol tables
14906If your program uses lots of shared libraries with debug info that
14907takes large amounts of memory, you can decrease the @value{GDBN}
14908memory footprint by preventing it from automatically loading the
14909symbols from shared libraries. To that end, type @kbd{set
14910auto-solib-add off} before running the inferior, then load each
14911library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 14912@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
14913the libraries whose symbols you want to be loaded.
14914
b7209cb4
FF
14915@kindex show auto-solib-add
14916@item show auto-solib-add
14917Display the current autoloading mode.
14918@end table
14919
c45da7e6 14920@cindex load shared library
b7209cb4
FF
14921To explicitly load shared library symbols, use the @code{sharedlibrary}
14922command:
14923
c906108c
SS
14924@table @code
14925@kindex info sharedlibrary
14926@kindex info share
55333a84
DE
14927@item info share @var{regex}
14928@itemx info sharedlibrary @var{regex}
14929Print the names of the shared libraries which are currently loaded
14930that match @var{regex}. If @var{regex} is omitted then print
14931all shared libraries that are loaded.
c906108c
SS
14932
14933@kindex sharedlibrary
14934@kindex share
14935@item sharedlibrary @var{regex}
14936@itemx share @var{regex}
c906108c
SS
14937Load shared object library symbols for files matching a
14938Unix regular expression.
14939As with files loaded automatically, it only loads shared libraries
14940required by your program for a core file or after typing @code{run}. If
14941@var{regex} is omitted all shared libraries required by your program are
14942loaded.
c45da7e6
EZ
14943
14944@item nosharedlibrary
14945@kindex nosharedlibrary
14946@cindex unload symbols from shared libraries
14947Unload all shared object library symbols. This discards all symbols
14948that have been loaded from all shared libraries. Symbols from shared
14949libraries that were loaded by explicit user requests are not
14950discarded.
c906108c
SS
14951@end table
14952
721c2651
EZ
14953Sometimes you may wish that @value{GDBN} stops and gives you control
14954when any of shared library events happen. Use the @code{set
14955stop-on-solib-events} command for this:
14956
14957@table @code
14958@item set stop-on-solib-events
14959@kindex set stop-on-solib-events
14960This command controls whether @value{GDBN} should give you control
14961when the dynamic linker notifies it about some shared library event.
14962The most common event of interest is loading or unloading of a new
14963shared library.
14964
14965@item show stop-on-solib-events
14966@kindex show stop-on-solib-events
14967Show whether @value{GDBN} stops and gives you control when shared
14968library events happen.
14969@end table
14970
f5ebfba0 14971Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
14972configurations. @value{GDBN} needs to have access to the target's libraries;
14973this can be accomplished either by providing copies of the libraries
14974on the host system, or by asking @value{GDBN} to automatically retrieve the
14975libraries from the target. If copies of the target libraries are
14976provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
14977copies on the target can be stripped as long as the copies on the host are
14978not.
14979
59b7b46f
EZ
14980@cindex where to look for shared libraries
14981For remote debugging, you need to tell @value{GDBN} where the target
14982libraries are, so that it can load the correct copies---otherwise, it
14983may try to load the host's libraries. @value{GDBN} has two variables
14984to specify the search directories for target libraries.
f5ebfba0
DJ
14985
14986@table @code
59b7b46f 14987@cindex prefix for shared library file names
f822c95b 14988@cindex system root, alternate
f5ebfba0 14989@kindex set solib-absolute-prefix
f822c95b
DJ
14990@kindex set sysroot
14991@item set sysroot @var{path}
14992Use @var{path} as the system root for the program being debugged. Any
14993absolute shared library paths will be prefixed with @var{path}; many
14994runtime loaders store the absolute paths to the shared library in the
14995target program's memory. If you use @code{set sysroot} to find shared
14996libraries, they need to be laid out in the same way that they are on
14997the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
14998under @var{path}.
14999
f1838a98
UW
15000If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
15001retrieve the target libraries from the remote system. This is only
15002supported when using a remote target that supports the @code{remote get}
15003command (@pxref{File Transfer,,Sending files to a remote system}).
15004The part of @var{path} following the initial @file{remote:}
15005(if present) is used as system root prefix on the remote file system.
15006@footnote{If you want to specify a local system root using a directory
15007that happens to be named @file{remote:}, you need to use some equivalent
15008variant of the name like @file{./remote:}.}
15009
ab38a727
PA
15010For targets with an MS-DOS based filesystem, such as MS-Windows and
15011SymbianOS, @value{GDBN} tries prefixing a few variants of the target
15012absolute file name with @var{path}. But first, on Unix hosts,
15013@value{GDBN} converts all backslash directory separators into forward
15014slashes, because the backslash is not a directory separator on Unix:
15015
15016@smallexample
15017 c:\foo\bar.dll @result{} c:/foo/bar.dll
15018@end smallexample
15019
15020Then, @value{GDBN} attempts prefixing the target file name with
15021@var{path}, and looks for the resulting file name in the host file
15022system:
15023
15024@smallexample
15025 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
15026@end smallexample
15027
15028If that does not find the shared library, @value{GDBN} tries removing
15029the @samp{:} character from the drive spec, both for convenience, and,
15030for the case of the host file system not supporting file names with
15031colons:
15032
15033@smallexample
15034 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
15035@end smallexample
15036
15037This makes it possible to have a system root that mirrors a target
15038with more than one drive. E.g., you may want to setup your local
15039copies of the target system shared libraries like so (note @samp{c} vs
15040@samp{z}):
15041
15042@smallexample
15043 @file{/path/to/sysroot/c/sys/bin/foo.dll}
15044 @file{/path/to/sysroot/c/sys/bin/bar.dll}
15045 @file{/path/to/sysroot/z/sys/bin/bar.dll}
15046@end smallexample
15047
15048@noindent
15049and point the system root at @file{/path/to/sysroot}, so that
15050@value{GDBN} can find the correct copies of both
15051@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
15052
15053If that still does not find the shared library, @value{GDBN} tries
15054removing the whole drive spec from the target file name:
15055
15056@smallexample
15057 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
15058@end smallexample
15059
15060This last lookup makes it possible to not care about the drive name,
15061if you don't want or need to.
15062
f822c95b
DJ
15063The @code{set solib-absolute-prefix} command is an alias for @code{set
15064sysroot}.
15065
15066@cindex default system root
59b7b46f 15067@cindex @samp{--with-sysroot}
f822c95b
DJ
15068You can set the default system root by using the configure-time
15069@samp{--with-sysroot} option. If the system root is inside
15070@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
15071@samp{--exec-prefix}), then the default system root will be updated
15072automatically if the installed @value{GDBN} is moved to a new
15073location.
15074
15075@kindex show sysroot
15076@item show sysroot
f5ebfba0
DJ
15077Display the current shared library prefix.
15078
15079@kindex set solib-search-path
15080@item set solib-search-path @var{path}
f822c95b
DJ
15081If this variable is set, @var{path} is a colon-separated list of
15082directories to search for shared libraries. @samp{solib-search-path}
15083is used after @samp{sysroot} fails to locate the library, or if the
15084path to the library is relative instead of absolute. If you want to
15085use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 15086@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 15087finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 15088it to a nonexistent directory may interfere with automatic loading
f822c95b 15089of shared library symbols.
f5ebfba0
DJ
15090
15091@kindex show solib-search-path
15092@item show solib-search-path
15093Display the current shared library search path.
ab38a727
PA
15094
15095@cindex DOS file-name semantics of file names.
15096@kindex set target-file-system-kind (unix|dos-based|auto)
15097@kindex show target-file-system-kind
15098@item set target-file-system-kind @var{kind}
15099Set assumed file system kind for target reported file names.
15100
15101Shared library file names as reported by the target system may not
15102make sense as is on the system @value{GDBN} is running on. For
15103example, when remote debugging a target that has MS-DOS based file
15104system semantics, from a Unix host, the target may be reporting to
15105@value{GDBN} a list of loaded shared libraries with file names such as
15106@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
15107drive letters, so the @samp{c:\} prefix is not normally understood as
15108indicating an absolute file name, and neither is the backslash
15109normally considered a directory separator character. In that case,
15110the native file system would interpret this whole absolute file name
15111as a relative file name with no directory components. This would make
15112it impossible to point @value{GDBN} at a copy of the remote target's
15113shared libraries on the host using @code{set sysroot}, and impractical
15114with @code{set solib-search-path}. Setting
15115@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
15116to interpret such file names similarly to how the target would, and to
15117map them to file names valid on @value{GDBN}'s native file system
15118semantics. The value of @var{kind} can be @code{"auto"}, in addition
15119to one of the supported file system kinds. In that case, @value{GDBN}
15120tries to determine the appropriate file system variant based on the
15121current target's operating system (@pxref{ABI, ,Configuring the
15122Current ABI}). The supported file system settings are:
15123
15124@table @code
15125@item unix
15126Instruct @value{GDBN} to assume the target file system is of Unix
15127kind. Only file names starting the forward slash (@samp{/}) character
15128are considered absolute, and the directory separator character is also
15129the forward slash.
15130
15131@item dos-based
15132Instruct @value{GDBN} to assume the target file system is DOS based.
15133File names starting with either a forward slash, or a drive letter
15134followed by a colon (e.g., @samp{c:}), are considered absolute, and
15135both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
15136considered directory separators.
15137
15138@item auto
15139Instruct @value{GDBN} to use the file system kind associated with the
15140target operating system (@pxref{ABI, ,Configuring the Current ABI}).
15141This is the default.
15142@end table
f5ebfba0
DJ
15143@end table
15144
5b5d99cf
JB
15145
15146@node Separate Debug Files
15147@section Debugging Information in Separate Files
15148@cindex separate debugging information files
15149@cindex debugging information in separate files
15150@cindex @file{.debug} subdirectories
15151@cindex debugging information directory, global
15152@cindex global debugging information directory
c7e83d54
EZ
15153@cindex build ID, and separate debugging files
15154@cindex @file{.build-id} directory
5b5d99cf
JB
15155
15156@value{GDBN} allows you to put a program's debugging information in a
15157file separate from the executable itself, in a way that allows
15158@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
15159Since debugging information can be very large---sometimes larger
15160than the executable code itself---some systems distribute debugging
5b5d99cf
JB
15161information for their executables in separate files, which users can
15162install only when they need to debug a problem.
15163
c7e83d54
EZ
15164@value{GDBN} supports two ways of specifying the separate debug info
15165file:
5b5d99cf
JB
15166
15167@itemize @bullet
15168@item
c7e83d54
EZ
15169The executable contains a @dfn{debug link} that specifies the name of
15170the separate debug info file. The separate debug file's name is
15171usually @file{@var{executable}.debug}, where @var{executable} is the
15172name of the corresponding executable file without leading directories
15173(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
15174debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
15175checksum for the debug file, which @value{GDBN} uses to validate that
15176the executable and the debug file came from the same build.
c7e83d54
EZ
15177
15178@item
7e27a47a 15179The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 15180also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
15181only on some operating systems, notably those which use the ELF format
15182for binary files and the @sc{gnu} Binutils.) For more details about
15183this feature, see the description of the @option{--build-id}
15184command-line option in @ref{Options, , Command Line Options, ld.info,
15185The GNU Linker}. The debug info file's name is not specified
15186explicitly by the build ID, but can be computed from the build ID, see
15187below.
d3750b24
JK
15188@end itemize
15189
c7e83d54
EZ
15190Depending on the way the debug info file is specified, @value{GDBN}
15191uses two different methods of looking for the debug file:
d3750b24
JK
15192
15193@itemize @bullet
15194@item
c7e83d54
EZ
15195For the ``debug link'' method, @value{GDBN} looks up the named file in
15196the directory of the executable file, then in a subdirectory of that
15197directory named @file{.debug}, and finally under the global debug
15198directory, in a subdirectory whose name is identical to the leading
15199directories of the executable's absolute file name.
15200
15201@item
83f83d7f 15202For the ``build ID'' method, @value{GDBN} looks in the
c7e83d54
EZ
15203@file{.build-id} subdirectory of the global debug directory for a file
15204named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
15205first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
15206are the rest of the bit string. (Real build ID strings are 32 or more
15207hex characters, not 10.)
c7e83d54
EZ
15208@end itemize
15209
15210So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
15211@file{/usr/bin/ls}, which has a debug link that specifies the
15212file @file{ls.debug}, and a build ID whose value in hex is
c7e83d54
EZ
15213@code{abcdef1234}. If the global debug directory is
15214@file{/usr/lib/debug}, then @value{GDBN} will look for the following
15215debug information files, in the indicated order:
15216
15217@itemize @minus
15218@item
15219@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 15220@item
c7e83d54 15221@file{/usr/bin/ls.debug}
5b5d99cf 15222@item
c7e83d54 15223@file{/usr/bin/.debug/ls.debug}
5b5d99cf 15224@item
c7e83d54 15225@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 15226@end itemize
5b5d99cf
JB
15227
15228You can set the global debugging info directory's name, and view the
15229name @value{GDBN} is currently using.
15230
15231@table @code
15232
15233@kindex set debug-file-directory
24ddea62
JK
15234@item set debug-file-directory @var{directories}
15235Set the directories which @value{GDBN} searches for separate debugging
15236information files to @var{directory}. Multiple directory components can be set
15237concatenating them by a directory separator.
5b5d99cf
JB
15238
15239@kindex show debug-file-directory
15240@item show debug-file-directory
24ddea62 15241Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
15242information files.
15243
15244@end table
15245
15246@cindex @code{.gnu_debuglink} sections
c7e83d54 15247@cindex debug link sections
5b5d99cf
JB
15248A debug link is a special section of the executable file named
15249@code{.gnu_debuglink}. The section must contain:
15250
15251@itemize
15252@item
15253A filename, with any leading directory components removed, followed by
15254a zero byte,
15255@item
15256zero to three bytes of padding, as needed to reach the next four-byte
15257boundary within the section, and
15258@item
15259a four-byte CRC checksum, stored in the same endianness used for the
15260executable file itself. The checksum is computed on the debugging
15261information file's full contents by the function given below, passing
15262zero as the @var{crc} argument.
15263@end itemize
15264
15265Any executable file format can carry a debug link, as long as it can
15266contain a section named @code{.gnu_debuglink} with the contents
15267described above.
15268
d3750b24 15269@cindex @code{.note.gnu.build-id} sections
c7e83d54 15270@cindex build ID sections
7e27a47a
EZ
15271The build ID is a special section in the executable file (and in other
15272ELF binary files that @value{GDBN} may consider). This section is
15273often named @code{.note.gnu.build-id}, but that name is not mandatory.
15274It contains unique identification for the built files---the ID remains
15275the same across multiple builds of the same build tree. The default
15276algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
15277content for the build ID string. The same section with an identical
15278value is present in the original built binary with symbols, in its
15279stripped variant, and in the separate debugging information file.
d3750b24 15280
5b5d99cf
JB
15281The debugging information file itself should be an ordinary
15282executable, containing a full set of linker symbols, sections, and
15283debugging information. The sections of the debugging information file
c7e83d54
EZ
15284should have the same names, addresses, and sizes as the original file,
15285but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
15286in an ordinary executable.
15287
7e27a47a 15288The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
15289@samp{objcopy} utility that can produce
15290the separated executable / debugging information file pairs using the
15291following commands:
15292
15293@smallexample
15294@kbd{objcopy --only-keep-debug foo foo.debug}
15295@kbd{strip -g foo}
c7e83d54
EZ
15296@end smallexample
15297
15298@noindent
15299These commands remove the debugging
83f83d7f
JK
15300information from the executable file @file{foo} and place it in the file
15301@file{foo.debug}. You can use the first, second or both methods to link the
15302two files:
15303
15304@itemize @bullet
15305@item
15306The debug link method needs the following additional command to also leave
15307behind a debug link in @file{foo}:
15308
15309@smallexample
15310@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
15311@end smallexample
15312
15313Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 15314a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
15315foo.debug} has the same functionality as the two @code{objcopy} commands and
15316the @code{ln -s} command above, together.
15317
15318@item
15319Build ID gets embedded into the main executable using @code{ld --build-id} or
15320the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
15321compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 15322utilities (Binutils) package since version 2.18.
83f83d7f
JK
15323@end itemize
15324
15325@noindent
d3750b24 15326
99e008fe
EZ
15327@cindex CRC algorithm definition
15328The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
15329IEEE 802.3 using the polynomial:
15330
15331@c TexInfo requires naked braces for multi-digit exponents for Tex
15332@c output, but this causes HTML output to barf. HTML has to be set using
15333@c raw commands. So we end up having to specify this equation in 2
15334@c different ways!
15335@ifhtml
15336@display
15337@html
15338 <em>x</em><sup>32</sup> + <em>x</em><sup>26</sup> + <em>x</em><sup>23</sup> + <em>x</em><sup>22</sup> + <em>x</em><sup>16</sup> + <em>x</em><sup>12</sup> + <em>x</em><sup>11</sup>
15339 + <em>x</em><sup>10</sup> + <em>x</em><sup>8</sup> + <em>x</em><sup>7</sup> + <em>x</em><sup>5</sup> + <em>x</em><sup>4</sup> + <em>x</em><sup>2</sup> + <em>x</em> + 1
15340@end html
15341@end display
15342@end ifhtml
15343@ifnothtml
15344@display
15345 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
15346 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
15347@end display
15348@end ifnothtml
15349
15350The function is computed byte at a time, taking the least
15351significant bit of each byte first. The initial pattern
15352@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
15353the final result is inverted to ensure trailing zeros also affect the
15354CRC.
15355
15356@emph{Note:} This is the same CRC polynomial as used in handling the
15357@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
15358, @value{GDBN} Remote Serial Protocol}). However in the
15359case of the Remote Serial Protocol, the CRC is computed @emph{most}
15360significant bit first, and the result is not inverted, so trailing
15361zeros have no effect on the CRC value.
15362
15363To complete the description, we show below the code of the function
15364which produces the CRC used in @code{.gnu_debuglink}. Inverting the
15365initially supplied @code{crc} argument means that an initial call to
15366this function passing in zero will start computing the CRC using
15367@code{0xffffffff}.
5b5d99cf 15368
4644b6e3 15369@kindex gnu_debuglink_crc32
5b5d99cf
JB
15370@smallexample
15371unsigned long
15372gnu_debuglink_crc32 (unsigned long crc,
15373 unsigned char *buf, size_t len)
15374@{
15375 static const unsigned long crc32_table[256] =
15376 @{
15377 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
15378 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
15379 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
15380 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
15381 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
15382 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
15383 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
15384 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
15385 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
15386 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
15387 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
15388 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
15389 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
15390 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
15391 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
15392 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
15393 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
15394 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
15395 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
15396 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
15397 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
15398 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
15399 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
15400 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
15401 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
15402 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
15403 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
15404 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
15405 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
15406 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
15407 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
15408 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
15409 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
15410 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
15411 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
15412 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
15413 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
15414 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
15415 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
15416 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
15417 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
15418 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
15419 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
15420 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
15421 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
15422 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
15423 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
15424 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
15425 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
15426 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
15427 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
15428 0x2d02ef8d
15429 @};
15430 unsigned char *end;
15431
15432 crc = ~crc & 0xffffffff;
15433 for (end = buf + len; buf < end; ++buf)
15434 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 15435 return ~crc & 0xffffffff;
5b5d99cf
JB
15436@}
15437@end smallexample
15438
c7e83d54
EZ
15439@noindent
15440This computation does not apply to the ``build ID'' method.
15441
5b5d99cf 15442
9291a0cd
TT
15443@node Index Files
15444@section Index Files Speed Up @value{GDBN}
15445@cindex index files
15446@cindex @samp{.gdb_index} section
15447
15448When @value{GDBN} finds a symbol file, it scans the symbols in the
15449file in order to construct an internal symbol table. This lets most
15450@value{GDBN} operations work quickly---at the cost of a delay early
15451on. For large programs, this delay can be quite lengthy, so
15452@value{GDBN} provides a way to build an index, which speeds up
15453startup.
15454
15455The index is stored as a section in the symbol file. @value{GDBN} can
15456write the index to a file, then you can put it into the symbol file
15457using @command{objcopy}.
15458
15459To create an index file, use the @code{save gdb-index} command:
15460
15461@table @code
15462@item save gdb-index @var{directory}
15463@kindex save gdb-index
15464Create an index file for each symbol file currently known by
15465@value{GDBN}. Each file is named after its corresponding symbol file,
15466with @samp{.gdb-index} appended, and is written into the given
15467@var{directory}.
15468@end table
15469
15470Once you have created an index file you can merge it into your symbol
15471file, here named @file{symfile}, using @command{objcopy}:
15472
15473@smallexample
15474$ objcopy --add-section .gdb_index=symfile.gdb-index \
15475 --set-section-flags .gdb_index=readonly symfile symfile
15476@end smallexample
15477
15478There are currently some limitation on indices. They only work when
15479for DWARF debugging information, not stabs. And, they do not
15480currently work for programs using Ada.
15481
6d2ebf8b 15482@node Symbol Errors
79a6e687 15483@section Errors Reading Symbol Files
c906108c
SS
15484
15485While reading a symbol file, @value{GDBN} occasionally encounters problems,
15486such as symbol types it does not recognize, or known bugs in compiler
15487output. By default, @value{GDBN} does not notify you of such problems, since
15488they are relatively common and primarily of interest to people
15489debugging compilers. If you are interested in seeing information
15490about ill-constructed symbol tables, you can either ask @value{GDBN} to print
15491only one message about each such type of problem, no matter how many
15492times the problem occurs; or you can ask @value{GDBN} to print more messages,
15493to see how many times the problems occur, with the @code{set
79a6e687
BW
15494complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
15495Messages}).
c906108c
SS
15496
15497The messages currently printed, and their meanings, include:
15498
15499@table @code
15500@item inner block not inside outer block in @var{symbol}
15501
15502The symbol information shows where symbol scopes begin and end
15503(such as at the start of a function or a block of statements). This
15504error indicates that an inner scope block is not fully contained
15505in its outer scope blocks.
15506
15507@value{GDBN} circumvents the problem by treating the inner block as if it had
15508the same scope as the outer block. In the error message, @var{symbol}
15509may be shown as ``@code{(don't know)}'' if the outer block is not a
15510function.
15511
15512@item block at @var{address} out of order
15513
15514The symbol information for symbol scope blocks should occur in
15515order of increasing addresses. This error indicates that it does not
15516do so.
15517
15518@value{GDBN} does not circumvent this problem, and has trouble
15519locating symbols in the source file whose symbols it is reading. (You
15520can often determine what source file is affected by specifying
79a6e687
BW
15521@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
15522Messages}.)
c906108c
SS
15523
15524@item bad block start address patched
15525
15526The symbol information for a symbol scope block has a start address
15527smaller than the address of the preceding source line. This is known
15528to occur in the SunOS 4.1.1 (and earlier) C compiler.
15529
15530@value{GDBN} circumvents the problem by treating the symbol scope block as
15531starting on the previous source line.
15532
15533@item bad string table offset in symbol @var{n}
15534
15535@cindex foo
15536Symbol number @var{n} contains a pointer into the string table which is
15537larger than the size of the string table.
15538
15539@value{GDBN} circumvents the problem by considering the symbol to have the
15540name @code{foo}, which may cause other problems if many symbols end up
15541with this name.
15542
15543@item unknown symbol type @code{0x@var{nn}}
15544
7a292a7a
SS
15545The symbol information contains new data types that @value{GDBN} does
15546not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 15547uncomprehended information, in hexadecimal.
c906108c 15548
7a292a7a
SS
15549@value{GDBN} circumvents the error by ignoring this symbol information.
15550This usually allows you to debug your program, though certain symbols
c906108c 15551are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
15552debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
15553on @code{complain}, then go up to the function @code{read_dbx_symtab}
15554and examine @code{*bufp} to see the symbol.
c906108c
SS
15555
15556@item stub type has NULL name
c906108c 15557
7a292a7a 15558@value{GDBN} could not find the full definition for a struct or class.
c906108c 15559
7a292a7a 15560@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 15561The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
15562information that recent versions of the compiler should have output for
15563it.
c906108c
SS
15564
15565@item info mismatch between compiler and debugger
15566
15567@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 15568
c906108c
SS
15569@end table
15570
b14b1491
TT
15571@node Data Files
15572@section GDB Data Files
15573
15574@cindex prefix for data files
15575@value{GDBN} will sometimes read an auxiliary data file. These files
15576are kept in a directory known as the @dfn{data directory}.
15577
15578You can set the data directory's name, and view the name @value{GDBN}
15579is currently using.
15580
15581@table @code
15582@kindex set data-directory
15583@item set data-directory @var{directory}
15584Set the directory which @value{GDBN} searches for auxiliary data files
15585to @var{directory}.
15586
15587@kindex show data-directory
15588@item show data-directory
15589Show the directory @value{GDBN} searches for auxiliary data files.
15590@end table
15591
15592@cindex default data directory
15593@cindex @samp{--with-gdb-datadir}
15594You can set the default data directory by using the configure-time
15595@samp{--with-gdb-datadir} option. If the data directory is inside
15596@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
15597@samp{--exec-prefix}), then the default data directory will be updated
15598automatically if the installed @value{GDBN} is moved to a new
15599location.
15600
6d2ebf8b 15601@node Targets
c906108c 15602@chapter Specifying a Debugging Target
7a292a7a 15603
c906108c 15604@cindex debugging target
c906108c 15605A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
15606
15607Often, @value{GDBN} runs in the same host environment as your program;
15608in that case, the debugging target is specified as a side effect when
15609you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
15610flexibility---for example, running @value{GDBN} on a physically separate
15611host, or controlling a standalone system over a serial port or a
53a5351d
JM
15612realtime system over a TCP/IP connection---you can use the @code{target}
15613command to specify one of the target types configured for @value{GDBN}
79a6e687 15614(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 15615
a8f24a35
EZ
15616@cindex target architecture
15617It is possible to build @value{GDBN} for several different @dfn{target
15618architectures}. When @value{GDBN} is built like that, you can choose
15619one of the available architectures with the @kbd{set architecture}
15620command.
15621
15622@table @code
15623@kindex set architecture
15624@kindex show architecture
15625@item set architecture @var{arch}
15626This command sets the current target architecture to @var{arch}. The
15627value of @var{arch} can be @code{"auto"}, in addition to one of the
15628supported architectures.
15629
15630@item show architecture
15631Show the current target architecture.
9c16f35a
EZ
15632
15633@item set processor
15634@itemx processor
15635@kindex set processor
15636@kindex show processor
15637These are alias commands for, respectively, @code{set architecture}
15638and @code{show architecture}.
a8f24a35
EZ
15639@end table
15640
c906108c
SS
15641@menu
15642* Active Targets:: Active targets
15643* Target Commands:: Commands for managing targets
c906108c 15644* Byte Order:: Choosing target byte order
c906108c
SS
15645@end menu
15646
6d2ebf8b 15647@node Active Targets
79a6e687 15648@section Active Targets
7a292a7a 15649
c906108c
SS
15650@cindex stacking targets
15651@cindex active targets
15652@cindex multiple targets
15653
8ea5bce5 15654There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
15655recording sessions. Core files belong to the process class, making core file
15656and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
15657on multiple active targets, one in each class. This allows you to (for
15658example) start a process and inspect its activity, while still having access to
15659the executable file after the process finishes. Or if you start process
15660recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
15661presented a virtual layer of the recording target, while the process target
15662remains stopped at the chronologically last point of the process execution.
15663
15664Use the @code{core-file} and @code{exec-file} commands to select a new core
15665file or executable target (@pxref{Files, ,Commands to Specify Files}). To
15666specify as a target a process that is already running, use the @code{attach}
15667command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 15668
6d2ebf8b 15669@node Target Commands
79a6e687 15670@section Commands for Managing Targets
c906108c
SS
15671
15672@table @code
15673@item target @var{type} @var{parameters}
7a292a7a
SS
15674Connects the @value{GDBN} host environment to a target machine or
15675process. A target is typically a protocol for talking to debugging
15676facilities. You use the argument @var{type} to specify the type or
15677protocol of the target machine.
c906108c
SS
15678
15679Further @var{parameters} are interpreted by the target protocol, but
15680typically include things like device names or host names to connect
15681with, process numbers, and baud rates.
c906108c
SS
15682
15683The @code{target} command does not repeat if you press @key{RET} again
15684after executing the command.
15685
15686@kindex help target
15687@item help target
15688Displays the names of all targets available. To display targets
15689currently selected, use either @code{info target} or @code{info files}
79a6e687 15690(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
15691
15692@item help target @var{name}
15693Describe a particular target, including any parameters necessary to
15694select it.
15695
15696@kindex set gnutarget
15697@item set gnutarget @var{args}
5d161b24 15698@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 15699knows whether it is reading an @dfn{executable},
5d161b24
DB
15700a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
15701with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
15702with @code{gnutarget} the @code{target} refers to a program, not a machine.
15703
d4f3574e 15704@quotation
c906108c
SS
15705@emph{Warning:} To specify a file format with @code{set gnutarget},
15706you must know the actual BFD name.
d4f3574e 15707@end quotation
c906108c 15708
d4f3574e 15709@noindent
79a6e687 15710@xref{Files, , Commands to Specify Files}.
c906108c 15711
5d161b24 15712@kindex show gnutarget
c906108c
SS
15713@item show gnutarget
15714Use the @code{show gnutarget} command to display what file format
15715@code{gnutarget} is set to read. If you have not set @code{gnutarget},
15716@value{GDBN} will determine the file format for each file automatically,
15717and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
15718@end table
15719
4644b6e3 15720@cindex common targets
c906108c
SS
15721Here are some common targets (available, or not, depending on the GDB
15722configuration):
c906108c
SS
15723
15724@table @code
4644b6e3 15725@kindex target
c906108c 15726@item target exec @var{program}
4644b6e3 15727@cindex executable file target
c906108c
SS
15728An executable file. @samp{target exec @var{program}} is the same as
15729@samp{exec-file @var{program}}.
15730
c906108c 15731@item target core @var{filename}
4644b6e3 15732@cindex core dump file target
c906108c
SS
15733A core dump file. @samp{target core @var{filename}} is the same as
15734@samp{core-file @var{filename}}.
c906108c 15735
1a10341b 15736@item target remote @var{medium}
4644b6e3 15737@cindex remote target
1a10341b
JB
15738A remote system connected to @value{GDBN} via a serial line or network
15739connection. This command tells @value{GDBN} to use its own remote
15740protocol over @var{medium} for debugging. @xref{Remote Debugging}.
15741
15742For example, if you have a board connected to @file{/dev/ttya} on the
15743machine running @value{GDBN}, you could say:
15744
15745@smallexample
15746target remote /dev/ttya
15747@end smallexample
15748
15749@code{target remote} supports the @code{load} command. This is only
15750useful if you have some other way of getting the stub to the target
15751system, and you can put it somewhere in memory where it won't get
15752clobbered by the download.
c906108c 15753
ee8e71d4 15754@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 15755@cindex built-in simulator target
2df3850c 15756Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 15757In general,
474c8240 15758@smallexample
104c1213
JM
15759 target sim
15760 load
15761 run
474c8240 15762@end smallexample
d4f3574e 15763@noindent
104c1213 15764works; however, you cannot assume that a specific memory map, device
d4f3574e 15765drivers, or even basic I/O is available, although some simulators do
104c1213
JM
15766provide these. For info about any processor-specific simulator details,
15767see the appropriate section in @ref{Embedded Processors, ,Embedded
15768Processors}.
15769
c906108c
SS
15770@end table
15771
104c1213 15772Some configurations may include these targets as well:
c906108c
SS
15773
15774@table @code
15775
c906108c 15776@item target nrom @var{dev}
4644b6e3 15777@cindex NetROM ROM emulator target
c906108c
SS
15778NetROM ROM emulator. This target only supports downloading.
15779
c906108c
SS
15780@end table
15781
5d161b24 15782Different targets are available on different configurations of @value{GDBN};
c906108c 15783your configuration may have more or fewer targets.
c906108c 15784
721c2651
EZ
15785Many remote targets require you to download the executable's code once
15786you've successfully established a connection. You may wish to control
3d00d119
DJ
15787various aspects of this process.
15788
15789@table @code
721c2651
EZ
15790
15791@item set hash
15792@kindex set hash@r{, for remote monitors}
15793@cindex hash mark while downloading
15794This command controls whether a hash mark @samp{#} is displayed while
15795downloading a file to the remote monitor. If on, a hash mark is
15796displayed after each S-record is successfully downloaded to the
15797monitor.
15798
15799@item show hash
15800@kindex show hash@r{, for remote monitors}
15801Show the current status of displaying the hash mark.
15802
15803@item set debug monitor
15804@kindex set debug monitor
15805@cindex display remote monitor communications
15806Enable or disable display of communications messages between
15807@value{GDBN} and the remote monitor.
15808
15809@item show debug monitor
15810@kindex show debug monitor
15811Show the current status of displaying communications between
15812@value{GDBN} and the remote monitor.
a8f24a35 15813@end table
c906108c
SS
15814
15815@table @code
15816
15817@kindex load @var{filename}
15818@item load @var{filename}
8edfe269 15819@anchor{load}
c906108c
SS
15820Depending on what remote debugging facilities are configured into
15821@value{GDBN}, the @code{load} command may be available. Where it exists, it
15822is meant to make @var{filename} (an executable) available for debugging
15823on the remote system---by downloading, or dynamic linking, for example.
15824@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
15825the @code{add-symbol-file} command.
15826
15827If your @value{GDBN} does not have a @code{load} command, attempting to
15828execute it gets the error message ``@code{You can't do that when your
15829target is @dots{}}''
c906108c
SS
15830
15831The file is loaded at whatever address is specified in the executable.
15832For some object file formats, you can specify the load address when you
15833link the program; for other formats, like a.out, the object file format
15834specifies a fixed address.
15835@c FIXME! This would be a good place for an xref to the GNU linker doc.
15836
68437a39
DJ
15837Depending on the remote side capabilities, @value{GDBN} may be able to
15838load programs into flash memory.
15839
c906108c
SS
15840@code{load} does not repeat if you press @key{RET} again after using it.
15841@end table
15842
6d2ebf8b 15843@node Byte Order
79a6e687 15844@section Choosing Target Byte Order
7a292a7a 15845
c906108c
SS
15846@cindex choosing target byte order
15847@cindex target byte order
c906108c 15848
172c2a43 15849Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
15850offer the ability to run either big-endian or little-endian byte
15851orders. Usually the executable or symbol will include a bit to
15852designate the endian-ness, and you will not need to worry about
15853which to use. However, you may still find it useful to adjust
d4f3574e 15854@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
15855
15856@table @code
4644b6e3 15857@kindex set endian
c906108c
SS
15858@item set endian big
15859Instruct @value{GDBN} to assume the target is big-endian.
15860
c906108c
SS
15861@item set endian little
15862Instruct @value{GDBN} to assume the target is little-endian.
15863
c906108c
SS
15864@item set endian auto
15865Instruct @value{GDBN} to use the byte order associated with the
15866executable.
15867
15868@item show endian
15869Display @value{GDBN}'s current idea of the target byte order.
15870
15871@end table
15872
15873Note that these commands merely adjust interpretation of symbolic
15874data on the host, and that they have absolutely no effect on the
15875target system.
15876
ea35711c
DJ
15877
15878@node Remote Debugging
15879@chapter Debugging Remote Programs
c906108c
SS
15880@cindex remote debugging
15881
15882If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
15883@value{GDBN} in the usual way, it is often useful to use remote debugging.
15884For example, you might use remote debugging on an operating system kernel,
c906108c
SS
15885or on a small system which does not have a general purpose operating system
15886powerful enough to run a full-featured debugger.
15887
15888Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
15889to make this work with particular debugging targets. In addition,
5d161b24 15890@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
15891but not specific to any particular target system) which you can use if you
15892write the remote stubs---the code that runs on the remote system to
15893communicate with @value{GDBN}.
15894
15895Other remote targets may be available in your
15896configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 15897
6b2f586d 15898@menu
07f31aa6 15899* Connecting:: Connecting to a remote target
a6b151f1 15900* File Transfer:: Sending files to a remote system
6b2f586d 15901* Server:: Using the gdbserver program
79a6e687
BW
15902* Remote Configuration:: Remote configuration
15903* Remote Stub:: Implementing a remote stub
6b2f586d
AC
15904@end menu
15905
07f31aa6 15906@node Connecting
79a6e687 15907@section Connecting to a Remote Target
07f31aa6
DJ
15908
15909On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 15910your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
15911Start up @value{GDBN} as usual, using the name of the local copy of your
15912program as the first argument.
15913
86941c27
JB
15914@cindex @code{target remote}
15915@value{GDBN} can communicate with the target over a serial line, or
15916over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
15917each case, @value{GDBN} uses the same protocol for debugging your
15918program; only the medium carrying the debugging packets varies. The
15919@code{target remote} command establishes a connection to the target.
15920Its arguments indicate which medium to use:
15921
15922@table @code
15923
15924@item target remote @var{serial-device}
07f31aa6 15925@cindex serial line, @code{target remote}
86941c27
JB
15926Use @var{serial-device} to communicate with the target. For example,
15927to use a serial line connected to the device named @file{/dev/ttyb}:
15928
15929@smallexample
15930target remote /dev/ttyb
15931@end smallexample
15932
07f31aa6
DJ
15933If you're using a serial line, you may want to give @value{GDBN} the
15934@w{@samp{--baud}} option, or use the @code{set remotebaud} command
79a6e687 15935(@pxref{Remote Configuration, set remotebaud}) before the
9c16f35a 15936@code{target} command.
07f31aa6 15937
86941c27
JB
15938@item target remote @code{@var{host}:@var{port}}
15939@itemx target remote @code{tcp:@var{host}:@var{port}}
15940@cindex @acronym{TCP} port, @code{target remote}
15941Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
15942The @var{host} may be either a host name or a numeric @acronym{IP}
15943address; @var{port} must be a decimal number. The @var{host} could be
15944the target machine itself, if it is directly connected to the net, or
15945it might be a terminal server which in turn has a serial line to the
15946target.
07f31aa6 15947
86941c27
JB
15948For example, to connect to port 2828 on a terminal server named
15949@code{manyfarms}:
07f31aa6
DJ
15950
15951@smallexample
15952target remote manyfarms:2828
15953@end smallexample
15954
86941c27
JB
15955If your remote target is actually running on the same machine as your
15956debugger session (e.g.@: a simulator for your target running on the
15957same host), you can omit the hostname. For example, to connect to
15958port 1234 on your local machine:
07f31aa6
DJ
15959
15960@smallexample
15961target remote :1234
15962@end smallexample
15963@noindent
15964
15965Note that the colon is still required here.
15966
86941c27
JB
15967@item target remote @code{udp:@var{host}:@var{port}}
15968@cindex @acronym{UDP} port, @code{target remote}
15969Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
15970connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
15971
15972@smallexample
15973target remote udp:manyfarms:2828
15974@end smallexample
15975
86941c27
JB
15976When using a @acronym{UDP} connection for remote debugging, you should
15977keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
15978can silently drop packets on busy or unreliable networks, which will
15979cause havoc with your debugging session.
15980
66b8c7f6
JB
15981@item target remote | @var{command}
15982@cindex pipe, @code{target remote} to
15983Run @var{command} in the background and communicate with it using a
15984pipe. The @var{command} is a shell command, to be parsed and expanded
15985by the system's command shell, @code{/bin/sh}; it should expect remote
15986protocol packets on its standard input, and send replies on its
15987standard output. You could use this to run a stand-alone simulator
15988that speaks the remote debugging protocol, to make net connections
15989using programs like @code{ssh}, or for other similar tricks.
15990
15991If @var{command} closes its standard output (perhaps by exiting),
15992@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
15993program has already exited, this will have no effect.)
15994
86941c27 15995@end table
07f31aa6 15996
86941c27 15997Once the connection has been established, you can use all the usual
8edfe269
DJ
15998commands to examine and change data. The remote program is already
15999running; you can use @kbd{step} and @kbd{continue}, and you do not
16000need to use @kbd{run}.
07f31aa6
DJ
16001
16002@cindex interrupting remote programs
16003@cindex remote programs, interrupting
16004Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 16005interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
16006program. This may or may not succeed, depending in part on the hardware
16007and the serial drivers the remote system uses. If you type the
16008interrupt character once again, @value{GDBN} displays this prompt:
16009
16010@smallexample
16011Interrupted while waiting for the program.
16012Give up (and stop debugging it)? (y or n)
16013@end smallexample
16014
16015If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
16016(If you decide you want to try again later, you can use @samp{target
16017remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
16018goes back to waiting.
16019
16020@table @code
16021@kindex detach (remote)
16022@item detach
16023When you have finished debugging the remote program, you can use the
16024@code{detach} command to release it from @value{GDBN} control.
16025Detaching from the target normally resumes its execution, but the results
16026will depend on your particular remote stub. After the @code{detach}
16027command, @value{GDBN} is free to connect to another target.
16028
16029@kindex disconnect
16030@item disconnect
16031The @code{disconnect} command behaves like @code{detach}, except that
16032the target is generally not resumed. It will wait for @value{GDBN}
16033(this instance or another one) to connect and continue debugging. After
16034the @code{disconnect} command, @value{GDBN} is again free to connect to
16035another target.
09d4efe1
EZ
16036
16037@cindex send command to remote monitor
fad38dfa
EZ
16038@cindex extend @value{GDBN} for remote targets
16039@cindex add new commands for external monitor
09d4efe1
EZ
16040@kindex monitor
16041@item monitor @var{cmd}
fad38dfa
EZ
16042This command allows you to send arbitrary commands directly to the
16043remote monitor. Since @value{GDBN} doesn't care about the commands it
16044sends like this, this command is the way to extend @value{GDBN}---you
16045can add new commands that only the external monitor will understand
16046and implement.
07f31aa6
DJ
16047@end table
16048
a6b151f1
DJ
16049@node File Transfer
16050@section Sending files to a remote system
16051@cindex remote target, file transfer
16052@cindex file transfer
16053@cindex sending files to remote systems
16054
16055Some remote targets offer the ability to transfer files over the same
16056connection used to communicate with @value{GDBN}. This is convenient
16057for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
16058running @code{gdbserver} over a network interface. For other targets,
16059e.g.@: embedded devices with only a single serial port, this may be
16060the only way to upload or download files.
16061
16062Not all remote targets support these commands.
16063
16064@table @code
16065@kindex remote put
16066@item remote put @var{hostfile} @var{targetfile}
16067Copy file @var{hostfile} from the host system (the machine running
16068@value{GDBN}) to @var{targetfile} on the target system.
16069
16070@kindex remote get
16071@item remote get @var{targetfile} @var{hostfile}
16072Copy file @var{targetfile} from the target system to @var{hostfile}
16073on the host system.
16074
16075@kindex remote delete
16076@item remote delete @var{targetfile}
16077Delete @var{targetfile} from the target system.
16078
16079@end table
16080
6f05cf9f 16081@node Server
79a6e687 16082@section Using the @code{gdbserver} Program
6f05cf9f
AC
16083
16084@kindex gdbserver
16085@cindex remote connection without stubs
16086@code{gdbserver} is a control program for Unix-like systems, which
16087allows you to connect your program with a remote @value{GDBN} via
16088@code{target remote}---but without linking in the usual debugging stub.
16089
16090@code{gdbserver} is not a complete replacement for the debugging stubs,
16091because it requires essentially the same operating-system facilities
16092that @value{GDBN} itself does. In fact, a system that can run
16093@code{gdbserver} to connect to a remote @value{GDBN} could also run
16094@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
16095because it is a much smaller program than @value{GDBN} itself. It is
16096also easier to port than all of @value{GDBN}, so you may be able to get
16097started more quickly on a new system by using @code{gdbserver}.
16098Finally, if you develop code for real-time systems, you may find that
16099the tradeoffs involved in real-time operation make it more convenient to
16100do as much development work as possible on another system, for example
16101by cross-compiling. You can use @code{gdbserver} to make a similar
16102choice for debugging.
16103
16104@value{GDBN} and @code{gdbserver} communicate via either a serial line
16105or a TCP connection, using the standard @value{GDBN} remote serial
16106protocol.
16107
2d717e4f
DJ
16108@quotation
16109@emph{Warning:} @code{gdbserver} does not have any built-in security.
16110Do not run @code{gdbserver} connected to any public network; a
16111@value{GDBN} connection to @code{gdbserver} provides access to the
16112target system with the same privileges as the user running
16113@code{gdbserver}.
16114@end quotation
16115
16116@subsection Running @code{gdbserver}
16117@cindex arguments, to @code{gdbserver}
16118
16119Run @code{gdbserver} on the target system. You need a copy of the
16120program you want to debug, including any libraries it requires.
6f05cf9f
AC
16121@code{gdbserver} does not need your program's symbol table, so you can
16122strip the program if necessary to save space. @value{GDBN} on the host
16123system does all the symbol handling.
16124
16125To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 16126the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
16127syntax is:
16128
16129@smallexample
16130target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
16131@end smallexample
16132
16133@var{comm} is either a device name (to use a serial line) or a TCP
16134hostname and portnumber. For example, to debug Emacs with the argument
16135@samp{foo.txt} and communicate with @value{GDBN} over the serial port
16136@file{/dev/com1}:
16137
16138@smallexample
16139target> gdbserver /dev/com1 emacs foo.txt
16140@end smallexample
16141
16142@code{gdbserver} waits passively for the host @value{GDBN} to communicate
16143with it.
16144
16145To use a TCP connection instead of a serial line:
16146
16147@smallexample
16148target> gdbserver host:2345 emacs foo.txt
16149@end smallexample
16150
16151The only difference from the previous example is the first argument,
16152specifying that you are communicating with the host @value{GDBN} via
16153TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
16154expect a TCP connection from machine @samp{host} to local TCP port 2345.
16155(Currently, the @samp{host} part is ignored.) You can choose any number
16156you want for the port number as long as it does not conflict with any
16157TCP ports already in use on the target system (for example, @code{23} is
16158reserved for @code{telnet}).@footnote{If you choose a port number that
16159conflicts with another service, @code{gdbserver} prints an error message
16160and exits.} You must use the same port number with the host @value{GDBN}
16161@code{target remote} command.
16162
2d717e4f
DJ
16163@subsubsection Attaching to a Running Program
16164
56460a61
DJ
16165On some targets, @code{gdbserver} can also attach to running programs.
16166This is accomplished via the @code{--attach} argument. The syntax is:
16167
16168@smallexample
2d717e4f 16169target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
16170@end smallexample
16171
16172@var{pid} is the process ID of a currently running process. It isn't necessary
16173to point @code{gdbserver} at a binary for the running process.
16174
b1fe9455
DJ
16175@pindex pidof
16176@cindex attach to a program by name
16177You can debug processes by name instead of process ID if your target has the
16178@code{pidof} utility:
16179
16180@smallexample
2d717e4f 16181target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
16182@end smallexample
16183
f822c95b 16184In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
16185has multiple threads, most versions of @code{pidof} support the
16186@code{-s} option to only return the first process ID.
16187
2d717e4f
DJ
16188@subsubsection Multi-Process Mode for @code{gdbserver}
16189@cindex gdbserver, multiple processes
16190@cindex multiple processes with gdbserver
16191
16192When you connect to @code{gdbserver} using @code{target remote},
16193@code{gdbserver} debugs the specified program only once. When the
16194program exits, or you detach from it, @value{GDBN} closes the connection
16195and @code{gdbserver} exits.
16196
6e6c6f50 16197If you connect using @kbd{target extended-remote}, @code{gdbserver}
2d717e4f
DJ
16198enters multi-process mode. When the debugged program exits, or you
16199detach from it, @value{GDBN} stays connected to @code{gdbserver} even
16200though no program is running. The @code{run} and @code{attach}
16201commands instruct @code{gdbserver} to run or attach to a new program.
16202The @code{run} command uses @code{set remote exec-file} (@pxref{set
16203remote exec-file}) to select the program to run. Command line
16204arguments are supported, except for wildcard expansion and I/O
16205redirection (@pxref{Arguments}).
16206
16207To start @code{gdbserver} without supplying an initial command to run
16208or process ID to attach, use the @option{--multi} command line option.
6e6c6f50 16209Then you can connect using @kbd{target extended-remote} and start
2d717e4f
DJ
16210the program you want to debug.
16211
16212@code{gdbserver} does not automatically exit in multi-process mode.
16213You can terminate it by using @code{monitor exit}
16214(@pxref{Monitor Commands for gdbserver}).
16215
16216@subsubsection Other Command-Line Arguments for @code{gdbserver}
16217
62709adf
PA
16218The @option{--debug} option tells @code{gdbserver} to display extra
16219status information about the debugging process. The
16220@option{--remote-debug} option tells @code{gdbserver} to display
16221remote protocol debug output. These options are intended for
16222@code{gdbserver} development and for bug reports to the developers.
2d717e4f 16223
ccd213ac
DJ
16224The @option{--wrapper} option specifies a wrapper to launch programs
16225for debugging. The option should be followed by the name of the
16226wrapper, then any command-line arguments to pass to the wrapper, then
16227@kbd{--} indicating the end of the wrapper arguments.
16228
16229@code{gdbserver} runs the specified wrapper program with a combined
16230command line including the wrapper arguments, then the name of the
16231program to debug, then any arguments to the program. The wrapper
16232runs until it executes your program, and then @value{GDBN} gains control.
16233
16234You can use any program that eventually calls @code{execve} with
16235its arguments as a wrapper. Several standard Unix utilities do
16236this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
16237with @code{exec "$@@"} will also work.
16238
16239For example, you can use @code{env} to pass an environment variable to
16240the debugged program, without setting the variable in @code{gdbserver}'s
16241environment:
16242
16243@smallexample
16244$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
16245@end smallexample
16246
2d717e4f
DJ
16247@subsection Connecting to @code{gdbserver}
16248
16249Run @value{GDBN} on the host system.
16250
16251First make sure you have the necessary symbol files. Load symbols for
f822c95b
DJ
16252your application using the @code{file} command before you connect. Use
16253@code{set sysroot} to locate target libraries (unless your @value{GDBN}
2d717e4f 16254was compiled with the correct sysroot using @code{--with-sysroot}).
f822c95b
DJ
16255
16256The symbol file and target libraries must exactly match the executable
16257and libraries on the target, with one exception: the files on the host
16258system should not be stripped, even if the files on the target system
16259are. Mismatched or missing files will lead to confusing results
16260during debugging. On @sc{gnu}/Linux targets, mismatched or missing
16261files may also prevent @code{gdbserver} from debugging multi-threaded
16262programs.
16263
79a6e687 16264Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
16265For TCP connections, you must start up @code{gdbserver} prior to using
16266the @code{target remote} command. Otherwise you may get an error whose
16267text depends on the host system, but which usually looks something like
2d717e4f 16268@samp{Connection refused}. Don't use the @code{load}
397ca115 16269command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 16270already on the target.
07f31aa6 16271
79a6e687 16272@subsection Monitor Commands for @code{gdbserver}
c74d0ad8 16273@cindex monitor commands, for @code{gdbserver}
2d717e4f 16274@anchor{Monitor Commands for gdbserver}
c74d0ad8
DJ
16275
16276During a @value{GDBN} session using @code{gdbserver}, you can use the
16277@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 16278Here are the available commands.
c74d0ad8
DJ
16279
16280@table @code
16281@item monitor help
16282List the available monitor commands.
16283
16284@item monitor set debug 0
16285@itemx monitor set debug 1
16286Disable or enable general debugging messages.
16287
16288@item monitor set remote-debug 0
16289@itemx monitor set remote-debug 1
16290Disable or enable specific debugging messages associated with the remote
16291protocol (@pxref{Remote Protocol}).
16292
cdbfd419
PP
16293@item monitor set libthread-db-search-path [PATH]
16294@cindex gdbserver, search path for @code{libthread_db}
16295When this command is issued, @var{path} is a colon-separated list of
16296directories to search for @code{libthread_db} (@pxref{Threads,,set
16297libthread-db-search-path}). If you omit @var{path},
16298@samp{libthread-db-search-path} will be reset to an empty list.
16299
2d717e4f
DJ
16300@item monitor exit
16301Tell gdbserver to exit immediately. This command should be followed by
16302@code{disconnect} to close the debugging session. @code{gdbserver} will
16303detach from any attached processes and kill any processes it created.
16304Use @code{monitor exit} to terminate @code{gdbserver} at the end
16305of a multi-process mode debug session.
16306
c74d0ad8
DJ
16307@end table
16308
fa593d66
PA
16309@subsection Tracepoints support in @code{gdbserver}
16310@cindex tracepoints support in @code{gdbserver}
16311
0fb4aa4b
PA
16312On some targets, @code{gdbserver} supports tracepoints, fast
16313tracepoints and static tracepoints.
fa593d66 16314
0fb4aa4b 16315For fast or static tracepoints to work, a special library called the
fa593d66
PA
16316@dfn{in-process agent} (IPA), must be loaded in the inferior process.
16317This library is built and distributed as an integral part of
0fb4aa4b
PA
16318@code{gdbserver}. In addition, support for static tracepoints
16319requires building the in-process agent library with static tracepoints
16320support. At present, the UST (LTTng Userspace Tracer,
16321@url{http://lttng.org/ust}) tracing engine is supported. This support
16322is automatically available if UST development headers are found in the
16323standard include path when @code{gdbserver} is built, or if
16324@code{gdbserver} was explicitly configured using @option{--with-ust}
16325to point at such headers. You can explicitly disable the support
16326using @option{--with-ust=no}.
fa593d66
PA
16327
16328There are several ways to load the in-process agent in your program:
16329
16330@table @code
16331@item Specifying it as dependency at link time
16332
16333You can link your program dynamically with the in-process agent
16334library. On most systems, this is accomplished by adding
16335@code{-linproctrace} to the link command.
16336
16337@item Using the system's preloading mechanisms
16338
16339You can force loading the in-process agent at startup time by using
16340your system's support for preloading shared libraries. Many Unixes
16341support the concept of preloading user defined libraries. In most
16342cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
16343in the environment. See also the description of @code{gdbserver}'s
16344@option{--wrapper} command line option.
16345
16346@item Using @value{GDBN} to force loading the agent at run time
16347
16348On some systems, you can force the inferior to load a shared library,
16349by calling a dynamic loader function in the inferior that takes care
16350of dynamically looking up and loading a shared library. On most Unix
16351systems, the function is @code{dlopen}. You'll use the @code{call}
16352command for that. For example:
16353
16354@smallexample
16355(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
16356@end smallexample
16357
16358Note that on most Unix systems, for the @code{dlopen} function to be
16359available, the program needs to be linked with @code{-ldl}.
16360@end table
16361
16362On systems that have a userspace dynamic loader, like most Unix
16363systems, when you connect to @code{gdbserver} using @code{target
16364remote}, you'll find that the program is stopped at the dynamic
16365loader's entry point, and no shared library has been loaded in the
16366program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
16367case, before being able to use any of the fast or static tracepoints
16368features, you need to let the loader run and load the shared
16369libraries. The simplest way to do that is to run the program to the
16370main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
16371@code{gdbserver} like so:
16372
16373@smallexample
16374$ gdbserver :9999 myprogram
16375@end smallexample
16376
16377Start GDB and connect to @code{gdbserver} like so, and run to main:
16378
16379@smallexample
16380$ gdb myprogram
16381(@value{GDBP}) target remote myhost:9999
163820x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
16383(@value{GDBP}) b main
16384(@value{GDBP}) continue
16385@end smallexample
16386
16387The in-process tracing agent library should now be loaded into the
16388process; you can confirm it with the @code{info sharedlibrary}
16389command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
16390process. You are now ready to install fast tracepoints, list static
16391tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
16392tracing.
16393
79a6e687
BW
16394@node Remote Configuration
16395@section Remote Configuration
501eef12 16396
9c16f35a
EZ
16397@kindex set remote
16398@kindex show remote
16399This section documents the configuration options available when
16400debugging remote programs. For the options related to the File I/O
fc320d37 16401extensions of the remote protocol, see @ref{system,
9c16f35a 16402system-call-allowed}.
501eef12
AC
16403
16404@table @code
9c16f35a 16405@item set remoteaddresssize @var{bits}
d3e8051b 16406@cindex address size for remote targets
9c16f35a
EZ
16407@cindex bits in remote address
16408Set the maximum size of address in a memory packet to the specified
16409number of bits. @value{GDBN} will mask off the address bits above
16410that number, when it passes addresses to the remote target. The
16411default value is the number of bits in the target's address.
16412
16413@item show remoteaddresssize
16414Show the current value of remote address size in bits.
16415
16416@item set remotebaud @var{n}
16417@cindex baud rate for remote targets
16418Set the baud rate for the remote serial I/O to @var{n} baud. The
16419value is used to set the speed of the serial port used for debugging
16420remote targets.
16421
16422@item show remotebaud
16423Show the current speed of the remote connection.
16424
16425@item set remotebreak
16426@cindex interrupt remote programs
16427@cindex BREAK signal instead of Ctrl-C
9a6253be 16428@anchor{set remotebreak}
9c16f35a 16429If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 16430when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 16431on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
16432character instead. The default is off, since most remote systems
16433expect to see @samp{Ctrl-C} as the interrupt signal.
16434
16435@item show remotebreak
16436Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
16437interrupt the remote program.
16438
23776285
MR
16439@item set remoteflow on
16440@itemx set remoteflow off
16441@kindex set remoteflow
16442Enable or disable hardware flow control (@code{RTS}/@code{CTS})
16443on the serial port used to communicate to the remote target.
16444
16445@item show remoteflow
16446@kindex show remoteflow
16447Show the current setting of hardware flow control.
16448
9c16f35a
EZ
16449@item set remotelogbase @var{base}
16450Set the base (a.k.a.@: radix) of logging serial protocol
16451communications to @var{base}. Supported values of @var{base} are:
16452@code{ascii}, @code{octal}, and @code{hex}. The default is
16453@code{ascii}.
16454
16455@item show remotelogbase
16456Show the current setting of the radix for logging remote serial
16457protocol.
16458
16459@item set remotelogfile @var{file}
16460@cindex record serial communications on file
16461Record remote serial communications on the named @var{file}. The
16462default is not to record at all.
16463
16464@item show remotelogfile.
16465Show the current setting of the file name on which to record the
16466serial communications.
16467
16468@item set remotetimeout @var{num}
16469@cindex timeout for serial communications
16470@cindex remote timeout
16471Set the timeout limit to wait for the remote target to respond to
16472@var{num} seconds. The default is 2 seconds.
16473
16474@item show remotetimeout
16475Show the current number of seconds to wait for the remote target
16476responses.
16477
16478@cindex limit hardware breakpoints and watchpoints
16479@cindex remote target, limit break- and watchpoints
501eef12
AC
16480@anchor{set remote hardware-watchpoint-limit}
16481@anchor{set remote hardware-breakpoint-limit}
16482@item set remote hardware-watchpoint-limit @var{limit}
16483@itemx set remote hardware-breakpoint-limit @var{limit}
16484Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
16485watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f
DJ
16486
16487@item set remote exec-file @var{filename}
16488@itemx show remote exec-file
16489@anchor{set remote exec-file}
16490@cindex executable file, for remote target
16491Select the file used for @code{run} with @code{target
16492extended-remote}. This should be set to a filename valid on the
16493target system. If it is not set, the target will use a default
16494filename (e.g.@: the last program run).
84603566 16495
9a7071a8
JB
16496@item set remote interrupt-sequence
16497@cindex interrupt remote programs
16498@cindex select Ctrl-C, BREAK or BREAK-g
16499Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
16500@samp{BREAK-g} as the
16501sequence to the remote target in order to interrupt the execution.
16502@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
16503is high level of serial line for some certain time.
16504Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
16505It is @code{BREAK} signal followed by character @code{g}.
16506
16507@item show interrupt-sequence
16508Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
16509is sent by @value{GDBN} to interrupt the remote program.
16510@code{BREAK-g} is BREAK signal followed by @code{g} and
16511also known as Magic SysRq g.
16512
16513@item set remote interrupt-on-connect
16514@cindex send interrupt-sequence on start
16515Specify whether interrupt-sequence is sent to remote target when
16516@value{GDBN} connects to it. This is mostly needed when you debug
16517Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
16518which is known as Magic SysRq g in order to connect @value{GDBN}.
16519
16520@item show interrupt-on-connect
16521Show whether interrupt-sequence is sent
16522to remote target when @value{GDBN} connects to it.
16523
84603566
SL
16524@kindex set tcp
16525@kindex show tcp
16526@item set tcp auto-retry on
16527@cindex auto-retry, for remote TCP target
16528Enable auto-retry for remote TCP connections. This is useful if the remote
16529debugging agent is launched in parallel with @value{GDBN}; there is a race
16530condition because the agent may not become ready to accept the connection
16531before @value{GDBN} attempts to connect. When auto-retry is
16532enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
16533to establish the connection using the timeout specified by
16534@code{set tcp connect-timeout}.
16535
16536@item set tcp auto-retry off
16537Do not auto-retry failed TCP connections.
16538
16539@item show tcp auto-retry
16540Show the current auto-retry setting.
16541
16542@item set tcp connect-timeout @var{seconds}
16543@cindex connection timeout, for remote TCP target
16544@cindex timeout, for remote target connection
16545Set the timeout for establishing a TCP connection to the remote target to
16546@var{seconds}. The timeout affects both polling to retry failed connections
16547(enabled by @code{set tcp auto-retry on}) and waiting for connections
16548that are merely slow to complete, and represents an approximate cumulative
16549value.
16550
16551@item show tcp connect-timeout
16552Show the current connection timeout setting.
501eef12
AC
16553@end table
16554
427c3a89
DJ
16555@cindex remote packets, enabling and disabling
16556The @value{GDBN} remote protocol autodetects the packets supported by
16557your debugging stub. If you need to override the autodetection, you
16558can use these commands to enable or disable individual packets. Each
16559packet can be set to @samp{on} (the remote target supports this
16560packet), @samp{off} (the remote target does not support this packet),
16561or @samp{auto} (detect remote target support for this packet). They
16562all default to @samp{auto}. For more information about each packet,
16563see @ref{Remote Protocol}.
16564
16565During normal use, you should not have to use any of these commands.
16566If you do, that may be a bug in your remote debugging stub, or a bug
16567in @value{GDBN}. You may want to report the problem to the
16568@value{GDBN} developers.
16569
cfa9d6d9
DJ
16570For each packet @var{name}, the command to enable or disable the
16571packet is @code{set remote @var{name}-packet}. The available settings
16572are:
427c3a89 16573
cfa9d6d9 16574@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
16575@item Command Name
16576@tab Remote Packet
16577@tab Related Features
16578
cfa9d6d9 16579@item @code{fetch-register}
427c3a89
DJ
16580@tab @code{p}
16581@tab @code{info registers}
16582
cfa9d6d9 16583@item @code{set-register}
427c3a89
DJ
16584@tab @code{P}
16585@tab @code{set}
16586
cfa9d6d9 16587@item @code{binary-download}
427c3a89
DJ
16588@tab @code{X}
16589@tab @code{load}, @code{set}
16590
cfa9d6d9 16591@item @code{read-aux-vector}
427c3a89
DJ
16592@tab @code{qXfer:auxv:read}
16593@tab @code{info auxv}
16594
cfa9d6d9 16595@item @code{symbol-lookup}
427c3a89
DJ
16596@tab @code{qSymbol}
16597@tab Detecting multiple threads
16598
2d717e4f
DJ
16599@item @code{attach}
16600@tab @code{vAttach}
16601@tab @code{attach}
16602
cfa9d6d9 16603@item @code{verbose-resume}
427c3a89
DJ
16604@tab @code{vCont}
16605@tab Stepping or resuming multiple threads
16606
2d717e4f
DJ
16607@item @code{run}
16608@tab @code{vRun}
16609@tab @code{run}
16610
cfa9d6d9 16611@item @code{software-breakpoint}
427c3a89
DJ
16612@tab @code{Z0}
16613@tab @code{break}
16614
cfa9d6d9 16615@item @code{hardware-breakpoint}
427c3a89
DJ
16616@tab @code{Z1}
16617@tab @code{hbreak}
16618
cfa9d6d9 16619@item @code{write-watchpoint}
427c3a89
DJ
16620@tab @code{Z2}
16621@tab @code{watch}
16622
cfa9d6d9 16623@item @code{read-watchpoint}
427c3a89
DJ
16624@tab @code{Z3}
16625@tab @code{rwatch}
16626
cfa9d6d9 16627@item @code{access-watchpoint}
427c3a89
DJ
16628@tab @code{Z4}
16629@tab @code{awatch}
16630
cfa9d6d9
DJ
16631@item @code{target-features}
16632@tab @code{qXfer:features:read}
16633@tab @code{set architecture}
16634
16635@item @code{library-info}
16636@tab @code{qXfer:libraries:read}
16637@tab @code{info sharedlibrary}
16638
16639@item @code{memory-map}
16640@tab @code{qXfer:memory-map:read}
16641@tab @code{info mem}
16642
0fb4aa4b
PA
16643@item @code{read-sdata-object}
16644@tab @code{qXfer:sdata:read}
16645@tab @code{print $_sdata}
16646
cfa9d6d9
DJ
16647@item @code{read-spu-object}
16648@tab @code{qXfer:spu:read}
16649@tab @code{info spu}
16650
16651@item @code{write-spu-object}
16652@tab @code{qXfer:spu:write}
16653@tab @code{info spu}
16654
4aa995e1
PA
16655@item @code{read-siginfo-object}
16656@tab @code{qXfer:siginfo:read}
16657@tab @code{print $_siginfo}
16658
16659@item @code{write-siginfo-object}
16660@tab @code{qXfer:siginfo:write}
16661@tab @code{set $_siginfo}
16662
dc146f7c
VP
16663@item @code{threads}
16664@tab @code{qXfer:threads:read}
16665@tab @code{info threads}
16666
cfa9d6d9 16667@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
16668@tab @code{qGetTLSAddr}
16669@tab Displaying @code{__thread} variables
16670
711e434b
PM
16671@item @code{get-thread-information-block-address}
16672@tab @code{qGetTIBAddr}
16673@tab Display MS-Windows Thread Information Block.
16674
08388c79
DE
16675@item @code{search-memory}
16676@tab @code{qSearch:memory}
16677@tab @code{find}
16678
427c3a89
DJ
16679@item @code{supported-packets}
16680@tab @code{qSupported}
16681@tab Remote communications parameters
16682
cfa9d6d9 16683@item @code{pass-signals}
89be2091
DJ
16684@tab @code{QPassSignals}
16685@tab @code{handle @var{signal}}
16686
a6b151f1
DJ
16687@item @code{hostio-close-packet}
16688@tab @code{vFile:close}
16689@tab @code{remote get}, @code{remote put}
16690
16691@item @code{hostio-open-packet}
16692@tab @code{vFile:open}
16693@tab @code{remote get}, @code{remote put}
16694
16695@item @code{hostio-pread-packet}
16696@tab @code{vFile:pread}
16697@tab @code{remote get}, @code{remote put}
16698
16699@item @code{hostio-pwrite-packet}
16700@tab @code{vFile:pwrite}
16701@tab @code{remote get}, @code{remote put}
16702
16703@item @code{hostio-unlink-packet}
16704@tab @code{vFile:unlink}
16705@tab @code{remote delete}
a6f3e723
SL
16706
16707@item @code{noack-packet}
16708@tab @code{QStartNoAckMode}
16709@tab Packet acknowledgment
07e059b5
VP
16710
16711@item @code{osdata}
16712@tab @code{qXfer:osdata:read}
16713@tab @code{info os}
0b16c5cf
PA
16714
16715@item @code{query-attached}
16716@tab @code{qAttached}
16717@tab Querying remote process attach state.
427c3a89
DJ
16718@end multitable
16719
79a6e687
BW
16720@node Remote Stub
16721@section Implementing a Remote Stub
7a292a7a 16722
8e04817f
AC
16723@cindex debugging stub, example
16724@cindex remote stub, example
16725@cindex stub example, remote debugging
16726The stub files provided with @value{GDBN} implement the target side of the
16727communication protocol, and the @value{GDBN} side is implemented in the
16728@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
16729these subroutines to communicate, and ignore the details. (If you're
16730implementing your own stub file, you can still ignore the details: start
16731with one of the existing stub files. @file{sparc-stub.c} is the best
16732organized, and therefore the easiest to read.)
16733
104c1213
JM
16734@cindex remote serial debugging, overview
16735To debug a program running on another machine (the debugging
16736@dfn{target} machine), you must first arrange for all the usual
16737prerequisites for the program to run by itself. For example, for a C
16738program, you need:
c906108c 16739
104c1213
JM
16740@enumerate
16741@item
16742A startup routine to set up the C runtime environment; these usually
16743have a name like @file{crt0}. The startup routine may be supplied by
16744your hardware supplier, or you may have to write your own.
96baa820 16745
5d161b24 16746@item
d4f3574e 16747A C subroutine library to support your program's
104c1213 16748subroutine calls, notably managing input and output.
96baa820 16749
104c1213
JM
16750@item
16751A way of getting your program to the other machine---for example, a
16752download program. These are often supplied by the hardware
16753manufacturer, but you may have to write your own from hardware
16754documentation.
16755@end enumerate
96baa820 16756
104c1213
JM
16757The next step is to arrange for your program to use a serial port to
16758communicate with the machine where @value{GDBN} is running (the @dfn{host}
16759machine). In general terms, the scheme looks like this:
96baa820 16760
104c1213
JM
16761@table @emph
16762@item On the host,
16763@value{GDBN} already understands how to use this protocol; when everything
16764else is set up, you can simply use the @samp{target remote} command
16765(@pxref{Targets,,Specifying a Debugging Target}).
16766
16767@item On the target,
16768you must link with your program a few special-purpose subroutines that
16769implement the @value{GDBN} remote serial protocol. The file containing these
16770subroutines is called a @dfn{debugging stub}.
16771
16772On certain remote targets, you can use an auxiliary program
16773@code{gdbserver} instead of linking a stub into your program.
79a6e687 16774@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 16775@end table
96baa820 16776
104c1213
JM
16777The debugging stub is specific to the architecture of the remote
16778machine; for example, use @file{sparc-stub.c} to debug programs on
16779@sc{sparc} boards.
96baa820 16780
104c1213
JM
16781@cindex remote serial stub list
16782These working remote stubs are distributed with @value{GDBN}:
96baa820 16783
104c1213
JM
16784@table @code
16785
16786@item i386-stub.c
41afff9a 16787@cindex @file{i386-stub.c}
104c1213
JM
16788@cindex Intel
16789@cindex i386
16790For Intel 386 and compatible architectures.
16791
16792@item m68k-stub.c
41afff9a 16793@cindex @file{m68k-stub.c}
104c1213
JM
16794@cindex Motorola 680x0
16795@cindex m680x0
16796For Motorola 680x0 architectures.
16797
16798@item sh-stub.c
41afff9a 16799@cindex @file{sh-stub.c}
172c2a43 16800@cindex Renesas
104c1213 16801@cindex SH
172c2a43 16802For Renesas SH architectures.
104c1213
JM
16803
16804@item sparc-stub.c
41afff9a 16805@cindex @file{sparc-stub.c}
104c1213
JM
16806@cindex Sparc
16807For @sc{sparc} architectures.
16808
16809@item sparcl-stub.c
41afff9a 16810@cindex @file{sparcl-stub.c}
104c1213
JM
16811@cindex Fujitsu
16812@cindex SparcLite
16813For Fujitsu @sc{sparclite} architectures.
16814
16815@end table
16816
16817The @file{README} file in the @value{GDBN} distribution may list other
16818recently added stubs.
16819
16820@menu
16821* Stub Contents:: What the stub can do for you
16822* Bootstrapping:: What you must do for the stub
16823* Debug Session:: Putting it all together
104c1213
JM
16824@end menu
16825
6d2ebf8b 16826@node Stub Contents
79a6e687 16827@subsection What the Stub Can Do for You
104c1213
JM
16828
16829@cindex remote serial stub
16830The debugging stub for your architecture supplies these three
16831subroutines:
16832
16833@table @code
16834@item set_debug_traps
4644b6e3 16835@findex set_debug_traps
104c1213
JM
16836@cindex remote serial stub, initialization
16837This routine arranges for @code{handle_exception} to run when your
16838program stops. You must call this subroutine explicitly near the
16839beginning of your program.
16840
16841@item handle_exception
4644b6e3 16842@findex handle_exception
104c1213
JM
16843@cindex remote serial stub, main routine
16844This is the central workhorse, but your program never calls it
16845explicitly---the setup code arranges for @code{handle_exception} to
16846run when a trap is triggered.
16847
16848@code{handle_exception} takes control when your program stops during
16849execution (for example, on a breakpoint), and mediates communications
16850with @value{GDBN} on the host machine. This is where the communications
16851protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 16852representative on the target machine. It begins by sending summary
104c1213
JM
16853information on the state of your program, then continues to execute,
16854retrieving and transmitting any information @value{GDBN} needs, until you
16855execute a @value{GDBN} command that makes your program resume; at that point,
16856@code{handle_exception} returns control to your own code on the target
5d161b24 16857machine.
104c1213
JM
16858
16859@item breakpoint
16860@cindex @code{breakpoint} subroutine, remote
16861Use this auxiliary subroutine to make your program contain a
16862breakpoint. Depending on the particular situation, this may be the only
16863way for @value{GDBN} to get control. For instance, if your target
16864machine has some sort of interrupt button, you won't need to call this;
16865pressing the interrupt button transfers control to
16866@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
16867simply receiving characters on the serial port may also trigger a trap;
16868again, in that situation, you don't need to call @code{breakpoint} from
16869your own program---simply running @samp{target remote} from the host
5d161b24 16870@value{GDBN} session gets control.
104c1213
JM
16871
16872Call @code{breakpoint} if none of these is true, or if you simply want
16873to make certain your program stops at a predetermined point for the
16874start of your debugging session.
16875@end table
16876
6d2ebf8b 16877@node Bootstrapping
79a6e687 16878@subsection What You Must Do for the Stub
104c1213
JM
16879
16880@cindex remote stub, support routines
16881The debugging stubs that come with @value{GDBN} are set up for a particular
16882chip architecture, but they have no information about the rest of your
16883debugging target machine.
16884
16885First of all you need to tell the stub how to communicate with the
16886serial port.
16887
16888@table @code
16889@item int getDebugChar()
4644b6e3 16890@findex getDebugChar
104c1213
JM
16891Write this subroutine to read a single character from the serial port.
16892It may be identical to @code{getchar} for your target system; a
16893different name is used to allow you to distinguish the two if you wish.
16894
16895@item void putDebugChar(int)
4644b6e3 16896@findex putDebugChar
104c1213 16897Write this subroutine to write a single character to the serial port.
5d161b24 16898It may be identical to @code{putchar} for your target system; a
104c1213
JM
16899different name is used to allow you to distinguish the two if you wish.
16900@end table
16901
16902@cindex control C, and remote debugging
16903@cindex interrupting remote targets
16904If you want @value{GDBN} to be able to stop your program while it is
16905running, you need to use an interrupt-driven serial driver, and arrange
16906for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
16907character). That is the character which @value{GDBN} uses to tell the
16908remote system to stop.
16909
16910Getting the debugging target to return the proper status to @value{GDBN}
16911probably requires changes to the standard stub; one quick and dirty way
16912is to just execute a breakpoint instruction (the ``dirty'' part is that
16913@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
16914
16915Other routines you need to supply are:
16916
16917@table @code
16918@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 16919@findex exceptionHandler
104c1213
JM
16920Write this function to install @var{exception_address} in the exception
16921handling tables. You need to do this because the stub does not have any
16922way of knowing what the exception handling tables on your target system
16923are like (for example, the processor's table might be in @sc{rom},
16924containing entries which point to a table in @sc{ram}).
16925@var{exception_number} is the exception number which should be changed;
16926its meaning is architecture-dependent (for example, different numbers
16927might represent divide by zero, misaligned access, etc). When this
16928exception occurs, control should be transferred directly to
16929@var{exception_address}, and the processor state (stack, registers,
16930and so on) should be just as it is when a processor exception occurs. So if
16931you want to use a jump instruction to reach @var{exception_address}, it
16932should be a simple jump, not a jump to subroutine.
16933
16934For the 386, @var{exception_address} should be installed as an interrupt
16935gate so that interrupts are masked while the handler runs. The gate
16936should be at privilege level 0 (the most privileged level). The
16937@sc{sparc} and 68k stubs are able to mask interrupts themselves without
16938help from @code{exceptionHandler}.
16939
16940@item void flush_i_cache()
4644b6e3 16941@findex flush_i_cache
d4f3574e 16942On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
16943instruction cache, if any, on your target machine. If there is no
16944instruction cache, this subroutine may be a no-op.
16945
16946On target machines that have instruction caches, @value{GDBN} requires this
16947function to make certain that the state of your program is stable.
16948@end table
16949
16950@noindent
16951You must also make sure this library routine is available:
16952
16953@table @code
16954@item void *memset(void *, int, int)
4644b6e3 16955@findex memset
104c1213
JM
16956This is the standard library function @code{memset} that sets an area of
16957memory to a known value. If you have one of the free versions of
16958@code{libc.a}, @code{memset} can be found there; otherwise, you must
16959either obtain it from your hardware manufacturer, or write your own.
16960@end table
16961
16962If you do not use the GNU C compiler, you may need other standard
16963library subroutines as well; this varies from one stub to another,
16964but in general the stubs are likely to use any of the common library
e22ea452 16965subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
16966
16967
6d2ebf8b 16968@node Debug Session
79a6e687 16969@subsection Putting it All Together
104c1213
JM
16970
16971@cindex remote serial debugging summary
16972In summary, when your program is ready to debug, you must follow these
16973steps.
16974
16975@enumerate
16976@item
6d2ebf8b 16977Make sure you have defined the supporting low-level routines
79a6e687 16978(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
16979@display
16980@code{getDebugChar}, @code{putDebugChar},
16981@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
16982@end display
16983
16984@item
16985Insert these lines near the top of your program:
16986
474c8240 16987@smallexample
104c1213
JM
16988set_debug_traps();
16989breakpoint();
474c8240 16990@end smallexample
104c1213
JM
16991
16992@item
16993For the 680x0 stub only, you need to provide a variable called
16994@code{exceptionHook}. Normally you just use:
16995
474c8240 16996@smallexample
104c1213 16997void (*exceptionHook)() = 0;
474c8240 16998@end smallexample
104c1213 16999
d4f3574e 17000@noindent
104c1213 17001but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 17002function in your program, that function is called when
104c1213
JM
17003@code{@value{GDBN}} continues after stopping on a trap (for example, bus
17004error). The function indicated by @code{exceptionHook} is called with
17005one parameter: an @code{int} which is the exception number.
17006
17007@item
17008Compile and link together: your program, the @value{GDBN} debugging stub for
17009your target architecture, and the supporting subroutines.
17010
17011@item
17012Make sure you have a serial connection between your target machine and
17013the @value{GDBN} host, and identify the serial port on the host.
17014
17015@item
17016@c The "remote" target now provides a `load' command, so we should
17017@c document that. FIXME.
17018Download your program to your target machine (or get it there by
17019whatever means the manufacturer provides), and start it.
17020
17021@item
07f31aa6 17022Start @value{GDBN} on the host, and connect to the target
79a6e687 17023(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 17024
104c1213
JM
17025@end enumerate
17026
8e04817f
AC
17027@node Configurations
17028@chapter Configuration-Specific Information
104c1213 17029
8e04817f
AC
17030While nearly all @value{GDBN} commands are available for all native and
17031cross versions of the debugger, there are some exceptions. This chapter
17032describes things that are only available in certain configurations.
104c1213 17033
8e04817f
AC
17034There are three major categories of configurations: native
17035configurations, where the host and target are the same, embedded
17036operating system configurations, which are usually the same for several
17037different processor architectures, and bare embedded processors, which
17038are quite different from each other.
104c1213 17039
8e04817f
AC
17040@menu
17041* Native::
17042* Embedded OS::
17043* Embedded Processors::
17044* Architectures::
17045@end menu
104c1213 17046
8e04817f
AC
17047@node Native
17048@section Native
104c1213 17049
8e04817f
AC
17050This section describes details specific to particular native
17051configurations.
6cf7e474 17052
8e04817f
AC
17053@menu
17054* HP-UX:: HP-UX
7561d450 17055* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
17056* SVR4 Process Information:: SVR4 process information
17057* DJGPP Native:: Features specific to the DJGPP port
78c47bea 17058* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 17059* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 17060* Neutrino:: Features specific to QNX Neutrino
a80b95ba 17061* Darwin:: Features specific to Darwin
8e04817f 17062@end menu
6cf7e474 17063
8e04817f
AC
17064@node HP-UX
17065@subsection HP-UX
104c1213 17066
8e04817f
AC
17067On HP-UX systems, if you refer to a function or variable name that
17068begins with a dollar sign, @value{GDBN} searches for a user or system
17069name first, before it searches for a convenience variable.
104c1213 17070
9c16f35a 17071
7561d450
MK
17072@node BSD libkvm Interface
17073@subsection BSD libkvm Interface
17074
17075@cindex libkvm
17076@cindex kernel memory image
17077@cindex kernel crash dump
17078
17079BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
17080interface that provides a uniform interface for accessing kernel virtual
17081memory images, including live systems and crash dumps. @value{GDBN}
17082uses this interface to allow you to debug live kernels and kernel crash
17083dumps on many native BSD configurations. This is implemented as a
17084special @code{kvm} debugging target. For debugging a live system, load
17085the currently running kernel into @value{GDBN} and connect to the
17086@code{kvm} target:
17087
17088@smallexample
17089(@value{GDBP}) @b{target kvm}
17090@end smallexample
17091
17092For debugging crash dumps, provide the file name of the crash dump as an
17093argument:
17094
17095@smallexample
17096(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
17097@end smallexample
17098
17099Once connected to the @code{kvm} target, the following commands are
17100available:
17101
17102@table @code
17103@kindex kvm
17104@item kvm pcb
721c2651 17105Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
17106
17107@item kvm proc
17108Set current context from proc address. This command isn't available on
17109modern FreeBSD systems.
17110@end table
17111
8e04817f 17112@node SVR4 Process Information
79a6e687 17113@subsection SVR4 Process Information
60bf7e09
EZ
17114@cindex /proc
17115@cindex examine process image
17116@cindex process info via @file{/proc}
104c1213 17117
60bf7e09
EZ
17118Many versions of SVR4 and compatible systems provide a facility called
17119@samp{/proc} that can be used to examine the image of a running
17120process using file-system subroutines. If @value{GDBN} is configured
17121for an operating system with this facility, the command @code{info
17122proc} is available to report information about the process running
17123your program, or about any process running on your system. @code{info
17124proc} works only on SVR4 systems that include the @code{procfs} code.
17125This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
17126Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 17127
8e04817f
AC
17128@table @code
17129@kindex info proc
60bf7e09 17130@cindex process ID
8e04817f 17131@item info proc
60bf7e09
EZ
17132@itemx info proc @var{process-id}
17133Summarize available information about any running process. If a
17134process ID is specified by @var{process-id}, display information about
17135that process; otherwise display information about the program being
17136debugged. The summary includes the debugged process ID, the command
17137line used to invoke it, its current working directory, and its
17138executable file's absolute file name.
17139
17140On some systems, @var{process-id} can be of the form
17141@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
17142within a process. If the optional @var{pid} part is missing, it means
17143a thread from the process being debugged (the leading @samp{/} still
17144needs to be present, or else @value{GDBN} will interpret the number as
17145a process ID rather than a thread ID).
6cf7e474 17146
8e04817f 17147@item info proc mappings
60bf7e09
EZ
17148@cindex memory address space mappings
17149Report the memory address space ranges accessible in the program, with
17150information on whether the process has read, write, or execute access
17151rights to each range. On @sc{gnu}/Linux systems, each memory range
17152includes the object file which is mapped to that range, instead of the
17153memory access rights to that range.
17154
17155@item info proc stat
17156@itemx info proc status
17157@cindex process detailed status information
17158These subcommands are specific to @sc{gnu}/Linux systems. They show
17159the process-related information, including the user ID and group ID;
17160how many threads are there in the process; its virtual memory usage;
17161the signals that are pending, blocked, and ignored; its TTY; its
17162consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 17163value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
17164(type @kbd{man 5 proc} from your shell prompt).
17165
17166@item info proc all
17167Show all the information about the process described under all of the
17168above @code{info proc} subcommands.
17169
8e04817f
AC
17170@ignore
17171@comment These sub-options of 'info proc' were not included when
17172@comment procfs.c was re-written. Keep their descriptions around
17173@comment against the day when someone finds the time to put them back in.
17174@kindex info proc times
17175@item info proc times
17176Starting time, user CPU time, and system CPU time for your program and
17177its children.
6cf7e474 17178
8e04817f
AC
17179@kindex info proc id
17180@item info proc id
17181Report on the process IDs related to your program: its own process ID,
17182the ID of its parent, the process group ID, and the session ID.
8e04817f 17183@end ignore
721c2651
EZ
17184
17185@item set procfs-trace
17186@kindex set procfs-trace
17187@cindex @code{procfs} API calls
17188This command enables and disables tracing of @code{procfs} API calls.
17189
17190@item show procfs-trace
17191@kindex show procfs-trace
17192Show the current state of @code{procfs} API call tracing.
17193
17194@item set procfs-file @var{file}
17195@kindex set procfs-file
17196Tell @value{GDBN} to write @code{procfs} API trace to the named
17197@var{file}. @value{GDBN} appends the trace info to the previous
17198contents of the file. The default is to display the trace on the
17199standard output.
17200
17201@item show procfs-file
17202@kindex show procfs-file
17203Show the file to which @code{procfs} API trace is written.
17204
17205@item proc-trace-entry
17206@itemx proc-trace-exit
17207@itemx proc-untrace-entry
17208@itemx proc-untrace-exit
17209@kindex proc-trace-entry
17210@kindex proc-trace-exit
17211@kindex proc-untrace-entry
17212@kindex proc-untrace-exit
17213These commands enable and disable tracing of entries into and exits
17214from the @code{syscall} interface.
17215
17216@item info pidlist
17217@kindex info pidlist
17218@cindex process list, QNX Neutrino
17219For QNX Neutrino only, this command displays the list of all the
17220processes and all the threads within each process.
17221
17222@item info meminfo
17223@kindex info meminfo
17224@cindex mapinfo list, QNX Neutrino
17225For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 17226@end table
104c1213 17227
8e04817f
AC
17228@node DJGPP Native
17229@subsection Features for Debugging @sc{djgpp} Programs
17230@cindex @sc{djgpp} debugging
17231@cindex native @sc{djgpp} debugging
17232@cindex MS-DOS-specific commands
104c1213 17233
514c4d71
EZ
17234@cindex DPMI
17235@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
17236MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
17237that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
17238top of real-mode DOS systems and their emulations.
104c1213 17239
8e04817f
AC
17240@value{GDBN} supports native debugging of @sc{djgpp} programs, and
17241defines a few commands specific to the @sc{djgpp} port. This
17242subsection describes those commands.
104c1213 17243
8e04817f
AC
17244@table @code
17245@kindex info dos
17246@item info dos
17247This is a prefix of @sc{djgpp}-specific commands which print
17248information about the target system and important OS structures.
f1251bdd 17249
8e04817f
AC
17250@kindex sysinfo
17251@cindex MS-DOS system info
17252@cindex free memory information (MS-DOS)
17253@item info dos sysinfo
17254This command displays assorted information about the underlying
17255platform: the CPU type and features, the OS version and flavor, the
17256DPMI version, and the available conventional and DPMI memory.
104c1213 17257
8e04817f
AC
17258@cindex GDT
17259@cindex LDT
17260@cindex IDT
17261@cindex segment descriptor tables
17262@cindex descriptor tables display
17263@item info dos gdt
17264@itemx info dos ldt
17265@itemx info dos idt
17266These 3 commands display entries from, respectively, Global, Local,
17267and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
17268tables are data structures which store a descriptor for each segment
17269that is currently in use. The segment's selector is an index into a
17270descriptor table; the table entry for that index holds the
17271descriptor's base address and limit, and its attributes and access
17272rights.
104c1213 17273
8e04817f
AC
17274A typical @sc{djgpp} program uses 3 segments: a code segment, a data
17275segment (used for both data and the stack), and a DOS segment (which
17276allows access to DOS/BIOS data structures and absolute addresses in
17277conventional memory). However, the DPMI host will usually define
17278additional segments in order to support the DPMI environment.
d4f3574e 17279
8e04817f
AC
17280@cindex garbled pointers
17281These commands allow to display entries from the descriptor tables.
17282Without an argument, all entries from the specified table are
17283displayed. An argument, which should be an integer expression, means
17284display a single entry whose index is given by the argument. For
17285example, here's a convenient way to display information about the
17286debugged program's data segment:
104c1213 17287
8e04817f
AC
17288@smallexample
17289@exdent @code{(@value{GDBP}) info dos ldt $ds}
17290@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
17291@end smallexample
104c1213 17292
8e04817f
AC
17293@noindent
17294This comes in handy when you want to see whether a pointer is outside
17295the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 17296
8e04817f
AC
17297@cindex page tables display (MS-DOS)
17298@item info dos pde
17299@itemx info dos pte
17300These two commands display entries from, respectively, the Page
17301Directory and the Page Tables. Page Directories and Page Tables are
17302data structures which control how virtual memory addresses are mapped
17303into physical addresses. A Page Table includes an entry for every
17304page of memory that is mapped into the program's address space; there
17305may be several Page Tables, each one holding up to 4096 entries. A
17306Page Directory has up to 4096 entries, one each for every Page Table
17307that is currently in use.
104c1213 17308
8e04817f
AC
17309Without an argument, @kbd{info dos pde} displays the entire Page
17310Directory, and @kbd{info dos pte} displays all the entries in all of
17311the Page Tables. An argument, an integer expression, given to the
17312@kbd{info dos pde} command means display only that entry from the Page
17313Directory table. An argument given to the @kbd{info dos pte} command
17314means display entries from a single Page Table, the one pointed to by
17315the specified entry in the Page Directory.
104c1213 17316
8e04817f
AC
17317@cindex direct memory access (DMA) on MS-DOS
17318These commands are useful when your program uses @dfn{DMA} (Direct
17319Memory Access), which needs physical addresses to program the DMA
17320controller.
104c1213 17321
8e04817f 17322These commands are supported only with some DPMI servers.
104c1213 17323
8e04817f
AC
17324@cindex physical address from linear address
17325@item info dos address-pte @var{addr}
17326This command displays the Page Table entry for a specified linear
514c4d71
EZ
17327address. The argument @var{addr} is a linear address which should
17328already have the appropriate segment's base address added to it,
17329because this command accepts addresses which may belong to @emph{any}
17330segment. For example, here's how to display the Page Table entry for
17331the page where a variable @code{i} is stored:
104c1213 17332
b383017d 17333@smallexample
8e04817f
AC
17334@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
17335@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 17336@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 17337@end smallexample
104c1213 17338
8e04817f
AC
17339@noindent
17340This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 17341whose physical base address is @code{0x02698000}, and shows all the
8e04817f 17342attributes of that page.
104c1213 17343
8e04817f
AC
17344Note that you must cast the addresses of variables to a @code{char *},
17345since otherwise the value of @code{__djgpp_base_address}, the base
17346address of all variables and functions in a @sc{djgpp} program, will
17347be added using the rules of C pointer arithmetics: if @code{i} is
17348declared an @code{int}, @value{GDBN} will add 4 times the value of
17349@code{__djgpp_base_address} to the address of @code{i}.
104c1213 17350
8e04817f
AC
17351Here's another example, it displays the Page Table entry for the
17352transfer buffer:
104c1213 17353
8e04817f
AC
17354@smallexample
17355@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
17356@exdent @code{Page Table entry for address 0x29110:}
17357@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
17358@end smallexample
104c1213 17359
8e04817f
AC
17360@noindent
17361(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
173623rd member of the @code{_go32_info_block} structure.) The output
17363clearly shows that this DPMI server maps the addresses in conventional
17364memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
17365linear (@code{0x29110}) addresses are identical.
104c1213 17366
8e04817f
AC
17367This command is supported only with some DPMI servers.
17368@end table
104c1213 17369
c45da7e6 17370@cindex DOS serial data link, remote debugging
a8f24a35
EZ
17371In addition to native debugging, the DJGPP port supports remote
17372debugging via a serial data link. The following commands are specific
17373to remote serial debugging in the DJGPP port of @value{GDBN}.
17374
17375@table @code
17376@kindex set com1base
17377@kindex set com1irq
17378@kindex set com2base
17379@kindex set com2irq
17380@kindex set com3base
17381@kindex set com3irq
17382@kindex set com4base
17383@kindex set com4irq
17384@item set com1base @var{addr}
17385This command sets the base I/O port address of the @file{COM1} serial
17386port.
17387
17388@item set com1irq @var{irq}
17389This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
17390for the @file{COM1} serial port.
17391
17392There are similar commands @samp{set com2base}, @samp{set com3irq},
17393etc.@: for setting the port address and the @code{IRQ} lines for the
17394other 3 COM ports.
17395
17396@kindex show com1base
17397@kindex show com1irq
17398@kindex show com2base
17399@kindex show com2irq
17400@kindex show com3base
17401@kindex show com3irq
17402@kindex show com4base
17403@kindex show com4irq
17404The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
17405display the current settings of the base address and the @code{IRQ}
17406lines used by the COM ports.
c45da7e6
EZ
17407
17408@item info serial
17409@kindex info serial
17410@cindex DOS serial port status
17411This command prints the status of the 4 DOS serial ports. For each
17412port, it prints whether it's active or not, its I/O base address and
17413IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
17414counts of various errors encountered so far.
a8f24a35
EZ
17415@end table
17416
17417
78c47bea 17418@node Cygwin Native
79a6e687 17419@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
17420@cindex MS Windows debugging
17421@cindex native Cygwin debugging
17422@cindex Cygwin-specific commands
17423
be448670 17424@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
17425DLLs with and without symbolic debugging information.
17426
17427@cindex Ctrl-BREAK, MS-Windows
17428@cindex interrupt debuggee on MS-Windows
17429MS-Windows programs that call @code{SetConsoleMode} to switch off the
17430special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
17431by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
17432supports @kbd{C-@key{BREAK}} as an alternative interrupt key
17433sequence, which can be used to interrupt the debuggee even if it
17434ignores @kbd{C-c}.
17435
17436There are various additional Cygwin-specific commands, described in
17437this section. Working with DLLs that have no debugging symbols is
17438described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
17439
17440@table @code
17441@kindex info w32
17442@item info w32
db2e3e2e 17443This is a prefix of MS Windows-specific commands which print
78c47bea
PM
17444information about the target system and important OS structures.
17445
17446@item info w32 selector
17447This command displays information returned by
17448the Win32 API @code{GetThreadSelectorEntry} function.
17449It takes an optional argument that is evaluated to
17450a long value to give the information about this given selector.
17451Without argument, this command displays information
d3e8051b 17452about the six segment registers.
78c47bea 17453
711e434b
PM
17454@item info w32 thread-information-block
17455This command displays thread specific information stored in the
17456Thread Information Block (readable on the X86 CPU family using @code{$fs}
17457selector for 32-bit programs and @code{$gs} for 64-bit programs).
17458
78c47bea
PM
17459@kindex info dll
17460@item info dll
db2e3e2e 17461This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
17462
17463@kindex dll-symbols
17464@item dll-symbols
17465This command loads symbols from a dll similarly to
17466add-sym command but without the need to specify a base address.
17467
be90c084 17468@kindex set cygwin-exceptions
e16b02ee
EZ
17469@cindex debugging the Cygwin DLL
17470@cindex Cygwin DLL, debugging
be90c084 17471@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
17472If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
17473happen inside the Cygwin DLL. If @var{mode} is @code{off},
17474@value{GDBN} will delay recognition of exceptions, and may ignore some
17475exceptions which seem to be caused by internal Cygwin DLL
17476``bookkeeping''. This option is meant primarily for debugging the
17477Cygwin DLL itself; the default value is @code{off} to avoid annoying
17478@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
17479
17480@kindex show cygwin-exceptions
17481@item show cygwin-exceptions
e16b02ee
EZ
17482Displays whether @value{GDBN} will break on exceptions that happen
17483inside the Cygwin DLL itself.
be90c084 17484
b383017d 17485@kindex set new-console
78c47bea 17486@item set new-console @var{mode}
b383017d 17487If @var{mode} is @code{on} the debuggee will
78c47bea 17488be started in a new console on next start.
e03e5e7b 17489If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
17490be started in the same console as the debugger.
17491
17492@kindex show new-console
17493@item show new-console
17494Displays whether a new console is used
17495when the debuggee is started.
17496
17497@kindex set new-group
17498@item set new-group @var{mode}
17499This boolean value controls whether the debuggee should
17500start a new group or stay in the same group as the debugger.
17501This affects the way the Windows OS handles
c8aa23ab 17502@samp{Ctrl-C}.
78c47bea
PM
17503
17504@kindex show new-group
17505@item show new-group
17506Displays current value of new-group boolean.
17507
17508@kindex set debugevents
17509@item set debugevents
219eec71
EZ
17510This boolean value adds debug output concerning kernel events related
17511to the debuggee seen by the debugger. This includes events that
17512signal thread and process creation and exit, DLL loading and
17513unloading, console interrupts, and debugging messages produced by the
17514Windows @code{OutputDebugString} API call.
78c47bea
PM
17515
17516@kindex set debugexec
17517@item set debugexec
b383017d 17518This boolean value adds debug output concerning execute events
219eec71 17519(such as resume thread) seen by the debugger.
78c47bea
PM
17520
17521@kindex set debugexceptions
17522@item set debugexceptions
219eec71
EZ
17523This boolean value adds debug output concerning exceptions in the
17524debuggee seen by the debugger.
78c47bea
PM
17525
17526@kindex set debugmemory
17527@item set debugmemory
219eec71
EZ
17528This boolean value adds debug output concerning debuggee memory reads
17529and writes by the debugger.
78c47bea
PM
17530
17531@kindex set shell
17532@item set shell
17533This boolean values specifies whether the debuggee is called
17534via a shell or directly (default value is on).
17535
17536@kindex show shell
17537@item show shell
17538Displays if the debuggee will be started with a shell.
17539
17540@end table
17541
be448670 17542@menu
79a6e687 17543* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
17544@end menu
17545
79a6e687
BW
17546@node Non-debug DLL Symbols
17547@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
17548@cindex DLLs with no debugging symbols
17549@cindex Minimal symbols and DLLs
17550
17551Very often on windows, some of the DLLs that your program relies on do
17552not include symbolic debugging information (for example,
db2e3e2e 17553@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 17554symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 17555information contained in the DLL's export table. This section
be448670
CF
17556describes working with such symbols, known internally to @value{GDBN} as
17557``minimal symbols''.
17558
17559Note that before the debugged program has started execution, no DLLs
db2e3e2e 17560will have been loaded. The easiest way around this problem is simply to
be448670 17561start the program --- either by setting a breakpoint or letting the
db2e3e2e 17562program run once to completion. It is also possible to force
be448670 17563@value{GDBN} to load a particular DLL before starting the executable ---
12c27660 17564see the shared library information in @ref{Files}, or the
db2e3e2e 17565@code{dll-symbols} command in @ref{Cygwin Native}. Currently,
be448670
CF
17566explicitly loading symbols from a DLL with no debugging information will
17567cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
17568which may adversely affect symbol lookup performance.
17569
79a6e687 17570@subsubsection DLL Name Prefixes
be448670
CF
17571
17572In keeping with the naming conventions used by the Microsoft debugging
17573tools, DLL export symbols are made available with a prefix based on the
17574DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
17575also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 17576sufficient. In some cases there will be name clashes within a program
be448670
CF
17577(particularly if the executable itself includes full debugging symbols)
17578necessitating the use of the fully qualified name when referring to the
99e008fe 17579contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
17580exclamation mark (``!'') being interpreted as a language operator.
17581
17582Note that the internal name of the DLL may be all upper-case, even
99e008fe 17583though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
17584symbols within @value{GDBN} are @emph{case-sensitive} this may cause
17585some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
17586@code{info variables} commands or even @code{maint print msymbols}
17587(@pxref{Symbols}). Here's an example:
be448670
CF
17588
17589@smallexample
f7dc1244 17590(@value{GDBP}) info function CreateFileA
be448670
CF
17591All functions matching regular expression "CreateFileA":
17592
17593Non-debugging symbols:
175940x77e885f4 CreateFileA
175950x77e885f4 KERNEL32!CreateFileA
17596@end smallexample
17597
17598@smallexample
f7dc1244 17599(@value{GDBP}) info function !
be448670
CF
17600All functions matching regular expression "!":
17601
17602Non-debugging symbols:
176030x6100114c cygwin1!__assert
176040x61004034 cygwin1!_dll_crt0@@0
176050x61004240 cygwin1!dll_crt0(per_process *)
17606[etc...]
17607@end smallexample
17608
79a6e687 17609@subsubsection Working with Minimal Symbols
be448670
CF
17610
17611Symbols extracted from a DLL's export table do not contain very much
17612type information. All that @value{GDBN} can do is guess whether a symbol
17613refers to a function or variable depending on the linker section that
17614contains the symbol. Also note that the actual contents of the memory
17615contained in a DLL are not available unless the program is running. This
17616means that you cannot examine the contents of a variable or disassemble
17617a function within a DLL without a running program.
17618
17619Variables are generally treated as pointers and dereferenced
17620automatically. For this reason, it is often necessary to prefix a
17621variable name with the address-of operator (``&'') and provide explicit
17622type information in the command. Here's an example of the type of
17623problem:
17624
17625@smallexample
f7dc1244 17626(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
17627$1 = 268572168
17628@end smallexample
17629
17630@smallexample
f7dc1244 17631(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
176320x10021610: "\230y\""
17633@end smallexample
17634
17635And two possible solutions:
17636
17637@smallexample
f7dc1244 17638(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
17639$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
17640@end smallexample
17641
17642@smallexample
f7dc1244 17643(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 176440x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 17645(@value{GDBP}) x/x 0x10021608
be448670 176460x10021608: 0x0022fd98
f7dc1244 17647(@value{GDBP}) x/s 0x0022fd98
be448670
CF
176480x22fd98: "/cygdrive/c/mydirectory/myprogram"
17649@end smallexample
17650
17651Setting a break point within a DLL is possible even before the program
17652starts execution. However, under these circumstances, @value{GDBN} can't
17653examine the initial instructions of the function in order to skip the
17654function's frame set-up code. You can work around this by using ``*&''
17655to set the breakpoint at a raw memory address:
17656
17657@smallexample
f7dc1244 17658(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
17659Breakpoint 1 at 0x1e04eff0
17660@end smallexample
17661
17662The author of these extensions is not entirely convinced that setting a
17663break point within a shared DLL like @file{kernel32.dll} is completely
17664safe.
17665
14d6dd68 17666@node Hurd Native
79a6e687 17667@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
17668@cindex @sc{gnu} Hurd debugging
17669
17670This subsection describes @value{GDBN} commands specific to the
17671@sc{gnu} Hurd native debugging.
17672
17673@table @code
17674@item set signals
17675@itemx set sigs
17676@kindex set signals@r{, Hurd command}
17677@kindex set sigs@r{, Hurd command}
17678This command toggles the state of inferior signal interception by
17679@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
17680affected by this command. @code{sigs} is a shorthand alias for
17681@code{signals}.
17682
17683@item show signals
17684@itemx show sigs
17685@kindex show signals@r{, Hurd command}
17686@kindex show sigs@r{, Hurd command}
17687Show the current state of intercepting inferior's signals.
17688
17689@item set signal-thread
17690@itemx set sigthread
17691@kindex set signal-thread
17692@kindex set sigthread
17693This command tells @value{GDBN} which thread is the @code{libc} signal
17694thread. That thread is run when a signal is delivered to a running
17695process. @code{set sigthread} is the shorthand alias of @code{set
17696signal-thread}.
17697
17698@item show signal-thread
17699@itemx show sigthread
17700@kindex show signal-thread
17701@kindex show sigthread
17702These two commands show which thread will run when the inferior is
17703delivered a signal.
17704
17705@item set stopped
17706@kindex set stopped@r{, Hurd command}
17707This commands tells @value{GDBN} that the inferior process is stopped,
17708as with the @code{SIGSTOP} signal. The stopped process can be
17709continued by delivering a signal to it.
17710
17711@item show stopped
17712@kindex show stopped@r{, Hurd command}
17713This command shows whether @value{GDBN} thinks the debuggee is
17714stopped.
17715
17716@item set exceptions
17717@kindex set exceptions@r{, Hurd command}
17718Use this command to turn off trapping of exceptions in the inferior.
17719When exception trapping is off, neither breakpoints nor
17720single-stepping will work. To restore the default, set exception
17721trapping on.
17722
17723@item show exceptions
17724@kindex show exceptions@r{, Hurd command}
17725Show the current state of trapping exceptions in the inferior.
17726
17727@item set task pause
17728@kindex set task@r{, Hurd commands}
17729@cindex task attributes (@sc{gnu} Hurd)
17730@cindex pause current task (@sc{gnu} Hurd)
17731This command toggles task suspension when @value{GDBN} has control.
17732Setting it to on takes effect immediately, and the task is suspended
17733whenever @value{GDBN} gets control. Setting it to off will take
17734effect the next time the inferior is continued. If this option is set
17735to off, you can use @code{set thread default pause on} or @code{set
17736thread pause on} (see below) to pause individual threads.
17737
17738@item show task pause
17739@kindex show task@r{, Hurd commands}
17740Show the current state of task suspension.
17741
17742@item set task detach-suspend-count
17743@cindex task suspend count
17744@cindex detach from task, @sc{gnu} Hurd
17745This command sets the suspend count the task will be left with when
17746@value{GDBN} detaches from it.
17747
17748@item show task detach-suspend-count
17749Show the suspend count the task will be left with when detaching.
17750
17751@item set task exception-port
17752@itemx set task excp
17753@cindex task exception port, @sc{gnu} Hurd
17754This command sets the task exception port to which @value{GDBN} will
17755forward exceptions. The argument should be the value of the @dfn{send
17756rights} of the task. @code{set task excp} is a shorthand alias.
17757
17758@item set noninvasive
17759@cindex noninvasive task options
17760This command switches @value{GDBN} to a mode that is the least
17761invasive as far as interfering with the inferior is concerned. This
17762is the same as using @code{set task pause}, @code{set exceptions}, and
17763@code{set signals} to values opposite to the defaults.
17764
17765@item info send-rights
17766@itemx info receive-rights
17767@itemx info port-rights
17768@itemx info port-sets
17769@itemx info dead-names
17770@itemx info ports
17771@itemx info psets
17772@cindex send rights, @sc{gnu} Hurd
17773@cindex receive rights, @sc{gnu} Hurd
17774@cindex port rights, @sc{gnu} Hurd
17775@cindex port sets, @sc{gnu} Hurd
17776@cindex dead names, @sc{gnu} Hurd
17777These commands display information about, respectively, send rights,
17778receive rights, port rights, port sets, and dead names of a task.
17779There are also shorthand aliases: @code{info ports} for @code{info
17780port-rights} and @code{info psets} for @code{info port-sets}.
17781
17782@item set thread pause
17783@kindex set thread@r{, Hurd command}
17784@cindex thread properties, @sc{gnu} Hurd
17785@cindex pause current thread (@sc{gnu} Hurd)
17786This command toggles current thread suspension when @value{GDBN} has
17787control. Setting it to on takes effect immediately, and the current
17788thread is suspended whenever @value{GDBN} gets control. Setting it to
17789off will take effect the next time the inferior is continued.
17790Normally, this command has no effect, since when @value{GDBN} has
17791control, the whole task is suspended. However, if you used @code{set
17792task pause off} (see above), this command comes in handy to suspend
17793only the current thread.
17794
17795@item show thread pause
17796@kindex show thread@r{, Hurd command}
17797This command shows the state of current thread suspension.
17798
17799@item set thread run
d3e8051b 17800This command sets whether the current thread is allowed to run.
14d6dd68
EZ
17801
17802@item show thread run
17803Show whether the current thread is allowed to run.
17804
17805@item set thread detach-suspend-count
17806@cindex thread suspend count, @sc{gnu} Hurd
17807@cindex detach from thread, @sc{gnu} Hurd
17808This command sets the suspend count @value{GDBN} will leave on a
17809thread when detaching. This number is relative to the suspend count
17810found by @value{GDBN} when it notices the thread; use @code{set thread
17811takeover-suspend-count} to force it to an absolute value.
17812
17813@item show thread detach-suspend-count
17814Show the suspend count @value{GDBN} will leave on the thread when
17815detaching.
17816
17817@item set thread exception-port
17818@itemx set thread excp
17819Set the thread exception port to which to forward exceptions. This
17820overrides the port set by @code{set task exception-port} (see above).
17821@code{set thread excp} is the shorthand alias.
17822
17823@item set thread takeover-suspend-count
17824Normally, @value{GDBN}'s thread suspend counts are relative to the
17825value @value{GDBN} finds when it notices each thread. This command
17826changes the suspend counts to be absolute instead.
17827
17828@item set thread default
17829@itemx show thread default
17830@cindex thread default settings, @sc{gnu} Hurd
17831Each of the above @code{set thread} commands has a @code{set thread
17832default} counterpart (e.g., @code{set thread default pause}, @code{set
17833thread default exception-port}, etc.). The @code{thread default}
17834variety of commands sets the default thread properties for all
17835threads; you can then change the properties of individual threads with
17836the non-default commands.
17837@end table
17838
17839
a64548ea
EZ
17840@node Neutrino
17841@subsection QNX Neutrino
17842@cindex QNX Neutrino
17843
17844@value{GDBN} provides the following commands specific to the QNX
17845Neutrino target:
17846
17847@table @code
17848@item set debug nto-debug
17849@kindex set debug nto-debug
17850When set to on, enables debugging messages specific to the QNX
17851Neutrino support.
17852
17853@item show debug nto-debug
17854@kindex show debug nto-debug
17855Show the current state of QNX Neutrino messages.
17856@end table
17857
a80b95ba
TG
17858@node Darwin
17859@subsection Darwin
17860@cindex Darwin
17861
17862@value{GDBN} provides the following commands specific to the Darwin target:
17863
17864@table @code
17865@item set debug darwin @var{num}
17866@kindex set debug darwin
17867When set to a non zero value, enables debugging messages specific to
17868the Darwin support. Higher values produce more verbose output.
17869
17870@item show debug darwin
17871@kindex show debug darwin
17872Show the current state of Darwin messages.
17873
17874@item set debug mach-o @var{num}
17875@kindex set debug mach-o
17876When set to a non zero value, enables debugging messages while
17877@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
17878file format used on Darwin for object and executable files.) Higher
17879values produce more verbose output. This is a command to diagnose
17880problems internal to @value{GDBN} and should not be needed in normal
17881usage.
17882
17883@item show debug mach-o
17884@kindex show debug mach-o
17885Show the current state of Mach-O file messages.
17886
17887@item set mach-exceptions on
17888@itemx set mach-exceptions off
17889@kindex set mach-exceptions
17890On Darwin, faults are first reported as a Mach exception and are then
17891mapped to a Posix signal. Use this command to turn on trapping of
17892Mach exceptions in the inferior. This might be sometimes useful to
17893better understand the cause of a fault. The default is off.
17894
17895@item show mach-exceptions
17896@kindex show mach-exceptions
17897Show the current state of exceptions trapping.
17898@end table
17899
a64548ea 17900
8e04817f
AC
17901@node Embedded OS
17902@section Embedded Operating Systems
104c1213 17903
8e04817f
AC
17904This section describes configurations involving the debugging of
17905embedded operating systems that are available for several different
17906architectures.
d4f3574e 17907
8e04817f
AC
17908@menu
17909* VxWorks:: Using @value{GDBN} with VxWorks
17910@end menu
104c1213 17911
8e04817f
AC
17912@value{GDBN} includes the ability to debug programs running on
17913various real-time operating systems.
104c1213 17914
8e04817f
AC
17915@node VxWorks
17916@subsection Using @value{GDBN} with VxWorks
104c1213 17917
8e04817f 17918@cindex VxWorks
104c1213 17919
8e04817f 17920@table @code
104c1213 17921
8e04817f
AC
17922@kindex target vxworks
17923@item target vxworks @var{machinename}
17924A VxWorks system, attached via TCP/IP. The argument @var{machinename}
17925is the target system's machine name or IP address.
104c1213 17926
8e04817f 17927@end table
104c1213 17928
8e04817f
AC
17929On VxWorks, @code{load} links @var{filename} dynamically on the
17930current target system as well as adding its symbols in @value{GDBN}.
104c1213 17931
8e04817f
AC
17932@value{GDBN} enables developers to spawn and debug tasks running on networked
17933VxWorks targets from a Unix host. Already-running tasks spawned from
17934the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
17935both the Unix host and on the VxWorks target. The program
17936@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
17937installed with the name @code{vxgdb}, to distinguish it from a
17938@value{GDBN} for debugging programs on the host itself.)
104c1213 17939
8e04817f
AC
17940@table @code
17941@item VxWorks-timeout @var{args}
17942@kindex vxworks-timeout
17943All VxWorks-based targets now support the option @code{vxworks-timeout}.
17944This option is set by the user, and @var{args} represents the number of
17945seconds @value{GDBN} waits for responses to rpc's. You might use this if
17946your VxWorks target is a slow software simulator or is on the far side
17947of a thin network line.
17948@end table
104c1213 17949
8e04817f
AC
17950The following information on connecting to VxWorks was current when
17951this manual was produced; newer releases of VxWorks may use revised
17952procedures.
104c1213 17953
4644b6e3 17954@findex INCLUDE_RDB
8e04817f
AC
17955To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
17956to include the remote debugging interface routines in the VxWorks
17957library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
17958VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
17959kernel. The resulting kernel contains @file{rdb.a}, and spawns the
17960source debugging task @code{tRdbTask} when VxWorks is booted. For more
17961information on configuring and remaking VxWorks, see the manufacturer's
17962manual.
17963@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 17964
8e04817f
AC
17965Once you have included @file{rdb.a} in your VxWorks system image and set
17966your Unix execution search path to find @value{GDBN}, you are ready to
17967run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
17968@code{vxgdb}, depending on your installation).
104c1213 17969
8e04817f 17970@value{GDBN} comes up showing the prompt:
104c1213 17971
474c8240 17972@smallexample
8e04817f 17973(vxgdb)
474c8240 17974@end smallexample
104c1213 17975
8e04817f
AC
17976@menu
17977* VxWorks Connection:: Connecting to VxWorks
17978* VxWorks Download:: VxWorks download
17979* VxWorks Attach:: Running tasks
17980@end menu
104c1213 17981
8e04817f
AC
17982@node VxWorks Connection
17983@subsubsection Connecting to VxWorks
104c1213 17984
8e04817f
AC
17985The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
17986network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 17987
474c8240 17988@smallexample
8e04817f 17989(vxgdb) target vxworks tt
474c8240 17990@end smallexample
104c1213 17991
8e04817f
AC
17992@need 750
17993@value{GDBN} displays messages like these:
104c1213 17994
8e04817f
AC
17995@smallexample
17996Attaching remote machine across net...
17997Connected to tt.
17998@end smallexample
104c1213 17999
8e04817f
AC
18000@need 1000
18001@value{GDBN} then attempts to read the symbol tables of any object modules
18002loaded into the VxWorks target since it was last booted. @value{GDBN} locates
18003these files by searching the directories listed in the command search
79a6e687 18004path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 18005to find an object file, it displays a message such as:
5d161b24 18006
474c8240 18007@smallexample
8e04817f 18008prog.o: No such file or directory.
474c8240 18009@end smallexample
104c1213 18010
8e04817f
AC
18011When this happens, add the appropriate directory to the search path with
18012the @value{GDBN} command @code{path}, and execute the @code{target}
18013command again.
104c1213 18014
8e04817f 18015@node VxWorks Download
79a6e687 18016@subsubsection VxWorks Download
104c1213 18017
8e04817f
AC
18018@cindex download to VxWorks
18019If you have connected to the VxWorks target and you want to debug an
18020object that has not yet been loaded, you can use the @value{GDBN}
18021@code{load} command to download a file from Unix to VxWorks
18022incrementally. The object file given as an argument to the @code{load}
18023command is actually opened twice: first by the VxWorks target in order
18024to download the code, then by @value{GDBN} in order to read the symbol
18025table. This can lead to problems if the current working directories on
18026the two systems differ. If both systems have NFS mounted the same
18027filesystems, you can avoid these problems by using absolute paths.
18028Otherwise, it is simplest to set the working directory on both systems
18029to the directory in which the object file resides, and then to reference
18030the file by its name, without any path. For instance, a program
18031@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
18032and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
18033program, type this on VxWorks:
104c1213 18034
474c8240 18035@smallexample
8e04817f 18036-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 18037@end smallexample
104c1213 18038
8e04817f
AC
18039@noindent
18040Then, in @value{GDBN}, type:
104c1213 18041
474c8240 18042@smallexample
8e04817f
AC
18043(vxgdb) cd @var{hostpath}/vw/demo/rdb
18044(vxgdb) load prog.o
474c8240 18045@end smallexample
104c1213 18046
8e04817f 18047@value{GDBN} displays a response similar to this:
104c1213 18048
8e04817f
AC
18049@smallexample
18050Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
18051@end smallexample
104c1213 18052
8e04817f
AC
18053You can also use the @code{load} command to reload an object module
18054after editing and recompiling the corresponding source file. Note that
18055this makes @value{GDBN} delete all currently-defined breakpoints,
18056auto-displays, and convenience variables, and to clear the value
18057history. (This is necessary in order to preserve the integrity of
18058debugger's data structures that reference the target system's symbol
18059table.)
104c1213 18060
8e04817f 18061@node VxWorks Attach
79a6e687 18062@subsubsection Running Tasks
104c1213
JM
18063
18064@cindex running VxWorks tasks
18065You can also attach to an existing task using the @code{attach} command as
18066follows:
18067
474c8240 18068@smallexample
104c1213 18069(vxgdb) attach @var{task}
474c8240 18070@end smallexample
104c1213
JM
18071
18072@noindent
18073where @var{task} is the VxWorks hexadecimal task ID. The task can be running
18074or suspended when you attach to it. Running tasks are suspended at
18075the time of attachment.
18076
6d2ebf8b 18077@node Embedded Processors
104c1213
JM
18078@section Embedded Processors
18079
18080This section goes into details specific to particular embedded
18081configurations.
18082
c45da7e6
EZ
18083@cindex send command to simulator
18084Whenever a specific embedded processor has a simulator, @value{GDBN}
18085allows to send an arbitrary command to the simulator.
18086
18087@table @code
18088@item sim @var{command}
18089@kindex sim@r{, a command}
18090Send an arbitrary @var{command} string to the simulator. Consult the
18091documentation for the specific simulator in use for information about
18092acceptable commands.
18093@end table
18094
7d86b5d5 18095
104c1213 18096@menu
c45da7e6 18097* ARM:: ARM RDI
172c2a43 18098* M32R/D:: Renesas M32R/D
104c1213 18099* M68K:: Motorola M68K
08be9d71 18100* MicroBlaze:: Xilinx MicroBlaze
104c1213 18101* MIPS Embedded:: MIPS Embedded
a37295f9 18102* OpenRISC 1000:: OpenRisc 1000
104c1213 18103* PA:: HP PA Embedded
4acd40f3 18104* PowerPC Embedded:: PowerPC Embedded
104c1213
JM
18105* Sparclet:: Tsqware Sparclet
18106* Sparclite:: Fujitsu Sparclite
104c1213 18107* Z8000:: Zilog Z8000
a64548ea
EZ
18108* AVR:: Atmel AVR
18109* CRIS:: CRIS
18110* Super-H:: Renesas Super-H
104c1213
JM
18111@end menu
18112
6d2ebf8b 18113@node ARM
104c1213 18114@subsection ARM
c45da7e6 18115@cindex ARM RDI
104c1213
JM
18116
18117@table @code
8e04817f
AC
18118@kindex target rdi
18119@item target rdi @var{dev}
18120ARM Angel monitor, via RDI library interface to ADP protocol. You may
18121use this target to communicate with both boards running the Angel
18122monitor, or with the EmbeddedICE JTAG debug device.
18123
18124@kindex target rdp
18125@item target rdp @var{dev}
18126ARM Demon monitor.
18127
18128@end table
18129
e2f4edfd
EZ
18130@value{GDBN} provides the following ARM-specific commands:
18131
18132@table @code
18133@item set arm disassembler
18134@kindex set arm
18135This commands selects from a list of disassembly styles. The
18136@code{"std"} style is the standard style.
18137
18138@item show arm disassembler
18139@kindex show arm
18140Show the current disassembly style.
18141
18142@item set arm apcs32
18143@cindex ARM 32-bit mode
18144This command toggles ARM operation mode between 32-bit and 26-bit.
18145
18146@item show arm apcs32
18147Display the current usage of the ARM 32-bit mode.
18148
18149@item set arm fpu @var{fputype}
18150This command sets the ARM floating-point unit (FPU) type. The
18151argument @var{fputype} can be one of these:
18152
18153@table @code
18154@item auto
18155Determine the FPU type by querying the OS ABI.
18156@item softfpa
18157Software FPU, with mixed-endian doubles on little-endian ARM
18158processors.
18159@item fpa
18160GCC-compiled FPA co-processor.
18161@item softvfp
18162Software FPU with pure-endian doubles.
18163@item vfp
18164VFP co-processor.
18165@end table
18166
18167@item show arm fpu
18168Show the current type of the FPU.
18169
18170@item set arm abi
18171This command forces @value{GDBN} to use the specified ABI.
18172
18173@item show arm abi
18174Show the currently used ABI.
18175
0428b8f5
DJ
18176@item set arm fallback-mode (arm|thumb|auto)
18177@value{GDBN} uses the symbol table, when available, to determine
18178whether instructions are ARM or Thumb. This command controls
18179@value{GDBN}'s default behavior when the symbol table is not
18180available. The default is @samp{auto}, which causes @value{GDBN} to
18181use the current execution mode (from the @code{T} bit in the @code{CPSR}
18182register).
18183
18184@item show arm fallback-mode
18185Show the current fallback instruction mode.
18186
18187@item set arm force-mode (arm|thumb|auto)
18188This command overrides use of the symbol table to determine whether
18189instructions are ARM or Thumb. The default is @samp{auto}, which
18190causes @value{GDBN} to use the symbol table and then the setting
18191of @samp{set arm fallback-mode}.
18192
18193@item show arm force-mode
18194Show the current forced instruction mode.
18195
e2f4edfd
EZ
18196@item set debug arm
18197Toggle whether to display ARM-specific debugging messages from the ARM
18198target support subsystem.
18199
18200@item show debug arm
18201Show whether ARM-specific debugging messages are enabled.
18202@end table
18203
c45da7e6
EZ
18204The following commands are available when an ARM target is debugged
18205using the RDI interface:
18206
18207@table @code
18208@item rdilogfile @r{[}@var{file}@r{]}
18209@kindex rdilogfile
18210@cindex ADP (Angel Debugger Protocol) logging
18211Set the filename for the ADP (Angel Debugger Protocol) packet log.
18212With an argument, sets the log file to the specified @var{file}. With
18213no argument, show the current log file name. The default log file is
18214@file{rdi.log}.
18215
18216@item rdilogenable @r{[}@var{arg}@r{]}
18217@kindex rdilogenable
18218Control logging of ADP packets. With an argument of 1 or @code{"yes"}
18219enables logging, with an argument 0 or @code{"no"} disables it. With
18220no arguments displays the current setting. When logging is enabled,
18221ADP packets exchanged between @value{GDBN} and the RDI target device
18222are logged to a file.
18223
18224@item set rdiromatzero
18225@kindex set rdiromatzero
18226@cindex ROM at zero address, RDI
18227Tell @value{GDBN} whether the target has ROM at address 0. If on,
18228vector catching is disabled, so that zero address can be used. If off
18229(the default), vector catching is enabled. For this command to take
18230effect, it needs to be invoked prior to the @code{target rdi} command.
18231
18232@item show rdiromatzero
18233@kindex show rdiromatzero
18234Show the current setting of ROM at zero address.
18235
18236@item set rdiheartbeat
18237@kindex set rdiheartbeat
18238@cindex RDI heartbeat
18239Enable or disable RDI heartbeat packets. It is not recommended to
18240turn on this option, since it confuses ARM and EPI JTAG interface, as
18241well as the Angel monitor.
18242
18243@item show rdiheartbeat
18244@kindex show rdiheartbeat
18245Show the setting of RDI heartbeat packets.
18246@end table
18247
ee8e71d4
EZ
18248@table @code
18249@item target sim @r{[}@var{simargs}@r{]} @dots{}
18250The @value{GDBN} ARM simulator accepts the following optional arguments.
18251
18252@table @code
18253@item --swi-support=@var{type}
18254Tell the simulator which SWI interfaces to support.
18255@var{type} may be a comma separated list of the following values.
18256The default value is @code{all}.
18257
18258@table @code
18259@item none
18260@item demon
18261@item angel
18262@item redboot
18263@item all
18264@end table
18265@end table
18266@end table
e2f4edfd 18267
8e04817f 18268@node M32R/D
ba04e063 18269@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
18270
18271@table @code
8e04817f
AC
18272@kindex target m32r
18273@item target m32r @var{dev}
172c2a43 18274Renesas M32R/D ROM monitor.
8e04817f 18275
fb3e19c0
KI
18276@kindex target m32rsdi
18277@item target m32rsdi @var{dev}
18278Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
18279@end table
18280
18281The following @value{GDBN} commands are specific to the M32R monitor:
18282
18283@table @code
18284@item set download-path @var{path}
18285@kindex set download-path
18286@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 18287Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
18288
18289@item show download-path
18290@kindex show download-path
18291Show the default path for downloadable @sc{srec} files.
fb3e19c0 18292
721c2651
EZ
18293@item set board-address @var{addr}
18294@kindex set board-address
18295@cindex M32-EVA target board address
18296Set the IP address for the M32R-EVA target board.
18297
18298@item show board-address
18299@kindex show board-address
18300Show the current IP address of the target board.
18301
18302@item set server-address @var{addr}
18303@kindex set server-address
18304@cindex download server address (M32R)
18305Set the IP address for the download server, which is the @value{GDBN}'s
18306host machine.
18307
18308@item show server-address
18309@kindex show server-address
18310Display the IP address of the download server.
18311
18312@item upload @r{[}@var{file}@r{]}
18313@kindex upload@r{, M32R}
18314Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
18315upload capability. If no @var{file} argument is given, the current
18316executable file is uploaded.
18317
18318@item tload @r{[}@var{file}@r{]}
18319@kindex tload@r{, M32R}
18320Test the @code{upload} command.
8e04817f
AC
18321@end table
18322
ba04e063
EZ
18323The following commands are available for M32R/SDI:
18324
18325@table @code
18326@item sdireset
18327@kindex sdireset
18328@cindex reset SDI connection, M32R
18329This command resets the SDI connection.
18330
18331@item sdistatus
18332@kindex sdistatus
18333This command shows the SDI connection status.
18334
18335@item debug_chaos
18336@kindex debug_chaos
18337@cindex M32R/Chaos debugging
18338Instructs the remote that M32R/Chaos debugging is to be used.
18339
18340@item use_debug_dma
18341@kindex use_debug_dma
18342Instructs the remote to use the DEBUG_DMA method of accessing memory.
18343
18344@item use_mon_code
18345@kindex use_mon_code
18346Instructs the remote to use the MON_CODE method of accessing memory.
18347
18348@item use_ib_break
18349@kindex use_ib_break
18350Instructs the remote to set breakpoints by IB break.
18351
18352@item use_dbt_break
18353@kindex use_dbt_break
18354Instructs the remote to set breakpoints by DBT.
18355@end table
18356
8e04817f
AC
18357@node M68K
18358@subsection M68k
18359
7ce59000
DJ
18360The Motorola m68k configuration includes ColdFire support, and a
18361target command for the following ROM monitor.
8e04817f
AC
18362
18363@table @code
18364
8e04817f
AC
18365@kindex target dbug
18366@item target dbug @var{dev}
18367dBUG ROM monitor for Motorola ColdFire.
18368
8e04817f
AC
18369@end table
18370
08be9d71
ME
18371@node MicroBlaze
18372@subsection MicroBlaze
18373@cindex Xilinx MicroBlaze
18374@cindex XMD, Xilinx Microprocessor Debugger
18375
18376The MicroBlaze is a soft-core processor supported on various Xilinx
18377FPGAs, such as Spartan or Virtex series. Boards with these processors
18378usually have JTAG ports which connect to a host system running the Xilinx
18379Embedded Development Kit (EDK) or Software Development Kit (SDK).
18380This host system is used to download the configuration bitstream to
18381the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
18382communicates with the target board using the JTAG interface and
18383presents a @code{gdbserver} interface to the board. By default
18384@code{xmd} uses port @code{1234}. (While it is possible to change
18385this default port, it requires the use of undocumented @code{xmd}
18386commands. Contact Xilinx support if you need to do this.)
18387
18388Use these GDB commands to connect to the MicroBlaze target processor.
18389
18390@table @code
18391@item target remote :1234
18392Use this command to connect to the target if you are running @value{GDBN}
18393on the same system as @code{xmd}.
18394
18395@item target remote @var{xmd-host}:1234
18396Use this command to connect to the target if it is connected to @code{xmd}
18397running on a different system named @var{xmd-host}.
18398
18399@item load
18400Use this command to download a program to the MicroBlaze target.
18401
18402@item set debug microblaze @var{n}
18403Enable MicroBlaze-specific debugging messages if non-zero.
18404
18405@item show debug microblaze @var{n}
18406Show MicroBlaze-specific debugging level.
18407@end table
18408
8e04817f
AC
18409@node MIPS Embedded
18410@subsection MIPS Embedded
18411
18412@cindex MIPS boards
18413@value{GDBN} can use the MIPS remote debugging protocol to talk to a
18414MIPS board attached to a serial line. This is available when
18415you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 18416
8e04817f
AC
18417@need 1000
18418Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 18419
8e04817f
AC
18420@table @code
18421@item target mips @var{port}
18422@kindex target mips @var{port}
18423To run a program on the board, start up @code{@value{GDBP}} with the
18424name of your program as the argument. To connect to the board, use the
18425command @samp{target mips @var{port}}, where @var{port} is the name of
18426the serial port connected to the board. If the program has not already
18427been downloaded to the board, you may use the @code{load} command to
18428download it. You can then use all the usual @value{GDBN} commands.
104c1213 18429
8e04817f
AC
18430For example, this sequence connects to the target board through a serial
18431port, and loads and runs a program called @var{prog} through the
18432debugger:
104c1213 18433
474c8240 18434@smallexample
8e04817f
AC
18435host$ @value{GDBP} @var{prog}
18436@value{GDBN} is free software and @dots{}
18437(@value{GDBP}) target mips /dev/ttyb
18438(@value{GDBP}) load @var{prog}
18439(@value{GDBP}) run
474c8240 18440@end smallexample
104c1213 18441
8e04817f
AC
18442@item target mips @var{hostname}:@var{portnumber}
18443On some @value{GDBN} host configurations, you can specify a TCP
18444connection (for instance, to a serial line managed by a terminal
18445concentrator) instead of a serial port, using the syntax
18446@samp{@var{hostname}:@var{portnumber}}.
104c1213 18447
8e04817f
AC
18448@item target pmon @var{port}
18449@kindex target pmon @var{port}
18450PMON ROM monitor.
104c1213 18451
8e04817f
AC
18452@item target ddb @var{port}
18453@kindex target ddb @var{port}
18454NEC's DDB variant of PMON for Vr4300.
104c1213 18455
8e04817f
AC
18456@item target lsi @var{port}
18457@kindex target lsi @var{port}
18458LSI variant of PMON.
104c1213 18459
8e04817f
AC
18460@kindex target r3900
18461@item target r3900 @var{dev}
18462Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 18463
8e04817f
AC
18464@kindex target array
18465@item target array @var{dev}
18466Array Tech LSI33K RAID controller board.
104c1213 18467
8e04817f 18468@end table
104c1213 18469
104c1213 18470
8e04817f
AC
18471@noindent
18472@value{GDBN} also supports these special commands for MIPS targets:
104c1213 18473
8e04817f 18474@table @code
8e04817f
AC
18475@item set mipsfpu double
18476@itemx set mipsfpu single
18477@itemx set mipsfpu none
a64548ea 18478@itemx set mipsfpu auto
8e04817f
AC
18479@itemx show mipsfpu
18480@kindex set mipsfpu
18481@kindex show mipsfpu
18482@cindex MIPS remote floating point
18483@cindex floating point, MIPS remote
18484If your target board does not support the MIPS floating point
18485coprocessor, you should use the command @samp{set mipsfpu none} (if you
18486need this, you may wish to put the command in your @value{GDBN} init
18487file). This tells @value{GDBN} how to find the return value of
18488functions which return floating point values. It also allows
18489@value{GDBN} to avoid saving the floating point registers when calling
18490functions on the board. If you are using a floating point coprocessor
18491with only single precision floating point support, as on the @sc{r4650}
18492processor, use the command @samp{set mipsfpu single}. The default
18493double precision floating point coprocessor may be selected using
18494@samp{set mipsfpu double}.
104c1213 18495
8e04817f
AC
18496In previous versions the only choices were double precision or no
18497floating point, so @samp{set mipsfpu on} will select double precision
18498and @samp{set mipsfpu off} will select no floating point.
104c1213 18499
8e04817f
AC
18500As usual, you can inquire about the @code{mipsfpu} variable with
18501@samp{show mipsfpu}.
104c1213 18502
8e04817f
AC
18503@item set timeout @var{seconds}
18504@itemx set retransmit-timeout @var{seconds}
18505@itemx show timeout
18506@itemx show retransmit-timeout
18507@cindex @code{timeout}, MIPS protocol
18508@cindex @code{retransmit-timeout}, MIPS protocol
18509@kindex set timeout
18510@kindex show timeout
18511@kindex set retransmit-timeout
18512@kindex show retransmit-timeout
18513You can control the timeout used while waiting for a packet, in the MIPS
18514remote protocol, with the @code{set timeout @var{seconds}} command. The
18515default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 18516waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
18517retransmit-timeout @var{seconds}} command. The default is 3 seconds.
18518You can inspect both values with @code{show timeout} and @code{show
18519retransmit-timeout}. (These commands are @emph{only} available when
18520@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 18521
8e04817f
AC
18522The timeout set by @code{set timeout} does not apply when @value{GDBN}
18523is waiting for your program to stop. In that case, @value{GDBN} waits
18524forever because it has no way of knowing how long the program is going
18525to run before stopping.
ba04e063
EZ
18526
18527@item set syn-garbage-limit @var{num}
18528@kindex set syn-garbage-limit@r{, MIPS remote}
18529@cindex synchronize with remote MIPS target
18530Limit the maximum number of characters @value{GDBN} should ignore when
18531it tries to synchronize with the remote target. The default is 10
18532characters. Setting the limit to -1 means there's no limit.
18533
18534@item show syn-garbage-limit
18535@kindex show syn-garbage-limit@r{, MIPS remote}
18536Show the current limit on the number of characters to ignore when
18537trying to synchronize with the remote system.
18538
18539@item set monitor-prompt @var{prompt}
18540@kindex set monitor-prompt@r{, MIPS remote}
18541@cindex remote monitor prompt
18542Tell @value{GDBN} to expect the specified @var{prompt} string from the
18543remote monitor. The default depends on the target:
18544@table @asis
18545@item pmon target
18546@samp{PMON}
18547@item ddb target
18548@samp{NEC010}
18549@item lsi target
18550@samp{PMON>}
18551@end table
18552
18553@item show monitor-prompt
18554@kindex show monitor-prompt@r{, MIPS remote}
18555Show the current strings @value{GDBN} expects as the prompt from the
18556remote monitor.
18557
18558@item set monitor-warnings
18559@kindex set monitor-warnings@r{, MIPS remote}
18560Enable or disable monitor warnings about hardware breakpoints. This
18561has effect only for the @code{lsi} target. When on, @value{GDBN} will
18562display warning messages whose codes are returned by the @code{lsi}
18563PMON monitor for breakpoint commands.
18564
18565@item show monitor-warnings
18566@kindex show monitor-warnings@r{, MIPS remote}
18567Show the current setting of printing monitor warnings.
18568
18569@item pmon @var{command}
18570@kindex pmon@r{, MIPS remote}
18571@cindex send PMON command
18572This command allows sending an arbitrary @var{command} string to the
18573monitor. The monitor must be in debug mode for this to work.
8e04817f 18574@end table
104c1213 18575
a37295f9
MM
18576@node OpenRISC 1000
18577@subsection OpenRISC 1000
18578@cindex OpenRISC 1000
18579
18580@cindex or1k boards
18581See OR1k Architecture document (@uref{www.opencores.org}) for more information
18582about platform and commands.
18583
18584@table @code
18585
18586@kindex target jtag
18587@item target jtag jtag://@var{host}:@var{port}
18588
18589Connects to remote JTAG server.
18590JTAG remote server can be either an or1ksim or JTAG server,
18591connected via parallel port to the board.
18592
18593Example: @code{target jtag jtag://localhost:9999}
18594
18595@kindex or1ksim
18596@item or1ksim @var{command}
18597If connected to @code{or1ksim} OpenRISC 1000 Architectural
18598Simulator, proprietary commands can be executed.
18599
18600@kindex info or1k spr
18601@item info or1k spr
18602Displays spr groups.
18603
18604@item info or1k spr @var{group}
18605@itemx info or1k spr @var{groupno}
18606Displays register names in selected group.
18607
18608@item info or1k spr @var{group} @var{register}
18609@itemx info or1k spr @var{register}
18610@itemx info or1k spr @var{groupno} @var{registerno}
18611@itemx info or1k spr @var{registerno}
18612Shows information about specified spr register.
18613
18614@kindex spr
18615@item spr @var{group} @var{register} @var{value}
18616@itemx spr @var{register @var{value}}
18617@itemx spr @var{groupno} @var{registerno @var{value}}
18618@itemx spr @var{registerno @var{value}}
18619Writes @var{value} to specified spr register.
18620@end table
18621
18622Some implementations of OpenRISC 1000 Architecture also have hardware trace.
18623It is very similar to @value{GDBN} trace, except it does not interfere with normal
18624program execution and is thus much faster. Hardware breakpoints/watchpoint
18625triggers can be set using:
18626@table @code
18627@item $LEA/$LDATA
18628Load effective address/data
18629@item $SEA/$SDATA
18630Store effective address/data
18631@item $AEA/$ADATA
18632Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
18633@item $FETCH
18634Fetch data
18635@end table
18636
18637When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
18638@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
18639
18640@code{htrace} commands:
18641@cindex OpenRISC 1000 htrace
18642@table @code
18643@kindex hwatch
18644@item hwatch @var{conditional}
d3e8051b 18645Set hardware watchpoint on combination of Load/Store Effective Address(es)
a37295f9
MM
18646or Data. For example:
18647
18648@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
18649
18650@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
18651
4644b6e3 18652@kindex htrace
a37295f9
MM
18653@item htrace info
18654Display information about current HW trace configuration.
18655
a37295f9
MM
18656@item htrace trigger @var{conditional}
18657Set starting criteria for HW trace.
18658
a37295f9
MM
18659@item htrace qualifier @var{conditional}
18660Set acquisition qualifier for HW trace.
18661
a37295f9
MM
18662@item htrace stop @var{conditional}
18663Set HW trace stopping criteria.
18664
f153cc92 18665@item htrace record [@var{data}]*
a37295f9
MM
18666Selects the data to be recorded, when qualifier is met and HW trace was
18667triggered.
18668
a37295f9 18669@item htrace enable
a37295f9
MM
18670@itemx htrace disable
18671Enables/disables the HW trace.
18672
f153cc92 18673@item htrace rewind [@var{filename}]
a37295f9
MM
18674Clears currently recorded trace data.
18675
18676If filename is specified, new trace file is made and any newly collected data
18677will be written there.
18678
f153cc92 18679@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
18680Prints trace buffer, using current record configuration.
18681
a37295f9
MM
18682@item htrace mode continuous
18683Set continuous trace mode.
18684
a37295f9
MM
18685@item htrace mode suspend
18686Set suspend trace mode.
18687
18688@end table
18689
4acd40f3
TJB
18690@node PowerPC Embedded
18691@subsection PowerPC Embedded
104c1213 18692
66b73624
TJB
18693@cindex DVC register
18694@value{GDBN} supports using the DVC (Data Value Compare) register to
18695implement in hardware simple hardware watchpoint conditions of the form:
18696
18697@smallexample
18698(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
18699 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
18700@end smallexample
18701
18702The DVC register will be automatically used whenever @value{GDBN} detects
18703such pattern in a condition expression. This feature is available in native
18704@value{GDBN} running on a Linux kernel version 2.6.34 or newer.
18705
55eddb0f
DJ
18706@value{GDBN} provides the following PowerPC-specific commands:
18707
104c1213 18708@table @code
55eddb0f
DJ
18709@kindex set powerpc
18710@item set powerpc soft-float
18711@itemx show powerpc soft-float
18712Force @value{GDBN} to use (or not use) a software floating point calling
18713convention. By default, @value{GDBN} selects the calling convention based
18714on the selected architecture and the provided executable file.
18715
18716@item set powerpc vector-abi
18717@itemx show powerpc vector-abi
18718Force @value{GDBN} to use the specified calling convention for vector
18719arguments and return values. The valid options are @samp{auto};
18720@samp{generic}, to avoid vector registers even if they are present;
18721@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
18722registers. By default, @value{GDBN} selects the calling convention
18723based on the selected architecture and the provided executable file.
18724
8e04817f
AC
18725@kindex target dink32
18726@item target dink32 @var{dev}
18727DINK32 ROM monitor.
104c1213 18728
8e04817f
AC
18729@kindex target ppcbug
18730@item target ppcbug @var{dev}
18731@kindex target ppcbug1
18732@item target ppcbug1 @var{dev}
18733PPCBUG ROM monitor for PowerPC.
104c1213 18734
8e04817f
AC
18735@kindex target sds
18736@item target sds @var{dev}
18737SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 18738@end table
8e04817f 18739
c45da7e6 18740@cindex SDS protocol
d52fb0e9 18741The following commands specific to the SDS protocol are supported
55eddb0f 18742by @value{GDBN}:
c45da7e6
EZ
18743
18744@table @code
18745@item set sdstimeout @var{nsec}
18746@kindex set sdstimeout
18747Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
18748default is 2 seconds.
18749
18750@item show sdstimeout
18751@kindex show sdstimeout
18752Show the current value of the SDS timeout.
18753
18754@item sds @var{command}
18755@kindex sds@r{, a command}
18756Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
18757@end table
18758
c45da7e6 18759
8e04817f
AC
18760@node PA
18761@subsection HP PA Embedded
104c1213
JM
18762
18763@table @code
18764
8e04817f
AC
18765@kindex target op50n
18766@item target op50n @var{dev}
18767OP50N monitor, running on an OKI HPPA board.
18768
18769@kindex target w89k
18770@item target w89k @var{dev}
18771W89K monitor, running on a Winbond HPPA board.
104c1213
JM
18772
18773@end table
18774
8e04817f
AC
18775@node Sparclet
18776@subsection Tsqware Sparclet
104c1213 18777
8e04817f
AC
18778@cindex Sparclet
18779
18780@value{GDBN} enables developers to debug tasks running on
18781Sparclet targets from a Unix host.
18782@value{GDBN} uses code that runs on
18783both the Unix host and on the Sparclet target. The program
18784@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 18785
8e04817f
AC
18786@table @code
18787@item remotetimeout @var{args}
18788@kindex remotetimeout
18789@value{GDBN} supports the option @code{remotetimeout}.
18790This option is set by the user, and @var{args} represents the number of
18791seconds @value{GDBN} waits for responses.
104c1213
JM
18792@end table
18793
8e04817f
AC
18794@cindex compiling, on Sparclet
18795When compiling for debugging, include the options @samp{-g} to get debug
18796information and @samp{-Ttext} to relocate the program to where you wish to
18797load it on the target. You may also want to add the options @samp{-n} or
18798@samp{-N} in order to reduce the size of the sections. Example:
104c1213 18799
474c8240 18800@smallexample
8e04817f 18801sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 18802@end smallexample
104c1213 18803
8e04817f 18804You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 18805
474c8240 18806@smallexample
8e04817f 18807sparclet-aout-objdump --headers --syms prog
474c8240 18808@end smallexample
104c1213 18809
8e04817f
AC
18810@cindex running, on Sparclet
18811Once you have set
18812your Unix execution search path to find @value{GDBN}, you are ready to
18813run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
18814(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 18815
8e04817f
AC
18816@value{GDBN} comes up showing the prompt:
18817
474c8240 18818@smallexample
8e04817f 18819(gdbslet)
474c8240 18820@end smallexample
104c1213
JM
18821
18822@menu
8e04817f
AC
18823* Sparclet File:: Setting the file to debug
18824* Sparclet Connection:: Connecting to Sparclet
18825* Sparclet Download:: Sparclet download
18826* Sparclet Execution:: Running and debugging
104c1213
JM
18827@end menu
18828
8e04817f 18829@node Sparclet File
79a6e687 18830@subsubsection Setting File to Debug
104c1213 18831
8e04817f 18832The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 18833
474c8240 18834@smallexample
8e04817f 18835(gdbslet) file prog
474c8240 18836@end smallexample
104c1213 18837
8e04817f
AC
18838@need 1000
18839@value{GDBN} then attempts to read the symbol table of @file{prog}.
18840@value{GDBN} locates
18841the file by searching the directories listed in the command search
18842path.
12c27660 18843If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
18844files will be searched as well.
18845@value{GDBN} locates
18846the source files by searching the directories listed in the directory search
79a6e687 18847path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
18848If it fails
18849to find a file, it displays a message such as:
104c1213 18850
474c8240 18851@smallexample
8e04817f 18852prog: No such file or directory.
474c8240 18853@end smallexample
104c1213 18854
8e04817f
AC
18855When this happens, add the appropriate directories to the search paths with
18856the @value{GDBN} commands @code{path} and @code{dir}, and execute the
18857@code{target} command again.
104c1213 18858
8e04817f
AC
18859@node Sparclet Connection
18860@subsubsection Connecting to Sparclet
104c1213 18861
8e04817f
AC
18862The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
18863To connect to a target on serial port ``@code{ttya}'', type:
104c1213 18864
474c8240 18865@smallexample
8e04817f
AC
18866(gdbslet) target sparclet /dev/ttya
18867Remote target sparclet connected to /dev/ttya
18868main () at ../prog.c:3
474c8240 18869@end smallexample
104c1213 18870
8e04817f
AC
18871@need 750
18872@value{GDBN} displays messages like these:
104c1213 18873
474c8240 18874@smallexample
8e04817f 18875Connected to ttya.
474c8240 18876@end smallexample
104c1213 18877
8e04817f 18878@node Sparclet Download
79a6e687 18879@subsubsection Sparclet Download
104c1213 18880
8e04817f
AC
18881@cindex download to Sparclet
18882Once connected to the Sparclet target,
18883you can use the @value{GDBN}
18884@code{load} command to download the file from the host to the target.
18885The file name and load offset should be given as arguments to the @code{load}
18886command.
18887Since the file format is aout, the program must be loaded to the starting
18888address. You can use @code{objdump} to find out what this value is. The load
18889offset is an offset which is added to the VMA (virtual memory address)
18890of each of the file's sections.
18891For instance, if the program
18892@file{prog} was linked to text address 0x1201000, with data at 0x12010160
18893and bss at 0x12010170, in @value{GDBN}, type:
104c1213 18894
474c8240 18895@smallexample
8e04817f
AC
18896(gdbslet) load prog 0x12010000
18897Loading section .text, size 0xdb0 vma 0x12010000
474c8240 18898@end smallexample
104c1213 18899
8e04817f
AC
18900If the code is loaded at a different address then what the program was linked
18901to, you may need to use the @code{section} and @code{add-symbol-file} commands
18902to tell @value{GDBN} where to map the symbol table.
18903
18904@node Sparclet Execution
79a6e687 18905@subsubsection Running and Debugging
8e04817f
AC
18906
18907@cindex running and debugging Sparclet programs
18908You can now begin debugging the task using @value{GDBN}'s execution control
18909commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
18910manual for the list of commands.
18911
474c8240 18912@smallexample
8e04817f
AC
18913(gdbslet) b main
18914Breakpoint 1 at 0x12010000: file prog.c, line 3.
18915(gdbslet) run
18916Starting program: prog
18917Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
189183 char *symarg = 0;
18919(gdbslet) step
189204 char *execarg = "hello!";
18921(gdbslet)
474c8240 18922@end smallexample
8e04817f
AC
18923
18924@node Sparclite
18925@subsection Fujitsu Sparclite
104c1213
JM
18926
18927@table @code
18928
8e04817f
AC
18929@kindex target sparclite
18930@item target sparclite @var{dev}
18931Fujitsu sparclite boards, used only for the purpose of loading.
18932You must use an additional command to debug the program.
18933For example: target remote @var{dev} using @value{GDBN} standard
18934remote protocol.
104c1213
JM
18935
18936@end table
18937
8e04817f
AC
18938@node Z8000
18939@subsection Zilog Z8000
104c1213 18940
8e04817f
AC
18941@cindex Z8000
18942@cindex simulator, Z8000
18943@cindex Zilog Z8000 simulator
104c1213 18944
8e04817f
AC
18945When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
18946a Z8000 simulator.
18947
18948For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
18949unsegmented variant of the Z8000 architecture) or the Z8001 (the
18950segmented variant). The simulator recognizes which architecture is
18951appropriate by inspecting the object code.
104c1213 18952
8e04817f
AC
18953@table @code
18954@item target sim @var{args}
18955@kindex sim
18956@kindex target sim@r{, with Z8000}
18957Debug programs on a simulated CPU. If the simulator supports setup
18958options, specify them via @var{args}.
104c1213
JM
18959@end table
18960
8e04817f
AC
18961@noindent
18962After specifying this target, you can debug programs for the simulated
18963CPU in the same style as programs for your host computer; use the
18964@code{file} command to load a new program image, the @code{run} command
18965to run your program, and so on.
18966
18967As well as making available all the usual machine registers
18968(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
18969additional items of information as specially named registers:
104c1213
JM
18970
18971@table @code
18972
8e04817f
AC
18973@item cycles
18974Counts clock-ticks in the simulator.
104c1213 18975
8e04817f
AC
18976@item insts
18977Counts instructions run in the simulator.
104c1213 18978
8e04817f
AC
18979@item time
18980Execution time in 60ths of a second.
104c1213 18981
8e04817f 18982@end table
104c1213 18983
8e04817f
AC
18984You can refer to these values in @value{GDBN} expressions with the usual
18985conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
18986conditional breakpoint that suspends only after at least 5000
18987simulated clock ticks.
104c1213 18988
a64548ea
EZ
18989@node AVR
18990@subsection Atmel AVR
18991@cindex AVR
18992
18993When configured for debugging the Atmel AVR, @value{GDBN} supports the
18994following AVR-specific commands:
18995
18996@table @code
18997@item info io_registers
18998@kindex info io_registers@r{, AVR}
18999@cindex I/O registers (Atmel AVR)
19000This command displays information about the AVR I/O registers. For
19001each register, @value{GDBN} prints its number and value.
19002@end table
19003
19004@node CRIS
19005@subsection CRIS
19006@cindex CRIS
19007
19008When configured for debugging CRIS, @value{GDBN} provides the
19009following CRIS-specific commands:
19010
19011@table @code
19012@item set cris-version @var{ver}
19013@cindex CRIS version
e22e55c9
OF
19014Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
19015The CRIS version affects register names and sizes. This command is useful in
19016case autodetection of the CRIS version fails.
a64548ea
EZ
19017
19018@item show cris-version
19019Show the current CRIS version.
19020
19021@item set cris-dwarf2-cfi
19022@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
19023Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
19024Change to @samp{off} when using @code{gcc-cris} whose version is below
19025@code{R59}.
a64548ea
EZ
19026
19027@item show cris-dwarf2-cfi
19028Show the current state of using DWARF-2 CFI.
e22e55c9
OF
19029
19030@item set cris-mode @var{mode}
19031@cindex CRIS mode
19032Set the current CRIS mode to @var{mode}. It should only be changed when
19033debugging in guru mode, in which case it should be set to
19034@samp{guru} (the default is @samp{normal}).
19035
19036@item show cris-mode
19037Show the current CRIS mode.
a64548ea
EZ
19038@end table
19039
19040@node Super-H
19041@subsection Renesas Super-H
19042@cindex Super-H
19043
19044For the Renesas Super-H processor, @value{GDBN} provides these
19045commands:
19046
19047@table @code
19048@item regs
19049@kindex regs@r{, Super-H}
19050Show the values of all Super-H registers.
c055b101
CV
19051
19052@item set sh calling-convention @var{convention}
19053@kindex set sh calling-convention
19054Set the calling-convention used when calling functions from @value{GDBN}.
19055Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
19056With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
19057convention. If the DWARF-2 information of the called function specifies
19058that the function follows the Renesas calling convention, the function
19059is called using the Renesas calling convention. If the calling convention
19060is set to @samp{renesas}, the Renesas calling convention is always used,
19061regardless of the DWARF-2 information. This can be used to override the
19062default of @samp{gcc} if debug information is missing, or the compiler
19063does not emit the DWARF-2 calling convention entry for a function.
19064
19065@item show sh calling-convention
19066@kindex show sh calling-convention
19067Show the current calling convention setting.
19068
a64548ea
EZ
19069@end table
19070
19071
8e04817f
AC
19072@node Architectures
19073@section Architectures
104c1213 19074
8e04817f
AC
19075This section describes characteristics of architectures that affect
19076all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 19077
8e04817f 19078@menu
9c16f35a 19079* i386::
8e04817f
AC
19080* A29K::
19081* Alpha::
19082* MIPS::
a64548ea 19083* HPPA:: HP PA architecture
23d964e7 19084* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 19085* PowerPC::
8e04817f 19086@end menu
104c1213 19087
9c16f35a 19088@node i386
db2e3e2e 19089@subsection x86 Architecture-specific Issues
9c16f35a
EZ
19090
19091@table @code
19092@item set struct-convention @var{mode}
19093@kindex set struct-convention
19094@cindex struct return convention
19095@cindex struct/union returned in registers
19096Set the convention used by the inferior to return @code{struct}s and
19097@code{union}s from functions to @var{mode}. Possible values of
19098@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
19099default). @code{"default"} or @code{"pcc"} means that @code{struct}s
19100are returned on the stack, while @code{"reg"} means that a
19101@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
19102be returned in a register.
19103
19104@item show struct-convention
19105@kindex show struct-convention
19106Show the current setting of the convention to return @code{struct}s
19107from functions.
19108@end table
19109
8e04817f
AC
19110@node A29K
19111@subsection A29K
104c1213
JM
19112
19113@table @code
104c1213 19114
8e04817f
AC
19115@kindex set rstack_high_address
19116@cindex AMD 29K register stack
19117@cindex register stack, AMD29K
19118@item set rstack_high_address @var{address}
19119On AMD 29000 family processors, registers are saved in a separate
19120@dfn{register stack}. There is no way for @value{GDBN} to determine the
19121extent of this stack. Normally, @value{GDBN} just assumes that the
19122stack is ``large enough''. This may result in @value{GDBN} referencing
19123memory locations that do not exist. If necessary, you can get around
19124this problem by specifying the ending address of the register stack with
19125the @code{set rstack_high_address} command. The argument should be an
19126address, which you probably want to precede with @samp{0x} to specify in
19127hexadecimal.
104c1213 19128
8e04817f
AC
19129@kindex show rstack_high_address
19130@item show rstack_high_address
19131Display the current limit of the register stack, on AMD 29000 family
19132processors.
104c1213 19133
8e04817f 19134@end table
104c1213 19135
8e04817f
AC
19136@node Alpha
19137@subsection Alpha
104c1213 19138
8e04817f 19139See the following section.
104c1213 19140
8e04817f
AC
19141@node MIPS
19142@subsection MIPS
104c1213 19143
8e04817f
AC
19144@cindex stack on Alpha
19145@cindex stack on MIPS
19146@cindex Alpha stack
19147@cindex MIPS stack
19148Alpha- and MIPS-based computers use an unusual stack frame, which
19149sometimes requires @value{GDBN} to search backward in the object code to
19150find the beginning of a function.
104c1213 19151
8e04817f
AC
19152@cindex response time, MIPS debugging
19153To improve response time (especially for embedded applications, where
19154@value{GDBN} may be restricted to a slow serial line for this search)
19155you may want to limit the size of this search, using one of these
19156commands:
104c1213 19157
8e04817f
AC
19158@table @code
19159@cindex @code{heuristic-fence-post} (Alpha, MIPS)
19160@item set heuristic-fence-post @var{limit}
19161Restrict @value{GDBN} to examining at most @var{limit} bytes in its
19162search for the beginning of a function. A value of @var{0} (the
19163default) means there is no limit. However, except for @var{0}, the
19164larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
19165and therefore the longer it takes to run. You should only need to use
19166this command when debugging a stripped executable.
104c1213 19167
8e04817f
AC
19168@item show heuristic-fence-post
19169Display the current limit.
19170@end table
104c1213
JM
19171
19172@noindent
8e04817f
AC
19173These commands are available @emph{only} when @value{GDBN} is configured
19174for debugging programs on Alpha or MIPS processors.
104c1213 19175
a64548ea
EZ
19176Several MIPS-specific commands are available when debugging MIPS
19177programs:
19178
19179@table @code
a64548ea
EZ
19180@item set mips abi @var{arg}
19181@kindex set mips abi
19182@cindex set ABI for MIPS
19183Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
19184values of @var{arg} are:
19185
19186@table @samp
19187@item auto
19188The default ABI associated with the current binary (this is the
19189default).
19190@item o32
19191@item o64
19192@item n32
19193@item n64
19194@item eabi32
19195@item eabi64
19196@item auto
19197@end table
19198
19199@item show mips abi
19200@kindex show mips abi
19201Show the MIPS ABI used by @value{GDBN} to debug the inferior.
19202
19203@item set mipsfpu
19204@itemx show mipsfpu
19205@xref{MIPS Embedded, set mipsfpu}.
19206
19207@item set mips mask-address @var{arg}
19208@kindex set mips mask-address
19209@cindex MIPS addresses, masking
19210This command determines whether the most-significant 32 bits of 64-bit
19211MIPS addresses are masked off. The argument @var{arg} can be
19212@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
19213setting, which lets @value{GDBN} determine the correct value.
19214
19215@item show mips mask-address
19216@kindex show mips mask-address
19217Show whether the upper 32 bits of MIPS addresses are masked off or
19218not.
19219
19220@item set remote-mips64-transfers-32bit-regs
19221@kindex set remote-mips64-transfers-32bit-regs
19222This command controls compatibility with 64-bit MIPS targets that
19223transfer data in 32-bit quantities. If you have an old MIPS 64 target
19224that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
19225and 64 bits for other registers, set this option to @samp{on}.
19226
19227@item show remote-mips64-transfers-32bit-regs
19228@kindex show remote-mips64-transfers-32bit-regs
19229Show the current setting of compatibility with older MIPS 64 targets.
19230
19231@item set debug mips
19232@kindex set debug mips
19233This command turns on and off debugging messages for the MIPS-specific
19234target code in @value{GDBN}.
19235
19236@item show debug mips
19237@kindex show debug mips
19238Show the current setting of MIPS debugging messages.
19239@end table
19240
19241
19242@node HPPA
19243@subsection HPPA
19244@cindex HPPA support
19245
d3e8051b 19246When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
19247following special commands:
19248
19249@table @code
19250@item set debug hppa
19251@kindex set debug hppa
db2e3e2e 19252This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
19253messages are to be displayed.
19254
19255@item show debug hppa
19256Show whether HPPA debugging messages are displayed.
19257
19258@item maint print unwind @var{address}
19259@kindex maint print unwind@r{, HPPA}
19260This command displays the contents of the unwind table entry at the
19261given @var{address}.
19262
19263@end table
19264
104c1213 19265
23d964e7
UW
19266@node SPU
19267@subsection Cell Broadband Engine SPU architecture
19268@cindex Cell Broadband Engine
19269@cindex SPU
19270
19271When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
19272it provides the following special commands:
19273
19274@table @code
19275@item info spu event
19276@kindex info spu
19277Display SPU event facility status. Shows current event mask
19278and pending event status.
19279
19280@item info spu signal
19281Display SPU signal notification facility status. Shows pending
19282signal-control word and signal notification mode of both signal
19283notification channels.
19284
19285@item info spu mailbox
19286Display SPU mailbox facility status. Shows all pending entries,
19287in order of processing, in each of the SPU Write Outbound,
19288SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
19289
19290@item info spu dma
19291Display MFC DMA status. Shows all pending commands in the MFC
19292DMA queue. For each entry, opcode, tag, class IDs, effective
19293and local store addresses and transfer size are shown.
19294
19295@item info spu proxydma
19296Display MFC Proxy-DMA status. Shows all pending commands in the MFC
19297Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
19298and local store addresses and transfer size are shown.
19299
19300@end table
19301
3285f3fe
UW
19302When @value{GDBN} is debugging a combined PowerPC/SPU application
19303on the Cell Broadband Engine, it provides in addition the following
19304special commands:
19305
19306@table @code
19307@item set spu stop-on-load @var{arg}
19308@kindex set spu
19309Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
19310will give control to the user when a new SPE thread enters its @code{main}
19311function. The default is @code{off}.
19312
19313@item show spu stop-on-load
19314@kindex show spu
19315Show whether to stop for new SPE threads.
19316
ff1a52c6
UW
19317@item set spu auto-flush-cache @var{arg}
19318Set whether to automatically flush the software-managed cache. When set to
19319@code{on}, @value{GDBN} will automatically cause the SPE software-managed
19320cache to be flushed whenever SPE execution stops. This provides a consistent
19321view of PowerPC memory that is accessed via the cache. If an application
19322does not use the software-managed cache, this option has no effect.
19323
19324@item show spu auto-flush-cache
19325Show whether to automatically flush the software-managed cache.
19326
3285f3fe
UW
19327@end table
19328
4acd40f3
TJB
19329@node PowerPC
19330@subsection PowerPC
19331@cindex PowerPC architecture
19332
19333When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
19334pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
19335numbers stored in the floating point registers. These values must be stored
19336in two consecutive registers, always starting at an even register like
19337@code{f0} or @code{f2}.
19338
19339The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
19340by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
19341@code{f2} and @code{f3} for @code{$dl1} and so on.
19342
aeac0ff9 19343For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
19344wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
19345
23d964e7 19346
8e04817f
AC
19347@node Controlling GDB
19348@chapter Controlling @value{GDBN}
19349
19350You can alter the way @value{GDBN} interacts with you by using the
19351@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 19352data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
19353described here.
19354
19355@menu
19356* Prompt:: Prompt
19357* Editing:: Command editing
d620b259 19358* Command History:: Command history
8e04817f
AC
19359* Screen Size:: Screen size
19360* Numbers:: Numbers
1e698235 19361* ABI:: Configuring the current ABI
8e04817f
AC
19362* Messages/Warnings:: Optional warnings and messages
19363* Debugging Output:: Optional messages about internal happenings
14fb1bac 19364* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
19365@end menu
19366
19367@node Prompt
19368@section Prompt
104c1213 19369
8e04817f 19370@cindex prompt
104c1213 19371
8e04817f
AC
19372@value{GDBN} indicates its readiness to read a command by printing a string
19373called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
19374can change the prompt string with the @code{set prompt} command. For
19375instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
19376the prompt in one of the @value{GDBN} sessions so that you can always tell
19377which one you are talking to.
104c1213 19378
8e04817f
AC
19379@emph{Note:} @code{set prompt} does not add a space for you after the
19380prompt you set. This allows you to set a prompt which ends in a space
19381or a prompt that does not.
104c1213 19382
8e04817f
AC
19383@table @code
19384@kindex set prompt
19385@item set prompt @var{newprompt}
19386Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 19387
8e04817f
AC
19388@kindex show prompt
19389@item show prompt
19390Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
19391@end table
19392
8e04817f 19393@node Editing
79a6e687 19394@section Command Editing
8e04817f
AC
19395@cindex readline
19396@cindex command line editing
104c1213 19397
703663ab 19398@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
19399@sc{gnu} library provides consistent behavior for programs which provide a
19400command line interface to the user. Advantages are @sc{gnu} Emacs-style
19401or @dfn{vi}-style inline editing of commands, @code{csh}-like history
19402substitution, and a storage and recall of command history across
19403debugging sessions.
104c1213 19404
8e04817f
AC
19405You may control the behavior of command line editing in @value{GDBN} with the
19406command @code{set}.
104c1213 19407
8e04817f
AC
19408@table @code
19409@kindex set editing
19410@cindex editing
19411@item set editing
19412@itemx set editing on
19413Enable command line editing (enabled by default).
104c1213 19414
8e04817f
AC
19415@item set editing off
19416Disable command line editing.
104c1213 19417
8e04817f
AC
19418@kindex show editing
19419@item show editing
19420Show whether command line editing is enabled.
104c1213
JM
19421@end table
19422
39037522
TT
19423@ifset SYSTEM_READLINE
19424@xref{Command Line Editing, , , rluserman, GNU Readline Library},
19425@end ifset
19426@ifclear SYSTEM_READLINE
19427@xref{Command Line Editing},
19428@end ifclear
19429for more details about the Readline
703663ab
EZ
19430interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
19431encouraged to read that chapter.
19432
d620b259 19433@node Command History
79a6e687 19434@section Command History
703663ab 19435@cindex command history
8e04817f
AC
19436
19437@value{GDBN} can keep track of the commands you type during your
19438debugging sessions, so that you can be certain of precisely what
19439happened. Use these commands to manage the @value{GDBN} command
19440history facility.
104c1213 19441
703663ab 19442@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
19443package, to provide the history facility.
19444@ifset SYSTEM_READLINE
19445@xref{Using History Interactively, , , history, GNU History Library},
19446@end ifset
19447@ifclear SYSTEM_READLINE
19448@xref{Using History Interactively},
19449@end ifclear
19450for the detailed description of the History library.
703663ab 19451
d620b259 19452To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
19453the state which is seen by users, prefix it with @samp{server }
19454(@pxref{Server Prefix}). This
d620b259
NR
19455means that this command will not affect the command history, nor will it
19456affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
19457pressed on a line by itself.
19458
19459@cindex @code{server}, command prefix
19460The server prefix does not affect the recording of values into the value
19461history; to print a value without recording it into the value history,
19462use the @code{output} command instead of the @code{print} command.
19463
703663ab
EZ
19464Here is the description of @value{GDBN} commands related to command
19465history.
19466
104c1213 19467@table @code
8e04817f
AC
19468@cindex history substitution
19469@cindex history file
19470@kindex set history filename
4644b6e3 19471@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
19472@item set history filename @var{fname}
19473Set the name of the @value{GDBN} command history file to @var{fname}.
19474This is the file where @value{GDBN} reads an initial command history
19475list, and where it writes the command history from this session when it
19476exits. You can access this list through history expansion or through
19477the history command editing characters listed below. This file defaults
19478to the value of the environment variable @code{GDBHISTFILE}, or to
19479@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
19480is not set.
104c1213 19481
9c16f35a
EZ
19482@cindex save command history
19483@kindex set history save
8e04817f
AC
19484@item set history save
19485@itemx set history save on
19486Record command history in a file, whose name may be specified with the
19487@code{set history filename} command. By default, this option is disabled.
104c1213 19488
8e04817f
AC
19489@item set history save off
19490Stop recording command history in a file.
104c1213 19491
8e04817f 19492@cindex history size
9c16f35a 19493@kindex set history size
6fc08d32 19494@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
19495@item set history size @var{size}
19496Set the number of commands which @value{GDBN} keeps in its history list.
19497This defaults to the value of the environment variable
19498@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
19499@end table
19500
8e04817f 19501History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
19502@ifset SYSTEM_READLINE
19503@xref{Event Designators, , , history, GNU History Library},
19504@end ifset
19505@ifclear SYSTEM_READLINE
19506@xref{Event Designators},
19507@end ifclear
19508for more details.
8e04817f 19509
703663ab 19510@cindex history expansion, turn on/off
8e04817f
AC
19511Since @kbd{!} is also the logical not operator in C, history expansion
19512is off by default. If you decide to enable history expansion with the
19513@code{set history expansion on} command, you may sometimes need to
19514follow @kbd{!} (when it is used as logical not, in an expression) with
19515a space or a tab to prevent it from being expanded. The readline
19516history facilities do not attempt substitution on the strings
19517@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
19518
19519The commands to control history expansion are:
104c1213
JM
19520
19521@table @code
8e04817f
AC
19522@item set history expansion on
19523@itemx set history expansion
703663ab 19524@kindex set history expansion
8e04817f 19525Enable history expansion. History expansion is off by default.
104c1213 19526
8e04817f
AC
19527@item set history expansion off
19528Disable history expansion.
104c1213 19529
8e04817f
AC
19530@c @group
19531@kindex show history
19532@item show history
19533@itemx show history filename
19534@itemx show history save
19535@itemx show history size
19536@itemx show history expansion
19537These commands display the state of the @value{GDBN} history parameters.
19538@code{show history} by itself displays all four states.
19539@c @end group
19540@end table
19541
19542@table @code
9c16f35a
EZ
19543@kindex show commands
19544@cindex show last commands
19545@cindex display command history
8e04817f
AC
19546@item show commands
19547Display the last ten commands in the command history.
104c1213 19548
8e04817f
AC
19549@item show commands @var{n}
19550Print ten commands centered on command number @var{n}.
19551
19552@item show commands +
19553Print ten commands just after the commands last printed.
104c1213
JM
19554@end table
19555
8e04817f 19556@node Screen Size
79a6e687 19557@section Screen Size
8e04817f
AC
19558@cindex size of screen
19559@cindex pauses in output
104c1213 19560
8e04817f
AC
19561Certain commands to @value{GDBN} may produce large amounts of
19562information output to the screen. To help you read all of it,
19563@value{GDBN} pauses and asks you for input at the end of each page of
19564output. Type @key{RET} when you want to continue the output, or @kbd{q}
19565to discard the remaining output. Also, the screen width setting
19566determines when to wrap lines of output. Depending on what is being
19567printed, @value{GDBN} tries to break the line at a readable place,
19568rather than simply letting it overflow onto the following line.
19569
19570Normally @value{GDBN} knows the size of the screen from the terminal
19571driver software. For example, on Unix @value{GDBN} uses the termcap data base
19572together with the value of the @code{TERM} environment variable and the
19573@code{stty rows} and @code{stty cols} settings. If this is not correct,
19574you can override it with the @code{set height} and @code{set
19575width} commands:
19576
19577@table @code
19578@kindex set height
19579@kindex set width
19580@kindex show width
19581@kindex show height
19582@item set height @var{lpp}
19583@itemx show height
19584@itemx set width @var{cpl}
19585@itemx show width
19586These @code{set} commands specify a screen height of @var{lpp} lines and
19587a screen width of @var{cpl} characters. The associated @code{show}
19588commands display the current settings.
104c1213 19589
8e04817f
AC
19590If you specify a height of zero lines, @value{GDBN} does not pause during
19591output no matter how long the output is. This is useful if output is to a
19592file or to an editor buffer.
104c1213 19593
8e04817f
AC
19594Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
19595from wrapping its output.
9c16f35a
EZ
19596
19597@item set pagination on
19598@itemx set pagination off
19599@kindex set pagination
19600Turn the output pagination on or off; the default is on. Turning
7c953934
TT
19601pagination off is the alternative to @code{set height 0}. Note that
19602running @value{GDBN} with the @option{--batch} option (@pxref{Mode
19603Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
19604
19605@item show pagination
19606@kindex show pagination
19607Show the current pagination mode.
104c1213
JM
19608@end table
19609
8e04817f
AC
19610@node Numbers
19611@section Numbers
19612@cindex number representation
19613@cindex entering numbers
104c1213 19614
8e04817f
AC
19615You can always enter numbers in octal, decimal, or hexadecimal in
19616@value{GDBN} by the usual conventions: octal numbers begin with
19617@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
19618begin with @samp{0x}. Numbers that neither begin with @samp{0} or
19619@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1962010; likewise, the default display for numbers---when no particular
19621format is specified---is base 10. You can change the default base for
19622both input and output with the commands described below.
104c1213 19623
8e04817f
AC
19624@table @code
19625@kindex set input-radix
19626@item set input-radix @var{base}
19627Set the default base for numeric input. Supported choices
19628for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 19629specified either unambiguously or using the current input radix; for
8e04817f 19630example, any of
104c1213 19631
8e04817f 19632@smallexample
9c16f35a
EZ
19633set input-radix 012
19634set input-radix 10.
19635set input-radix 0xa
8e04817f 19636@end smallexample
104c1213 19637
8e04817f 19638@noindent
9c16f35a 19639sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
19640leaves the input radix unchanged, no matter what it was, since
19641@samp{10}, being without any leading or trailing signs of its base, is
19642interpreted in the current radix. Thus, if the current radix is 16,
19643@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
19644change the radix.
104c1213 19645
8e04817f
AC
19646@kindex set output-radix
19647@item set output-radix @var{base}
19648Set the default base for numeric display. Supported choices
19649for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 19650specified either unambiguously or using the current input radix.
104c1213 19651
8e04817f
AC
19652@kindex show input-radix
19653@item show input-radix
19654Display the current default base for numeric input.
104c1213 19655
8e04817f
AC
19656@kindex show output-radix
19657@item show output-radix
19658Display the current default base for numeric display.
9c16f35a
EZ
19659
19660@item set radix @r{[}@var{base}@r{]}
19661@itemx show radix
19662@kindex set radix
19663@kindex show radix
19664These commands set and show the default base for both input and output
19665of numbers. @code{set radix} sets the radix of input and output to
19666the same base; without an argument, it resets the radix back to its
19667default value of 10.
19668
8e04817f 19669@end table
104c1213 19670
1e698235 19671@node ABI
79a6e687 19672@section Configuring the Current ABI
1e698235
DJ
19673
19674@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
19675application automatically. However, sometimes you need to override its
19676conclusions. Use these commands to manage @value{GDBN}'s view of the
19677current ABI.
19678
98b45e30
DJ
19679@cindex OS ABI
19680@kindex set osabi
b4e9345d 19681@kindex show osabi
98b45e30
DJ
19682
19683One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 19684system targets, either via remote debugging or native emulation.
98b45e30
DJ
19685@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
19686but you can override its conclusion using the @code{set osabi} command.
19687One example where this is useful is in debugging of binaries which use
19688an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
19689not have the same identifying marks that the standard C library for your
19690platform provides.
19691
19692@table @code
19693@item show osabi
19694Show the OS ABI currently in use.
19695
19696@item set osabi
19697With no argument, show the list of registered available OS ABI's.
19698
19699@item set osabi @var{abi}
19700Set the current OS ABI to @var{abi}.
19701@end table
19702
1e698235 19703@cindex float promotion
1e698235
DJ
19704
19705Generally, the way that an argument of type @code{float} is passed to a
19706function depends on whether the function is prototyped. For a prototyped
19707(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
19708according to the architecture's convention for @code{float}. For unprototyped
19709(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
19710@code{double} and then passed.
19711
19712Unfortunately, some forms of debug information do not reliably indicate whether
19713a function is prototyped. If @value{GDBN} calls a function that is not marked
19714as prototyped, it consults @kbd{set coerce-float-to-double}.
19715
19716@table @code
a8f24a35 19717@kindex set coerce-float-to-double
1e698235
DJ
19718@item set coerce-float-to-double
19719@itemx set coerce-float-to-double on
19720Arguments of type @code{float} will be promoted to @code{double} when passed
19721to an unprototyped function. This is the default setting.
19722
19723@item set coerce-float-to-double off
19724Arguments of type @code{float} will be passed directly to unprototyped
19725functions.
9c16f35a
EZ
19726
19727@kindex show coerce-float-to-double
19728@item show coerce-float-to-double
19729Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
19730@end table
19731
f1212245
DJ
19732@kindex set cp-abi
19733@kindex show cp-abi
19734@value{GDBN} needs to know the ABI used for your program's C@t{++}
19735objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
19736used to build your application. @value{GDBN} only fully supports
19737programs with a single C@t{++} ABI; if your program contains code using
19738multiple C@t{++} ABI's or if @value{GDBN} can not identify your
19739program's ABI correctly, you can tell @value{GDBN} which ABI to use.
19740Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
19741before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
19742``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
19743use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
19744``auto''.
19745
19746@table @code
19747@item show cp-abi
19748Show the C@t{++} ABI currently in use.
19749
19750@item set cp-abi
19751With no argument, show the list of supported C@t{++} ABI's.
19752
19753@item set cp-abi @var{abi}
19754@itemx set cp-abi auto
19755Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
19756@end table
19757
8e04817f 19758@node Messages/Warnings
79a6e687 19759@section Optional Warnings and Messages
104c1213 19760
9c16f35a
EZ
19761@cindex verbose operation
19762@cindex optional warnings
8e04817f
AC
19763By default, @value{GDBN} is silent about its inner workings. If you are
19764running on a slow machine, you may want to use the @code{set verbose}
19765command. This makes @value{GDBN} tell you when it does a lengthy
19766internal operation, so you will not think it has crashed.
104c1213 19767
8e04817f
AC
19768Currently, the messages controlled by @code{set verbose} are those
19769which announce that the symbol table for a source file is being read;
79a6e687 19770see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 19771
8e04817f
AC
19772@table @code
19773@kindex set verbose
19774@item set verbose on
19775Enables @value{GDBN} output of certain informational messages.
104c1213 19776
8e04817f
AC
19777@item set verbose off
19778Disables @value{GDBN} output of certain informational messages.
104c1213 19779
8e04817f
AC
19780@kindex show verbose
19781@item show verbose
19782Displays whether @code{set verbose} is on or off.
19783@end table
104c1213 19784
8e04817f
AC
19785By default, if @value{GDBN} encounters bugs in the symbol table of an
19786object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
19787find this information useful (@pxref{Symbol Errors, ,Errors Reading
19788Symbol Files}).
104c1213 19789
8e04817f 19790@table @code
104c1213 19791
8e04817f
AC
19792@kindex set complaints
19793@item set complaints @var{limit}
19794Permits @value{GDBN} to output @var{limit} complaints about each type of
19795unusual symbols before becoming silent about the problem. Set
19796@var{limit} to zero to suppress all complaints; set it to a large number
19797to prevent complaints from being suppressed.
104c1213 19798
8e04817f
AC
19799@kindex show complaints
19800@item show complaints
19801Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 19802
8e04817f 19803@end table
104c1213 19804
d837706a 19805@anchor{confirmation requests}
8e04817f
AC
19806By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
19807lot of stupid questions to confirm certain commands. For example, if
19808you try to run a program which is already running:
104c1213 19809
474c8240 19810@smallexample
8e04817f
AC
19811(@value{GDBP}) run
19812The program being debugged has been started already.
19813Start it from the beginning? (y or n)
474c8240 19814@end smallexample
104c1213 19815
8e04817f
AC
19816If you are willing to unflinchingly face the consequences of your own
19817commands, you can disable this ``feature'':
104c1213 19818
8e04817f 19819@table @code
104c1213 19820
8e04817f
AC
19821@kindex set confirm
19822@cindex flinching
19823@cindex confirmation
19824@cindex stupid questions
19825@item set confirm off
7c953934
TT
19826Disables confirmation requests. Note that running @value{GDBN} with
19827the @option{--batch} option (@pxref{Mode Options, -batch}) also
19828automatically disables confirmation requests.
104c1213 19829
8e04817f
AC
19830@item set confirm on
19831Enables confirmation requests (the default).
104c1213 19832
8e04817f
AC
19833@kindex show confirm
19834@item show confirm
19835Displays state of confirmation requests.
19836
19837@end table
104c1213 19838
16026cd7
AS
19839@cindex command tracing
19840If you need to debug user-defined commands or sourced files you may find it
19841useful to enable @dfn{command tracing}. In this mode each command will be
19842printed as it is executed, prefixed with one or more @samp{+} symbols, the
19843quantity denoting the call depth of each command.
19844
19845@table @code
19846@kindex set trace-commands
19847@cindex command scripts, debugging
19848@item set trace-commands on
19849Enable command tracing.
19850@item set trace-commands off
19851Disable command tracing.
19852@item show trace-commands
19853Display the current state of command tracing.
19854@end table
19855
8e04817f 19856@node Debugging Output
79a6e687 19857@section Optional Messages about Internal Happenings
4644b6e3
EZ
19858@cindex optional debugging messages
19859
da316a69
EZ
19860@value{GDBN} has commands that enable optional debugging messages from
19861various @value{GDBN} subsystems; normally these commands are of
19862interest to @value{GDBN} maintainers, or when reporting a bug. This
19863section documents those commands.
19864
104c1213 19865@table @code
a8f24a35
EZ
19866@kindex set exec-done-display
19867@item set exec-done-display
19868Turns on or off the notification of asynchronous commands'
19869completion. When on, @value{GDBN} will print a message when an
19870asynchronous command finishes its execution. The default is off.
19871@kindex show exec-done-display
19872@item show exec-done-display
19873Displays the current setting of asynchronous command completion
19874notification.
4644b6e3
EZ
19875@kindex set debug
19876@cindex gdbarch debugging info
a8f24a35 19877@cindex architecture debugging info
8e04817f 19878@item set debug arch
a8f24a35 19879Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 19880@kindex show debug
8e04817f
AC
19881@item show debug arch
19882Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
19883@item set debug aix-thread
19884@cindex AIX threads
19885Display debugging messages about inner workings of the AIX thread
19886module.
19887@item show debug aix-thread
19888Show the current state of AIX thread debugging info display.
d97bc12b
DE
19889@item set debug dwarf2-die
19890@cindex DWARF2 DIEs
19891Dump DWARF2 DIEs after they are read in.
19892The value is the number of nesting levels to print.
19893A value of zero turns off the display.
19894@item show debug dwarf2-die
19895Show the current state of DWARF2 DIE debugging.
237fc4c9
PA
19896@item set debug displaced
19897@cindex displaced stepping debugging info
19898Turns on or off display of @value{GDBN} debugging info for the
19899displaced stepping support. The default is off.
19900@item show debug displaced
19901Displays the current state of displaying @value{GDBN} debugging info
19902related to displaced stepping.
8e04817f 19903@item set debug event
4644b6e3 19904@cindex event debugging info
a8f24a35 19905Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 19906default is off.
8e04817f
AC
19907@item show debug event
19908Displays the current state of displaying @value{GDBN} event debugging
19909info.
8e04817f 19910@item set debug expression
4644b6e3 19911@cindex expression debugging info
721c2651
EZ
19912Turns on or off display of debugging info about @value{GDBN}
19913expression parsing. The default is off.
8e04817f 19914@item show debug expression
721c2651
EZ
19915Displays the current state of displaying debugging info about
19916@value{GDBN} expression parsing.
7453dc06 19917@item set debug frame
4644b6e3 19918@cindex frame debugging info
7453dc06
AC
19919Turns on or off display of @value{GDBN} frame debugging info. The
19920default is off.
7453dc06
AC
19921@item show debug frame
19922Displays the current state of displaying @value{GDBN} frame debugging
19923info.
cbe54154
PA
19924@item set debug gnu-nat
19925@cindex @sc{gnu}/Hurd debug messages
19926Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
19927@item show debug gnu-nat
19928Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
19929@item set debug infrun
19930@cindex inferior debugging info
19931Turns on or off display of @value{GDBN} debugging info for running the inferior.
19932The default is off. @file{infrun.c} contains GDB's runtime state machine used
19933for implementing operations such as single-stepping the inferior.
19934@item show debug infrun
19935Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
19936@item set debug lin-lwp
19937@cindex @sc{gnu}/Linux LWP debug messages
19938@cindex Linux lightweight processes
721c2651 19939Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
19940@item show debug lin-lwp
19941Show the current state of Linux LWP debugging messages.
b84876c2
PA
19942@item set debug lin-lwp-async
19943@cindex @sc{gnu}/Linux LWP async debug messages
19944@cindex Linux lightweight processes
19945Turns on or off debugging messages from the Linux LWP async debug support.
19946@item show debug lin-lwp-async
19947Show the current state of Linux LWP async debugging messages.
2b4855ab 19948@item set debug observer
4644b6e3 19949@cindex observer debugging info
2b4855ab
AC
19950Turns on or off display of @value{GDBN} observer debugging. This
19951includes info such as the notification of observable events.
2b4855ab
AC
19952@item show debug observer
19953Displays the current state of observer debugging.
8e04817f 19954@item set debug overload
4644b6e3 19955@cindex C@t{++} overload debugging info
8e04817f 19956Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 19957info. This includes info such as ranking of functions, etc. The default
8e04817f 19958is off.
8e04817f
AC
19959@item show debug overload
19960Displays the current state of displaying @value{GDBN} C@t{++} overload
19961debugging info.
92981e24
TT
19962@cindex expression parser, debugging info
19963@cindex debug expression parser
19964@item set debug parser
19965Turns on or off the display of expression parser debugging output.
19966Internally, this sets the @code{yydebug} variable in the expression
19967parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
19968details. The default is off.
19969@item show debug parser
19970Show the current state of expression parser debugging.
8e04817f
AC
19971@cindex packets, reporting on stdout
19972@cindex serial connections, debugging
605a56cb
DJ
19973@cindex debug remote protocol
19974@cindex remote protocol debugging
19975@cindex display remote packets
8e04817f
AC
19976@item set debug remote
19977Turns on or off display of reports on all packets sent back and forth across
19978the serial line to the remote machine. The info is printed on the
19979@value{GDBN} standard output stream. The default is off.
8e04817f
AC
19980@item show debug remote
19981Displays the state of display of remote packets.
8e04817f
AC
19982@item set debug serial
19983Turns on or off display of @value{GDBN} serial debugging info. The
19984default is off.
8e04817f
AC
19985@item show debug serial
19986Displays the current state of displaying @value{GDBN} serial debugging
19987info.
c45da7e6
EZ
19988@item set debug solib-frv
19989@cindex FR-V shared-library debugging
19990Turns on or off debugging messages for FR-V shared-library code.
19991@item show debug solib-frv
19992Display the current state of FR-V shared-library code debugging
19993messages.
8e04817f 19994@item set debug target
4644b6e3 19995@cindex target debugging info
8e04817f
AC
19996Turns on or off display of @value{GDBN} target debugging info. This info
19997includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
19998default is 0. Set it to 1 to track events, and to 2 to also track the
19999value of large memory transfers. Changes to this flag do not take effect
20000until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
20001@item show debug target
20002Displays the current state of displaying @value{GDBN} target debugging
20003info.
75feb17d
DJ
20004@item set debug timestamp
20005@cindex timestampping debugging info
20006Turns on or off display of timestamps with @value{GDBN} debugging info.
20007When enabled, seconds and microseconds are displayed before each debugging
20008message.
20009@item show debug timestamp
20010Displays the current state of displaying timestamps with @value{GDBN}
20011debugging info.
c45da7e6 20012@item set debugvarobj
4644b6e3 20013@cindex variable object debugging info
8e04817f
AC
20014Turns on or off display of @value{GDBN} variable object debugging
20015info. The default is off.
c45da7e6 20016@item show debugvarobj
8e04817f
AC
20017Displays the current state of displaying @value{GDBN} variable object
20018debugging info.
e776119f
DJ
20019@item set debug xml
20020@cindex XML parser debugging
20021Turns on or off debugging messages for built-in XML parsers.
20022@item show debug xml
20023Displays the current state of XML debugging messages.
8e04817f 20024@end table
104c1213 20025
14fb1bac
JB
20026@node Other Misc Settings
20027@section Other Miscellaneous Settings
20028@cindex miscellaneous settings
20029
20030@table @code
20031@kindex set interactive-mode
20032@item set interactive-mode
20033If @code{on}, forces @value{GDBN} to operate interactively.
20034If @code{off}, forces @value{GDBN} to operate non-interactively,
20035If @code{auto} (the default), @value{GDBN} guesses which mode to use,
20036based on whether the debugger was started in a terminal or not.
20037
20038In the vast majority of cases, the debugger should be able to guess
20039correctly which mode should be used. But this setting can be useful
20040in certain specific cases, such as running a MinGW @value{GDBN}
20041inside a cygwin window.
20042
20043@kindex show interactive-mode
20044@item show interactive-mode
20045Displays whether the debugger is operating in interactive mode or not.
20046@end table
20047
d57a3c85
TJB
20048@node Extending GDB
20049@chapter Extending @value{GDBN}
20050@cindex extending GDB
20051
20052@value{GDBN} provides two mechanisms for extension. The first is based
20053on composition of @value{GDBN} commands, and the second is based on the
20054Python scripting language.
20055
95433b34
JB
20056To facilitate the use of these extensions, @value{GDBN} is capable
20057of evaluating the contents of a file. When doing so, @value{GDBN}
20058can recognize which scripting language is being used by looking at
20059the filename extension. Files with an unrecognized filename extension
20060are always treated as a @value{GDBN} Command Files.
20061@xref{Command Files,, Command files}.
20062
20063You can control how @value{GDBN} evaluates these files with the following
20064setting:
20065
20066@table @code
20067@kindex set script-extension
20068@kindex show script-extension
20069@item set script-extension off
20070All scripts are always evaluated as @value{GDBN} Command Files.
20071
20072@item set script-extension soft
20073The debugger determines the scripting language based on filename
20074extension. If this scripting language is supported, @value{GDBN}
20075evaluates the script using that language. Otherwise, it evaluates
20076the file as a @value{GDBN} Command File.
20077
20078@item set script-extension strict
20079The debugger determines the scripting language based on filename
20080extension, and evaluates the script using that language. If the
20081language is not supported, then the evaluation fails.
20082
20083@item show script-extension
20084Display the current value of the @code{script-extension} option.
20085
20086@end table
20087
d57a3c85
TJB
20088@menu
20089* Sequences:: Canned Sequences of Commands
20090* Python:: Scripting @value{GDBN} using Python
20091@end menu
20092
8e04817f 20093@node Sequences
d57a3c85 20094@section Canned Sequences of Commands
104c1213 20095
8e04817f 20096Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 20097Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
20098commands for execution as a unit: user-defined commands and command
20099files.
104c1213 20100
8e04817f 20101@menu
fcc73fe3
EZ
20102* Define:: How to define your own commands
20103* Hooks:: Hooks for user-defined commands
20104* Command Files:: How to write scripts of commands to be stored in a file
20105* Output:: Commands for controlled output
8e04817f 20106@end menu
104c1213 20107
8e04817f 20108@node Define
d57a3c85 20109@subsection User-defined Commands
104c1213 20110
8e04817f 20111@cindex user-defined command
fcc73fe3 20112@cindex arguments, to user-defined commands
8e04817f
AC
20113A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
20114which you assign a new name as a command. This is done with the
20115@code{define} command. User commands may accept up to 10 arguments
20116separated by whitespace. Arguments are accessed within the user command
c03c782f 20117via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 20118
8e04817f
AC
20119@smallexample
20120define adder
20121 print $arg0 + $arg1 + $arg2
c03c782f 20122end
8e04817f 20123@end smallexample
104c1213
JM
20124
20125@noindent
8e04817f 20126To execute the command use:
104c1213 20127
8e04817f
AC
20128@smallexample
20129adder 1 2 3
20130@end smallexample
104c1213 20131
8e04817f
AC
20132@noindent
20133This defines the command @code{adder}, which prints the sum of
20134its three arguments. Note the arguments are text substitutions, so they may
20135reference variables, use complex expressions, or even perform inferior
20136functions calls.
104c1213 20137
fcc73fe3
EZ
20138@cindex argument count in user-defined commands
20139@cindex how many arguments (user-defined commands)
c03c782f
AS
20140In addition, @code{$argc} may be used to find out how many arguments have
20141been passed. This expands to a number in the range 0@dots{}10.
20142
20143@smallexample
20144define adder
20145 if $argc == 2
20146 print $arg0 + $arg1
20147 end
20148 if $argc == 3
20149 print $arg0 + $arg1 + $arg2
20150 end
20151end
20152@end smallexample
20153
104c1213 20154@table @code
104c1213 20155
8e04817f
AC
20156@kindex define
20157@item define @var{commandname}
20158Define a command named @var{commandname}. If there is already a command
20159by that name, you are asked to confirm that you want to redefine it.
adb483fe
DJ
20160@var{commandname} may be a bare command name consisting of letters,
20161numbers, dashes, and underscores. It may also start with any predefined
20162prefix command. For example, @samp{define target my-target} creates
20163a user-defined @samp{target my-target} command.
104c1213 20164
8e04817f
AC
20165The definition of the command is made up of other @value{GDBN} command lines,
20166which are given following the @code{define} command. The end of these
20167commands is marked by a line containing @code{end}.
104c1213 20168
8e04817f 20169@kindex document
ca91424e 20170@kindex end@r{ (user-defined commands)}
8e04817f
AC
20171@item document @var{commandname}
20172Document the user-defined command @var{commandname}, so that it can be
20173accessed by @code{help}. The command @var{commandname} must already be
20174defined. This command reads lines of documentation just as @code{define}
20175reads the lines of the command definition, ending with @code{end}.
20176After the @code{document} command is finished, @code{help} on command
20177@var{commandname} displays the documentation you have written.
104c1213 20178
8e04817f
AC
20179You may use the @code{document} command again to change the
20180documentation of a command. Redefining the command with @code{define}
20181does not change the documentation.
104c1213 20182
c45da7e6
EZ
20183@kindex dont-repeat
20184@cindex don't repeat command
20185@item dont-repeat
20186Used inside a user-defined command, this tells @value{GDBN} that this
20187command should not be repeated when the user hits @key{RET}
20188(@pxref{Command Syntax, repeat last command}).
20189
8e04817f
AC
20190@kindex help user-defined
20191@item help user-defined
20192List all user-defined commands, with the first line of the documentation
20193(if any) for each.
104c1213 20194
8e04817f
AC
20195@kindex show user
20196@item show user
20197@itemx show user @var{commandname}
20198Display the @value{GDBN} commands used to define @var{commandname} (but
20199not its documentation). If no @var{commandname} is given, display the
20200definitions for all user-defined commands.
104c1213 20201
fcc73fe3 20202@cindex infinite recursion in user-defined commands
20f01a46
DH
20203@kindex show max-user-call-depth
20204@kindex set max-user-call-depth
20205@item show max-user-call-depth
5ca0cb28
DH
20206@itemx set max-user-call-depth
20207The value of @code{max-user-call-depth} controls how many recursion
3f94c067 20208levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 20209infinite recursion and aborts the command.
104c1213
JM
20210@end table
20211
fcc73fe3
EZ
20212In addition to the above commands, user-defined commands frequently
20213use control flow commands, described in @ref{Command Files}.
20214
8e04817f
AC
20215When user-defined commands are executed, the
20216commands of the definition are not printed. An error in any command
20217stops execution of the user-defined command.
104c1213 20218
8e04817f
AC
20219If used interactively, commands that would ask for confirmation proceed
20220without asking when used inside a user-defined command. Many @value{GDBN}
20221commands that normally print messages to say what they are doing omit the
20222messages when used in a user-defined command.
104c1213 20223
8e04817f 20224@node Hooks
d57a3c85 20225@subsection User-defined Command Hooks
8e04817f
AC
20226@cindex command hooks
20227@cindex hooks, for commands
20228@cindex hooks, pre-command
104c1213 20229
8e04817f 20230@kindex hook
8e04817f
AC
20231You may define @dfn{hooks}, which are a special kind of user-defined
20232command. Whenever you run the command @samp{foo}, if the user-defined
20233command @samp{hook-foo} exists, it is executed (with no arguments)
20234before that command.
104c1213 20235
8e04817f
AC
20236@cindex hooks, post-command
20237@kindex hookpost
8e04817f
AC
20238A hook may also be defined which is run after the command you executed.
20239Whenever you run the command @samp{foo}, if the user-defined command
20240@samp{hookpost-foo} exists, it is executed (with no arguments) after
20241that command. Post-execution hooks may exist simultaneously with
20242pre-execution hooks, for the same command.
104c1213 20243
8e04817f 20244It is valid for a hook to call the command which it hooks. If this
9f1c6395 20245occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 20246
8e04817f
AC
20247@c It would be nice if hookpost could be passed a parameter indicating
20248@c if the command it hooks executed properly or not. FIXME!
104c1213 20249
8e04817f
AC
20250@kindex stop@r{, a pseudo-command}
20251In addition, a pseudo-command, @samp{stop} exists. Defining
20252(@samp{hook-stop}) makes the associated commands execute every time
20253execution stops in your program: before breakpoint commands are run,
20254displays are printed, or the stack frame is printed.
104c1213 20255
8e04817f
AC
20256For example, to ignore @code{SIGALRM} signals while
20257single-stepping, but treat them normally during normal execution,
20258you could define:
104c1213 20259
474c8240 20260@smallexample
8e04817f
AC
20261define hook-stop
20262handle SIGALRM nopass
20263end
104c1213 20264
8e04817f
AC
20265define hook-run
20266handle SIGALRM pass
20267end
104c1213 20268
8e04817f 20269define hook-continue
d3e8051b 20270handle SIGALRM pass
8e04817f 20271end
474c8240 20272@end smallexample
104c1213 20273
d3e8051b 20274As a further example, to hook at the beginning and end of the @code{echo}
b383017d 20275command, and to add extra text to the beginning and end of the message,
8e04817f 20276you could define:
104c1213 20277
474c8240 20278@smallexample
8e04817f
AC
20279define hook-echo
20280echo <<<---
20281end
104c1213 20282
8e04817f
AC
20283define hookpost-echo
20284echo --->>>\n
20285end
104c1213 20286
8e04817f
AC
20287(@value{GDBP}) echo Hello World
20288<<<---Hello World--->>>
20289(@value{GDBP})
104c1213 20290
474c8240 20291@end smallexample
104c1213 20292
8e04817f
AC
20293You can define a hook for any single-word command in @value{GDBN}, but
20294not for command aliases; you should define a hook for the basic command
c1468174 20295name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
20296@c FIXME! So how does Joe User discover whether a command is an alias
20297@c or not?
adb483fe
DJ
20298You can hook a multi-word command by adding @code{hook-} or
20299@code{hookpost-} to the last word of the command, e.g.@:
20300@samp{define target hook-remote} to add a hook to @samp{target remote}.
20301
8e04817f
AC
20302If an error occurs during the execution of your hook, execution of
20303@value{GDBN} commands stops and @value{GDBN} issues a prompt
20304(before the command that you actually typed had a chance to run).
104c1213 20305
8e04817f
AC
20306If you try to define a hook which does not match any known command, you
20307get a warning from the @code{define} command.
c906108c 20308
8e04817f 20309@node Command Files
d57a3c85 20310@subsection Command Files
c906108c 20311
8e04817f 20312@cindex command files
fcc73fe3 20313@cindex scripting commands
6fc08d32
EZ
20314A command file for @value{GDBN} is a text file made of lines that are
20315@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
20316also be included. An empty line in a command file does nothing; it
20317does not mean to repeat the last command, as it would from the
20318terminal.
c906108c 20319
6fc08d32 20320You can request the execution of a command file with the @code{source}
95433b34
JB
20321command. Note that the @code{source} command is also used to evaluate
20322scripts that are not Command Files. The exact behavior can be configured
20323using the @code{script-extension} setting.
20324@xref{Extending GDB,, Extending GDB}.
c906108c 20325
8e04817f
AC
20326@table @code
20327@kindex source
ca91424e 20328@cindex execute commands from a file
3f7b2faa 20329@item source [-s] [-v] @var{filename}
8e04817f 20330Execute the command file @var{filename}.
c906108c
SS
20331@end table
20332
fcc73fe3
EZ
20333The lines in a command file are generally executed sequentially,
20334unless the order of execution is changed by one of the
20335@emph{flow-control commands} described below. The commands are not
a71ec265
DH
20336printed as they are executed. An error in any command terminates
20337execution of the command file and control is returned to the console.
c906108c 20338
08001717
DE
20339@value{GDBN} first searches for @var{filename} in the current directory.
20340If the file is not found there, and @var{filename} does not specify a
20341directory, then @value{GDBN} also looks for the file on the source search path
20342(specified with the @samp{directory} command);
20343except that @file{$cdir} is not searched because the compilation directory
20344is not relevant to scripts.
4b505b12 20345
3f7b2faa
DE
20346If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
20347on the search path even if @var{filename} specifies a directory.
20348The search is done by appending @var{filename} to each element of the
20349search path. So, for example, if @var{filename} is @file{mylib/myscript}
20350and the search path contains @file{/home/user} then @value{GDBN} will
20351look for the script @file{/home/user/mylib/myscript}.
20352The search is also done if @var{filename} is an absolute path.
20353For example, if @var{filename} is @file{/tmp/myscript} and
20354the search path contains @file{/home/user} then @value{GDBN} will
20355look for the script @file{/home/user/tmp/myscript}.
20356For DOS-like systems, if @var{filename} contains a drive specification,
20357it is stripped before concatenation. For example, if @var{filename} is
20358@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
20359will look for the script @file{c:/tmp/myscript}.
20360
16026cd7
AS
20361If @code{-v}, for verbose mode, is given then @value{GDBN} displays
20362each command as it is executed. The option must be given before
20363@var{filename}, and is interpreted as part of the filename anywhere else.
20364
8e04817f
AC
20365Commands that would ask for confirmation if used interactively proceed
20366without asking when used in a command file. Many @value{GDBN} commands that
20367normally print messages to say what they are doing omit the messages
20368when called from command files.
c906108c 20369
8e04817f
AC
20370@value{GDBN} also accepts command input from standard input. In this
20371mode, normal output goes to standard output and error output goes to
20372standard error. Errors in a command file supplied on standard input do
6fc08d32 20373not terminate execution of the command file---execution continues with
8e04817f 20374the next command.
c906108c 20375
474c8240 20376@smallexample
8e04817f 20377gdb < cmds > log 2>&1
474c8240 20378@end smallexample
c906108c 20379
8e04817f
AC
20380(The syntax above will vary depending on the shell used.) This example
20381will execute commands from the file @file{cmds}. All output and errors
20382would be directed to @file{log}.
c906108c 20383
fcc73fe3
EZ
20384Since commands stored on command files tend to be more general than
20385commands typed interactively, they frequently need to deal with
20386complicated situations, such as different or unexpected values of
20387variables and symbols, changes in how the program being debugged is
20388built, etc. @value{GDBN} provides a set of flow-control commands to
20389deal with these complexities. Using these commands, you can write
20390complex scripts that loop over data structures, execute commands
20391conditionally, etc.
20392
20393@table @code
20394@kindex if
20395@kindex else
20396@item if
20397@itemx else
20398This command allows to include in your script conditionally executed
20399commands. The @code{if} command takes a single argument, which is an
20400expression to evaluate. It is followed by a series of commands that
20401are executed only if the expression is true (its value is nonzero).
20402There can then optionally be an @code{else} line, followed by a series
20403of commands that are only executed if the expression was false. The
20404end of the list is marked by a line containing @code{end}.
20405
20406@kindex while
20407@item while
20408This command allows to write loops. Its syntax is similar to
20409@code{if}: the command takes a single argument, which is an expression
20410to evaluate, and must be followed by the commands to execute, one per
20411line, terminated by an @code{end}. These commands are called the
20412@dfn{body} of the loop. The commands in the body of @code{while} are
20413executed repeatedly as long as the expression evaluates to true.
20414
20415@kindex loop_break
20416@item loop_break
20417This command exits the @code{while} loop in whose body it is included.
20418Execution of the script continues after that @code{while}s @code{end}
20419line.
20420
20421@kindex loop_continue
20422@item loop_continue
20423This command skips the execution of the rest of the body of commands
20424in the @code{while} loop in whose body it is included. Execution
20425branches to the beginning of the @code{while} loop, where it evaluates
20426the controlling expression.
ca91424e
EZ
20427
20428@kindex end@r{ (if/else/while commands)}
20429@item end
20430Terminate the block of commands that are the body of @code{if},
20431@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
20432@end table
20433
20434
8e04817f 20435@node Output
d57a3c85 20436@subsection Commands for Controlled Output
c906108c 20437
8e04817f
AC
20438During the execution of a command file or a user-defined command, normal
20439@value{GDBN} output is suppressed; the only output that appears is what is
20440explicitly printed by the commands in the definition. This section
20441describes three commands useful for generating exactly the output you
20442want.
c906108c
SS
20443
20444@table @code
8e04817f
AC
20445@kindex echo
20446@item echo @var{text}
20447@c I do not consider backslash-space a standard C escape sequence
20448@c because it is not in ANSI.
20449Print @var{text}. Nonprinting characters can be included in
20450@var{text} using C escape sequences, such as @samp{\n} to print a
20451newline. @strong{No newline is printed unless you specify one.}
20452In addition to the standard C escape sequences, a backslash followed
20453by a space stands for a space. This is useful for displaying a
20454string with spaces at the beginning or the end, since leading and
20455trailing spaces are otherwise trimmed from all arguments.
20456To print @samp{@w{ }and foo =@w{ }}, use the command
20457@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 20458
8e04817f
AC
20459A backslash at the end of @var{text} can be used, as in C, to continue
20460the command onto subsequent lines. For example,
c906108c 20461
474c8240 20462@smallexample
8e04817f
AC
20463echo This is some text\n\
20464which is continued\n\
20465onto several lines.\n
474c8240 20466@end smallexample
c906108c 20467
8e04817f 20468produces the same output as
c906108c 20469
474c8240 20470@smallexample
8e04817f
AC
20471echo This is some text\n
20472echo which is continued\n
20473echo onto several lines.\n
474c8240 20474@end smallexample
c906108c 20475
8e04817f
AC
20476@kindex output
20477@item output @var{expression}
20478Print the value of @var{expression} and nothing but that value: no
20479newlines, no @samp{$@var{nn} = }. The value is not entered in the
20480value history either. @xref{Expressions, ,Expressions}, for more information
20481on expressions.
c906108c 20482
8e04817f
AC
20483@item output/@var{fmt} @var{expression}
20484Print the value of @var{expression} in format @var{fmt}. You can use
20485the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 20486Formats}, for more information.
c906108c 20487
8e04817f 20488@kindex printf
82160952
EZ
20489@item printf @var{template}, @var{expressions}@dots{}
20490Print the values of one or more @var{expressions} under the control of
20491the string @var{template}. To print several values, make
20492@var{expressions} be a comma-separated list of individual expressions,
20493which may be either numbers or pointers. Their values are printed as
20494specified by @var{template}, exactly as a C program would do by
20495executing the code below:
c906108c 20496
474c8240 20497@smallexample
82160952 20498printf (@var{template}, @var{expressions}@dots{});
474c8240 20499@end smallexample
c906108c 20500
82160952
EZ
20501As in @code{C} @code{printf}, ordinary characters in @var{template}
20502are printed verbatim, while @dfn{conversion specification} introduced
20503by the @samp{%} character cause subsequent @var{expressions} to be
20504evaluated, their values converted and formatted according to type and
20505style information encoded in the conversion specifications, and then
20506printed.
20507
8e04817f 20508For example, you can print two values in hex like this:
c906108c 20509
8e04817f
AC
20510@smallexample
20511printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
20512@end smallexample
c906108c 20513
82160952
EZ
20514@code{printf} supports all the standard @code{C} conversion
20515specifications, including the flags and modifiers between the @samp{%}
20516character and the conversion letter, with the following exceptions:
20517
20518@itemize @bullet
20519@item
20520The argument-ordering modifiers, such as @samp{2$}, are not supported.
20521
20522@item
20523The modifier @samp{*} is not supported for specifying precision or
20524width.
20525
20526@item
20527The @samp{'} flag (for separation of digits into groups according to
20528@code{LC_NUMERIC'}) is not supported.
20529
20530@item
20531The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
20532supported.
20533
20534@item
20535The conversion letter @samp{n} (as in @samp{%n}) is not supported.
20536
20537@item
20538The conversion letters @samp{a} and @samp{A} are not supported.
20539@end itemize
20540
20541@noindent
20542Note that the @samp{ll} type modifier is supported only if the
20543underlying @code{C} implementation used to build @value{GDBN} supports
20544the @code{long long int} type, and the @samp{L} type modifier is
20545supported only if @code{long double} type is available.
20546
20547As in @code{C}, @code{printf} supports simple backslash-escape
20548sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
20549@samp{\a}, and @samp{\f}, that consist of backslash followed by a
20550single character. Octal and hexadecimal escape sequences are not
20551supported.
1a619819
LM
20552
20553Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
20554(@dfn{Decimal Floating Point}) types using the following length modifiers
20555together with a floating point specifier.
1a619819
LM
20556letters:
20557
20558@itemize @bullet
20559@item
20560@samp{H} for printing @code{Decimal32} types.
20561
20562@item
20563@samp{D} for printing @code{Decimal64} types.
20564
20565@item
20566@samp{DD} for printing @code{Decimal128} types.
20567@end itemize
20568
20569If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 20570support for the three length modifiers for DFP types, other modifiers
3b784c4f 20571such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
20572
20573In case there is no such @code{C} support, no additional modifiers will be
20574available and the value will be printed in the standard way.
20575
20576Here's an example of printing DFP types using the above conversion letters:
20577@smallexample
0aea4bf3 20578printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
20579@end smallexample
20580
f1421989
HZ
20581@kindex eval
20582@item eval @var{template}, @var{expressions}@dots{}
20583Convert the values of one or more @var{expressions} under the control of
20584the string @var{template} to a command line, and call it.
20585
c906108c
SS
20586@end table
20587
d57a3c85
TJB
20588@node Python
20589@section Scripting @value{GDBN} using Python
20590@cindex python scripting
20591@cindex scripting with python
20592
20593You can script @value{GDBN} using the @uref{http://www.python.org/,
20594Python programming language}. This feature is available only if
20595@value{GDBN} was configured using @option{--with-python}.
20596
9279c692
JB
20597@cindex python directory
20598Python scripts used by @value{GDBN} should be installed in
20599@file{@var{data-directory}/python}, where @var{data-directory} is
9eeee977
DE
20600the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
20601This directory, known as the @dfn{python directory},
9279c692
JB
20602is automatically added to the Python Search Path in order to allow
20603the Python interpreter to locate all scripts installed at this location.
20604
d57a3c85
TJB
20605@menu
20606* Python Commands:: Accessing Python from @value{GDBN}.
20607* Python API:: Accessing @value{GDBN} from Python.
8a1ea21f 20608* Auto-loading:: Automatically loading Python code.
0e3509db 20609* Python modules:: Python modules provided by @value{GDBN}.
d57a3c85
TJB
20610@end menu
20611
20612@node Python Commands
20613@subsection Python Commands
20614@cindex python commands
20615@cindex commands to access python
20616
20617@value{GDBN} provides one command for accessing the Python interpreter,
20618and one related setting:
20619
20620@table @code
20621@kindex python
20622@item python @r{[}@var{code}@r{]}
20623The @code{python} command can be used to evaluate Python code.
20624
20625If given an argument, the @code{python} command will evaluate the
20626argument as a Python command. For example:
20627
20628@smallexample
20629(@value{GDBP}) python print 23
2063023
20631@end smallexample
20632
20633If you do not provide an argument to @code{python}, it will act as a
20634multi-line command, like @code{define}. In this case, the Python
20635script is made up of subsequent command lines, given after the
20636@code{python} command. This command list is terminated using a line
20637containing @code{end}. For example:
20638
20639@smallexample
20640(@value{GDBP}) python
20641Type python script
20642End with a line saying just "end".
20643>print 23
20644>end
2064523
20646@end smallexample
20647
20648@kindex maint set python print-stack
20649@item maint set python print-stack
20650By default, @value{GDBN} will print a stack trace when an error occurs
20651in a Python script. This can be controlled using @code{maint set
20652python print-stack}: if @code{on}, the default, then Python stack
20653printing is enabled; if @code{off}, then Python stack printing is
20654disabled.
20655@end table
20656
95433b34
JB
20657It is also possible to execute a Python script from the @value{GDBN}
20658interpreter:
20659
20660@table @code
20661@item source @file{script-name}
20662The script name must end with @samp{.py} and @value{GDBN} must be configured
20663to recognize the script language based on filename extension using
20664the @code{script-extension} setting. @xref{Extending GDB, ,Extending GDB}.
20665
20666@item python execfile ("script-name")
20667This method is based on the @code{execfile} Python built-in function,
20668and thus is always available.
20669@end table
20670
d57a3c85
TJB
20671@node Python API
20672@subsection Python API
20673@cindex python api
20674@cindex programming in python
20675
20676@cindex python stdout
20677@cindex python pagination
20678At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
20679@code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
20680A Python program which outputs to one of these streams may have its
20681output interrupted by the user (@pxref{Screen Size}). In this
20682situation, a Python @code{KeyboardInterrupt} exception is thrown.
20683
20684@menu
20685* Basic Python:: Basic Python Functions.
20686* Exception Handling::
a08702d6 20687* Values From Inferior::
4c374409
JK
20688* Types In Python:: Python representation of types.
20689* Pretty Printing API:: Pretty-printing values.
a6bac58e 20690* Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
7b51bc51 20691* Writing a Pretty-Printer:: Writing a Pretty-Printer.
595939de
PM
20692* Inferiors In Python:: Python representation of inferiors (processes)
20693* Threads In Python:: Accessing inferior threads from Python.
d8906c6f 20694* Commands In Python:: Implementing new commands in Python.
d7b32ed3 20695* Parameters In Python:: Adding new @value{GDBN} parameters.
bc3b79fd 20696* Functions In Python:: Writing new convenience functions.
fa33c3cd 20697* Progspaces In Python:: Program spaces.
89c73ade 20698* Objfiles In Python:: Object files.
f3e9a817
PM
20699* Frames In Python:: Accessing inferior stack frames from Python.
20700* Blocks In Python:: Accessing frame blocks from Python.
20701* Symbols In Python:: Python representation of symbols.
20702* Symbol Tables In Python:: Python representation of symbol tables.
be759fcf 20703* Lazy Strings In Python:: Python representation of lazy strings.
adc36818 20704* Breakpoints In Python:: Manipulating breakpoints using Python.
d57a3c85
TJB
20705@end menu
20706
20707@node Basic Python
20708@subsubsection Basic Python
20709
20710@cindex python functions
20711@cindex python module
20712@cindex gdb module
20713@value{GDBN} introduces a new Python module, named @code{gdb}. All
20714methods and classes added by @value{GDBN} are placed in this module.
20715@value{GDBN} automatically @code{import}s the @code{gdb} module for
20716use in all scripts evaluated by the @code{python} command.
20717
9279c692
JB
20718@findex gdb.PYTHONDIR
20719@defvar PYTHONDIR
20720A string containing the python directory (@pxref{Python}).
20721@end defvar
20722
d57a3c85 20723@findex gdb.execute
bc9f0842 20724@defun execute command [from_tty] [to_string]
d57a3c85
TJB
20725Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
20726If a GDB exception happens while @var{command} runs, it is
20727translated as described in @ref{Exception Handling,,Exception Handling}.
12453b93
TJB
20728
20729@var{from_tty} specifies whether @value{GDBN} ought to consider this
20730command as having originated from the user invoking it interactively.
20731It must be a boolean value. If omitted, it defaults to @code{False}.
bc9f0842
TT
20732
20733By default, any output produced by @var{command} is sent to
20734@value{GDBN}'s standard output. If the @var{to_string} parameter is
20735@code{True}, then output will be collected by @code{gdb.execute} and
20736returned as a string. The default is @code{False}, in which case the
5da1313b
JK
20737return value is @code{None}. If @var{to_string} is @code{True}, the
20738@value{GDBN} virtual terminal will be temporarily set to unlimited width
20739and height, and its pagination will be disabled; @pxref{Screen Size}.
d57a3c85
TJB
20740@end defun
20741
adc36818
PM
20742@findex gdb.breakpoints
20743@defun breakpoints
20744Return a sequence holding all of @value{GDBN}'s breakpoints.
20745@xref{Breakpoints In Python}, for more information.
20746@end defun
20747
8f500870
TT
20748@findex gdb.parameter
20749@defun parameter parameter
d57a3c85
TJB
20750Return the value of a @value{GDBN} parameter. @var{parameter} is a
20751string naming the parameter to look up; @var{parameter} may contain
20752spaces if the parameter has a multi-part name. For example,
20753@samp{print object} is a valid parameter name.
20754
20755If the named parameter does not exist, this function throws a
621c8364
TT
20756@code{gdb.error} (@pxref{Exception Handling}). Otherwise, the
20757parameter's value is converted to a Python value of the appropriate
20758type, and returned.
d57a3c85
TJB
20759@end defun
20760
08c637de
TJB
20761@findex gdb.history
20762@defun history number
20763Return a value from @value{GDBN}'s value history (@pxref{Value
20764History}). @var{number} indicates which history element to return.
20765If @var{number} is negative, then @value{GDBN} will take its absolute value
20766and count backward from the last element (i.e., the most recent element) to
20767find the value to return. If @var{number} is zero, then @value{GDBN} will
a0c36267 20768return the most recent element. If the element specified by @var{number}
621c8364 20769doesn't exist in the value history, a @code{gdb.error} exception will be
08c637de
TJB
20770raised.
20771
20772If no exception is raised, the return value is always an instance of
20773@code{gdb.Value} (@pxref{Values From Inferior}).
20774@end defun
20775
57a1d736
TT
20776@findex gdb.parse_and_eval
20777@defun parse_and_eval expression
20778Parse @var{expression} as an expression in the current language,
20779evaluate it, and return the result as a @code{gdb.Value}.
20780@var{expression} must be a string.
20781
20782This function can be useful when implementing a new command
20783(@pxref{Commands In Python}), as it provides a way to parse the
20784command's argument as an expression. It is also useful simply to
20785compute values, for example, it is the only way to get the value of a
20786convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
20787@end defun
20788
ca5c20b6
PM
20789@findex gdb.post_event
20790@defun post_event event
20791Put @var{event}, a callable object taking no arguments, into
20792@value{GDBN}'s internal event queue. This callable will be invoked at
20793some later point, during @value{GDBN}'s event processing. Events
20794posted using @code{post_event} will be run in the order in which they
20795were posted; however, there is no way to know when they will be
20796processed relative to other events inside @value{GDBN}.
20797
20798@value{GDBN} is not thread-safe. If your Python program uses multiple
20799threads, you must be careful to only call @value{GDBN}-specific
20800functions in the main @value{GDBN} thread. @code{post_event} ensures
20801this. For example:
20802
20803@smallexample
20804(@value{GDBP}) python
20805>import threading
20806>
20807>class Writer():
20808> def __init__(self, message):
20809> self.message = message;
20810> def __call__(self):
20811> gdb.write(self.message)
20812>
20813>class MyThread1 (threading.Thread):
20814> def run (self):
20815> gdb.post_event(Writer("Hello "))
20816>
20817>class MyThread2 (threading.Thread):
20818> def run (self):
20819> gdb.post_event(Writer("World\n"))
20820>
20821>MyThread1().start()
20822>MyThread2().start()
20823>end
20824(@value{GDBP}) Hello World
20825@end smallexample
20826@end defun
20827
d57a3c85
TJB
20828@findex gdb.write
20829@defun write string
20830Print a string to @value{GDBN}'s paginated standard output stream.
20831Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
20832call this function.
20833@end defun
20834
20835@findex gdb.flush
20836@defun flush
20837Flush @value{GDBN}'s paginated standard output stream. Flushing
20838@code{sys.stdout} or @code{sys.stderr} will automatically call this
20839function.
20840@end defun
20841
f870a310
TT
20842@findex gdb.target_charset
20843@defun target_charset
20844Return the name of the current target character set (@pxref{Character
20845Sets}). This differs from @code{gdb.parameter('target-charset')} in
20846that @samp{auto} is never returned.
20847@end defun
20848
20849@findex gdb.target_wide_charset
20850@defun target_wide_charset
20851Return the name of the current target wide character set
20852(@pxref{Character Sets}). This differs from
20853@code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
20854never returned.
20855@end defun
20856
cb2e07a6
PM
20857@findex gdb.solib_name
20858@defun solib_name address
20859Return the name of the shared library holding the given @var{address}
20860as a string, or @code{None}.
20861@end defun
20862
20863@findex gdb.decode_line
20864@defun decode_line @r{[}expression@r{]}
20865Return locations of the line specified by @var{expression}, or of the
20866current line if no argument was given. This function returns a Python
20867tuple containing two elements. The first element contains a string
20868holding any unparsed section of @var{expression} (or @code{None} if
20869the expression has been fully parsed). The second element contains
20870either @code{None} or another tuple that contains all the locations
20871that match the expression represented as @code{gdb.Symtab_and_line}
20872objects (@pxref{Symbol Tables In Python}). If @var{expression} is
20873provided, it is decoded the way that @value{GDBN}'s inbuilt
20874@code{break} or @code{edit} commands do (@pxref{Specify Location}).
20875@end defun
20876
d57a3c85
TJB
20877@node Exception Handling
20878@subsubsection Exception Handling
20879@cindex python exceptions
20880@cindex exceptions, python
20881
20882When executing the @code{python} command, Python exceptions
20883uncaught within the Python code are translated to calls to
20884@value{GDBN} error-reporting mechanism. If the command that called
20885@code{python} does not handle the error, @value{GDBN} will
20886terminate it and print an error message containing the Python
20887exception name, the associated value, and the Python call stack
20888backtrace at the point where the exception was raised. Example:
20889
20890@smallexample
20891(@value{GDBP}) python print foo
20892Traceback (most recent call last):
20893 File "<string>", line 1, in <module>
20894NameError: name 'foo' is not defined
20895@end smallexample
20896
621c8364
TT
20897@value{GDBN} errors that happen in @value{GDBN} commands invoked by
20898Python code are converted to Python exceptions. The type of the
20899Python exception depends on the error.
20900
20901@ftable @code
20902@item gdb.error
20903This is the base class for most exceptions generated by @value{GDBN}.
20904It is derived from @code{RuntimeError}, for compatibility with earlier
20905versions of @value{GDBN}.
20906
20907If an error occurring in @value{GDBN} does not fit into some more
20908specific category, then the generated exception will have this type.
20909
20910@item gdb.MemoryError
20911This is a subclass of @code{gdb.error} which is thrown when an
20912operation tried to access invalid memory in the inferior.
20913
20914@item KeyboardInterrupt
20915User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
20916prompt) is translated to a Python @code{KeyboardInterrupt} exception.
20917@end ftable
20918
20919In all cases, your exception handler will see the @value{GDBN} error
20920message as its value and the Python call stack backtrace at the Python
20921statement closest to where the @value{GDBN} error occured as the
d57a3c85
TJB
20922traceback.
20923
07ca107c
DE
20924@findex gdb.GdbError
20925When implementing @value{GDBN} commands in Python via @code{gdb.Command},
20926it is useful to be able to throw an exception that doesn't cause a
20927traceback to be printed. For example, the user may have invoked the
20928command incorrectly. Use the @code{gdb.GdbError} exception
20929to handle this case. Example:
20930
20931@smallexample
20932(gdb) python
20933>class HelloWorld (gdb.Command):
20934> """Greet the whole world."""
20935> def __init__ (self):
20936> super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE)
20937> def invoke (self, args, from_tty):
20938> argv = gdb.string_to_argv (args)
20939> if len (argv) != 0:
20940> raise gdb.GdbError ("hello-world takes no arguments")
20941> print "Hello, World!"
20942>HelloWorld ()
20943>end
20944(gdb) hello-world 42
20945hello-world takes no arguments
20946@end smallexample
20947
a08702d6
TJB
20948@node Values From Inferior
20949@subsubsection Values From Inferior
20950@cindex values from inferior, with Python
20951@cindex python, working with values from inferior
20952
20953@cindex @code{gdb.Value}
20954@value{GDBN} provides values it obtains from the inferior program in
20955an object of type @code{gdb.Value}. @value{GDBN} uses this object
20956for its internal bookkeeping of the inferior's values, and for
20957fetching values when necessary.
20958
20959Inferior values that are simple scalars can be used directly in
20960Python expressions that are valid for the value's data type. Here's
20961an example for an integer or floating-point value @code{some_val}:
20962
20963@smallexample
20964bar = some_val + 2
20965@end smallexample
20966
20967@noindent
20968As result of this, @code{bar} will also be a @code{gdb.Value} object
20969whose values are of the same type as those of @code{some_val}.
20970
20971Inferior values that are structures or instances of some class can
20972be accessed using the Python @dfn{dictionary syntax}. For example, if
20973@code{some_val} is a @code{gdb.Value} instance holding a structure, you
20974can access its @code{foo} element with:
20975
20976@smallexample
20977bar = some_val['foo']
20978@end smallexample
20979
20980Again, @code{bar} will also be a @code{gdb.Value} object.
20981
5374244e
PM
20982A @code{gdb.Value} that represents a function can be executed via
20983inferior function call. Any arguments provided to the call must match
20984the function's prototype, and must be provided in the order specified
20985by that prototype.
20986
20987For example, @code{some_val} is a @code{gdb.Value} instance
20988representing a function that takes two integers as arguments. To
20989execute this function, call it like so:
20990
20991@smallexample
20992result = some_val (10,20)
20993@end smallexample
20994
20995Any values returned from a function call will be stored as a
20996@code{gdb.Value}.
20997
c0c6f777 20998The following attributes are provided:
a08702d6 20999
def2b000 21000@table @code
2c74e833 21001@defivar Value address
c0c6f777
TJB
21002If this object is addressable, this read-only attribute holds a
21003@code{gdb.Value} object representing the address. Otherwise,
21004this attribute holds @code{None}.
2c74e833 21005@end defivar
c0c6f777 21006
def2b000 21007@cindex optimized out value in Python
2c74e833 21008@defivar Value is_optimized_out
def2b000
TJB
21009This read-only boolean attribute is true if the compiler optimized out
21010this value, thus it is not available for fetching from the inferior.
2c74e833
TT
21011@end defivar
21012
21013@defivar Value type
21014The type of this @code{gdb.Value}. The value of this attribute is a
44592cc4 21015@code{gdb.Type} object (@pxref{Types In Python}).
2c74e833 21016@end defivar
03f17ccf
TT
21017
21018@defivar Value dynamic_type
21019The dynamic type of this @code{gdb.Value}. This uses C@t{++} run-time
fccd1d1e
EZ
21020type information (@acronym{RTTI}) to determine the dynamic type of the
21021value. If this value is of class type, it will return the class in
21022which the value is embedded, if any. If this value is of pointer or
21023reference to a class type, it will compute the dynamic type of the
21024referenced object, and return a pointer or reference to that type,
21025respectively. In all other cases, it will return the value's static
21026type.
21027
21028Note that this feature will only work when debugging a C@t{++} program
21029that includes @acronym{RTTI} for the object in question. Otherwise,
21030it will just return the static type of the value as in @kbd{ptype foo}
21031(@pxref{Symbols, ptype}).
03f17ccf 21032@end defivar
def2b000
TJB
21033@end table
21034
21035The following methods are provided:
21036
21037@table @code
e8467610
TT
21038@defmethod Value __init__ @var{val}
21039Many Python values can be converted directly to a @code{gdb.Value} via
21040this object initializer. Specifically:
21041
21042@table @asis
21043@item Python boolean
21044A Python boolean is converted to the boolean type from the current
21045language.
21046
21047@item Python integer
21048A Python integer is converted to the C @code{long} type for the
21049current architecture.
21050
21051@item Python long
21052A Python long is converted to the C @code{long long} type for the
21053current architecture.
21054
21055@item Python float
21056A Python float is converted to the C @code{double} type for the
21057current architecture.
21058
21059@item Python string
21060A Python string is converted to a target string, using the current
21061target encoding.
21062
21063@item @code{gdb.Value}
21064If @code{val} is a @code{gdb.Value}, then a copy of the value is made.
21065
21066@item @code{gdb.LazyString}
21067If @code{val} is a @code{gdb.LazyString} (@pxref{Lazy Strings In
21068Python}), then the lazy string's @code{value} method is called, and
21069its result is used.
21070@end table
21071@end defmethod
21072
14ff2235
PM
21073@defmethod Value cast type
21074Return a new instance of @code{gdb.Value} that is the result of
21075casting this instance to the type described by @var{type}, which must
21076be a @code{gdb.Type} object. If the cast cannot be performed for some
21077reason, this method throws an exception.
21078@end defmethod
21079
a08702d6 21080@defmethod Value dereference
def2b000
TJB
21081For pointer data types, this method returns a new @code{gdb.Value} object
21082whose contents is the object pointed to by the pointer. For example, if
21083@code{foo} is a C pointer to an @code{int}, declared in your C program as
a08702d6
TJB
21084
21085@smallexample
21086int *foo;
21087@end smallexample
21088
21089@noindent
21090then you can use the corresponding @code{gdb.Value} to access what
21091@code{foo} points to like this:
21092
21093@smallexample
21094bar = foo.dereference ()
21095@end smallexample
21096
21097The result @code{bar} will be a @code{gdb.Value} object holding the
21098value pointed to by @code{foo}.
21099@end defmethod
21100
f9ffd4bb
TT
21101@defmethod Value dynamic_cast type
21102Like @code{Value.cast}, but works as if the C@t{++} @code{dynamic_cast}
21103operator were used. Consult a C@t{++} reference for details.
21104@end defmethod
21105
21106@defmethod Value reinterpret_cast type
21107Like @code{Value.cast}, but works as if the C@t{++} @code{reinterpret_cast}
21108operator were used. Consult a C@t{++} reference for details.
21109@end defmethod
21110
fbb8f299 21111@defmethod Value string @r{[}encoding@r{]} @r{[}errors@r{]} @r{[}length@r{]}
b6cb8e7d
TJB
21112If this @code{gdb.Value} represents a string, then this method
21113converts the contents to a Python string. Otherwise, this method will
21114throw an exception.
21115
21116Strings are recognized in a language-specific way; whether a given
21117@code{gdb.Value} represents a string is determined by the current
21118language.
21119
21120For C-like languages, a value is a string if it is a pointer to or an
21121array of characters or ints. The string is assumed to be terminated
fbb8f299
PM
21122by a zero of the appropriate width. However if the optional length
21123argument is given, the string will be converted to that given length,
21124ignoring any embedded zeros that the string may contain.
b6cb8e7d
TJB
21125
21126If the optional @var{encoding} argument is given, it must be a string
21127naming the encoding of the string in the @code{gdb.Value}, such as
21128@code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
21129the same encodings as the corresponding argument to Python's
21130@code{string.decode} method, and the Python codec machinery will be used
21131to convert the string. If @var{encoding} is not given, or if
21132@var{encoding} is the empty string, then either the @code{target-charset}
21133(@pxref{Character Sets}) will be used, or a language-specific encoding
21134will be used, if the current language is able to supply one.
21135
21136The optional @var{errors} argument is the same as the corresponding
21137argument to Python's @code{string.decode} method.
fbb8f299
PM
21138
21139If the optional @var{length} argument is given, the string will be
21140fetched and converted to the given length.
b6cb8e7d 21141@end defmethod
be759fcf
PM
21142
21143@defmethod Value lazy_string @r{[}encoding@r{]} @r{[}length@r{]}
21144If this @code{gdb.Value} represents a string, then this method
21145converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
21146In Python}). Otherwise, this method will throw an exception.
21147
21148If the optional @var{encoding} argument is given, it must be a string
21149naming the encoding of the @code{gdb.LazyString}. Some examples are:
21150@samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
21151@var{encoding} argument is an encoding that @value{GDBN} does
21152recognize, @value{GDBN} will raise an error.
21153
21154When a lazy string is printed, the @value{GDBN} encoding machinery is
21155used to convert the string during printing. If the optional
21156@var{encoding} argument is not provided, or is an empty string,
21157@value{GDBN} will automatically select the encoding most suitable for
21158the string type. For further information on encoding in @value{GDBN}
21159please see @ref{Character Sets}.
21160
21161If the optional @var{length} argument is given, the string will be
21162fetched and encoded to the length of characters specified. If
21163the @var{length} argument is not provided, the string will be fetched
21164and encoded until a null of appropriate width is found.
21165@end defmethod
def2b000 21166@end table
b6cb8e7d 21167
2c74e833
TT
21168@node Types In Python
21169@subsubsection Types In Python
21170@cindex types in Python
21171@cindex Python, working with types
21172
21173@tindex gdb.Type
21174@value{GDBN} represents types from the inferior using the class
21175@code{gdb.Type}.
21176
21177The following type-related functions are available in the @code{gdb}
21178module:
21179
21180@findex gdb.lookup_type
21181@defun lookup_type name [block]
21182This function looks up a type by name. @var{name} is the name of the
21183type to look up. It must be a string.
21184
5107b149
PM
21185If @var{block} is given, then @var{name} is looked up in that scope.
21186Otherwise, it is searched for globally.
21187
2c74e833
TT
21188Ordinarily, this function will return an instance of @code{gdb.Type}.
21189If the named type cannot be found, it will throw an exception.
21190@end defun
21191
21192An instance of @code{Type} has the following attributes:
21193
21194@table @code
21195@defivar Type code
21196The type code for this type. The type code will be one of the
21197@code{TYPE_CODE_} constants defined below.
21198@end defivar
21199
21200@defivar Type sizeof
21201The size of this type, in target @code{char} units. Usually, a
21202target's @code{char} type will be an 8-bit byte. However, on some
21203unusual platforms, this type may have a different size.
21204@end defivar
21205
21206@defivar Type tag
21207The tag name for this type. The tag name is the name after
21208@code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
21209languages have this concept. If this type has no tag name, then
21210@code{None} is returned.
21211@end defivar
21212@end table
21213
21214The following methods are provided:
21215
21216@table @code
21217@defmethod Type fields
21218For structure and union types, this method returns the fields. Range
21219types have two fields, the minimum and maximum values. Enum types
21220have one field per enum constant. Function and method types have one
21221field per parameter. The base types of C@t{++} classes are also
21222represented as fields. If the type has no fields, or does not fit
21223into one of these categories, an empty sequence will be returned.
21224
21225Each field is an object, with some pre-defined attributes:
21226@table @code
21227@item bitpos
21228This attribute is not available for @code{static} fields (as in
21229C@t{++} or Java). For non-@code{static} fields, the value is the bit
21230position of the field.
21231
21232@item name
21233The name of the field, or @code{None} for anonymous fields.
21234
21235@item artificial
21236This is @code{True} if the field is artificial, usually meaning that
21237it was provided by the compiler and not the user. This attribute is
21238always provided, and is @code{False} if the field is not artificial.
21239
bfd31e71
PM
21240@item is_base_class
21241This is @code{True} if the field represents a base class of a C@t{++}
21242structure. This attribute is always provided, and is @code{False}
21243if the field is not a base class of the type that is the argument of
21244@code{fields}, or if that type was not a C@t{++} class.
21245
2c74e833
TT
21246@item bitsize
21247If the field is packed, or is a bitfield, then this will have a
21248non-zero value, which is the size of the field in bits. Otherwise,
21249this will be zero; in this case the field's size is given by its type.
21250
21251@item type
21252The type of the field. This is usually an instance of @code{Type},
21253but it can be @code{None} in some situations.
21254@end table
21255@end defmethod
21256
702c2711
TT
21257@defmethod Type array @var{n1} @r{[}@var{n2}@r{]}
21258Return a new @code{gdb.Type} object which represents an array of this
21259type. If one argument is given, it is the inclusive upper bound of
21260the array; in this case the lower bound is zero. If two arguments are
21261given, the first argument is the lower bound of the array, and the
21262second argument is the upper bound of the array. An array's length
21263must not be negative, but the bounds can be.
21264@end defmethod
21265
2c74e833
TT
21266@defmethod Type const
21267Return a new @code{gdb.Type} object which represents a
21268@code{const}-qualified variant of this type.
21269@end defmethod
21270
21271@defmethod Type volatile
21272Return a new @code{gdb.Type} object which represents a
21273@code{volatile}-qualified variant of this type.
21274@end defmethod
21275
21276@defmethod Type unqualified
21277Return a new @code{gdb.Type} object which represents an unqualified
21278variant of this type. That is, the result is neither @code{const} nor
21279@code{volatile}.
21280@end defmethod
21281
361ae042
PM
21282@defmethod Type range
21283Return a Python @code{Tuple} object that contains two elements: the
21284low bound of the argument type and the high bound of that type. If
21285the type does not have a range, @value{GDBN} will raise a
621c8364 21286@code{gdb.error} exception (@pxref{Exception Handling}).
361ae042
PM
21287@end defmethod
21288
2c74e833
TT
21289@defmethod Type reference
21290Return a new @code{gdb.Type} object which represents a reference to this
21291type.
21292@end defmethod
21293
7a6973ad
TT
21294@defmethod Type pointer
21295Return a new @code{gdb.Type} object which represents a pointer to this
21296type.
21297@end defmethod
21298
2c74e833
TT
21299@defmethod Type strip_typedefs
21300Return a new @code{gdb.Type} that represents the real type,
21301after removing all layers of typedefs.
21302@end defmethod
21303
21304@defmethod Type target
21305Return a new @code{gdb.Type} object which represents the target type
21306of this type.
21307
21308For a pointer type, the target type is the type of the pointed-to
21309object. For an array type (meaning C-like arrays), the target type is
21310the type of the elements of the array. For a function or method type,
21311the target type is the type of the return value. For a complex type,
21312the target type is the type of the elements. For a typedef, the
21313target type is the aliased type.
21314
21315If the type does not have a target, this method will throw an
21316exception.
21317@end defmethod
21318
5107b149 21319@defmethod Type template_argument n [block]
2c74e833
TT
21320If this @code{gdb.Type} is an instantiation of a template, this will
21321return a new @code{gdb.Type} which represents the type of the
21322@var{n}th template argument.
21323
21324If this @code{gdb.Type} is not a template type, this will throw an
21325exception. Ordinarily, only C@t{++} code will have template types.
21326
5107b149
PM
21327If @var{block} is given, then @var{name} is looked up in that scope.
21328Otherwise, it is searched for globally.
2c74e833
TT
21329@end defmethod
21330@end table
21331
21332
21333Each type has a code, which indicates what category this type falls
21334into. The available type categories are represented by constants
21335defined in the @code{gdb} module:
21336
21337@table @code
21338@findex TYPE_CODE_PTR
21339@findex gdb.TYPE_CODE_PTR
21340@item TYPE_CODE_PTR
21341The type is a pointer.
21342
21343@findex TYPE_CODE_ARRAY
21344@findex gdb.TYPE_CODE_ARRAY
21345@item TYPE_CODE_ARRAY
21346The type is an array.
21347
21348@findex TYPE_CODE_STRUCT
21349@findex gdb.TYPE_CODE_STRUCT
21350@item TYPE_CODE_STRUCT
21351The type is a structure.
21352
21353@findex TYPE_CODE_UNION
21354@findex gdb.TYPE_CODE_UNION
21355@item TYPE_CODE_UNION
21356The type is a union.
21357
21358@findex TYPE_CODE_ENUM
21359@findex gdb.TYPE_CODE_ENUM
21360@item TYPE_CODE_ENUM
21361The type is an enum.
21362
21363@findex TYPE_CODE_FLAGS
21364@findex gdb.TYPE_CODE_FLAGS
21365@item TYPE_CODE_FLAGS
21366A bit flags type, used for things such as status registers.
21367
21368@findex TYPE_CODE_FUNC
21369@findex gdb.TYPE_CODE_FUNC
21370@item TYPE_CODE_FUNC
21371The type is a function.
21372
21373@findex TYPE_CODE_INT
21374@findex gdb.TYPE_CODE_INT
21375@item TYPE_CODE_INT
21376The type is an integer type.
21377
21378@findex TYPE_CODE_FLT
21379@findex gdb.TYPE_CODE_FLT
21380@item TYPE_CODE_FLT
21381A floating point type.
21382
21383@findex TYPE_CODE_VOID
21384@findex gdb.TYPE_CODE_VOID
21385@item TYPE_CODE_VOID
21386The special type @code{void}.
21387
21388@findex TYPE_CODE_SET
21389@findex gdb.TYPE_CODE_SET
21390@item TYPE_CODE_SET
21391A Pascal set type.
21392
21393@findex TYPE_CODE_RANGE
21394@findex gdb.TYPE_CODE_RANGE
21395@item TYPE_CODE_RANGE
21396A range type, that is, an integer type with bounds.
21397
21398@findex TYPE_CODE_STRING
21399@findex gdb.TYPE_CODE_STRING
21400@item TYPE_CODE_STRING
21401A string type. Note that this is only used for certain languages with
21402language-defined string types; C strings are not represented this way.
21403
21404@findex TYPE_CODE_BITSTRING
21405@findex gdb.TYPE_CODE_BITSTRING
21406@item TYPE_CODE_BITSTRING
21407A string of bits.
21408
21409@findex TYPE_CODE_ERROR
21410@findex gdb.TYPE_CODE_ERROR
21411@item TYPE_CODE_ERROR
21412An unknown or erroneous type.
21413
21414@findex TYPE_CODE_METHOD
21415@findex gdb.TYPE_CODE_METHOD
21416@item TYPE_CODE_METHOD
21417A method type, as found in C@t{++} or Java.
21418
21419@findex TYPE_CODE_METHODPTR
21420@findex gdb.TYPE_CODE_METHODPTR
21421@item TYPE_CODE_METHODPTR
21422A pointer-to-member-function.
21423
21424@findex TYPE_CODE_MEMBERPTR
21425@findex gdb.TYPE_CODE_MEMBERPTR
21426@item TYPE_CODE_MEMBERPTR
21427A pointer-to-member.
21428
21429@findex TYPE_CODE_REF
21430@findex gdb.TYPE_CODE_REF
21431@item TYPE_CODE_REF
21432A reference type.
21433
21434@findex TYPE_CODE_CHAR
21435@findex gdb.TYPE_CODE_CHAR
21436@item TYPE_CODE_CHAR
21437A character type.
21438
21439@findex TYPE_CODE_BOOL
21440@findex gdb.TYPE_CODE_BOOL
21441@item TYPE_CODE_BOOL
21442A boolean type.
21443
21444@findex TYPE_CODE_COMPLEX
21445@findex gdb.TYPE_CODE_COMPLEX
21446@item TYPE_CODE_COMPLEX
21447A complex float type.
21448
21449@findex TYPE_CODE_TYPEDEF
21450@findex gdb.TYPE_CODE_TYPEDEF
21451@item TYPE_CODE_TYPEDEF
21452A typedef to some other type.
21453
21454@findex TYPE_CODE_NAMESPACE
21455@findex gdb.TYPE_CODE_NAMESPACE
21456@item TYPE_CODE_NAMESPACE
21457A C@t{++} namespace.
21458
21459@findex TYPE_CODE_DECFLOAT
21460@findex gdb.TYPE_CODE_DECFLOAT
21461@item TYPE_CODE_DECFLOAT
21462A decimal floating point type.
21463
21464@findex TYPE_CODE_INTERNAL_FUNCTION
21465@findex gdb.TYPE_CODE_INTERNAL_FUNCTION
21466@item TYPE_CODE_INTERNAL_FUNCTION
21467A function internal to @value{GDBN}. This is the type used to represent
21468convenience functions.
21469@end table
21470
0e3509db
DE
21471Further support for types is provided in the @code{gdb.types}
21472Python module (@pxref{gdb.types}).
21473
4c374409
JK
21474@node Pretty Printing API
21475@subsubsection Pretty Printing API
a6bac58e 21476
4c374409 21477An example output is provided (@pxref{Pretty Printing}).
a6bac58e
TT
21478
21479A pretty-printer is just an object that holds a value and implements a
21480specific interface, defined here.
21481
21482@defop Operation {pretty printer} children (self)
21483@value{GDBN} will call this method on a pretty-printer to compute the
21484children of the pretty-printer's value.
21485
21486This method must return an object conforming to the Python iterator
21487protocol. Each item returned by the iterator must be a tuple holding
21488two elements. The first element is the ``name'' of the child; the
21489second element is the child's value. The value can be any Python
21490object which is convertible to a @value{GDBN} value.
21491
21492This method is optional. If it does not exist, @value{GDBN} will act
21493as though the value has no children.
21494@end defop
21495
21496@defop Operation {pretty printer} display_hint (self)
21497The CLI may call this method and use its result to change the
21498formatting of a value. The result will also be supplied to an MI
21499consumer as a @samp{displayhint} attribute of the variable being
21500printed.
21501
21502This method is optional. If it does exist, this method must return a
21503string.
21504
21505Some display hints are predefined by @value{GDBN}:
21506
21507@table @samp
21508@item array
21509Indicate that the object being printed is ``array-like''. The CLI
21510uses this to respect parameters such as @code{set print elements} and
21511@code{set print array}.
21512
21513@item map
21514Indicate that the object being printed is ``map-like'', and that the
21515children of this value can be assumed to alternate between keys and
21516values.
21517
21518@item string
21519Indicate that the object being printed is ``string-like''. If the
21520printer's @code{to_string} method returns a Python string of some
21521kind, then @value{GDBN} will call its internal language-specific
21522string-printing function to format the string. For the CLI this means
21523adding quotation marks, possibly escaping some characters, respecting
21524@code{set print elements}, and the like.
21525@end table
21526@end defop
21527
21528@defop Operation {pretty printer} to_string (self)
21529@value{GDBN} will call this method to display the string
21530representation of the value passed to the object's constructor.
21531
21532When printing from the CLI, if the @code{to_string} method exists,
21533then @value{GDBN} will prepend its result to the values returned by
21534@code{children}. Exactly how this formatting is done is dependent on
21535the display hint, and may change as more hints are added. Also,
21536depending on the print settings (@pxref{Print Settings}), the CLI may
21537print just the result of @code{to_string} in a stack trace, omitting
21538the result of @code{children}.
21539
21540If this method returns a string, it is printed verbatim.
21541
21542Otherwise, if this method returns an instance of @code{gdb.Value},
21543then @value{GDBN} prints this value. This may result in a call to
21544another pretty-printer.
21545
21546If instead the method returns a Python value which is convertible to a
21547@code{gdb.Value}, then @value{GDBN} performs the conversion and prints
21548the resulting value. Again, this may result in a call to another
21549pretty-printer. Python scalars (integers, floats, and booleans) and
21550strings are convertible to @code{gdb.Value}; other types are not.
21551
79f283fe
PM
21552Finally, if this method returns @code{None} then no further operations
21553are peformed in this method and nothing is printed.
21554
a6bac58e
TT
21555If the result is not one of these types, an exception is raised.
21556@end defop
21557
464b3efb
TT
21558@value{GDBN} provides a function which can be used to look up the
21559default pretty-printer for a @code{gdb.Value}:
21560
21561@findex gdb.default_visualizer
21562@defun default_visualizer value
21563This function takes a @code{gdb.Value} object as an argument. If a
21564pretty-printer for this value exists, then it is returned. If no such
21565printer exists, then this returns @code{None}.
21566@end defun
21567
a6bac58e
TT
21568@node Selecting Pretty-Printers
21569@subsubsection Selecting Pretty-Printers
21570
21571The Python list @code{gdb.pretty_printers} contains an array of
967cf477 21572functions or callable objects that have been registered via addition
7b51bc51
DE
21573as a pretty-printer. Printers in this list are called @code{global}
21574printers, they're available when debugging all inferiors.
fa33c3cd 21575Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
a6bac58e
TT
21576Each @code{gdb.Objfile} also contains a @code{pretty_printers}
21577attribute.
21578
7b51bc51 21579Each function on these lists is passed a single @code{gdb.Value}
a6bac58e 21580argument and should return a pretty-printer object conforming to the
4c374409 21581interface definition above (@pxref{Pretty Printing API}). If a function
a6bac58e
TT
21582cannot create a pretty-printer for the value, it should return
21583@code{None}.
21584
21585@value{GDBN} first checks the @code{pretty_printers} attribute of each
fa33c3cd 21586@code{gdb.Objfile} in the current program space and iteratively calls
7b51bc51
DE
21587each enabled lookup routine in the list for that @code{gdb.Objfile}
21588until it receives a pretty-printer object.
fa33c3cd
DE
21589If no pretty-printer is found in the objfile lists, @value{GDBN} then
21590searches the pretty-printer list of the current program space,
967cf477 21591calling each enabled function until an object is returned.
a6bac58e 21592After these lists have been exhausted, it tries the global
967cf477 21593@code{gdb.pretty_printers} list, again calling each enabled function until an
a6bac58e
TT
21594object is returned.
21595
21596The order in which the objfiles are searched is not specified. For a
21597given list, functions are always invoked from the head of the list,
21598and iterated over sequentially until the end of the list, or a printer
21599object is returned.
21600
7b51bc51
DE
21601For various reasons a pretty-printer may not work.
21602For example, the underlying data structure may have changed and
21603the pretty-printer is out of date.
21604
21605The consequences of a broken pretty-printer are severe enough that
21606@value{GDBN} provides support for enabling and disabling individual
21607printers. For example, if @code{print frame-arguments} is on,
21608a backtrace can become highly illegible if any argument is printed
21609with a broken printer.
21610
21611Pretty-printers are enabled and disabled by attaching an @code{enabled}
21612attribute to the registered function or callable object. If this attribute
21613is present and its value is @code{False}, the printer is disabled, otherwise
21614the printer is enabled.
21615
21616@node Writing a Pretty-Printer
21617@subsubsection Writing a Pretty-Printer
21618@cindex writing a pretty-printer
21619
21620A pretty-printer consists of two parts: a lookup function to detect
21621if the type is supported, and the printer itself.
21622
a6bac58e 21623Here is an example showing how a @code{std::string} printer might be
7b51bc51
DE
21624written. @xref{Pretty Printing API}, for details on the API this class
21625must provide.
a6bac58e
TT
21626
21627@smallexample
7b51bc51 21628class StdStringPrinter(object):
a6bac58e
TT
21629 "Print a std::string"
21630
7b51bc51 21631 def __init__(self, val):
a6bac58e
TT
21632 self.val = val
21633
7b51bc51 21634 def to_string(self):
a6bac58e
TT
21635 return self.val['_M_dataplus']['_M_p']
21636
7b51bc51 21637 def display_hint(self):
a6bac58e
TT
21638 return 'string'
21639@end smallexample
21640
21641And here is an example showing how a lookup function for the printer
21642example above might be written.
21643
21644@smallexample
7b51bc51 21645def str_lookup_function(val):
a6bac58e 21646 lookup_tag = val.type.tag
a6bac58e
TT
21647 if lookup_tag == None:
21648 return None
7b51bc51
DE
21649 regex = re.compile("^std::basic_string<char,.*>$")
21650 if regex.match(lookup_tag):
21651 return StdStringPrinter(val)
a6bac58e
TT
21652 return None
21653@end smallexample
21654
21655The example lookup function extracts the value's type, and attempts to
21656match it to a type that it can pretty-print. If it is a type the
21657printer can pretty-print, it will return a printer object. If not, it
21658returns @code{None}.
21659
21660We recommend that you put your core pretty-printers into a Python
21661package. If your pretty-printers are for use with a library, we
21662further recommend embedding a version number into the package name.
21663This practice will enable @value{GDBN} to load multiple versions of
21664your pretty-printers at the same time, because they will have
21665different names.
21666
21667You should write auto-loaded code (@pxref{Auto-loading}) such that it
21668can be evaluated multiple times without changing its meaning. An
21669ideal auto-load file will consist solely of @code{import}s of your
21670printer modules, followed by a call to a register pretty-printers with
21671the current objfile.
21672
21673Taken as a whole, this approach will scale nicely to multiple
21674inferiors, each potentially using a different library version.
21675Embedding a version number in the Python package name will ensure that
21676@value{GDBN} is able to load both sets of printers simultaneously.
21677Then, because the search for pretty-printers is done by objfile, and
21678because your auto-loaded code took care to register your library's
21679printers with a specific objfile, @value{GDBN} will find the correct
21680printers for the specific version of the library used by each
21681inferior.
21682
4c374409 21683To continue the @code{std::string} example (@pxref{Pretty Printing API}),
a6bac58e
TT
21684this code might appear in @code{gdb.libstdcxx.v6}:
21685
21686@smallexample
7b51bc51
DE
21687def register_printers(objfile):
21688 objfile.pretty_printers.add(str_lookup_function)
a6bac58e
TT
21689@end smallexample
21690
21691@noindent
21692And then the corresponding contents of the auto-load file would be:
21693
21694@smallexample
21695import gdb.libstdcxx.v6
7b51bc51 21696gdb.libstdcxx.v6.register_printers(gdb.current_objfile())
a6bac58e
TT
21697@end smallexample
21698
7b51bc51
DE
21699The previous example illustrates a basic pretty-printer.
21700There are a few things that can be improved on.
21701The printer doesn't have a name, making it hard to identify in a
21702list of installed printers. The lookup function has a name, but
21703lookup functions can have arbitrary, even identical, names.
967cf477 21704
7b51bc51
DE
21705Second, the printer only handles one type, whereas a library typically has
21706several types. One could install a lookup function for each desired type
21707in the library, but one could also have a single lookup function recognize
21708several types. The latter is the conventional way this is handled.
21709If a pretty-printer can handle multiple data types, then its
21710@dfn{subprinters} are the printers for the individual data types.
967cf477 21711
7b51bc51
DE
21712The @code{gdb.printing} module provides a formal way of solving these
21713problems (@pxref{gdb.printing}).
21714Here is another example that handles multiple types.
967cf477 21715
7b51bc51
DE
21716These are the types we are going to pretty-print:
21717
21718@smallexample
21719struct foo @{ int a, b; @};
21720struct bar @{ struct foo x, y; @};
21721@end smallexample
21722
21723Here are the printers:
21724
21725@smallexample
21726class fooPrinter:
21727 """Print a foo object."""
21728
21729 def __init__(self, val):
21730 self.val = val
21731
21732 def to_string(self):
21733 return ("a=<" + str(self.val["a"]) +
21734 "> b=<" + str(self.val["b"]) + ">")
21735
21736class barPrinter:
21737 """Print a bar object."""
21738
21739 def __init__(self, val):
21740 self.val = val
21741
21742 def to_string(self):
21743 return ("x=<" + str(self.val["x"]) +
21744 "> y=<" + str(self.val["y"]) + ">")
21745@end smallexample
21746
21747This example doesn't need a lookup function, that is handled by the
21748@code{gdb.printing} module. Instead a function is provided to build up
21749the object that handles the lookup.
21750
21751@smallexample
21752import gdb.printing
21753
21754def build_pretty_printer():
21755 pp = gdb.printing.RegexpCollectionPrettyPrinter(
21756 "my_library")
21757 pp.add_printer('foo', '^foo$', fooPrinter)
21758 pp.add_printer('bar', '^bar$', barPrinter)
21759 return pp
21760@end smallexample
21761
21762And here is the autoload support:
21763
21764@smallexample
21765import gdb.printing
21766import my_library
21767gdb.printing.register_pretty_printer(
21768 gdb.current_objfile(),
21769 my_library.build_pretty_printer())
21770@end smallexample
21771
21772Finally, when this printer is loaded into @value{GDBN}, here is the
21773corresponding output of @samp{info pretty-printer}:
21774
21775@smallexample
21776(gdb) info pretty-printer
21777my_library.so:
21778 my_library
21779 foo
21780 bar
21781@end smallexample
967cf477 21782
595939de
PM
21783@node Inferiors In Python
21784@subsubsection Inferiors In Python
21785@cindex inferiors in python
21786
21787@findex gdb.Inferior
21788Programs which are being run under @value{GDBN} are called inferiors
21789(@pxref{Inferiors and Programs}). Python scripts can access
21790information about and manipulate inferiors controlled by @value{GDBN}
21791via objects of the @code{gdb.Inferior} class.
21792
21793The following inferior-related functions are available in the @code{gdb}
21794module:
21795
21796@defun inferiors
21797Return a tuple containing all inferior objects.
21798@end defun
21799
21800A @code{gdb.Inferior} object has the following attributes:
21801
21802@table @code
21803@defivar Inferior num
21804ID of inferior, as assigned by GDB.
21805@end defivar
21806
21807@defivar Inferior pid
21808Process ID of the inferior, as assigned by the underlying operating
21809system.
21810@end defivar
21811
21812@defivar Inferior was_attached
21813Boolean signaling whether the inferior was created using `attach', or
21814started by @value{GDBN} itself.
21815@end defivar
21816@end table
21817
21818A @code{gdb.Inferior} object has the following methods:
21819
21820@table @code
21821@defmethod Inferior threads
21822This method returns a tuple holding all the threads which are valid
21823when it is called. If there are no valid threads, the method will
21824return an empty tuple.
21825@end defmethod
21826
21827@findex gdb.read_memory
21828@defmethod Inferior read_memory address length
21829Read @var{length} bytes of memory from the inferior, starting at
21830@var{address}. Returns a buffer object, which behaves much like an array
21831or a string. It can be modified and given to the @code{gdb.write_memory}
21832function.
21833@end defmethod
21834
21835@findex gdb.write_memory
21836@defmethod Inferior write_memory address buffer @r{[}length@r{]}
21837Write the contents of @var{buffer} to the inferior, starting at
21838@var{address}. The @var{buffer} parameter must be a Python object
21839which supports the buffer protocol, i.e., a string, an array or the
21840object returned from @code{gdb.read_memory}. If given, @var{length}
21841determines the number of bytes from @var{buffer} to be written.
21842@end defmethod
21843
21844@findex gdb.search_memory
21845@defmethod Inferior search_memory address length pattern
21846Search a region of the inferior memory starting at @var{address} with
21847the given @var{length} using the search pattern supplied in
21848@var{pattern}. The @var{pattern} parameter must be a Python object
21849which supports the buffer protocol, i.e., a string, an array or the
21850object returned from @code{gdb.read_memory}. Returns a Python @code{Long}
21851containing the address where the pattern was found, or @code{None} if
21852the pattern could not be found.
21853@end defmethod
21854@end table
21855
21856@node Threads In Python
21857@subsubsection Threads In Python
21858@cindex threads in python
21859
21860@findex gdb.InferiorThread
21861Python scripts can access information about, and manipulate inferior threads
21862controlled by @value{GDBN}, via objects of the @code{gdb.InferiorThread} class.
21863
21864The following thread-related functions are available in the @code{gdb}
21865module:
21866
21867@findex gdb.selected_thread
21868@defun selected_thread
21869This function returns the thread object for the selected thread. If there
21870is no selected thread, this will return @code{None}.
21871@end defun
21872
21873A @code{gdb.InferiorThread} object has the following attributes:
21874
21875@table @code
21876@defivar InferiorThread num
21877ID of the thread, as assigned by GDB.
21878@end defivar
21879
21880@defivar InferiorThread ptid
21881ID of the thread, as assigned by the operating system. This attribute is a
21882tuple containing three integers. The first is the Process ID (PID); the second
21883is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
21884Either the LWPID or TID may be 0, which indicates that the operating system
21885does not use that identifier.
21886@end defivar
21887@end table
21888
21889A @code{gdb.InferiorThread} object has the following methods:
21890
dc3b15be 21891@table @code
595939de
PM
21892@defmethod InferiorThread switch
21893This changes @value{GDBN}'s currently selected thread to the one represented
21894by this object.
21895@end defmethod
21896
21897@defmethod InferiorThread is_stopped
21898Return a Boolean indicating whether the thread is stopped.
21899@end defmethod
21900
21901@defmethod InferiorThread is_running
21902Return a Boolean indicating whether the thread is running.
21903@end defmethod
21904
21905@defmethod InferiorThread is_exited
21906Return a Boolean indicating whether the thread is exited.
21907@end defmethod
21908@end table
21909
d8906c6f
TJB
21910@node Commands In Python
21911@subsubsection Commands In Python
21912
21913@cindex commands in python
21914@cindex python commands
d8906c6f
TJB
21915You can implement new @value{GDBN} CLI commands in Python. A CLI
21916command is implemented using an instance of the @code{gdb.Command}
21917class, most commonly using a subclass.
21918
cc924cad 21919@defmethod Command __init__ name @var{command_class} @r{[}@var{completer_class}@r{]} @r{[}@var{prefix}@r{]}
d8906c6f
TJB
21920The object initializer for @code{Command} registers the new command
21921with @value{GDBN}. This initializer is normally invoked from the
21922subclass' own @code{__init__} method.
21923
21924@var{name} is the name of the command. If @var{name} consists of
21925multiple words, then the initial words are looked for as prefix
21926commands. In this case, if one of the prefix commands does not exist,
21927an exception is raised.
21928
21929There is no support for multi-line commands.
21930
cc924cad 21931@var{command_class} should be one of the @samp{COMMAND_} constants
d8906c6f
TJB
21932defined below. This argument tells @value{GDBN} how to categorize the
21933new command in the help system.
21934
cc924cad 21935@var{completer_class} is an optional argument. If given, it should be
d8906c6f
TJB
21936one of the @samp{COMPLETE_} constants defined below. This argument
21937tells @value{GDBN} how to perform completion for this command. If not
21938given, @value{GDBN} will attempt to complete using the object's
21939@code{complete} method (see below); if no such method is found, an
21940error will occur when completion is attempted.
21941
21942@var{prefix} is an optional argument. If @code{True}, then the new
21943command is a prefix command; sub-commands of this command may be
21944registered.
21945
21946The help text for the new command is taken from the Python
21947documentation string for the command's class, if there is one. If no
21948documentation string is provided, the default value ``This command is
21949not documented.'' is used.
21950@end defmethod
21951
a0c36267 21952@cindex don't repeat Python command
d8906c6f
TJB
21953@defmethod Command dont_repeat
21954By default, a @value{GDBN} command is repeated when the user enters a
21955blank line at the command prompt. A command can suppress this
21956behavior by invoking the @code{dont_repeat} method. This is similar
21957to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
21958@end defmethod
21959
21960@defmethod Command invoke argument from_tty
21961This method is called by @value{GDBN} when this command is invoked.
21962
21963@var{argument} is a string. It is the argument to the command, after
21964leading and trailing whitespace has been stripped.
21965
21966@var{from_tty} is a boolean argument. When true, this means that the
21967command was entered by the user at the terminal; when false it means
21968that the command came from elsewhere.
21969
21970If this method throws an exception, it is turned into a @value{GDBN}
21971@code{error} call. Otherwise, the return value is ignored.
07ca107c
DE
21972
21973@findex gdb.string_to_argv
21974To break @var{argument} up into an argv-like string use
21975@code{gdb.string_to_argv}. This function behaves identically to
21976@value{GDBN}'s internal argument lexer @code{buildargv}.
21977It is recommended to use this for consistency.
21978Arguments are separated by spaces and may be quoted.
21979Example:
21980
21981@smallexample
21982print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
21983['1', '2 "3', '4 "5', "6 '7"]
21984@end smallexample
21985
d8906c6f
TJB
21986@end defmethod
21987
a0c36267 21988@cindex completion of Python commands
d8906c6f
TJB
21989@defmethod Command complete text word
21990This method is called by @value{GDBN} when the user attempts
21991completion on this command. All forms of completion are handled by
a0c36267
EZ
21992this method, that is, the @key{TAB} and @key{M-?} key bindings
21993(@pxref{Completion}), and the @code{complete} command (@pxref{Help,
21994complete}).
d8906c6f
TJB
21995
21996The arguments @var{text} and @var{word} are both strings. @var{text}
21997holds the complete command line up to the cursor's location.
21998@var{word} holds the last word of the command line; this is computed
21999using a word-breaking heuristic.
22000
22001The @code{complete} method can return several values:
22002@itemize @bullet
22003@item
22004If the return value is a sequence, the contents of the sequence are
22005used as the completions. It is up to @code{complete} to ensure that the
22006contents actually do complete the word. A zero-length sequence is
22007allowed, it means that there were no completions available. Only
22008string elements of the sequence are used; other elements in the
22009sequence are ignored.
22010
22011@item
22012If the return value is one of the @samp{COMPLETE_} constants defined
22013below, then the corresponding @value{GDBN}-internal completion
22014function is invoked, and its result is used.
22015
22016@item
22017All other results are treated as though there were no available
22018completions.
22019@end itemize
22020@end defmethod
22021
d8906c6f
TJB
22022When a new command is registered, it must be declared as a member of
22023some general class of commands. This is used to classify top-level
22024commands in the on-line help system; note that prefix commands are not
22025listed under their own category but rather that of their top-level
22026command. The available classifications are represented by constants
22027defined in the @code{gdb} module:
22028
22029@table @code
22030@findex COMMAND_NONE
22031@findex gdb.COMMAND_NONE
22032@item COMMAND_NONE
22033The command does not belong to any particular class. A command in
22034this category will not be displayed in any of the help categories.
22035
22036@findex COMMAND_RUNNING
22037@findex gdb.COMMAND_RUNNING
a0c36267 22038@item COMMAND_RUNNING
d8906c6f
TJB
22039The command is related to running the inferior. For example,
22040@code{start}, @code{step}, and @code{continue} are in this category.
a0c36267 22041Type @kbd{help running} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
22042commands in this category.
22043
22044@findex COMMAND_DATA
22045@findex gdb.COMMAND_DATA
a0c36267 22046@item COMMAND_DATA
d8906c6f
TJB
22047The command is related to data or variables. For example,
22048@code{call}, @code{find}, and @code{print} are in this category. Type
a0c36267 22049@kbd{help data} at the @value{GDBN} prompt to see a list of commands
d8906c6f
TJB
22050in this category.
22051
22052@findex COMMAND_STACK
22053@findex gdb.COMMAND_STACK
22054@item COMMAND_STACK
22055The command has to do with manipulation of the stack. For example,
22056@code{backtrace}, @code{frame}, and @code{return} are in this
a0c36267 22057category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
d8906c6f
TJB
22058list of commands in this category.
22059
22060@findex COMMAND_FILES
22061@findex gdb.COMMAND_FILES
22062@item COMMAND_FILES
22063This class is used for file-related commands. For example,
22064@code{file}, @code{list} and @code{section} are in this category.
a0c36267 22065Type @kbd{help files} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
22066commands in this category.
22067
22068@findex COMMAND_SUPPORT
22069@findex gdb.COMMAND_SUPPORT
22070@item COMMAND_SUPPORT
22071This should be used for ``support facilities'', generally meaning
22072things that are useful to the user when interacting with @value{GDBN},
22073but not related to the state of the inferior. For example,
22074@code{help}, @code{make}, and @code{shell} are in this category. Type
a0c36267 22075@kbd{help support} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
22076commands in this category.
22077
22078@findex COMMAND_STATUS
22079@findex gdb.COMMAND_STATUS
a0c36267 22080@item COMMAND_STATUS
d8906c6f
TJB
22081The command is an @samp{info}-related command, that is, related to the
22082state of @value{GDBN} itself. For example, @code{info}, @code{macro},
a0c36267 22083and @code{show} are in this category. Type @kbd{help status} at the
d8906c6f
TJB
22084@value{GDBN} prompt to see a list of commands in this category.
22085
22086@findex COMMAND_BREAKPOINTS
22087@findex gdb.COMMAND_BREAKPOINTS
a0c36267 22088@item COMMAND_BREAKPOINTS
d8906c6f 22089The command has to do with breakpoints. For example, @code{break},
a0c36267 22090@code{clear}, and @code{delete} are in this category. Type @kbd{help
d8906c6f
TJB
22091breakpoints} at the @value{GDBN} prompt to see a list of commands in
22092this category.
22093
22094@findex COMMAND_TRACEPOINTS
22095@findex gdb.COMMAND_TRACEPOINTS
a0c36267 22096@item COMMAND_TRACEPOINTS
d8906c6f
TJB
22097The command has to do with tracepoints. For example, @code{trace},
22098@code{actions}, and @code{tfind} are in this category. Type
a0c36267 22099@kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
22100commands in this category.
22101
22102@findex COMMAND_OBSCURE
22103@findex gdb.COMMAND_OBSCURE
22104@item COMMAND_OBSCURE
22105The command is only used in unusual circumstances, or is not of
22106general interest to users. For example, @code{checkpoint},
a0c36267 22107@code{fork}, and @code{stop} are in this category. Type @kbd{help
d8906c6f
TJB
22108obscure} at the @value{GDBN} prompt to see a list of commands in this
22109category.
22110
22111@findex COMMAND_MAINTENANCE
22112@findex gdb.COMMAND_MAINTENANCE
22113@item COMMAND_MAINTENANCE
22114The command is only useful to @value{GDBN} maintainers. The
22115@code{maintenance} and @code{flushregs} commands are in this category.
a0c36267 22116Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
22117commands in this category.
22118@end table
22119
d8906c6f
TJB
22120A new command can use a predefined completion function, either by
22121specifying it via an argument at initialization, or by returning it
22122from the @code{complete} method. These predefined completion
22123constants are all defined in the @code{gdb} module:
22124
22125@table @code
22126@findex COMPLETE_NONE
22127@findex gdb.COMPLETE_NONE
22128@item COMPLETE_NONE
22129This constant means that no completion should be done.
22130
22131@findex COMPLETE_FILENAME
22132@findex gdb.COMPLETE_FILENAME
22133@item COMPLETE_FILENAME
22134This constant means that filename completion should be performed.
22135
22136@findex COMPLETE_LOCATION
22137@findex gdb.COMPLETE_LOCATION
22138@item COMPLETE_LOCATION
22139This constant means that location completion should be done.
22140@xref{Specify Location}.
22141
22142@findex COMPLETE_COMMAND
22143@findex gdb.COMPLETE_COMMAND
22144@item COMPLETE_COMMAND
22145This constant means that completion should examine @value{GDBN}
22146command names.
22147
22148@findex COMPLETE_SYMBOL
22149@findex gdb.COMPLETE_SYMBOL
22150@item COMPLETE_SYMBOL
22151This constant means that completion should be done using symbol names
22152as the source.
22153@end table
22154
22155The following code snippet shows how a trivial CLI command can be
22156implemented in Python:
22157
22158@smallexample
22159class HelloWorld (gdb.Command):
22160 """Greet the whole world."""
22161
22162 def __init__ (self):
22163 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE)
22164
22165 def invoke (self, arg, from_tty):
22166 print "Hello, World!"
22167
22168HelloWorld ()
22169@end smallexample
22170
22171The last line instantiates the class, and is necessary to trigger the
22172registration of the command with @value{GDBN}. Depending on how the
22173Python code is read into @value{GDBN}, you may need to import the
22174@code{gdb} module explicitly.
22175
d7b32ed3
PM
22176@node Parameters In Python
22177@subsubsection Parameters In Python
22178
22179@cindex parameters in python
22180@cindex python parameters
22181@tindex gdb.Parameter
22182@tindex Parameter
22183You can implement new @value{GDBN} parameters using Python. A new
22184parameter is implemented as an instance of the @code{gdb.Parameter}
22185class.
22186
22187Parameters are exposed to the user via the @code{set} and
22188@code{show} commands. @xref{Help}.
22189
22190There are many parameters that already exist and can be set in
22191@value{GDBN}. Two examples are: @code{set follow fork} and
22192@code{set charset}. Setting these parameters influences certain
22193behavior in @value{GDBN}. Similarly, you can define parameters that
22194can be used to influence behavior in custom Python scripts and commands.
22195
22196@defmethod Parameter __init__ name @var{command-class} @var{parameter-class} @r{[}@var{enum-sequence}@r{]}
22197The object initializer for @code{Parameter} registers the new
22198parameter with @value{GDBN}. This initializer is normally invoked
22199from the subclass' own @code{__init__} method.
22200
22201@var{name} is the name of the new parameter. If @var{name} consists
22202of multiple words, then the initial words are looked for as prefix
22203parameters. An example of this can be illustrated with the
22204@code{set print} set of parameters. If @var{name} is
22205@code{print foo}, then @code{print} will be searched as the prefix
22206parameter. In this case the parameter can subsequently be accessed in
22207@value{GDBN} as @code{set print foo}.
22208
22209If @var{name} consists of multiple words, and no prefix parameter group
22210can be found, an exception is raised.
22211
22212@var{command-class} should be one of the @samp{COMMAND_} constants
22213(@pxref{Commands In Python}). This argument tells @value{GDBN} how to
22214categorize the new parameter in the help system.
22215
22216@var{parameter-class} should be one of the @samp{PARAM_} constants
22217defined below. This argument tells @value{GDBN} the type of the new
22218parameter; this information is used for input validation and
22219completion.
22220
22221If @var{parameter-class} is @code{PARAM_ENUM}, then
22222@var{enum-sequence} must be a sequence of strings. These strings
22223represent the possible values for the parameter.
22224
22225If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
22226of a fourth argument will cause an exception to be thrown.
22227
22228The help text for the new parameter is taken from the Python
22229documentation string for the parameter's class, if there is one. If
22230there is no documentation string, a default value is used.
22231@end defmethod
22232
22233@defivar Parameter set_doc
22234If this attribute exists, and is a string, then its value is used as
22235the help text for this parameter's @code{set} command. The value is
22236examined when @code{Parameter.__init__} is invoked; subsequent changes
22237have no effect.
22238@end defivar
22239
22240@defivar Parameter show_doc
22241If this attribute exists, and is a string, then its value is used as
22242the help text for this parameter's @code{show} command. The value is
22243examined when @code{Parameter.__init__} is invoked; subsequent changes
22244have no effect.
22245@end defivar
22246
22247@defivar Parameter value
22248The @code{value} attribute holds the underlying value of the
22249parameter. It can be read and assigned to just as any other
22250attribute. @value{GDBN} does validation when assignments are made.
22251@end defivar
22252
22253
22254When a new parameter is defined, its type must be specified. The
22255available types are represented by constants defined in the @code{gdb}
22256module:
22257
22258@table @code
22259@findex PARAM_BOOLEAN
22260@findex gdb.PARAM_BOOLEAN
22261@item PARAM_BOOLEAN
22262The value is a plain boolean. The Python boolean values, @code{True}
22263and @code{False} are the only valid values.
22264
22265@findex PARAM_AUTO_BOOLEAN
22266@findex gdb.PARAM_AUTO_BOOLEAN
22267@item PARAM_AUTO_BOOLEAN
22268The value has three possible states: true, false, and @samp{auto}. In
22269Python, true and false are represented using boolean constants, and
22270@samp{auto} is represented using @code{None}.
22271
22272@findex PARAM_UINTEGER
22273@findex gdb.PARAM_UINTEGER
22274@item PARAM_UINTEGER
22275The value is an unsigned integer. The value of 0 should be
22276interpreted to mean ``unlimited''.
22277
22278@findex PARAM_INTEGER
22279@findex gdb.PARAM_INTEGER
22280@item PARAM_INTEGER
22281The value is a signed integer. The value of 0 should be interpreted
22282to mean ``unlimited''.
22283
22284@findex PARAM_STRING
22285@findex gdb.PARAM_STRING
22286@item PARAM_STRING
22287The value is a string. When the user modifies the string, any escape
22288sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
22289translated into corresponding characters and encoded into the current
22290host charset.
22291
22292@findex PARAM_STRING_NOESCAPE
22293@findex gdb.PARAM_STRING_NOESCAPE
22294@item PARAM_STRING_NOESCAPE
22295The value is a string. When the user modifies the string, escapes are
22296passed through untranslated.
22297
22298@findex PARAM_OPTIONAL_FILENAME
22299@findex gdb.PARAM_OPTIONAL_FILENAME
22300@item PARAM_OPTIONAL_FILENAME
22301The value is a either a filename (a string), or @code{None}.
22302
22303@findex PARAM_FILENAME
22304@findex gdb.PARAM_FILENAME
22305@item PARAM_FILENAME
22306The value is a filename. This is just like
22307@code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
22308
22309@findex PARAM_ZINTEGER
22310@findex gdb.PARAM_ZINTEGER
22311@item PARAM_ZINTEGER
22312The value is an integer. This is like @code{PARAM_INTEGER}, except 0
22313is interpreted as itself.
22314
22315@findex PARAM_ENUM
22316@findex gdb.PARAM_ENUM
22317@item PARAM_ENUM
22318The value is a string, which must be one of a collection string
22319constants provided when the parameter is created.
22320@end table
22321
bc3b79fd
TJB
22322@node Functions In Python
22323@subsubsection Writing new convenience functions
22324
22325@cindex writing convenience functions
22326@cindex convenience functions in python
22327@cindex python convenience functions
22328@tindex gdb.Function
22329@tindex Function
22330You can implement new convenience functions (@pxref{Convenience Vars})
22331in Python. A convenience function is an instance of a subclass of the
22332class @code{gdb.Function}.
22333
22334@defmethod Function __init__ name
22335The initializer for @code{Function} registers the new function with
22336@value{GDBN}. The argument @var{name} is the name of the function,
22337a string. The function will be visible to the user as a convenience
22338variable of type @code{internal function}, whose name is the same as
22339the given @var{name}.
22340
22341The documentation for the new function is taken from the documentation
22342string for the new class.
22343@end defmethod
22344
22345@defmethod Function invoke @var{*args}
22346When a convenience function is evaluated, its arguments are converted
22347to instances of @code{gdb.Value}, and then the function's
22348@code{invoke} method is called. Note that @value{GDBN} does not
22349predetermine the arity of convenience functions. Instead, all
22350available arguments are passed to @code{invoke}, following the
22351standard Python calling convention. In particular, a convenience
22352function can have default values for parameters without ill effect.
22353
22354The return value of this method is used as its value in the enclosing
22355expression. If an ordinary Python value is returned, it is converted
22356to a @code{gdb.Value} following the usual rules.
22357@end defmethod
22358
22359The following code snippet shows how a trivial convenience function can
22360be implemented in Python:
22361
22362@smallexample
22363class Greet (gdb.Function):
22364 """Return string to greet someone.
22365Takes a name as argument."""
22366
22367 def __init__ (self):
22368 super (Greet, self).__init__ ("greet")
22369
22370 def invoke (self, name):
22371 return "Hello, %s!" % name.string ()
22372
22373Greet ()
22374@end smallexample
22375
22376The last line instantiates the class, and is necessary to trigger the
22377registration of the function with @value{GDBN}. Depending on how the
22378Python code is read into @value{GDBN}, you may need to import the
22379@code{gdb} module explicitly.
22380
fa33c3cd
DE
22381@node Progspaces In Python
22382@subsubsection Program Spaces In Python
22383
22384@cindex progspaces in python
22385@tindex gdb.Progspace
22386@tindex Progspace
22387A program space, or @dfn{progspace}, represents a symbolic view
22388of an address space.
22389It consists of all of the objfiles of the program.
22390@xref{Objfiles In Python}.
22391@xref{Inferiors and Programs, program spaces}, for more details
22392about program spaces.
22393
22394The following progspace-related functions are available in the
22395@code{gdb} module:
22396
22397@findex gdb.current_progspace
22398@defun current_progspace
22399This function returns the program space of the currently selected inferior.
22400@xref{Inferiors and Programs}.
22401@end defun
22402
22403@findex gdb.progspaces
22404@defun progspaces
22405Return a sequence of all the progspaces currently known to @value{GDBN}.
22406@end defun
22407
22408Each progspace is represented by an instance of the @code{gdb.Progspace}
22409class.
22410
22411@defivar Progspace filename
22412The file name of the progspace as a string.
22413@end defivar
22414
22415@defivar Progspace pretty_printers
22416The @code{pretty_printers} attribute is a list of functions. It is
22417used to look up pretty-printers. A @code{Value} is passed to each
22418function in order; if the function returns @code{None}, then the
22419search continues. Otherwise, the return value should be an object
4c374409 22420which is used to format the value. @xref{Pretty Printing API}, for more
fa33c3cd
DE
22421information.
22422@end defivar
22423
89c73ade
TT
22424@node Objfiles In Python
22425@subsubsection Objfiles In Python
22426
22427@cindex objfiles in python
22428@tindex gdb.Objfile
22429@tindex Objfile
22430@value{GDBN} loads symbols for an inferior from various
22431symbol-containing files (@pxref{Files}). These include the primary
22432executable file, any shared libraries used by the inferior, and any
22433separate debug info files (@pxref{Separate Debug Files}).
22434@value{GDBN} calls these symbol-containing files @dfn{objfiles}.
22435
22436The following objfile-related functions are available in the
22437@code{gdb} module:
22438
22439@findex gdb.current_objfile
22440@defun current_objfile
22441When auto-loading a Python script (@pxref{Auto-loading}), @value{GDBN}
22442sets the ``current objfile'' to the corresponding objfile. This
22443function returns the current objfile. If there is no current objfile,
22444this function returns @code{None}.
22445@end defun
22446
22447@findex gdb.objfiles
22448@defun objfiles
22449Return a sequence of all the objfiles current known to @value{GDBN}.
22450@xref{Objfiles In Python}.
22451@end defun
22452
22453Each objfile is represented by an instance of the @code{gdb.Objfile}
22454class.
22455
22456@defivar Objfile filename
22457The file name of the objfile as a string.
22458@end defivar
22459
22460@defivar Objfile pretty_printers
22461The @code{pretty_printers} attribute is a list of functions. It is
22462used to look up pretty-printers. A @code{Value} is passed to each
22463function in order; if the function returns @code{None}, then the
22464search continues. Otherwise, the return value should be an object
4c374409 22465which is used to format the value. @xref{Pretty Printing API}, for more
a6bac58e 22466information.
89c73ade
TT
22467@end defivar
22468
f8f6f20b 22469@node Frames In Python
f3e9a817 22470@subsubsection Accessing inferior stack frames from Python.
f8f6f20b
TJB
22471
22472@cindex frames in python
22473When the debugged program stops, @value{GDBN} is able to analyze its call
22474stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
22475represents a frame in the stack. A @code{gdb.Frame} object is only valid
22476while its corresponding frame exists in the inferior's stack. If you try
621c8364
TT
22477to use an invalid frame object, @value{GDBN} will throw a @code{gdb.error}
22478exception (@pxref{Exception Handling}).
f8f6f20b
TJB
22479
22480Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
22481operator, like:
22482
22483@smallexample
22484(@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
22485True
22486@end smallexample
22487
22488The following frame-related functions are available in the @code{gdb} module:
22489
22490@findex gdb.selected_frame
22491@defun selected_frame
22492Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
22493@end defun
22494
22495@defun frame_stop_reason_string reason
22496Return a string explaining the reason why @value{GDBN} stopped unwinding
22497frames, as expressed by the given @var{reason} code (an integer, see the
22498@code{unwind_stop_reason} method further down in this section).
22499@end defun
22500
22501A @code{gdb.Frame} object has the following methods:
22502
22503@table @code
22504@defmethod Frame is_valid
22505Returns true if the @code{gdb.Frame} object is valid, false if not.
22506A frame object can become invalid if the frame it refers to doesn't
22507exist anymore in the inferior. All @code{gdb.Frame} methods will throw
22508an exception if it is invalid at the time the method is called.
22509@end defmethod
22510
22511@defmethod Frame name
22512Returns the function name of the frame, or @code{None} if it can't be
22513obtained.
22514@end defmethod
22515
22516@defmethod Frame type
22517Returns the type of the frame. The value can be one of
22518@code{gdb.NORMAL_FRAME}, @code{gdb.DUMMY_FRAME}, @code{gdb.SIGTRAMP_FRAME}
22519or @code{gdb.SENTINEL_FRAME}.
22520@end defmethod
22521
22522@defmethod Frame unwind_stop_reason
22523Return an integer representing the reason why it's not possible to find
22524more frames toward the outermost frame. Use
22525@code{gdb.frame_stop_reason_string} to convert the value returned by this
22526function to a string.
22527@end defmethod
22528
22529@defmethod Frame pc
22530Returns the frame's resume address.
22531@end defmethod
22532
f3e9a817
PM
22533@defmethod Frame block
22534Return the frame's code block. @xref{Blocks In Python}.
22535@end defmethod
22536
22537@defmethod Frame function
22538Return the symbol for the function corresponding to this frame.
22539@xref{Symbols In Python}.
22540@end defmethod
22541
f8f6f20b
TJB
22542@defmethod Frame older
22543Return the frame that called this frame.
22544@end defmethod
22545
22546@defmethod Frame newer
22547Return the frame called by this frame.
22548@end defmethod
22549
f3e9a817
PM
22550@defmethod Frame find_sal
22551Return the frame's symtab and line object.
22552@xref{Symbol Tables In Python}.
22553@end defmethod
22554
dc00d89f
PM
22555@defmethod Frame read_var variable @r{[}block@r{]}
22556Return the value of @var{variable} in this frame. If the optional
22557argument @var{block} is provided, search for the variable from that
22558block; otherwise start at the frame's current block (which is
22559determined by the frame's current program counter). @var{variable}
22560must be a string or a @code{gdb.Symbol} object. @var{block} must be a
22561@code{gdb.Block} object.
f8f6f20b 22562@end defmethod
f3e9a817
PM
22563
22564@defmethod Frame select
22565Set this frame to be the selected frame. @xref{Stack, ,Examining the
22566Stack}.
22567@end defmethod
22568@end table
22569
22570@node Blocks In Python
22571@subsubsection Accessing frame blocks from Python.
22572
22573@cindex blocks in python
22574@tindex gdb.Block
22575
22576Within each frame, @value{GDBN} maintains information on each block
22577stored in that frame. These blocks are organized hierarchically, and
22578are represented individually in Python as a @code{gdb.Block}.
22579Please see @ref{Frames In Python}, for a more in-depth discussion on
22580frames. Furthermore, see @ref{Stack, ,Examining the Stack}, for more
22581detailed technical information on @value{GDBN}'s book-keeping of the
22582stack.
22583
22584The following block-related functions are available in the @code{gdb}
22585module:
22586
22587@findex gdb.block_for_pc
22588@defun block_for_pc pc
22589Return the @code{gdb.Block} containing the given @var{pc} value. If the
22590block cannot be found for the @var{pc} value specified, the function
22591will return @code{None}.
22592@end defun
22593
22594A @code{gdb.Block} object has the following attributes:
22595
22596@table @code
22597@defivar Block start
22598The start address of the block. This attribute is not writable.
22599@end defivar
22600
22601@defivar Block end
22602The end address of the block. This attribute is not writable.
22603@end defivar
22604
22605@defivar Block function
22606The name of the block represented as a @code{gdb.Symbol}. If the
22607block is not named, then this attribute holds @code{None}. This
22608attribute is not writable.
22609@end defivar
22610
22611@defivar Block superblock
22612The block containing this block. If this parent block does not exist,
22613this attribute holds @code{None}. This attribute is not writable.
22614@end defivar
22615@end table
22616
22617@node Symbols In Python
22618@subsubsection Python representation of Symbols.
22619
22620@cindex symbols in python
22621@tindex gdb.Symbol
22622
22623@value{GDBN} represents every variable, function and type as an
22624entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}.
22625Similarly, Python represents these symbols in @value{GDBN} with the
22626@code{gdb.Symbol} object.
22627
22628The following symbol-related functions are available in the @code{gdb}
22629module:
22630
22631@findex gdb.lookup_symbol
22632@defun lookup_symbol name [block] [domain]
22633This function searches for a symbol by name. The search scope can be
22634restricted to the parameters defined in the optional domain and block
22635arguments.
22636
22637@var{name} is the name of the symbol. It must be a string. The
22638optional @var{block} argument restricts the search to symbols visible
22639in that @var{block}. The @var{block} argument must be a
22640@code{gdb.Block} object. The optional @var{domain} argument restricts
22641the search to the domain type. The @var{domain} argument must be a
22642domain constant defined in the @code{gdb} module and described later
22643in this chapter.
22644@end defun
22645
22646A @code{gdb.Symbol} object has the following attributes:
22647
22648@table @code
22649@defivar Symbol symtab
22650The symbol table in which the symbol appears. This attribute is
22651represented as a @code{gdb.Symtab} object. @xref{Symbol Tables In
22652Python}. This attribute is not writable.
22653@end defivar
22654
22655@defivar Symbol name
22656The name of the symbol as a string. This attribute is not writable.
22657@end defivar
22658
22659@defivar Symbol linkage_name
22660The name of the symbol, as used by the linker (i.e., may be mangled).
22661This attribute is not writable.
22662@end defivar
22663
22664@defivar Symbol print_name
22665The name of the symbol in a form suitable for output. This is either
22666@code{name} or @code{linkage_name}, depending on whether the user
22667asked @value{GDBN} to display demangled or mangled names.
22668@end defivar
22669
22670@defivar Symbol addr_class
22671The address class of the symbol. This classifies how to find the value
22672of a symbol. Each address class is a constant defined in the
22673@code{gdb} module and described later in this chapter.
22674@end defivar
22675
22676@defivar Symbol is_argument
22677@code{True} if the symbol is an argument of a function.
22678@end defivar
22679
22680@defivar Symbol is_constant
22681@code{True} if the symbol is a constant.
22682@end defivar
22683
22684@defivar Symbol is_function
22685@code{True} if the symbol is a function or a method.
22686@end defivar
22687
22688@defivar Symbol is_variable
22689@code{True} if the symbol is a variable.
22690@end defivar
22691@end table
22692
22693The available domain categories in @code{gdb.Symbol} are represented
22694as constants in the @code{gdb} module:
22695
22696@table @code
22697@findex SYMBOL_UNDEF_DOMAIN
22698@findex gdb.SYMBOL_UNDEF_DOMAIN
22699@item SYMBOL_UNDEF_DOMAIN
22700This is used when a domain has not been discovered or none of the
22701following domains apply. This usually indicates an error either
22702in the symbol information or in @value{GDBN}'s handling of symbols.
22703@findex SYMBOL_VAR_DOMAIN
22704@findex gdb.SYMBOL_VAR_DOMAIN
22705@item SYMBOL_VAR_DOMAIN
22706This domain contains variables, function names, typedef names and enum
22707type values.
22708@findex SYMBOL_STRUCT_DOMAIN
22709@findex gdb.SYMBOL_STRUCT_DOMAIN
22710@item SYMBOL_STRUCT_DOMAIN
22711This domain holds struct, union and enum type names.
22712@findex SYMBOL_LABEL_DOMAIN
22713@findex gdb.SYMBOL_LABEL_DOMAIN
22714@item SYMBOL_LABEL_DOMAIN
22715This domain contains names of labels (for gotos).
22716@findex SYMBOL_VARIABLES_DOMAIN
22717@findex gdb.SYMBOL_VARIABLES_DOMAIN
22718@item SYMBOL_VARIABLES_DOMAIN
22719This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
22720contains everything minus functions and types.
22721@findex SYMBOL_FUNCTIONS_DOMAIN
22722@findex gdb.SYMBOL_FUNCTIONS_DOMAIN
22723@item SYMBOL_FUNCTION_DOMAIN
22724This domain contains all functions.
22725@findex SYMBOL_TYPES_DOMAIN
22726@findex gdb.SYMBOL_TYPES_DOMAIN
22727@item SYMBOL_TYPES_DOMAIN
22728This domain contains all types.
22729@end table
22730
22731The available address class categories in @code{gdb.Symbol} are represented
22732as constants in the @code{gdb} module:
22733
22734@table @code
22735@findex SYMBOL_LOC_UNDEF
22736@findex gdb.SYMBOL_LOC_UNDEF
22737@item SYMBOL_LOC_UNDEF
22738If this is returned by address class, it indicates an error either in
22739the symbol information or in @value{GDBN}'s handling of symbols.
22740@findex SYMBOL_LOC_CONST
22741@findex gdb.SYMBOL_LOC_CONST
22742@item SYMBOL_LOC_CONST
22743Value is constant int.
22744@findex SYMBOL_LOC_STATIC
22745@findex gdb.SYMBOL_LOC_STATIC
22746@item SYMBOL_LOC_STATIC
22747Value is at a fixed address.
22748@findex SYMBOL_LOC_REGISTER
22749@findex gdb.SYMBOL_LOC_REGISTER
22750@item SYMBOL_LOC_REGISTER
22751Value is in a register.
22752@findex SYMBOL_LOC_ARG
22753@findex gdb.SYMBOL_LOC_ARG
22754@item SYMBOL_LOC_ARG
22755Value is an argument. This value is at the offset stored within the
22756symbol inside the frame's argument list.
22757@findex SYMBOL_LOC_REF_ARG
22758@findex gdb.SYMBOL_LOC_REF_ARG
22759@item SYMBOL_LOC_REF_ARG
22760Value address is stored in the frame's argument list. Just like
22761@code{LOC_ARG} except that the value's address is stored at the
22762offset, not the value itself.
22763@findex SYMBOL_LOC_REGPARM_ADDR
22764@findex gdb.SYMBOL_LOC_REGPARM_ADDR
22765@item SYMBOL_LOC_REGPARM_ADDR
22766Value is a specified register. Just like @code{LOC_REGISTER} except
22767the register holds the address of the argument instead of the argument
22768itself.
22769@findex SYMBOL_LOC_LOCAL
22770@findex gdb.SYMBOL_LOC_LOCAL
22771@item SYMBOL_LOC_LOCAL
22772Value is a local variable.
22773@findex SYMBOL_LOC_TYPEDEF
22774@findex gdb.SYMBOL_LOC_TYPEDEF
22775@item SYMBOL_LOC_TYPEDEF
22776Value not used. Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
22777have this class.
22778@findex SYMBOL_LOC_BLOCK
22779@findex gdb.SYMBOL_LOC_BLOCK
22780@item SYMBOL_LOC_BLOCK
22781Value is a block.
22782@findex SYMBOL_LOC_CONST_BYTES
22783@findex gdb.SYMBOL_LOC_CONST_BYTES
22784@item SYMBOL_LOC_CONST_BYTES
22785Value is a byte-sequence.
22786@findex SYMBOL_LOC_UNRESOLVED
22787@findex gdb.SYMBOL_LOC_UNRESOLVED
22788@item SYMBOL_LOC_UNRESOLVED
22789Value is at a fixed address, but the address of the variable has to be
22790determined from the minimal symbol table whenever the variable is
22791referenced.
22792@findex SYMBOL_LOC_OPTIMIZED_OUT
22793@findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
22794@item SYMBOL_LOC_OPTIMIZED_OUT
22795The value does not actually exist in the program.
22796@findex SYMBOL_LOC_COMPUTED
22797@findex gdb.SYMBOL_LOC_COMPUTED
22798@item SYMBOL_LOC_COMPUTED
22799The value's address is a computed location.
22800@end table
22801
22802@node Symbol Tables In Python
22803@subsubsection Symbol table representation in Python.
22804
22805@cindex symbol tables in python
22806@tindex gdb.Symtab
22807@tindex gdb.Symtab_and_line
22808
22809Access to symbol table data maintained by @value{GDBN} on the inferior
22810is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
22811@code{gdb.Symtab}. Symbol table and line data for a frame is returned
22812from the @code{find_sal} method in @code{gdb.Frame} object.
22813@xref{Frames In Python}.
22814
22815For more information on @value{GDBN}'s symbol table management, see
22816@ref{Symbols, ,Examining the Symbol Table}, for more information.
22817
22818A @code{gdb.Symtab_and_line} object has the following attributes:
22819
22820@table @code
22821@defivar Symtab_and_line symtab
22822The symbol table object (@code{gdb.Symtab}) for this frame.
22823This attribute is not writable.
22824@end defivar
22825
22826@defivar Symtab_and_line pc
22827Indicates the current program counter address. This attribute is not
22828writable.
22829@end defivar
22830
22831@defivar Symtab_and_line line
22832Indicates the current line number for this object. This
22833attribute is not writable.
22834@end defivar
22835@end table
22836
22837A @code{gdb.Symtab} object has the following attributes:
22838
22839@table @code
22840@defivar Symtab filename
22841The symbol table's source filename. This attribute is not writable.
22842@end defivar
22843
22844@defivar Symtab objfile
22845The symbol table's backing object file. @xref{Objfiles In Python}.
22846This attribute is not writable.
22847@end defivar
22848@end table
22849
22850The following methods are provided:
22851
22852@table @code
22853@defmethod Symtab fullname
22854Return the symbol table's source absolute file name.
22855@end defmethod
f8f6f20b
TJB
22856@end table
22857
adc36818
PM
22858@node Breakpoints In Python
22859@subsubsection Manipulating breakpoints using Python
22860
22861@cindex breakpoints in python
22862@tindex gdb.Breakpoint
22863
22864Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
22865class.
22866
84f4c1fe 22867@defmethod Breakpoint __init__ spec @r{[}type@r{]} @r{[}wp_class@r{]} @r{[}internal@r{]}
adc36818
PM
22868Create a new breakpoint. @var{spec} is a string naming the
22869location of the breakpoint, or an expression that defines a
22870watchpoint. The contents can be any location recognized by the
22871@code{break} command, or in the case of a watchpoint, by the @code{watch}
22872command. The optional @var{type} denotes the breakpoint to create
22873from the types defined later in this chapter. This argument can be
22874either: @code{BP_BREAKPOINT} or @code{BP_WATCHPOINT}. @var{type}
84f4c1fe
PM
22875defaults to @code{BP_BREAKPOINT}. The optional @var{internal} argument
22876allows the breakpoint to become invisible to the user. The breakpoint
22877will neither be reported when created, nor will it be listed in the
22878output from @code{info breakpoints} (but will be listed with the
22879@code{maint info breakpoints} command). The optional @var{wp_class}
adc36818 22880argument defines the class of watchpoint to create, if @var{type} is
84f4c1fe
PM
22881@code{BP_WATCHPOINT}. If a watchpoint class is not provided, it is
22882assumed to be a @var{WP_WRITE} class.
adc36818
PM
22883@end defmethod
22884
22885The available watchpoint types represented by constants are defined in the
22886@code{gdb} module:
22887
22888@table @code
22889@findex WP_READ
22890@findex gdb.WP_READ
22891@item WP_READ
22892Read only watchpoint.
22893
22894@findex WP_WRITE
22895@findex gdb.WP_WRITE
22896@item WP_WRITE
22897Write only watchpoint.
22898
22899@findex WP_ACCESS
22900@findex gdb.WP_ACCESS
22901@item WP_ACCESS
22902Read/Write watchpoint.
22903@end table
22904
22905@defmethod Breakpoint is_valid
22906Return @code{True} if this @code{Breakpoint} object is valid,
22907@code{False} otherwise. A @code{Breakpoint} object can become invalid
22908if the user deletes the breakpoint. In this case, the object still
22909exists, but the underlying breakpoint does not. In the cases of
22910watchpoint scope, the watchpoint remains valid even if execution of the
22911inferior leaves the scope of that watchpoint.
22912@end defmethod
22913
94b6973e
PM
22914@defmethod Breakpoint delete
22915Permanently deletes the @value{GDBN} breakpoint. This also
22916invalidates the Python @code{Breakpoint} object. Any further access
22917to this object's attributes or methods will raise an error.
22918@end defmethod
22919
adc36818
PM
22920@defivar Breakpoint enabled
22921This attribute is @code{True} if the breakpoint is enabled, and
22922@code{False} otherwise. This attribute is writable.
22923@end defivar
22924
22925@defivar Breakpoint silent
22926This attribute is @code{True} if the breakpoint is silent, and
22927@code{False} otherwise. This attribute is writable.
22928
22929Note that a breakpoint can also be silent if it has commands and the
22930first command is @code{silent}. This is not reported by the
22931@code{silent} attribute.
22932@end defivar
22933
22934@defivar Breakpoint thread
22935If the breakpoint is thread-specific, this attribute holds the thread
22936id. If the breakpoint is not thread-specific, this attribute is
22937@code{None}. This attribute is writable.
22938@end defivar
22939
22940@defivar Breakpoint task
22941If the breakpoint is Ada task-specific, this attribute holds the Ada task
22942id. If the breakpoint is not task-specific (or the underlying
22943language is not Ada), this attribute is @code{None}. This attribute
22944is writable.
22945@end defivar
22946
22947@defivar Breakpoint ignore_count
22948This attribute holds the ignore count for the breakpoint, an integer.
22949This attribute is writable.
22950@end defivar
22951
22952@defivar Breakpoint number
22953This attribute holds the breakpoint's number --- the identifier used by
22954the user to manipulate the breakpoint. This attribute is not writable.
22955@end defivar
22956
22957@defivar Breakpoint type
22958This attribute holds the breakpoint's type --- the identifier used to
22959determine the actual breakpoint type or use-case. This attribute is not
22960writable.
22961@end defivar
22962
84f4c1fe
PM
22963@defivar Breakpoint visible
22964This attribute tells whether the breakpoint is visible to the user
22965when set, or when the @samp{info breakpoints} command is run. This
22966attribute is not writable.
22967@end defivar
22968
adc36818
PM
22969The available types are represented by constants defined in the @code{gdb}
22970module:
22971
22972@table @code
22973@findex BP_BREAKPOINT
22974@findex gdb.BP_BREAKPOINT
22975@item BP_BREAKPOINT
22976Normal code breakpoint.
22977
22978@findex BP_WATCHPOINT
22979@findex gdb.BP_WATCHPOINT
22980@item BP_WATCHPOINT
22981Watchpoint breakpoint.
22982
22983@findex BP_HARDWARE_WATCHPOINT
22984@findex gdb.BP_HARDWARE_WATCHPOINT
22985@item BP_HARDWARE_WATCHPOINT
22986Hardware assisted watchpoint.
22987
22988@findex BP_READ_WATCHPOINT
22989@findex gdb.BP_READ_WATCHPOINT
22990@item BP_READ_WATCHPOINT
22991Hardware assisted read watchpoint.
22992
22993@findex BP_ACCESS_WATCHPOINT
22994@findex gdb.BP_ACCESS_WATCHPOINT
22995@item BP_ACCESS_WATCHPOINT
22996Hardware assisted access watchpoint.
22997@end table
22998
22999@defivar Breakpoint hit_count
23000This attribute holds the hit count for the breakpoint, an integer.
23001This attribute is writable, but currently it can only be set to zero.
23002@end defivar
23003
23004@defivar Breakpoint location
23005This attribute holds the location of the breakpoint, as specified by
23006the user. It is a string. If the breakpoint does not have a location
23007(that is, it is a watchpoint) the attribute's value is @code{None}. This
23008attribute is not writable.
23009@end defivar
23010
23011@defivar Breakpoint expression
23012This attribute holds a breakpoint expression, as specified by
23013the user. It is a string. If the breakpoint does not have an
23014expression (the breakpoint is not a watchpoint) the attribute's value
23015is @code{None}. This attribute is not writable.
23016@end defivar
23017
23018@defivar Breakpoint condition
23019This attribute holds the condition of the breakpoint, as specified by
23020the user. It is a string. If there is no condition, this attribute's
23021value is @code{None}. This attribute is writable.
23022@end defivar
23023
23024@defivar Breakpoint commands
23025This attribute holds the commands attached to the breakpoint. If
23026there are commands, this attribute's value is a string holding all the
23027commands, separated by newlines. If there are no commands, this
23028attribute is @code{None}. This attribute is not writable.
23029@end defivar
23030
be759fcf
PM
23031@node Lazy Strings In Python
23032@subsubsection Python representation of lazy strings.
23033
23034@cindex lazy strings in python
23035@tindex gdb.LazyString
23036
23037A @dfn{lazy string} is a string whose contents is not retrieved or
23038encoded until it is needed.
23039
23040A @code{gdb.LazyString} is represented in @value{GDBN} as an
23041@code{address} that points to a region of memory, an @code{encoding}
23042that will be used to encode that region of memory, and a @code{length}
23043to delimit the region of memory that represents the string. The
23044difference between a @code{gdb.LazyString} and a string wrapped within
23045a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
23046differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
23047retrieved and encoded during printing, while a @code{gdb.Value}
23048wrapping a string is immediately retrieved and encoded on creation.
23049
23050A @code{gdb.LazyString} object has the following functions:
23051
23052@defmethod LazyString value
23053Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
23054will point to the string in memory, but will lose all the delayed
23055retrieval, encoding and handling that @value{GDBN} applies to a
23056@code{gdb.LazyString}.
23057@end defmethod
23058
23059@defivar LazyString address
23060This attribute holds the address of the string. This attribute is not
23061writable.
23062@end defivar
23063
23064@defivar LazyString length
23065This attribute holds the length of the string in characters. If the
23066length is -1, then the string will be fetched and encoded up to the
23067first null of appropriate width. This attribute is not writable.
23068@end defivar
23069
23070@defivar LazyString encoding
23071This attribute holds the encoding that will be applied to the string
23072when the string is printed by @value{GDBN}. If the encoding is not
23073set, or contains an empty string, then @value{GDBN} will select the
23074most appropriate encoding when the string is printed. This attribute
23075is not writable.
23076@end defivar
23077
23078@defivar LazyString type
23079This attribute holds the type that is represented by the lazy string's
23080type. For a lazy string this will always be a pointer type. To
23081resolve this to the lazy string's character type, use the type's
23082@code{target} method. @xref{Types In Python}. This attribute is not
23083writable.
23084@end defivar
23085
8a1ea21f
DE
23086@node Auto-loading
23087@subsection Auto-loading
23088@cindex auto-loading, Python
23089
23090When a new object file is read (for example, due to the @code{file}
23091command, or because the inferior has loaded a shared library),
23092@value{GDBN} will look for Python support scripts in several ways:
23093@file{@var{objfile}-gdb.py} and @code{.debug_gdb_scripts} section.
23094
23095@menu
23096* objfile-gdb.py file:: The @file{@var{objfile}-gdb.py} file
23097* .debug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
23098* Which flavor to choose?::
23099@end menu
23100
23101The auto-loading feature is useful for supplying application-specific
23102debugging commands and scripts.
23103
23104Auto-loading can be enabled or disabled.
23105
23106@table @code
23107@kindex maint set python auto-load
23108@item maint set python auto-load [yes|no]
23109Enable or disable the Python auto-loading feature.
23110
23111@kindex maint show python auto-load
23112@item maint show python auto-load
23113Show whether Python auto-loading is enabled or disabled.
23114@end table
23115
23116When reading an auto-loaded file, @value{GDBN} sets the
23117@dfn{current objfile}. This is available via the @code{gdb.current_objfile}
23118function (@pxref{Objfiles In Python}). This can be useful for
23119registering objfile-specific pretty-printers.
23120
23121@node objfile-gdb.py file
23122@subsubsection The @file{@var{objfile}-gdb.py} file
23123@cindex @file{@var{objfile}-gdb.py}
23124
23125When a new object file is read, @value{GDBN} looks for
23126a file named @file{@var{objfile}-gdb.py},
23127where @var{objfile} is the object file's real name, formed by ensuring
23128that the file name is absolute, following all symlinks, and resolving
23129@code{.} and @code{..} components. If this file exists and is
23130readable, @value{GDBN} will evaluate it as a Python script.
23131
23132If this file does not exist, and if the parameter
23133@code{debug-file-directory} is set (@pxref{Separate Debug Files}),
23134then @value{GDBN} will look for @var{real-name} in all of the
23135directories mentioned in the value of @code{debug-file-directory}.
23136
23137Finally, if this file does not exist, then @value{GDBN} will look for
23138a file named @file{@var{data-directory}/python/auto-load/@var{real-name}}, where
23139@var{data-directory} is @value{GDBN}'s data directory (available via
23140@code{show data-directory}, @pxref{Data Files}), and @var{real-name}
23141is the object file's real name, as described above.
23142
23143@value{GDBN} does not track which files it has already auto-loaded this way.
23144@value{GDBN} will load the associated script every time the corresponding
23145@var{objfile} is opened.
23146So your @file{-gdb.py} file should be careful to avoid errors if it
23147is evaluated more than once.
23148
23149@node .debug_gdb_scripts section
23150@subsubsection The @code{.debug_gdb_scripts} section
23151@cindex @code{.debug_gdb_scripts} section
23152
23153For systems using file formats like ELF and COFF,
23154when @value{GDBN} loads a new object file
23155it will look for a special section named @samp{.debug_gdb_scripts}.
23156If this section exists, its contents is a list of names of scripts to load.
23157
23158@value{GDBN} will look for each specified script file first in the
23159current directory and then along the source search path
23160(@pxref{Source Path, ,Specifying Source Directories}),
23161except that @file{$cdir} is not searched, since the compilation
23162directory is not relevant to scripts.
23163
23164Entries can be placed in section @code{.debug_gdb_scripts} with,
23165for example, this GCC macro:
23166
23167@example
a3a7127e 23168/* Note: The "MS" section flags are to remove duplicates. */
8a1ea21f
DE
23169#define DEFINE_GDB_SCRIPT(script_name) \
23170 asm("\
23171.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
23172.byte 1\n\
23173.asciz \"" script_name "\"\n\
23174.popsection \n\
23175");
23176@end example
23177
23178@noindent
23179Then one can reference the macro in a header or source file like this:
23180
23181@example
23182DEFINE_GDB_SCRIPT ("my-app-scripts.py")
23183@end example
23184
23185The script name may include directories if desired.
23186
23187If the macro is put in a header, any application or library
23188using this header will get a reference to the specified script.
23189
23190@node Which flavor to choose?
23191@subsubsection Which flavor to choose?
23192
23193Given the multiple ways of auto-loading Python scripts, it might not always
23194be clear which one to choose. This section provides some guidance.
23195
23196Benefits of the @file{-gdb.py} way:
23197
23198@itemize @bullet
23199@item
23200Can be used with file formats that don't support multiple sections.
23201
23202@item
23203Ease of finding scripts for public libraries.
23204
23205Scripts specified in the @code{.debug_gdb_scripts} section are searched for
23206in the source search path.
23207For publicly installed libraries, e.g., @file{libstdc++}, there typically
23208isn't a source directory in which to find the script.
23209
23210@item
23211Doesn't require source code additions.
23212@end itemize
23213
23214Benefits of the @code{.debug_gdb_scripts} way:
23215
23216@itemize @bullet
23217@item
23218Works with static linking.
23219
23220Scripts for libraries done the @file{-gdb.py} way require an objfile to
23221trigger their loading. When an application is statically linked the only
23222objfile available is the executable, and it is cumbersome to attach all the
23223scripts from all the input libraries to the executable's @file{-gdb.py} script.
23224
23225@item
23226Works with classes that are entirely inlined.
23227
23228Some classes can be entirely inlined, and thus there may not be an associated
23229shared library to attach a @file{-gdb.py} script to.
23230
23231@item
23232Scripts needn't be copied out of the source tree.
23233
23234In some circumstances, apps can be built out of large collections of internal
23235libraries, and the build infrastructure necessary to install the
23236@file{-gdb.py} scripts in a place where @value{GDBN} can find them is
23237cumbersome. It may be easier to specify the scripts in the
23238@code{.debug_gdb_scripts} section as relative paths, and add a path to the
23239top of the source tree to the source search path.
23240@end itemize
23241
0e3509db
DE
23242@node Python modules
23243@subsection Python modules
23244@cindex python modules
23245
0e3509db
DE
23246@value{GDBN} comes with a module to assist writing Python code.
23247
23248@menu
7b51bc51 23249* gdb.printing:: Building and registering pretty-printers.
0e3509db
DE
23250* gdb.types:: Utilities for working with types.
23251@end menu
23252
7b51bc51
DE
23253@node gdb.printing
23254@subsubsection gdb.printing
23255@cindex gdb.printing
23256
23257This module provides a collection of utilities for working with
23258pretty-printers.
23259
23260@table @code
23261@item PrettyPrinter (@var{name}, @var{subprinters}=None)
23262This class specifies the API that makes @samp{info pretty-printer},
23263@samp{enable pretty-printer} and @samp{disable pretty-printer} work.
23264Pretty-printers should generally inherit from this class.
23265
23266@item SubPrettyPrinter (@var{name})
23267For printers that handle multiple types, this class specifies the
23268corresponding API for the subprinters.
23269
23270@item RegexpCollectionPrettyPrinter (@var{name})
23271Utility class for handling multiple printers, all recognized via
23272regular expressions.
23273@xref{Writing a Pretty-Printer}, for an example.
23274
23275@item register_pretty_printer (@var{obj}, @var{printer})
23276Register @var{printer} with the pretty-printer list of @var{obj}.
23277@end table
23278
0e3509db
DE
23279@node gdb.types
23280@subsubsection gdb.types
7b51bc51 23281@cindex gdb.types
0e3509db
DE
23282
23283This module provides a collection of utilities for working with
23284@code{gdb.Types} objects.
23285
23286@table @code
23287@item get_basic_type (@var{type})
23288Return @var{type} with const and volatile qualifiers stripped,
23289and with typedefs and C@t{++} references converted to the underlying type.
23290
23291C@t{++} example:
23292
23293@smallexample
23294typedef const int const_int;
23295const_int foo (3);
23296const_int& foo_ref (foo);
23297int main () @{ return 0; @}
23298@end smallexample
23299
23300Then in gdb:
23301
23302@smallexample
23303(gdb) start
23304(gdb) python import gdb.types
23305(gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
23306(gdb) python print gdb.types.get_basic_type(foo_ref.type)
23307int
23308@end smallexample
23309
23310@item has_field (@var{type}, @var{field})
23311Return @code{True} if @var{type}, assumed to be a type with fields
23312(e.g., a structure or union), has field @var{field}.
23313
23314@item make_enum_dict (@var{enum_type})
23315Return a Python @code{dictionary} type produced from @var{enum_type}.
23316@end table
23317
21c294e6
AC
23318@node Interpreters
23319@chapter Command Interpreters
23320@cindex command interpreters
23321
23322@value{GDBN} supports multiple command interpreters, and some command
23323infrastructure to allow users or user interface writers to switch
23324between interpreters or run commands in other interpreters.
23325
23326@value{GDBN} currently supports two command interpreters, the console
23327interpreter (sometimes called the command-line interpreter or @sc{cli})
23328and the machine interface interpreter (or @sc{gdb/mi}). This manual
23329describes both of these interfaces in great detail.
23330
23331By default, @value{GDBN} will start with the console interpreter.
23332However, the user may choose to start @value{GDBN} with another
23333interpreter by specifying the @option{-i} or @option{--interpreter}
23334startup options. Defined interpreters include:
23335
23336@table @code
23337@item console
23338@cindex console interpreter
23339The traditional console or command-line interpreter. This is the most often
23340used interpreter with @value{GDBN}. With no interpreter specified at runtime,
23341@value{GDBN} will use this interpreter.
23342
23343@item mi
23344@cindex mi interpreter
23345The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
23346by programs wishing to use @value{GDBN} as a backend for a debugger GUI
23347or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
23348Interface}.
23349
23350@item mi2
23351@cindex mi2 interpreter
23352The current @sc{gdb/mi} interface.
23353
23354@item mi1
23355@cindex mi1 interpreter
23356The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
23357
23358@end table
23359
23360@cindex invoke another interpreter
23361The interpreter being used by @value{GDBN} may not be dynamically
23362switched at runtime. Although possible, this could lead to a very
23363precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
23364enters the command "interpreter-set console" in a console view,
23365@value{GDBN} would switch to using the console interpreter, rendering
23366the IDE inoperable!
23367
23368@kindex interpreter-exec
23369Although you may only choose a single interpreter at startup, you may execute
23370commands in any interpreter from the current interpreter using the appropriate
23371command. If you are running the console interpreter, simply use the
23372@code{interpreter-exec} command:
23373
23374@smallexample
23375interpreter-exec mi "-data-list-register-names"
23376@end smallexample
23377
23378@sc{gdb/mi} has a similar command, although it is only available in versions of
23379@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
23380
8e04817f
AC
23381@node TUI
23382@chapter @value{GDBN} Text User Interface
23383@cindex TUI
d0d5df6f 23384@cindex Text User Interface
c906108c 23385
8e04817f
AC
23386@menu
23387* TUI Overview:: TUI overview
23388* TUI Keys:: TUI key bindings
7cf36c78 23389* TUI Single Key Mode:: TUI single key mode
db2e3e2e 23390* TUI Commands:: TUI-specific commands
8e04817f
AC
23391* TUI Configuration:: TUI configuration variables
23392@end menu
c906108c 23393
46ba6afa 23394The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
23395interface which uses the @code{curses} library to show the source
23396file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
23397commands in separate text windows. The TUI mode is supported only
23398on platforms where a suitable version of the @code{curses} library
23399is available.
d0d5df6f 23400
46ba6afa
BW
23401@pindex @value{GDBTUI}
23402The TUI mode is enabled by default when you invoke @value{GDBN} as
23403either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
23404You can also switch in and out of TUI mode while @value{GDBN} runs by
23405using various TUI commands and key bindings, such as @kbd{C-x C-a}.
23406@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 23407
8e04817f 23408@node TUI Overview
79a6e687 23409@section TUI Overview
c906108c 23410
46ba6afa 23411In TUI mode, @value{GDBN} can display several text windows:
c906108c 23412
8e04817f
AC
23413@table @emph
23414@item command
23415This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
23416prompt and the @value{GDBN} output. The @value{GDBN} input is still
23417managed using readline.
c906108c 23418
8e04817f
AC
23419@item source
23420The source window shows the source file of the program. The current
46ba6afa 23421line and active breakpoints are displayed in this window.
c906108c 23422
8e04817f
AC
23423@item assembly
23424The assembly window shows the disassembly output of the program.
c906108c 23425
8e04817f 23426@item register
46ba6afa
BW
23427This window shows the processor registers. Registers are highlighted
23428when their values change.
c906108c
SS
23429@end table
23430
269c21fe 23431The source and assembly windows show the current program position
46ba6afa
BW
23432by highlighting the current line and marking it with a @samp{>} marker.
23433Breakpoints are indicated with two markers. The first marker
269c21fe
SC
23434indicates the breakpoint type:
23435
23436@table @code
23437@item B
23438Breakpoint which was hit at least once.
23439
23440@item b
23441Breakpoint which was never hit.
23442
23443@item H
23444Hardware breakpoint which was hit at least once.
23445
23446@item h
23447Hardware breakpoint which was never hit.
269c21fe
SC
23448@end table
23449
23450The second marker indicates whether the breakpoint is enabled or not:
23451
23452@table @code
23453@item +
23454Breakpoint is enabled.
23455
23456@item -
23457Breakpoint is disabled.
269c21fe
SC
23458@end table
23459
46ba6afa
BW
23460The source, assembly and register windows are updated when the current
23461thread changes, when the frame changes, or when the program counter
23462changes.
23463
23464These windows are not all visible at the same time. The command
23465window is always visible. The others can be arranged in several
23466layouts:
c906108c 23467
8e04817f
AC
23468@itemize @bullet
23469@item
46ba6afa 23470source only,
2df3850c 23471
8e04817f 23472@item
46ba6afa 23473assembly only,
8e04817f
AC
23474
23475@item
46ba6afa 23476source and assembly,
8e04817f
AC
23477
23478@item
46ba6afa 23479source and registers, or
c906108c 23480
8e04817f 23481@item
46ba6afa 23482assembly and registers.
8e04817f 23483@end itemize
c906108c 23484
46ba6afa 23485A status line above the command window shows the following information:
b7bb15bc
SC
23486
23487@table @emph
23488@item target
46ba6afa 23489Indicates the current @value{GDBN} target.
b7bb15bc
SC
23490(@pxref{Targets, ,Specifying a Debugging Target}).
23491
23492@item process
46ba6afa 23493Gives the current process or thread number.
b7bb15bc
SC
23494When no process is being debugged, this field is set to @code{No process}.
23495
23496@item function
23497Gives the current function name for the selected frame.
23498The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 23499When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
23500the string @code{??} is displayed.
23501
23502@item line
23503Indicates the current line number for the selected frame.
46ba6afa 23504When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
23505
23506@item pc
23507Indicates the current program counter address.
b7bb15bc
SC
23508@end table
23509
8e04817f
AC
23510@node TUI Keys
23511@section TUI Key Bindings
23512@cindex TUI key bindings
c906108c 23513
8e04817f 23514The TUI installs several key bindings in the readline keymaps
39037522
TT
23515@ifset SYSTEM_READLINE
23516(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
23517@end ifset
23518@ifclear SYSTEM_READLINE
23519(@pxref{Command Line Editing}).
23520@end ifclear
23521The following key bindings are installed for both TUI mode and the
23522@value{GDBN} standard mode.
c906108c 23523
8e04817f
AC
23524@table @kbd
23525@kindex C-x C-a
23526@item C-x C-a
23527@kindex C-x a
23528@itemx C-x a
23529@kindex C-x A
23530@itemx C-x A
46ba6afa
BW
23531Enter or leave the TUI mode. When leaving the TUI mode,
23532the curses window management stops and @value{GDBN} operates using
23533its standard mode, writing on the terminal directly. When reentering
23534the TUI mode, control is given back to the curses windows.
8e04817f 23535The screen is then refreshed.
c906108c 23536
8e04817f
AC
23537@kindex C-x 1
23538@item C-x 1
23539Use a TUI layout with only one window. The layout will
23540either be @samp{source} or @samp{assembly}. When the TUI mode
23541is not active, it will switch to the TUI mode.
2df3850c 23542
8e04817f 23543Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 23544
8e04817f
AC
23545@kindex C-x 2
23546@item C-x 2
23547Use a TUI layout with at least two windows. When the current
46ba6afa 23548layout already has two windows, the next layout with two windows is used.
8e04817f
AC
23549When a new layout is chosen, one window will always be common to the
23550previous layout and the new one.
c906108c 23551
8e04817f 23552Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 23553
72ffddc9
SC
23554@kindex C-x o
23555@item C-x o
23556Change the active window. The TUI associates several key bindings
46ba6afa 23557(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
23558gives the focus to the next TUI window.
23559
23560Think of it as the Emacs @kbd{C-x o} binding.
23561
7cf36c78
SC
23562@kindex C-x s
23563@item C-x s
46ba6afa
BW
23564Switch in and out of the TUI SingleKey mode that binds single
23565keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
23566@end table
23567
46ba6afa 23568The following key bindings only work in the TUI mode:
5d161b24 23569
46ba6afa 23570@table @asis
8e04817f 23571@kindex PgUp
46ba6afa 23572@item @key{PgUp}
8e04817f 23573Scroll the active window one page up.
c906108c 23574
8e04817f 23575@kindex PgDn
46ba6afa 23576@item @key{PgDn}
8e04817f 23577Scroll the active window one page down.
c906108c 23578
8e04817f 23579@kindex Up
46ba6afa 23580@item @key{Up}
8e04817f 23581Scroll the active window one line up.
c906108c 23582
8e04817f 23583@kindex Down
46ba6afa 23584@item @key{Down}
8e04817f 23585Scroll the active window one line down.
c906108c 23586
8e04817f 23587@kindex Left
46ba6afa 23588@item @key{Left}
8e04817f 23589Scroll the active window one column left.
c906108c 23590
8e04817f 23591@kindex Right
46ba6afa 23592@item @key{Right}
8e04817f 23593Scroll the active window one column right.
c906108c 23594
8e04817f 23595@kindex C-L
46ba6afa 23596@item @kbd{C-L}
8e04817f 23597Refresh the screen.
8e04817f 23598@end table
c906108c 23599
46ba6afa
BW
23600Because the arrow keys scroll the active window in the TUI mode, they
23601are not available for their normal use by readline unless the command
23602window has the focus. When another window is active, you must use
23603other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
23604and @kbd{C-f} to control the command window.
8e04817f 23605
7cf36c78
SC
23606@node TUI Single Key Mode
23607@section TUI Single Key Mode
23608@cindex TUI single key mode
23609
46ba6afa
BW
23610The TUI also provides a @dfn{SingleKey} mode, which binds several
23611frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
23612switch into this mode, where the following key bindings are used:
7cf36c78
SC
23613
23614@table @kbd
23615@kindex c @r{(SingleKey TUI key)}
23616@item c
23617continue
23618
23619@kindex d @r{(SingleKey TUI key)}
23620@item d
23621down
23622
23623@kindex f @r{(SingleKey TUI key)}
23624@item f
23625finish
23626
23627@kindex n @r{(SingleKey TUI key)}
23628@item n
23629next
23630
23631@kindex q @r{(SingleKey TUI key)}
23632@item q
46ba6afa 23633exit the SingleKey mode.
7cf36c78
SC
23634
23635@kindex r @r{(SingleKey TUI key)}
23636@item r
23637run
23638
23639@kindex s @r{(SingleKey TUI key)}
23640@item s
23641step
23642
23643@kindex u @r{(SingleKey TUI key)}
23644@item u
23645up
23646
23647@kindex v @r{(SingleKey TUI key)}
23648@item v
23649info locals
23650
23651@kindex w @r{(SingleKey TUI key)}
23652@item w
23653where
7cf36c78
SC
23654@end table
23655
23656Other keys temporarily switch to the @value{GDBN} command prompt.
23657The key that was pressed is inserted in the editing buffer so that
23658it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
23659with the TUI SingleKey mode. Once the command is entered the TUI
23660SingleKey mode is restored. The only way to permanently leave
7f9087cb 23661this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
23662
23663
8e04817f 23664@node TUI Commands
db2e3e2e 23665@section TUI-specific Commands
8e04817f
AC
23666@cindex TUI commands
23667
23668The TUI has specific commands to control the text windows.
46ba6afa
BW
23669These commands are always available, even when @value{GDBN} is not in
23670the TUI mode. When @value{GDBN} is in the standard mode, most
23671of these commands will automatically switch to the TUI mode.
c906108c 23672
ff12863f
PA
23673Note that if @value{GDBN}'s @code{stdout} is not connected to a
23674terminal, or @value{GDBN} has been started with the machine interface
23675interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
23676these commands will fail with an error, because it would not be
23677possible or desirable to enable curses window management.
23678
c906108c 23679@table @code
3d757584
SC
23680@item info win
23681@kindex info win
23682List and give the size of all displayed windows.
23683
8e04817f 23684@item layout next
4644b6e3 23685@kindex layout
8e04817f 23686Display the next layout.
2df3850c 23687
8e04817f 23688@item layout prev
8e04817f 23689Display the previous layout.
c906108c 23690
8e04817f 23691@item layout src
8e04817f 23692Display the source window only.
c906108c 23693
8e04817f 23694@item layout asm
8e04817f 23695Display the assembly window only.
c906108c 23696
8e04817f 23697@item layout split
8e04817f 23698Display the source and assembly window.
c906108c 23699
8e04817f 23700@item layout regs
8e04817f
AC
23701Display the register window together with the source or assembly window.
23702
46ba6afa 23703@item focus next
8e04817f 23704@kindex focus
46ba6afa
BW
23705Make the next window active for scrolling.
23706
23707@item focus prev
23708Make the previous window active for scrolling.
23709
23710@item focus src
23711Make the source window active for scrolling.
23712
23713@item focus asm
23714Make the assembly window active for scrolling.
23715
23716@item focus regs
23717Make the register window active for scrolling.
23718
23719@item focus cmd
23720Make the command window active for scrolling.
c906108c 23721
8e04817f
AC
23722@item refresh
23723@kindex refresh
7f9087cb 23724Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 23725
6a1b180d
SC
23726@item tui reg float
23727@kindex tui reg
23728Show the floating point registers in the register window.
23729
23730@item tui reg general
23731Show the general registers in the register window.
23732
23733@item tui reg next
23734Show the next register group. The list of register groups as well as
23735their order is target specific. The predefined register groups are the
23736following: @code{general}, @code{float}, @code{system}, @code{vector},
23737@code{all}, @code{save}, @code{restore}.
23738
23739@item tui reg system
23740Show the system registers in the register window.
23741
8e04817f
AC
23742@item update
23743@kindex update
23744Update the source window and the current execution point.
c906108c 23745
8e04817f
AC
23746@item winheight @var{name} +@var{count}
23747@itemx winheight @var{name} -@var{count}
23748@kindex winheight
23749Change the height of the window @var{name} by @var{count}
23750lines. Positive counts increase the height, while negative counts
23751decrease it.
2df3850c 23752
46ba6afa
BW
23753@item tabset @var{nchars}
23754@kindex tabset
c45da7e6 23755Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
23756@end table
23757
8e04817f 23758@node TUI Configuration
79a6e687 23759@section TUI Configuration Variables
8e04817f 23760@cindex TUI configuration variables
c906108c 23761
46ba6afa 23762Several configuration variables control the appearance of TUI windows.
c906108c 23763
8e04817f
AC
23764@table @code
23765@item set tui border-kind @var{kind}
23766@kindex set tui border-kind
23767Select the border appearance for the source, assembly and register windows.
23768The possible values are the following:
23769@table @code
23770@item space
23771Use a space character to draw the border.
c906108c 23772
8e04817f 23773@item ascii
46ba6afa 23774Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 23775
8e04817f
AC
23776@item acs
23777Use the Alternate Character Set to draw the border. The border is
23778drawn using character line graphics if the terminal supports them.
8e04817f 23779@end table
c78b4128 23780
8e04817f
AC
23781@item set tui border-mode @var{mode}
23782@kindex set tui border-mode
46ba6afa
BW
23783@itemx set tui active-border-mode @var{mode}
23784@kindex set tui active-border-mode
23785Select the display attributes for the borders of the inactive windows
23786or the active window. The @var{mode} can be one of the following:
8e04817f
AC
23787@table @code
23788@item normal
23789Use normal attributes to display the border.
c906108c 23790
8e04817f
AC
23791@item standout
23792Use standout mode.
c906108c 23793
8e04817f
AC
23794@item reverse
23795Use reverse video mode.
c906108c 23796
8e04817f
AC
23797@item half
23798Use half bright mode.
c906108c 23799
8e04817f
AC
23800@item half-standout
23801Use half bright and standout mode.
c906108c 23802
8e04817f
AC
23803@item bold
23804Use extra bright or bold mode.
c78b4128 23805
8e04817f
AC
23806@item bold-standout
23807Use extra bright or bold and standout mode.
8e04817f 23808@end table
8e04817f 23809@end table
c78b4128 23810
8e04817f
AC
23811@node Emacs
23812@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 23813
8e04817f
AC
23814@cindex Emacs
23815@cindex @sc{gnu} Emacs
23816A special interface allows you to use @sc{gnu} Emacs to view (and
23817edit) the source files for the program you are debugging with
23818@value{GDBN}.
c906108c 23819
8e04817f
AC
23820To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
23821executable file you want to debug as an argument. This command starts
23822@value{GDBN} as a subprocess of Emacs, with input and output through a newly
23823created Emacs buffer.
23824@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 23825
5e252a2e 23826Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 23827things:
c906108c 23828
8e04817f
AC
23829@itemize @bullet
23830@item
5e252a2e
NR
23831All ``terminal'' input and output goes through an Emacs buffer, called
23832the GUD buffer.
c906108c 23833
8e04817f
AC
23834This applies both to @value{GDBN} commands and their output, and to the input
23835and output done by the program you are debugging.
bf0184be 23836
8e04817f
AC
23837This is useful because it means that you can copy the text of previous
23838commands and input them again; you can even use parts of the output
23839in this way.
bf0184be 23840
8e04817f
AC
23841All the facilities of Emacs' Shell mode are available for interacting
23842with your program. In particular, you can send signals the usual
23843way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
23844stop.
bf0184be
ND
23845
23846@item
8e04817f 23847@value{GDBN} displays source code through Emacs.
bf0184be 23848
8e04817f
AC
23849Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
23850source file for that frame and puts an arrow (@samp{=>}) at the
23851left margin of the current line. Emacs uses a separate buffer for
23852source display, and splits the screen to show both your @value{GDBN} session
23853and the source.
bf0184be 23854
8e04817f
AC
23855Explicit @value{GDBN} @code{list} or search commands still produce output as
23856usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
23857@end itemize
23858
23859We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
23860a graphical mode, enabled by default, which provides further buffers
23861that can control the execution and describe the state of your program.
23862@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 23863
64fabec2
AC
23864If you specify an absolute file name when prompted for the @kbd{M-x
23865gdb} argument, then Emacs sets your current working directory to where
23866your program resides. If you only specify the file name, then Emacs
23867sets your current working directory to to the directory associated
23868with the previous buffer. In this case, @value{GDBN} may find your
23869program by searching your environment's @code{PATH} variable, but on
23870some operating systems it might not find the source. So, although the
23871@value{GDBN} input and output session proceeds normally, the auxiliary
23872buffer does not display the current source and line of execution.
23873
23874The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
23875line of the GUD buffer and this serves as a default for the commands
23876that specify files for @value{GDBN} to operate on. @xref{Files,
23877,Commands to Specify Files}.
64fabec2
AC
23878
23879By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
23880need to call @value{GDBN} by a different name (for example, if you
23881keep several configurations around, with different names) you can
23882customize the Emacs variable @code{gud-gdb-command-name} to run the
23883one you want.
8e04817f 23884
5e252a2e 23885In the GUD buffer, you can use these special Emacs commands in
8e04817f 23886addition to the standard Shell mode commands:
c906108c 23887
8e04817f
AC
23888@table @kbd
23889@item C-h m
5e252a2e 23890Describe the features of Emacs' GUD Mode.
c906108c 23891
64fabec2 23892@item C-c C-s
8e04817f
AC
23893Execute to another source line, like the @value{GDBN} @code{step} command; also
23894update the display window to show the current file and location.
c906108c 23895
64fabec2 23896@item C-c C-n
8e04817f
AC
23897Execute to next source line in this function, skipping all function
23898calls, like the @value{GDBN} @code{next} command. Then update the display window
23899to show the current file and location.
c906108c 23900
64fabec2 23901@item C-c C-i
8e04817f
AC
23902Execute one instruction, like the @value{GDBN} @code{stepi} command; update
23903display window accordingly.
c906108c 23904
8e04817f
AC
23905@item C-c C-f
23906Execute until exit from the selected stack frame, like the @value{GDBN}
23907@code{finish} command.
c906108c 23908
64fabec2 23909@item C-c C-r
8e04817f
AC
23910Continue execution of your program, like the @value{GDBN} @code{continue}
23911command.
b433d00b 23912
64fabec2 23913@item C-c <
8e04817f
AC
23914Go up the number of frames indicated by the numeric argument
23915(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
23916like the @value{GDBN} @code{up} command.
b433d00b 23917
64fabec2 23918@item C-c >
8e04817f
AC
23919Go down the number of frames indicated by the numeric argument, like the
23920@value{GDBN} @code{down} command.
8e04817f 23921@end table
c906108c 23922
7f9087cb 23923In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 23924tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 23925
5e252a2e
NR
23926In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
23927separate frame which shows a backtrace when the GUD buffer is current.
23928Move point to any frame in the stack and type @key{RET} to make it
23929become the current frame and display the associated source in the
23930source buffer. Alternatively, click @kbd{Mouse-2} to make the
23931selected frame become the current one. In graphical mode, the
23932speedbar displays watch expressions.
64fabec2 23933
8e04817f
AC
23934If you accidentally delete the source-display buffer, an easy way to get
23935it back is to type the command @code{f} in the @value{GDBN} buffer, to
23936request a frame display; when you run under Emacs, this recreates
23937the source buffer if necessary to show you the context of the current
23938frame.
c906108c 23939
8e04817f
AC
23940The source files displayed in Emacs are in ordinary Emacs buffers
23941which are visiting the source files in the usual way. You can edit
23942the files with these buffers if you wish; but keep in mind that @value{GDBN}
23943communicates with Emacs in terms of line numbers. If you add or
23944delete lines from the text, the line numbers that @value{GDBN} knows cease
23945to correspond properly with the code.
b383017d 23946
5e252a2e
NR
23947A more detailed description of Emacs' interaction with @value{GDBN} is
23948given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
23949Emacs Manual}).
c906108c 23950
8e04817f
AC
23951@c The following dropped because Epoch is nonstandard. Reactivate
23952@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
23953@ignore
23954@kindex Emacs Epoch environment
23955@kindex Epoch
23956@kindex inspect
c906108c 23957
8e04817f
AC
23958Version 18 of @sc{gnu} Emacs has a built-in window system
23959called the @code{epoch}
23960environment. Users of this environment can use a new command,
23961@code{inspect} which performs identically to @code{print} except that
23962each value is printed in its own window.
23963@end ignore
c906108c 23964
922fbb7b
AC
23965
23966@node GDB/MI
23967@chapter The @sc{gdb/mi} Interface
23968
23969@unnumberedsec Function and Purpose
23970
23971@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
23972@sc{gdb/mi} is a line based machine oriented text interface to
23973@value{GDBN} and is activated by specifying using the
23974@option{--interpreter} command line option (@pxref{Mode Options}). It
23975is specifically intended to support the development of systems which
23976use the debugger as just one small component of a larger system.
922fbb7b
AC
23977
23978This chapter is a specification of the @sc{gdb/mi} interface. It is written
23979in the form of a reference manual.
23980
23981Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
23982features described below are incomplete and subject to change
23983(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
23984
23985@unnumberedsec Notation and Terminology
23986
23987@cindex notational conventions, for @sc{gdb/mi}
23988This chapter uses the following notation:
23989
23990@itemize @bullet
23991@item
23992@code{|} separates two alternatives.
23993
23994@item
23995@code{[ @var{something} ]} indicates that @var{something} is optional:
23996it may or may not be given.
23997
23998@item
23999@code{( @var{group} )*} means that @var{group} inside the parentheses
24000may repeat zero or more times.
24001
24002@item
24003@code{( @var{group} )+} means that @var{group} inside the parentheses
24004may repeat one or more times.
24005
24006@item
24007@code{"@var{string}"} means a literal @var{string}.
24008@end itemize
24009
24010@ignore
24011@heading Dependencies
24012@end ignore
24013
922fbb7b 24014@menu
c3b108f7 24015* GDB/MI General Design::
922fbb7b
AC
24016* GDB/MI Command Syntax::
24017* GDB/MI Compatibility with CLI::
af6eff6f 24018* GDB/MI Development and Front Ends::
922fbb7b 24019* GDB/MI Output Records::
ef21caaf 24020* GDB/MI Simple Examples::
922fbb7b 24021* GDB/MI Command Description Format::
ef21caaf 24022* GDB/MI Breakpoint Commands::
a2c02241
NR
24023* GDB/MI Program Context::
24024* GDB/MI Thread Commands::
24025* GDB/MI Program Execution::
24026* GDB/MI Stack Manipulation::
24027* GDB/MI Variable Objects::
922fbb7b 24028* GDB/MI Data Manipulation::
a2c02241
NR
24029* GDB/MI Tracepoint Commands::
24030* GDB/MI Symbol Query::
351ff01a 24031* GDB/MI File Commands::
922fbb7b
AC
24032@ignore
24033* GDB/MI Kod Commands::
24034* GDB/MI Memory Overlay Commands::
24035* GDB/MI Signal Handling Commands::
24036@end ignore
922fbb7b 24037* GDB/MI Target Manipulation::
a6b151f1 24038* GDB/MI File Transfer Commands::
ef21caaf 24039* GDB/MI Miscellaneous Commands::
922fbb7b
AC
24040@end menu
24041
c3b108f7
VP
24042@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24043@node GDB/MI General Design
24044@section @sc{gdb/mi} General Design
24045@cindex GDB/MI General Design
24046
24047Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
24048parts---commands sent to @value{GDBN}, responses to those commands
24049and notifications. Each command results in exactly one response,
24050indicating either successful completion of the command, or an error.
24051For the commands that do not resume the target, the response contains the
24052requested information. For the commands that resume the target, the
24053response only indicates whether the target was successfully resumed.
24054Notifications is the mechanism for reporting changes in the state of the
24055target, or in @value{GDBN} state, that cannot conveniently be associated with
24056a command and reported as part of that command response.
24057
24058The important examples of notifications are:
24059@itemize @bullet
24060
24061@item
24062Exec notifications. These are used to report changes in
24063target state---when a target is resumed, or stopped. It would not
24064be feasible to include this information in response of resuming
24065commands, because one resume commands can result in multiple events in
24066different threads. Also, quite some time may pass before any event
24067happens in the target, while a frontend needs to know whether the resuming
24068command itself was successfully executed.
24069
24070@item
24071Console output, and status notifications. Console output
24072notifications are used to report output of CLI commands, as well as
24073diagnostics for other commands. Status notifications are used to
24074report the progress of a long-running operation. Naturally, including
24075this information in command response would mean no output is produced
24076until the command is finished, which is undesirable.
24077
24078@item
24079General notifications. Commands may have various side effects on
24080the @value{GDBN} or target state beyond their official purpose. For example,
24081a command may change the selected thread. Although such changes can
24082be included in command response, using notification allows for more
24083orthogonal frontend design.
24084
24085@end itemize
24086
24087There's no guarantee that whenever an MI command reports an error,
24088@value{GDBN} or the target are in any specific state, and especially,
24089the state is not reverted to the state before the MI command was
24090processed. Therefore, whenever an MI command results in an error,
24091we recommend that the frontend refreshes all the information shown in
24092the user interface.
24093
508094de
NR
24094
24095@menu
24096* Context management::
24097* Asynchronous and non-stop modes::
24098* Thread groups::
24099@end menu
24100
24101@node Context management
c3b108f7
VP
24102@subsection Context management
24103
24104In most cases when @value{GDBN} accesses the target, this access is
24105done in context of a specific thread and frame (@pxref{Frames}).
24106Often, even when accessing global data, the target requires that a thread
24107be specified. The CLI interface maintains the selected thread and frame,
24108and supplies them to target on each command. This is convenient,
24109because a command line user would not want to specify that information
24110explicitly on each command, and because user interacts with
24111@value{GDBN} via a single terminal, so no confusion is possible as
24112to what thread and frame are the current ones.
24113
24114In the case of MI, the concept of selected thread and frame is less
24115useful. First, a frontend can easily remember this information
24116itself. Second, a graphical frontend can have more than one window,
24117each one used for debugging a different thread, and the frontend might
24118want to access additional threads for internal purposes. This
24119increases the risk that by relying on implicitly selected thread, the
24120frontend may be operating on a wrong one. Therefore, each MI command
24121should explicitly specify which thread and frame to operate on. To
24122make it possible, each MI command accepts the @samp{--thread} and
24123@samp{--frame} options, the value to each is @value{GDBN} identifier
24124for thread and frame to operate on.
24125
24126Usually, each top-level window in a frontend allows the user to select
24127a thread and a frame, and remembers the user selection for further
24128operations. However, in some cases @value{GDBN} may suggest that the
24129current thread be changed. For example, when stopping on a breakpoint
24130it is reasonable to switch to the thread where breakpoint is hit. For
24131another example, if the user issues the CLI @samp{thread} command via
24132the frontend, it is desirable to change the frontend's selected thread to the
24133one specified by user. @value{GDBN} communicates the suggestion to
24134change current thread using the @samp{=thread-selected} notification.
24135No such notification is available for the selected frame at the moment.
24136
24137Note that historically, MI shares the selected thread with CLI, so
24138frontends used the @code{-thread-select} to execute commands in the
24139right context. However, getting this to work right is cumbersome. The
24140simplest way is for frontend to emit @code{-thread-select} command
24141before every command. This doubles the number of commands that need
24142to be sent. The alternative approach is to suppress @code{-thread-select}
24143if the selected thread in @value{GDBN} is supposed to be identical to the
24144thread the frontend wants to operate on. However, getting this
24145optimization right can be tricky. In particular, if the frontend
24146sends several commands to @value{GDBN}, and one of the commands changes the
24147selected thread, then the behaviour of subsequent commands will
24148change. So, a frontend should either wait for response from such
24149problematic commands, or explicitly add @code{-thread-select} for
24150all subsequent commands. No frontend is known to do this exactly
24151right, so it is suggested to just always pass the @samp{--thread} and
24152@samp{--frame} options.
24153
508094de 24154@node Asynchronous and non-stop modes
c3b108f7
VP
24155@subsection Asynchronous command execution and non-stop mode
24156
24157On some targets, @value{GDBN} is capable of processing MI commands
24158even while the target is running. This is called @dfn{asynchronous
24159command execution} (@pxref{Background Execution}). The frontend may
24160specify a preferrence for asynchronous execution using the
24161@code{-gdb-set target-async 1} command, which should be emitted before
24162either running the executable or attaching to the target. After the
24163frontend has started the executable or attached to the target, it can
24164find if asynchronous execution is enabled using the
24165@code{-list-target-features} command.
24166
24167Even if @value{GDBN} can accept a command while target is running,
24168many commands that access the target do not work when the target is
24169running. Therefore, asynchronous command execution is most useful
24170when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
24171it is possible to examine the state of one thread, while other threads
24172are running.
24173
24174When a given thread is running, MI commands that try to access the
24175target in the context of that thread may not work, or may work only on
24176some targets. In particular, commands that try to operate on thread's
24177stack will not work, on any target. Commands that read memory, or
24178modify breakpoints, may work or not work, depending on the target. Note
24179that even commands that operate on global state, such as @code{print},
24180@code{set}, and breakpoint commands, still access the target in the
24181context of a specific thread, so frontend should try to find a
24182stopped thread and perform the operation on that thread (using the
24183@samp{--thread} option).
24184
24185Which commands will work in the context of a running thread is
24186highly target dependent. However, the two commands
24187@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
24188to find the state of a thread, will always work.
24189
508094de 24190@node Thread groups
c3b108f7
VP
24191@subsection Thread groups
24192@value{GDBN} may be used to debug several processes at the same time.
24193On some platfroms, @value{GDBN} may support debugging of several
24194hardware systems, each one having several cores with several different
24195processes running on each core. This section describes the MI
24196mechanism to support such debugging scenarios.
24197
24198The key observation is that regardless of the structure of the
24199target, MI can have a global list of threads, because most commands that
24200accept the @samp{--thread} option do not need to know what process that
24201thread belongs to. Therefore, it is not necessary to introduce
24202neither additional @samp{--process} option, nor an notion of the
24203current process in the MI interface. The only strictly new feature
24204that is required is the ability to find how the threads are grouped
24205into processes.
24206
24207To allow the user to discover such grouping, and to support arbitrary
24208hierarchy of machines/cores/processes, MI introduces the concept of a
24209@dfn{thread group}. Thread group is a collection of threads and other
24210thread groups. A thread group always has a string identifier, a type,
24211and may have additional attributes specific to the type. A new
24212command, @code{-list-thread-groups}, returns the list of top-level
24213thread groups, which correspond to processes that @value{GDBN} is
24214debugging at the moment. By passing an identifier of a thread group
24215to the @code{-list-thread-groups} command, it is possible to obtain
24216the members of specific thread group.
24217
24218To allow the user to easily discover processes, and other objects, he
24219wishes to debug, a concept of @dfn{available thread group} is
24220introduced. Available thread group is an thread group that
24221@value{GDBN} is not debugging, but that can be attached to, using the
24222@code{-target-attach} command. The list of available top-level thread
24223groups can be obtained using @samp{-list-thread-groups --available}.
24224In general, the content of a thread group may be only retrieved only
24225after attaching to that thread group.
24226
a79b8f6e
VP
24227Thread groups are related to inferiors (@pxref{Inferiors and
24228Programs}). Each inferior corresponds to a thread group of a special
24229type @samp{process}, and some additional operations are permitted on
24230such thread groups.
24231
922fbb7b
AC
24232@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24233@node GDB/MI Command Syntax
24234@section @sc{gdb/mi} Command Syntax
24235
24236@menu
24237* GDB/MI Input Syntax::
24238* GDB/MI Output Syntax::
922fbb7b
AC
24239@end menu
24240
24241@node GDB/MI Input Syntax
24242@subsection @sc{gdb/mi} Input Syntax
24243
24244@cindex input syntax for @sc{gdb/mi}
24245@cindex @sc{gdb/mi}, input syntax
24246@table @code
24247@item @var{command} @expansion{}
24248@code{@var{cli-command} | @var{mi-command}}
24249
24250@item @var{cli-command} @expansion{}
24251@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
24252@var{cli-command} is any existing @value{GDBN} CLI command.
24253
24254@item @var{mi-command} @expansion{}
24255@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
24256@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
24257
24258@item @var{token} @expansion{}
24259"any sequence of digits"
24260
24261@item @var{option} @expansion{}
24262@code{"-" @var{parameter} [ " " @var{parameter} ]}
24263
24264@item @var{parameter} @expansion{}
24265@code{@var{non-blank-sequence} | @var{c-string}}
24266
24267@item @var{operation} @expansion{}
24268@emph{any of the operations described in this chapter}
24269
24270@item @var{non-blank-sequence} @expansion{}
24271@emph{anything, provided it doesn't contain special characters such as
24272"-", @var{nl}, """ and of course " "}
24273
24274@item @var{c-string} @expansion{}
24275@code{""" @var{seven-bit-iso-c-string-content} """}
24276
24277@item @var{nl} @expansion{}
24278@code{CR | CR-LF}
24279@end table
24280
24281@noindent
24282Notes:
24283
24284@itemize @bullet
24285@item
24286The CLI commands are still handled by the @sc{mi} interpreter; their
24287output is described below.
24288
24289@item
24290The @code{@var{token}}, when present, is passed back when the command
24291finishes.
24292
24293@item
24294Some @sc{mi} commands accept optional arguments as part of the parameter
24295list. Each option is identified by a leading @samp{-} (dash) and may be
24296followed by an optional argument parameter. Options occur first in the
24297parameter list and can be delimited from normal parameters using
24298@samp{--} (this is useful when some parameters begin with a dash).
24299@end itemize
24300
24301Pragmatics:
24302
24303@itemize @bullet
24304@item
24305We want easy access to the existing CLI syntax (for debugging).
24306
24307@item
24308We want it to be easy to spot a @sc{mi} operation.
24309@end itemize
24310
24311@node GDB/MI Output Syntax
24312@subsection @sc{gdb/mi} Output Syntax
24313
24314@cindex output syntax of @sc{gdb/mi}
24315@cindex @sc{gdb/mi}, output syntax
24316The output from @sc{gdb/mi} consists of zero or more out-of-band records
24317followed, optionally, by a single result record. This result record
24318is for the most recent command. The sequence of output records is
594fe323 24319terminated by @samp{(gdb)}.
922fbb7b
AC
24320
24321If an input command was prefixed with a @code{@var{token}} then the
24322corresponding output for that command will also be prefixed by that same
24323@var{token}.
24324
24325@table @code
24326@item @var{output} @expansion{}
594fe323 24327@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
24328
24329@item @var{result-record} @expansion{}
24330@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
24331
24332@item @var{out-of-band-record} @expansion{}
24333@code{@var{async-record} | @var{stream-record}}
24334
24335@item @var{async-record} @expansion{}
24336@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
24337
24338@item @var{exec-async-output} @expansion{}
24339@code{[ @var{token} ] "*" @var{async-output}}
24340
24341@item @var{status-async-output} @expansion{}
24342@code{[ @var{token} ] "+" @var{async-output}}
24343
24344@item @var{notify-async-output} @expansion{}
24345@code{[ @var{token} ] "=" @var{async-output}}
24346
24347@item @var{async-output} @expansion{}
24348@code{@var{async-class} ( "," @var{result} )* @var{nl}}
24349
24350@item @var{result-class} @expansion{}
24351@code{"done" | "running" | "connected" | "error" | "exit"}
24352
24353@item @var{async-class} @expansion{}
24354@code{"stopped" | @var{others}} (where @var{others} will be added
24355depending on the needs---this is still in development).
24356
24357@item @var{result} @expansion{}
24358@code{ @var{variable} "=" @var{value}}
24359
24360@item @var{variable} @expansion{}
24361@code{ @var{string} }
24362
24363@item @var{value} @expansion{}
24364@code{ @var{const} | @var{tuple} | @var{list} }
24365
24366@item @var{const} @expansion{}
24367@code{@var{c-string}}
24368
24369@item @var{tuple} @expansion{}
24370@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
24371
24372@item @var{list} @expansion{}
24373@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
24374@var{result} ( "," @var{result} )* "]" }
24375
24376@item @var{stream-record} @expansion{}
24377@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
24378
24379@item @var{console-stream-output} @expansion{}
24380@code{"~" @var{c-string}}
24381
24382@item @var{target-stream-output} @expansion{}
24383@code{"@@" @var{c-string}}
24384
24385@item @var{log-stream-output} @expansion{}
24386@code{"&" @var{c-string}}
24387
24388@item @var{nl} @expansion{}
24389@code{CR | CR-LF}
24390
24391@item @var{token} @expansion{}
24392@emph{any sequence of digits}.
24393@end table
24394
24395@noindent
24396Notes:
24397
24398@itemize @bullet
24399@item
24400All output sequences end in a single line containing a period.
24401
24402@item
721c02de
VP
24403The @code{@var{token}} is from the corresponding request. Note that
24404for all async output, while the token is allowed by the grammar and
24405may be output by future versions of @value{GDBN} for select async
24406output messages, it is generally omitted. Frontends should treat
24407all async output as reporting general changes in the state of the
24408target and there should be no need to associate async output to any
24409prior command.
922fbb7b
AC
24410
24411@item
24412@cindex status output in @sc{gdb/mi}
24413@var{status-async-output} contains on-going status information about the
24414progress of a slow operation. It can be discarded. All status output is
24415prefixed by @samp{+}.
24416
24417@item
24418@cindex async output in @sc{gdb/mi}
24419@var{exec-async-output} contains asynchronous state change on the target
24420(stopped, started, disappeared). All async output is prefixed by
24421@samp{*}.
24422
24423@item
24424@cindex notify output in @sc{gdb/mi}
24425@var{notify-async-output} contains supplementary information that the
24426client should handle (e.g., a new breakpoint information). All notify
24427output is prefixed by @samp{=}.
24428
24429@item
24430@cindex console output in @sc{gdb/mi}
24431@var{console-stream-output} is output that should be displayed as is in the
24432console. It is the textual response to a CLI command. All the console
24433output is prefixed by @samp{~}.
24434
24435@item
24436@cindex target output in @sc{gdb/mi}
24437@var{target-stream-output} is the output produced by the target program.
24438All the target output is prefixed by @samp{@@}.
24439
24440@item
24441@cindex log output in @sc{gdb/mi}
24442@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
24443instance messages that should be displayed as part of an error log. All
24444the log output is prefixed by @samp{&}.
24445
24446@item
24447@cindex list output in @sc{gdb/mi}
24448New @sc{gdb/mi} commands should only output @var{lists} containing
24449@var{values}.
24450
24451
24452@end itemize
24453
24454@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
24455details about the various output records.
24456
922fbb7b
AC
24457@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24458@node GDB/MI Compatibility with CLI
24459@section @sc{gdb/mi} Compatibility with CLI
24460
24461@cindex compatibility, @sc{gdb/mi} and CLI
24462@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 24463
a2c02241
NR
24464For the developers convenience CLI commands can be entered directly,
24465but there may be some unexpected behaviour. For example, commands
24466that query the user will behave as if the user replied yes, breakpoint
24467command lists are not executed and some CLI commands, such as
24468@code{if}, @code{when} and @code{define}, prompt for further input with
24469@samp{>}, which is not valid MI output.
ef21caaf
NR
24470
24471This feature may be removed at some stage in the future and it is
a2c02241
NR
24472recommended that front ends use the @code{-interpreter-exec} command
24473(@pxref{-interpreter-exec}).
922fbb7b 24474
af6eff6f
NR
24475@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24476@node GDB/MI Development and Front Ends
24477@section @sc{gdb/mi} Development and Front Ends
24478@cindex @sc{gdb/mi} development
24479
24480The application which takes the MI output and presents the state of the
24481program being debugged to the user is called a @dfn{front end}.
24482
24483Although @sc{gdb/mi} is still incomplete, it is currently being used
24484by a variety of front ends to @value{GDBN}. This makes it difficult
24485to introduce new functionality without breaking existing usage. This
24486section tries to minimize the problems by describing how the protocol
24487might change.
24488
24489Some changes in MI need not break a carefully designed front end, and
24490for these the MI version will remain unchanged. The following is a
24491list of changes that may occur within one level, so front ends should
24492parse MI output in a way that can handle them:
24493
24494@itemize @bullet
24495@item
24496New MI commands may be added.
24497
24498@item
24499New fields may be added to the output of any MI command.
24500
36ece8b3
NR
24501@item
24502The range of values for fields with specified values, e.g.,
9f708cb2 24503@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 24504
af6eff6f
NR
24505@c The format of field's content e.g type prefix, may change so parse it
24506@c at your own risk. Yes, in general?
24507
24508@c The order of fields may change? Shouldn't really matter but it might
24509@c resolve inconsistencies.
24510@end itemize
24511
24512If the changes are likely to break front ends, the MI version level
24513will be increased by one. This will allow the front end to parse the
24514output according to the MI version. Apart from mi0, new versions of
24515@value{GDBN} will not support old versions of MI and it will be the
24516responsibility of the front end to work with the new one.
24517
24518@c Starting with mi3, add a new command -mi-version that prints the MI
24519@c version?
24520
24521The best way to avoid unexpected changes in MI that might break your front
24522end is to make your project known to @value{GDBN} developers and
7a9a6b69 24523follow development on @email{gdb@@sourceware.org} and
fa0f268d 24524@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
24525@cindex mailing lists
24526
922fbb7b
AC
24527@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24528@node GDB/MI Output Records
24529@section @sc{gdb/mi} Output Records
24530
24531@menu
24532* GDB/MI Result Records::
24533* GDB/MI Stream Records::
82f68b1c 24534* GDB/MI Async Records::
c3b108f7 24535* GDB/MI Frame Information::
dc146f7c 24536* GDB/MI Thread Information::
922fbb7b
AC
24537@end menu
24538
24539@node GDB/MI Result Records
24540@subsection @sc{gdb/mi} Result Records
24541
24542@cindex result records in @sc{gdb/mi}
24543@cindex @sc{gdb/mi}, result records
24544In addition to a number of out-of-band notifications, the response to a
24545@sc{gdb/mi} command includes one of the following result indications:
24546
24547@table @code
24548@findex ^done
24549@item "^done" [ "," @var{results} ]
24550The synchronous operation was successful, @code{@var{results}} are the return
24551values.
24552
24553@item "^running"
24554@findex ^running
8e9c5e02
VP
24555This result record is equivalent to @samp{^done}. Historically, it
24556was output instead of @samp{^done} if the command has resumed the
24557target. This behaviour is maintained for backward compatibility, but
24558all frontends should treat @samp{^done} and @samp{^running}
24559identically and rely on the @samp{*running} output record to determine
24560which threads are resumed.
922fbb7b 24561
ef21caaf
NR
24562@item "^connected"
24563@findex ^connected
3f94c067 24564@value{GDBN} has connected to a remote target.
ef21caaf 24565
922fbb7b
AC
24566@item "^error" "," @var{c-string}
24567@findex ^error
24568The operation failed. The @code{@var{c-string}} contains the corresponding
24569error message.
ef21caaf
NR
24570
24571@item "^exit"
24572@findex ^exit
3f94c067 24573@value{GDBN} has terminated.
ef21caaf 24574
922fbb7b
AC
24575@end table
24576
24577@node GDB/MI Stream Records
24578@subsection @sc{gdb/mi} Stream Records
24579
24580@cindex @sc{gdb/mi}, stream records
24581@cindex stream records in @sc{gdb/mi}
24582@value{GDBN} internally maintains a number of output streams: the console, the
24583target, and the log. The output intended for each of these streams is
24584funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
24585
24586Each stream record begins with a unique @dfn{prefix character} which
24587identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
24588Syntax}). In addition to the prefix, each stream record contains a
24589@code{@var{string-output}}. This is either raw text (with an implicit new
24590line) or a quoted C string (which does not contain an implicit newline).
24591
24592@table @code
24593@item "~" @var{string-output}
24594The console output stream contains text that should be displayed in the
24595CLI console window. It contains the textual responses to CLI commands.
24596
24597@item "@@" @var{string-output}
24598The target output stream contains any textual output from the running
ef21caaf
NR
24599target. This is only present when GDB's event loop is truly
24600asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
24601
24602@item "&" @var{string-output}
24603The log stream contains debugging messages being produced by @value{GDBN}'s
24604internals.
24605@end table
24606
82f68b1c
VP
24607@node GDB/MI Async Records
24608@subsection @sc{gdb/mi} Async Records
922fbb7b 24609
82f68b1c
VP
24610@cindex async records in @sc{gdb/mi}
24611@cindex @sc{gdb/mi}, async records
24612@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 24613additional changes that have occurred. Those changes can either be a
82f68b1c 24614consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
24615target activity (e.g., target stopped).
24616
8eb41542 24617The following is the list of possible async records:
922fbb7b
AC
24618
24619@table @code
034dad6f 24620
e1ac3328
VP
24621@item *running,thread-id="@var{thread}"
24622The target is now running. The @var{thread} field tells which
24623specific thread is now running, and can be @samp{all} if all threads
24624are running. The frontend should assume that no interaction with a
24625running thread is possible after this notification is produced.
24626The frontend should not assume that this notification is output
24627only once for any command. @value{GDBN} may emit this notification
24628several times, either for different threads, because it cannot resume
24629all threads together, or even for a single thread, if the thread must
24630be stepped though some code before letting it run freely.
24631
dc146f7c 24632@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
24633The target has stopped. The @var{reason} field can have one of the
24634following values:
034dad6f
BR
24635
24636@table @code
24637@item breakpoint-hit
24638A breakpoint was reached.
24639@item watchpoint-trigger
24640A watchpoint was triggered.
24641@item read-watchpoint-trigger
24642A read watchpoint was triggered.
24643@item access-watchpoint-trigger
24644An access watchpoint was triggered.
24645@item function-finished
24646An -exec-finish or similar CLI command was accomplished.
24647@item location-reached
24648An -exec-until or similar CLI command was accomplished.
24649@item watchpoint-scope
24650A watchpoint has gone out of scope.
24651@item end-stepping-range
24652An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
24653similar CLI command was accomplished.
24654@item exited-signalled
24655The inferior exited because of a signal.
24656@item exited
24657The inferior exited.
24658@item exited-normally
24659The inferior exited normally.
24660@item signal-received
24661A signal was received by the inferior.
922fbb7b
AC
24662@end table
24663
c3b108f7
VP
24664The @var{id} field identifies the thread that directly caused the stop
24665-- for example by hitting a breakpoint. Depending on whether all-stop
24666mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
24667stop all threads, or only the thread that directly triggered the stop.
24668If all threads are stopped, the @var{stopped} field will have the
24669value of @code{"all"}. Otherwise, the value of the @var{stopped}
24670field will be a list of thread identifiers. Presently, this list will
24671always include a single thread, but frontend should be prepared to see
dc146f7c
VP
24672several threads in the list. The @var{core} field reports the
24673processor core on which the stop event has happened. This field may be absent
24674if such information is not available.
c3b108f7 24675
a79b8f6e
VP
24676@item =thread-group-added,id="@var{id}"
24677@itemx =thread-group-removed,id="@var{id}"
24678A thread group was either added or removed. The @var{id} field
24679contains the @value{GDBN} identifier of the thread group. When a thread
24680group is added, it generally might not be associated with a running
24681process. When a thread group is removed, its id becomes invalid and
24682cannot be used in any way.
24683
24684@item =thread-group-started,id="@var{id}",pid="@var{pid}"
24685A thread group became associated with a running program,
24686either because the program was just started or the thread group
24687was attached to a program. The @var{id} field contains the
24688@value{GDBN} identifier of the thread group. The @var{pid} field
24689contains process identifier, specific to the operating system.
24690
c3b108f7 24691@itemx =thread-group-exited,id="@var{id}"
a79b8f6e
VP
24692A thread group is no longer associated with a running program,
24693either because the program has exited, or because it was detached
c3b108f7
VP
24694from. The @var{id} field contains the @value{GDBN} identifier of the
24695thread group.
24696
24697@item =thread-created,id="@var{id}",group-id="@var{gid}"
24698@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 24699A thread either was created, or has exited. The @var{id} field
c3b108f7
VP
24700contains the @value{GDBN} identifier of the thread. The @var{gid}
24701field identifies the thread group this thread belongs to.
66bb093b
VP
24702
24703@item =thread-selected,id="@var{id}"
24704Informs that the selected thread was changed as result of the last
24705command. This notification is not emitted as result of @code{-thread-select}
24706command but is emitted whenever an MI command that is not documented
24707to change the selected thread actually changes it. In particular,
24708invoking, directly or indirectly (via user-defined command), the CLI
24709@code{thread} command, will generate this notification.
24710
24711We suggest that in response to this notification, front ends
24712highlight the selected thread and cause subsequent commands to apply to
24713that thread.
24714
c86cf029
VP
24715@item =library-loaded,...
24716Reports that a new library file was loaded by the program. This
24717notification has 4 fields---@var{id}, @var{target-name},
134eb42c 24718@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
c86cf029
VP
24719opaque identifier of the library. For remote debugging case,
24720@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
24721library file on the target, and on the host respectively. For native
24722debugging, both those fields have the same value. The
c86cf029 24723@var{symbols-loaded} field reports if the debug symbols for this
a79b8f6e
VP
24724library are loaded. The @var{thread-group} field, if present,
24725specifies the id of the thread group in whose context the library was loaded.
24726If the field is absent, it means the library was loaded in the context
24727of all present thread groups.
c86cf029
VP
24728
24729@item =library-unloaded,...
134eb42c 24730Reports that a library was unloaded by the program. This notification
c86cf029 24731has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
24732the same meaning as for the @code{=library-loaded} notification.
24733The @var{thread-group} field, if present, specifies the id of the
24734thread group in whose context the library was unloaded. If the field is
24735absent, it means the library was unloaded in the context of all present
24736thread groups.
c86cf029 24737
82f68b1c
VP
24738@end table
24739
c3b108f7
VP
24740@node GDB/MI Frame Information
24741@subsection @sc{gdb/mi} Frame Information
24742
24743Response from many MI commands includes an information about stack
24744frame. This information is a tuple that may have the following
24745fields:
24746
24747@table @code
24748@item level
24749The level of the stack frame. The innermost frame has the level of
24750zero. This field is always present.
24751
24752@item func
24753The name of the function corresponding to the frame. This field may
24754be absent if @value{GDBN} is unable to determine the function name.
24755
24756@item addr
24757The code address for the frame. This field is always present.
24758
24759@item file
24760The name of the source files that correspond to the frame's code
24761address. This field may be absent.
24762
24763@item line
24764The source line corresponding to the frames' code address. This field
24765may be absent.
24766
24767@item from
24768The name of the binary file (either executable or shared library) the
24769corresponds to the frame's code address. This field may be absent.
24770
24771@end table
82f68b1c 24772
dc146f7c
VP
24773@node GDB/MI Thread Information
24774@subsection @sc{gdb/mi} Thread Information
24775
24776Whenever @value{GDBN} has to report an information about a thread, it
24777uses a tuple with the following fields:
24778
24779@table @code
24780@item id
24781The numeric id assigned to the thread by @value{GDBN}. This field is
24782always present.
24783
24784@item target-id
24785Target-specific string identifying the thread. This field is always present.
24786
24787@item details
24788Additional information about the thread provided by the target.
24789It is supposed to be human-readable and not interpreted by the
24790frontend. This field is optional.
24791
24792@item state
24793Either @samp{stopped} or @samp{running}, depending on whether the
24794thread is presently running. This field is always present.
24795
24796@item core
24797The value of this field is an integer number of the processor core the
24798thread was last seen on. This field is optional.
24799@end table
24800
922fbb7b 24801
ef21caaf
NR
24802@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24803@node GDB/MI Simple Examples
24804@section Simple Examples of @sc{gdb/mi} Interaction
24805@cindex @sc{gdb/mi}, simple examples
24806
24807This subsection presents several simple examples of interaction using
24808the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
24809following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
24810the output received from @sc{gdb/mi}.
24811
d3e8051b 24812Note the line breaks shown in the examples are here only for
ef21caaf
NR
24813readability, they don't appear in the real output.
24814
79a6e687 24815@subheading Setting a Breakpoint
ef21caaf
NR
24816
24817Setting a breakpoint generates synchronous output which contains detailed
24818information of the breakpoint.
24819
24820@smallexample
24821-> -break-insert main
24822<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
24823 enabled="y",addr="0x08048564",func="main",file="myprog.c",
24824 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
24825<- (gdb)
24826@end smallexample
24827
24828@subheading Program Execution
24829
24830Program execution generates asynchronous records and MI gives the
24831reason that execution stopped.
24832
24833@smallexample
24834-> -exec-run
24835<- ^running
24836<- (gdb)
a47ec5fe 24837<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
24838 frame=@{addr="0x08048564",func="main",
24839 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
24840 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
24841<- (gdb)
24842-> -exec-continue
24843<- ^running
24844<- (gdb)
24845<- *stopped,reason="exited-normally"
24846<- (gdb)
24847@end smallexample
24848
3f94c067 24849@subheading Quitting @value{GDBN}
ef21caaf 24850
3f94c067 24851Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
24852
24853@smallexample
24854-> (gdb)
24855<- -gdb-exit
24856<- ^exit
24857@end smallexample
24858
a6b29f87
VP
24859Please note that @samp{^exit} is printed immediately, but it might
24860take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
24861performs necessary cleanups, including killing programs being debugged
24862or disconnecting from debug hardware, so the frontend should wait till
24863@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
24864fails to exit in reasonable time.
24865
a2c02241 24866@subheading A Bad Command
ef21caaf
NR
24867
24868Here's what happens if you pass a non-existent command:
24869
24870@smallexample
24871-> -rubbish
24872<- ^error,msg="Undefined MI command: rubbish"
594fe323 24873<- (gdb)
ef21caaf
NR
24874@end smallexample
24875
24876
922fbb7b
AC
24877@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24878@node GDB/MI Command Description Format
24879@section @sc{gdb/mi} Command Description Format
24880
24881The remaining sections describe blocks of commands. Each block of
24882commands is laid out in a fashion similar to this section.
24883
922fbb7b
AC
24884@subheading Motivation
24885
24886The motivation for this collection of commands.
24887
24888@subheading Introduction
24889
24890A brief introduction to this collection of commands as a whole.
24891
24892@subheading Commands
24893
24894For each command in the block, the following is described:
24895
24896@subsubheading Synopsis
24897
24898@smallexample
24899 -command @var{args}@dots{}
24900@end smallexample
24901
922fbb7b
AC
24902@subsubheading Result
24903
265eeb58 24904@subsubheading @value{GDBN} Command
922fbb7b 24905
265eeb58 24906The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
24907
24908@subsubheading Example
24909
ef21caaf
NR
24910Example(s) formatted for readability. Some of the described commands have
24911not been implemented yet and these are labeled N.A.@: (not available).
24912
24913
922fbb7b 24914@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
24915@node GDB/MI Breakpoint Commands
24916@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
24917
24918@cindex breakpoint commands for @sc{gdb/mi}
24919@cindex @sc{gdb/mi}, breakpoint commands
24920This section documents @sc{gdb/mi} commands for manipulating
24921breakpoints.
24922
24923@subheading The @code{-break-after} Command
24924@findex -break-after
24925
24926@subsubheading Synopsis
24927
24928@smallexample
24929 -break-after @var{number} @var{count}
24930@end smallexample
24931
24932The breakpoint number @var{number} is not in effect until it has been
24933hit @var{count} times. To see how this is reflected in the output of
24934the @samp{-break-list} command, see the description of the
24935@samp{-break-list} command below.
24936
24937@subsubheading @value{GDBN} Command
24938
24939The corresponding @value{GDBN} command is @samp{ignore}.
24940
24941@subsubheading Example
24942
24943@smallexample
594fe323 24944(gdb)
922fbb7b 24945-break-insert main
a47ec5fe
AR
24946^done,bkpt=@{number="1",type="breakpoint",disp="keep",
24947enabled="y",addr="0x000100d0",func="main",file="hello.c",
948d5102 24948fullname="/home/foo/hello.c",line="5",times="0"@}
594fe323 24949(gdb)
922fbb7b
AC
24950-break-after 1 3
24951~
24952^done
594fe323 24953(gdb)
922fbb7b
AC
24954-break-list
24955^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
24956hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24957@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24958@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24959@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24960@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24961@{width="40",alignment="2",col_name="what",colhdr="What"@}],
24962body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
24963addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
24964line="5",times="0",ignore="3"@}]@}
594fe323 24965(gdb)
922fbb7b
AC
24966@end smallexample
24967
24968@ignore
24969@subheading The @code{-break-catch} Command
24970@findex -break-catch
48cb2d85 24971@end ignore
922fbb7b
AC
24972
24973@subheading The @code{-break-commands} Command
24974@findex -break-commands
922fbb7b 24975
48cb2d85
VP
24976@subsubheading Synopsis
24977
24978@smallexample
24979 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
24980@end smallexample
24981
24982Specifies the CLI commands that should be executed when breakpoint
24983@var{number} is hit. The parameters @var{command1} to @var{commandN}
24984are the commands. If no command is specified, any previously-set
24985commands are cleared. @xref{Break Commands}. Typical use of this
24986functionality is tracing a program, that is, printing of values of
24987some variables whenever breakpoint is hit and then continuing.
24988
24989@subsubheading @value{GDBN} Command
24990
24991The corresponding @value{GDBN} command is @samp{commands}.
24992
24993@subsubheading Example
24994
24995@smallexample
24996(gdb)
24997-break-insert main
24998^done,bkpt=@{number="1",type="breakpoint",disp="keep",
24999enabled="y",addr="0x000100d0",func="main",file="hello.c",
25000fullname="/home/foo/hello.c",line="5",times="0"@}
25001(gdb)
25002-break-commands 1 "print v" "continue"
25003^done
25004(gdb)
25005@end smallexample
922fbb7b
AC
25006
25007@subheading The @code{-break-condition} Command
25008@findex -break-condition
25009
25010@subsubheading Synopsis
25011
25012@smallexample
25013 -break-condition @var{number} @var{expr}
25014@end smallexample
25015
25016Breakpoint @var{number} will stop the program only if the condition in
25017@var{expr} is true. The condition becomes part of the
25018@samp{-break-list} output (see the description of the @samp{-break-list}
25019command below).
25020
25021@subsubheading @value{GDBN} Command
25022
25023The corresponding @value{GDBN} command is @samp{condition}.
25024
25025@subsubheading Example
25026
25027@smallexample
594fe323 25028(gdb)
922fbb7b
AC
25029-break-condition 1 1
25030^done
594fe323 25031(gdb)
922fbb7b
AC
25032-break-list
25033^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
25034hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25035@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25036@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25037@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25038@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25039@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25040body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
25041addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
25042line="5",cond="1",times="0",ignore="3"@}]@}
594fe323 25043(gdb)
922fbb7b
AC
25044@end smallexample
25045
25046@subheading The @code{-break-delete} Command
25047@findex -break-delete
25048
25049@subsubheading Synopsis
25050
25051@smallexample
25052 -break-delete ( @var{breakpoint} )+
25053@end smallexample
25054
25055Delete the breakpoint(s) whose number(s) are specified in the argument
25056list. This is obviously reflected in the breakpoint list.
25057
79a6e687 25058@subsubheading @value{GDBN} Command
922fbb7b
AC
25059
25060The corresponding @value{GDBN} command is @samp{delete}.
25061
25062@subsubheading Example
25063
25064@smallexample
594fe323 25065(gdb)
922fbb7b
AC
25066-break-delete 1
25067^done
594fe323 25068(gdb)
922fbb7b
AC
25069-break-list
25070^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
25071hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25072@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25073@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25074@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25075@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25076@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25077body=[]@}
594fe323 25078(gdb)
922fbb7b
AC
25079@end smallexample
25080
25081@subheading The @code{-break-disable} Command
25082@findex -break-disable
25083
25084@subsubheading Synopsis
25085
25086@smallexample
25087 -break-disable ( @var{breakpoint} )+
25088@end smallexample
25089
25090Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
25091break list is now set to @samp{n} for the named @var{breakpoint}(s).
25092
25093@subsubheading @value{GDBN} Command
25094
25095The corresponding @value{GDBN} command is @samp{disable}.
25096
25097@subsubheading Example
25098
25099@smallexample
594fe323 25100(gdb)
922fbb7b
AC
25101-break-disable 2
25102^done
594fe323 25103(gdb)
922fbb7b
AC
25104-break-list
25105^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
25106hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25107@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25108@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25109@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25110@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25111@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25112body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102
NR
25113addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
25114line="5",times="0"@}]@}
594fe323 25115(gdb)
922fbb7b
AC
25116@end smallexample
25117
25118@subheading The @code{-break-enable} Command
25119@findex -break-enable
25120
25121@subsubheading Synopsis
25122
25123@smallexample
25124 -break-enable ( @var{breakpoint} )+
25125@end smallexample
25126
25127Enable (previously disabled) @var{breakpoint}(s).
25128
25129@subsubheading @value{GDBN} Command
25130
25131The corresponding @value{GDBN} command is @samp{enable}.
25132
25133@subsubheading Example
25134
25135@smallexample
594fe323 25136(gdb)
922fbb7b
AC
25137-break-enable 2
25138^done
594fe323 25139(gdb)
922fbb7b
AC
25140-break-list
25141^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
25142hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25143@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25144@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25145@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25146@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25147@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25148body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
25149addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
25150line="5",times="0"@}]@}
594fe323 25151(gdb)
922fbb7b
AC
25152@end smallexample
25153
25154@subheading The @code{-break-info} Command
25155@findex -break-info
25156
25157@subsubheading Synopsis
25158
25159@smallexample
25160 -break-info @var{breakpoint}
25161@end smallexample
25162
25163@c REDUNDANT???
25164Get information about a single breakpoint.
25165
79a6e687 25166@subsubheading @value{GDBN} Command
922fbb7b
AC
25167
25168The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
25169
25170@subsubheading Example
25171N.A.
25172
25173@subheading The @code{-break-insert} Command
25174@findex -break-insert
25175
25176@subsubheading Synopsis
25177
25178@smallexample
18148017 25179 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 25180 [ -c @var{condition} ] [ -i @var{ignore-count} ]
afe8ab22 25181 [ -p @var{thread} ] [ @var{location} ]
922fbb7b
AC
25182@end smallexample
25183
25184@noindent
afe8ab22 25185If specified, @var{location}, can be one of:
922fbb7b
AC
25186
25187@itemize @bullet
25188@item function
25189@c @item +offset
25190@c @item -offset
25191@c @item linenum
25192@item filename:linenum
25193@item filename:function
25194@item *address
25195@end itemize
25196
25197The possible optional parameters of this command are:
25198
25199@table @samp
25200@item -t
948d5102 25201Insert a temporary breakpoint.
922fbb7b
AC
25202@item -h
25203Insert a hardware breakpoint.
25204@item -c @var{condition}
25205Make the breakpoint conditional on @var{condition}.
25206@item -i @var{ignore-count}
25207Initialize the @var{ignore-count}.
afe8ab22
VP
25208@item -f
25209If @var{location} cannot be parsed (for example if it
25210refers to unknown files or functions), create a pending
25211breakpoint. Without this flag, @value{GDBN} will report
25212an error, and won't create a breakpoint, if @var{location}
25213cannot be parsed.
41447f92
VP
25214@item -d
25215Create a disabled breakpoint.
18148017
VP
25216@item -a
25217Create a tracepoint. @xref{Tracepoints}. When this parameter
25218is used together with @samp{-h}, a fast tracepoint is created.
922fbb7b
AC
25219@end table
25220
25221@subsubheading Result
25222
25223The result is in the form:
25224
25225@smallexample
948d5102
NR
25226^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
25227enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
ef21caaf
NR
25228fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
25229times="@var{times}"@}
922fbb7b
AC
25230@end smallexample
25231
25232@noindent
948d5102
NR
25233where @var{number} is the @value{GDBN} number for this breakpoint,
25234@var{funcname} is the name of the function where the breakpoint was
25235inserted, @var{filename} is the name of the source file which contains
25236this function, @var{lineno} is the source line number within that file
25237and @var{times} the number of times that the breakpoint has been hit
25238(always 0 for -break-insert but may be greater for -break-info or -break-list
25239which use the same output).
922fbb7b
AC
25240
25241Note: this format is open to change.
25242@c An out-of-band breakpoint instead of part of the result?
25243
25244@subsubheading @value{GDBN} Command
25245
25246The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
25247@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
25248
25249@subsubheading Example
25250
25251@smallexample
594fe323 25252(gdb)
922fbb7b 25253-break-insert main
948d5102
NR
25254^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
25255fullname="/home/foo/recursive2.c,line="4",times="0"@}
594fe323 25256(gdb)
922fbb7b 25257-break-insert -t foo
948d5102
NR
25258^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
25259fullname="/home/foo/recursive2.c,line="11",times="0"@}
594fe323 25260(gdb)
922fbb7b
AC
25261-break-list
25262^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
25263hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25264@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25265@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25266@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25267@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25268@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25269body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
25270addr="0x0001072c", func="main",file="recursive2.c",
25271fullname="/home/foo/recursive2.c,"line="4",times="0"@},
922fbb7b 25272bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102
NR
25273addr="0x00010774",func="foo",file="recursive2.c",
25274fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
594fe323 25275(gdb)
922fbb7b
AC
25276-break-insert -r foo.*
25277~int foo(int, int);
948d5102
NR
25278^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
25279"fullname="/home/foo/recursive2.c",line="11",times="0"@}
594fe323 25280(gdb)
922fbb7b
AC
25281@end smallexample
25282
25283@subheading The @code{-break-list} Command
25284@findex -break-list
25285
25286@subsubheading Synopsis
25287
25288@smallexample
25289 -break-list
25290@end smallexample
25291
25292Displays the list of inserted breakpoints, showing the following fields:
25293
25294@table @samp
25295@item Number
25296number of the breakpoint
25297@item Type
25298type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
25299@item Disposition
25300should the breakpoint be deleted or disabled when it is hit: @samp{keep}
25301or @samp{nokeep}
25302@item Enabled
25303is the breakpoint enabled or no: @samp{y} or @samp{n}
25304@item Address
25305memory location at which the breakpoint is set
25306@item What
25307logical location of the breakpoint, expressed by function name, file
25308name, line number
25309@item Times
25310number of times the breakpoint has been hit
25311@end table
25312
25313If there are no breakpoints or watchpoints, the @code{BreakpointTable}
25314@code{body} field is an empty list.
25315
25316@subsubheading @value{GDBN} Command
25317
25318The corresponding @value{GDBN} command is @samp{info break}.
25319
25320@subsubheading Example
25321
25322@smallexample
594fe323 25323(gdb)
922fbb7b
AC
25324-break-list
25325^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
25326hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25327@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25328@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25329@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25330@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25331@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25332body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
25333addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
25334bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
25335addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
25336line="13",times="0"@}]@}
594fe323 25337(gdb)
922fbb7b
AC
25338@end smallexample
25339
25340Here's an example of the result when there are no breakpoints:
25341
25342@smallexample
594fe323 25343(gdb)
922fbb7b
AC
25344-break-list
25345^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
25346hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25347@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25348@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25349@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25350@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25351@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25352body=[]@}
594fe323 25353(gdb)
922fbb7b
AC
25354@end smallexample
25355
18148017
VP
25356@subheading The @code{-break-passcount} Command
25357@findex -break-passcount
25358
25359@subsubheading Synopsis
25360
25361@smallexample
25362 -break-passcount @var{tracepoint-number} @var{passcount}
25363@end smallexample
25364
25365Set the passcount for tracepoint @var{tracepoint-number} to
25366@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
25367is not a tracepoint, error is emitted. This corresponds to CLI
25368command @samp{passcount}.
25369
922fbb7b
AC
25370@subheading The @code{-break-watch} Command
25371@findex -break-watch
25372
25373@subsubheading Synopsis
25374
25375@smallexample
25376 -break-watch [ -a | -r ]
25377@end smallexample
25378
25379Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 25380@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 25381read from or on a write to the memory location. With the @samp{-r}
d3e8051b 25382option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
25383trigger only when the memory location is accessed for reading. Without
25384either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 25385i.e., it will trigger when the memory location is accessed for writing.
79a6e687 25386@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
25387
25388Note that @samp{-break-list} will report a single list of watchpoints and
25389breakpoints inserted.
25390
25391@subsubheading @value{GDBN} Command
25392
25393The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
25394@samp{rwatch}.
25395
25396@subsubheading Example
25397
25398Setting a watchpoint on a variable in the @code{main} function:
25399
25400@smallexample
594fe323 25401(gdb)
922fbb7b
AC
25402-break-watch x
25403^done,wpt=@{number="2",exp="x"@}
594fe323 25404(gdb)
922fbb7b
AC
25405-exec-continue
25406^running
0869d01b
NR
25407(gdb)
25408*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 25409value=@{old="-268439212",new="55"@},
76ff342d 25410frame=@{func="main",args=[],file="recursive2.c",
948d5102 25411fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 25412(gdb)
922fbb7b
AC
25413@end smallexample
25414
25415Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
25416the program execution twice: first for the variable changing value, then
25417for the watchpoint going out of scope.
25418
25419@smallexample
594fe323 25420(gdb)
922fbb7b
AC
25421-break-watch C
25422^done,wpt=@{number="5",exp="C"@}
594fe323 25423(gdb)
922fbb7b
AC
25424-exec-continue
25425^running
0869d01b
NR
25426(gdb)
25427*stopped,reason="watchpoint-trigger",
922fbb7b
AC
25428wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
25429frame=@{func="callee4",args=[],
76ff342d
DJ
25430file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25431fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 25432(gdb)
922fbb7b
AC
25433-exec-continue
25434^running
0869d01b
NR
25435(gdb)
25436*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
25437frame=@{func="callee3",args=[@{name="strarg",
25438value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
25439file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25440fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 25441(gdb)
922fbb7b
AC
25442@end smallexample
25443
25444Listing breakpoints and watchpoints, at different points in the program
25445execution. Note that once the watchpoint goes out of scope, it is
25446deleted.
25447
25448@smallexample
594fe323 25449(gdb)
922fbb7b
AC
25450-break-watch C
25451^done,wpt=@{number="2",exp="C"@}
594fe323 25452(gdb)
922fbb7b
AC
25453-break-list
25454^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
25455hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25456@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25457@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25458@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25459@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25460@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25461body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
25462addr="0x00010734",func="callee4",
948d5102
NR
25463file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25464fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
922fbb7b
AC
25465bkpt=@{number="2",type="watchpoint",disp="keep",
25466enabled="y",addr="",what="C",times="0"@}]@}
594fe323 25467(gdb)
922fbb7b
AC
25468-exec-continue
25469^running
0869d01b
NR
25470(gdb)
25471*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
25472value=@{old="-276895068",new="3"@},
25473frame=@{func="callee4",args=[],
76ff342d
DJ
25474file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25475fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 25476(gdb)
922fbb7b
AC
25477-break-list
25478^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
25479hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25480@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25481@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25482@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25483@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25484@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25485body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
25486addr="0x00010734",func="callee4",
948d5102
NR
25487file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25488fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
922fbb7b
AC
25489bkpt=@{number="2",type="watchpoint",disp="keep",
25490enabled="y",addr="",what="C",times="-5"@}]@}
594fe323 25491(gdb)
922fbb7b
AC
25492-exec-continue
25493^running
25494^done,reason="watchpoint-scope",wpnum="2",
25495frame=@{func="callee3",args=[@{name="strarg",
25496value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
25497file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25498fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 25499(gdb)
922fbb7b
AC
25500-break-list
25501^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
25502hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25503@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25504@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25505@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25506@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25507@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25508body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
25509addr="0x00010734",func="callee4",
948d5102
NR
25510file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25511fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
25512times="1"@}]@}
594fe323 25513(gdb)
922fbb7b
AC
25514@end smallexample
25515
25516@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
25517@node GDB/MI Program Context
25518@section @sc{gdb/mi} Program Context
922fbb7b 25519
a2c02241
NR
25520@subheading The @code{-exec-arguments} Command
25521@findex -exec-arguments
922fbb7b 25522
922fbb7b
AC
25523
25524@subsubheading Synopsis
25525
25526@smallexample
a2c02241 25527 -exec-arguments @var{args}
922fbb7b
AC
25528@end smallexample
25529
a2c02241
NR
25530Set the inferior program arguments, to be used in the next
25531@samp{-exec-run}.
922fbb7b 25532
a2c02241 25533@subsubheading @value{GDBN} Command
922fbb7b 25534
a2c02241 25535The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 25536
a2c02241 25537@subsubheading Example
922fbb7b 25538
fbc5282e
MK
25539@smallexample
25540(gdb)
25541-exec-arguments -v word
25542^done
25543(gdb)
25544@end smallexample
922fbb7b 25545
a2c02241 25546
9901a55b 25547@ignore
a2c02241
NR
25548@subheading The @code{-exec-show-arguments} Command
25549@findex -exec-show-arguments
25550
25551@subsubheading Synopsis
25552
25553@smallexample
25554 -exec-show-arguments
25555@end smallexample
25556
25557Print the arguments of the program.
922fbb7b
AC
25558
25559@subsubheading @value{GDBN} Command
25560
a2c02241 25561The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
25562
25563@subsubheading Example
a2c02241 25564N.A.
9901a55b 25565@end ignore
922fbb7b 25566
922fbb7b 25567
a2c02241
NR
25568@subheading The @code{-environment-cd} Command
25569@findex -environment-cd
922fbb7b 25570
a2c02241 25571@subsubheading Synopsis
922fbb7b
AC
25572
25573@smallexample
a2c02241 25574 -environment-cd @var{pathdir}
922fbb7b
AC
25575@end smallexample
25576
a2c02241 25577Set @value{GDBN}'s working directory.
922fbb7b 25578
a2c02241 25579@subsubheading @value{GDBN} Command
922fbb7b 25580
a2c02241
NR
25581The corresponding @value{GDBN} command is @samp{cd}.
25582
25583@subsubheading Example
922fbb7b
AC
25584
25585@smallexample
594fe323 25586(gdb)
a2c02241
NR
25587-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
25588^done
594fe323 25589(gdb)
922fbb7b
AC
25590@end smallexample
25591
25592
a2c02241
NR
25593@subheading The @code{-environment-directory} Command
25594@findex -environment-directory
922fbb7b
AC
25595
25596@subsubheading Synopsis
25597
25598@smallexample
a2c02241 25599 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
25600@end smallexample
25601
a2c02241
NR
25602Add directories @var{pathdir} to beginning of search path for source files.
25603If the @samp{-r} option is used, the search path is reset to the default
25604search path. If directories @var{pathdir} are supplied in addition to the
25605@samp{-r} option, the search path is first reset and then addition
25606occurs as normal.
25607Multiple directories may be specified, separated by blanks. Specifying
25608multiple directories in a single command
25609results in the directories added to the beginning of the
25610search path in the same order they were presented in the command.
25611If blanks are needed as
25612part of a directory name, double-quotes should be used around
25613the name. In the command output, the path will show up separated
d3e8051b 25614by the system directory-separator character. The directory-separator
a2c02241
NR
25615character must not be used
25616in any directory name.
25617If no directories are specified, the current search path is displayed.
922fbb7b
AC
25618
25619@subsubheading @value{GDBN} Command
25620
a2c02241 25621The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
25622
25623@subsubheading Example
25624
922fbb7b 25625@smallexample
594fe323 25626(gdb)
a2c02241
NR
25627-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
25628^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 25629(gdb)
a2c02241
NR
25630-environment-directory ""
25631^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 25632(gdb)
a2c02241
NR
25633-environment-directory -r /home/jjohnstn/src/gdb /usr/src
25634^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 25635(gdb)
a2c02241
NR
25636-environment-directory -r
25637^done,source-path="$cdir:$cwd"
594fe323 25638(gdb)
922fbb7b
AC
25639@end smallexample
25640
25641
a2c02241
NR
25642@subheading The @code{-environment-path} Command
25643@findex -environment-path
922fbb7b
AC
25644
25645@subsubheading Synopsis
25646
25647@smallexample
a2c02241 25648 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
25649@end smallexample
25650
a2c02241
NR
25651Add directories @var{pathdir} to beginning of search path for object files.
25652If the @samp{-r} option is used, the search path is reset to the original
25653search path that existed at gdb start-up. If directories @var{pathdir} are
25654supplied in addition to the
25655@samp{-r} option, the search path is first reset and then addition
25656occurs as normal.
25657Multiple directories may be specified, separated by blanks. Specifying
25658multiple directories in a single command
25659results in the directories added to the beginning of the
25660search path in the same order they were presented in the command.
25661If blanks are needed as
25662part of a directory name, double-quotes should be used around
25663the name. In the command output, the path will show up separated
d3e8051b 25664by the system directory-separator character. The directory-separator
a2c02241
NR
25665character must not be used
25666in any directory name.
25667If no directories are specified, the current path is displayed.
25668
922fbb7b
AC
25669
25670@subsubheading @value{GDBN} Command
25671
a2c02241 25672The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
25673
25674@subsubheading Example
25675
922fbb7b 25676@smallexample
594fe323 25677(gdb)
a2c02241
NR
25678-environment-path
25679^done,path="/usr/bin"
594fe323 25680(gdb)
a2c02241
NR
25681-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
25682^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 25683(gdb)
a2c02241
NR
25684-environment-path -r /usr/local/bin
25685^done,path="/usr/local/bin:/usr/bin"
594fe323 25686(gdb)
922fbb7b
AC
25687@end smallexample
25688
25689
a2c02241
NR
25690@subheading The @code{-environment-pwd} Command
25691@findex -environment-pwd
922fbb7b
AC
25692
25693@subsubheading Synopsis
25694
25695@smallexample
a2c02241 25696 -environment-pwd
922fbb7b
AC
25697@end smallexample
25698
a2c02241 25699Show the current working directory.
922fbb7b 25700
79a6e687 25701@subsubheading @value{GDBN} Command
922fbb7b 25702
a2c02241 25703The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
25704
25705@subsubheading Example
25706
922fbb7b 25707@smallexample
594fe323 25708(gdb)
a2c02241
NR
25709-environment-pwd
25710^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 25711(gdb)
922fbb7b
AC
25712@end smallexample
25713
a2c02241
NR
25714@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25715@node GDB/MI Thread Commands
25716@section @sc{gdb/mi} Thread Commands
25717
25718
25719@subheading The @code{-thread-info} Command
25720@findex -thread-info
922fbb7b
AC
25721
25722@subsubheading Synopsis
25723
25724@smallexample
8e8901c5 25725 -thread-info [ @var{thread-id} ]
922fbb7b
AC
25726@end smallexample
25727
8e8901c5
VP
25728Reports information about either a specific thread, if
25729the @var{thread-id} parameter is present, or about all
25730threads. When printing information about all threads,
25731also reports the current thread.
25732
79a6e687 25733@subsubheading @value{GDBN} Command
922fbb7b 25734
8e8901c5
VP
25735The @samp{info thread} command prints the same information
25736about all threads.
922fbb7b
AC
25737
25738@subsubheading Example
922fbb7b
AC
25739
25740@smallexample
8e8901c5
VP
25741-thread-info
25742^done,threads=[
25743@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
c3b108f7 25744 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
8e8901c5
VP
25745@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
25746 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
c3b108f7 25747 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}],
8e8901c5
VP
25748current-thread-id="1"
25749(gdb)
922fbb7b
AC
25750@end smallexample
25751
c3b108f7
VP
25752The @samp{state} field may have the following values:
25753
25754@table @code
25755@item stopped
25756The thread is stopped. Frame information is available for stopped
25757threads.
25758
25759@item running
25760The thread is running. There's no frame information for running
25761threads.
25762
25763@end table
25764
a2c02241
NR
25765@subheading The @code{-thread-list-ids} Command
25766@findex -thread-list-ids
922fbb7b 25767
a2c02241 25768@subsubheading Synopsis
922fbb7b 25769
a2c02241
NR
25770@smallexample
25771 -thread-list-ids
25772@end smallexample
922fbb7b 25773
a2c02241
NR
25774Produces a list of the currently known @value{GDBN} thread ids. At the
25775end of the list it also prints the total number of such threads.
922fbb7b 25776
c3b108f7
VP
25777This command is retained for historical reasons, the
25778@code{-thread-info} command should be used instead.
25779
922fbb7b
AC
25780@subsubheading @value{GDBN} Command
25781
a2c02241 25782Part of @samp{info threads} supplies the same information.
922fbb7b
AC
25783
25784@subsubheading Example
25785
922fbb7b 25786@smallexample
594fe323 25787(gdb)
a2c02241
NR
25788-thread-list-ids
25789^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 25790current-thread-id="1",number-of-threads="3"
594fe323 25791(gdb)
922fbb7b
AC
25792@end smallexample
25793
a2c02241
NR
25794
25795@subheading The @code{-thread-select} Command
25796@findex -thread-select
922fbb7b
AC
25797
25798@subsubheading Synopsis
25799
25800@smallexample
a2c02241 25801 -thread-select @var{threadnum}
922fbb7b
AC
25802@end smallexample
25803
a2c02241
NR
25804Make @var{threadnum} the current thread. It prints the number of the new
25805current thread, and the topmost frame for that thread.
922fbb7b 25806
c3b108f7
VP
25807This command is deprecated in favor of explicitly using the
25808@samp{--thread} option to each command.
25809
922fbb7b
AC
25810@subsubheading @value{GDBN} Command
25811
a2c02241 25812The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
25813
25814@subsubheading Example
922fbb7b
AC
25815
25816@smallexample
594fe323 25817(gdb)
a2c02241
NR
25818-exec-next
25819^running
594fe323 25820(gdb)
a2c02241
NR
25821*stopped,reason="end-stepping-range",thread-id="2",line="187",
25822file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 25823(gdb)
a2c02241
NR
25824-thread-list-ids
25825^done,
25826thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
25827number-of-threads="3"
594fe323 25828(gdb)
a2c02241
NR
25829-thread-select 3
25830^done,new-thread-id="3",
25831frame=@{level="0",func="vprintf",
25832args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
25833@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 25834(gdb)
922fbb7b
AC
25835@end smallexample
25836
a2c02241
NR
25837@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25838@node GDB/MI Program Execution
25839@section @sc{gdb/mi} Program Execution
922fbb7b 25840
ef21caaf 25841These are the asynchronous commands which generate the out-of-band
3f94c067 25842record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
25843asynchronously with remote targets and this interaction is mimicked in
25844other cases.
922fbb7b 25845
922fbb7b
AC
25846@subheading The @code{-exec-continue} Command
25847@findex -exec-continue
25848
25849@subsubheading Synopsis
25850
25851@smallexample
540aa8e7 25852 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
25853@end smallexample
25854
540aa8e7
MS
25855Resumes the execution of the inferior program, which will continue
25856to execute until it reaches a debugger stop event. If the
25857@samp{--reverse} option is specified, execution resumes in reverse until
25858it reaches a stop event. Stop events may include
25859@itemize @bullet
25860@item
25861breakpoints or watchpoints
25862@item
25863signals or exceptions
25864@item
25865the end of the process (or its beginning under @samp{--reverse})
25866@item
25867the end or beginning of a replay log if one is being used.
25868@end itemize
25869In all-stop mode (@pxref{All-Stop
25870Mode}), may resume only one thread, or all threads, depending on the
25871value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 25872specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
25873ignored in all-stop mode. If the @samp{--thread-group} options is
25874specified, then all threads in that thread group are resumed.
922fbb7b
AC
25875
25876@subsubheading @value{GDBN} Command
25877
25878The corresponding @value{GDBN} corresponding is @samp{continue}.
25879
25880@subsubheading Example
25881
25882@smallexample
25883-exec-continue
25884^running
594fe323 25885(gdb)
922fbb7b 25886@@Hello world
a47ec5fe
AR
25887*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
25888func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
25889line="13"@}
594fe323 25890(gdb)
922fbb7b
AC
25891@end smallexample
25892
25893
25894@subheading The @code{-exec-finish} Command
25895@findex -exec-finish
25896
25897@subsubheading Synopsis
25898
25899@smallexample
540aa8e7 25900 -exec-finish [--reverse]
922fbb7b
AC
25901@end smallexample
25902
ef21caaf
NR
25903Resumes the execution of the inferior program until the current
25904function is exited. Displays the results returned by the function.
540aa8e7
MS
25905If the @samp{--reverse} option is specified, resumes the reverse
25906execution of the inferior program until the point where current
25907function was called.
922fbb7b
AC
25908
25909@subsubheading @value{GDBN} Command
25910
25911The corresponding @value{GDBN} command is @samp{finish}.
25912
25913@subsubheading Example
25914
25915Function returning @code{void}.
25916
25917@smallexample
25918-exec-finish
25919^running
594fe323 25920(gdb)
922fbb7b
AC
25921@@hello from foo
25922*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 25923file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 25924(gdb)
922fbb7b
AC
25925@end smallexample
25926
25927Function returning other than @code{void}. The name of the internal
25928@value{GDBN} variable storing the result is printed, together with the
25929value itself.
25930
25931@smallexample
25932-exec-finish
25933^running
594fe323 25934(gdb)
922fbb7b
AC
25935*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
25936args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 25937file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 25938gdb-result-var="$1",return-value="0"
594fe323 25939(gdb)
922fbb7b
AC
25940@end smallexample
25941
25942
25943@subheading The @code{-exec-interrupt} Command
25944@findex -exec-interrupt
25945
25946@subsubheading Synopsis
25947
25948@smallexample
c3b108f7 25949 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
25950@end smallexample
25951
ef21caaf
NR
25952Interrupts the background execution of the target. Note how the token
25953associated with the stop message is the one for the execution command
25954that has been interrupted. The token for the interrupt itself only
25955appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
25956interrupt a non-running program, an error message will be printed.
25957
c3b108f7
VP
25958Note that when asynchronous execution is enabled, this command is
25959asynchronous just like other execution commands. That is, first the
25960@samp{^done} response will be printed, and the target stop will be
25961reported after that using the @samp{*stopped} notification.
25962
25963In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
25964All threads (in all inferiors) will be interrupted if the
25965@samp{--all} option is specified. If the @samp{--thread-group}
25966option is specified, all threads in that group will be interrupted.
c3b108f7 25967
922fbb7b
AC
25968@subsubheading @value{GDBN} Command
25969
25970The corresponding @value{GDBN} command is @samp{interrupt}.
25971
25972@subsubheading Example
25973
25974@smallexample
594fe323 25975(gdb)
922fbb7b
AC
25976111-exec-continue
25977111^running
25978
594fe323 25979(gdb)
922fbb7b
AC
25980222-exec-interrupt
25981222^done
594fe323 25982(gdb)
922fbb7b 25983111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 25984frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 25985fullname="/home/foo/bar/try.c",line="13"@}
594fe323 25986(gdb)
922fbb7b 25987
594fe323 25988(gdb)
922fbb7b
AC
25989-exec-interrupt
25990^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 25991(gdb)
922fbb7b
AC
25992@end smallexample
25993
83eba9b7
VP
25994@subheading The @code{-exec-jump} Command
25995@findex -exec-jump
25996
25997@subsubheading Synopsis
25998
25999@smallexample
26000 -exec-jump @var{location}
26001@end smallexample
26002
26003Resumes execution of the inferior program at the location specified by
26004parameter. @xref{Specify Location}, for a description of the
26005different forms of @var{location}.
26006
26007@subsubheading @value{GDBN} Command
26008
26009The corresponding @value{GDBN} command is @samp{jump}.
26010
26011@subsubheading Example
26012
26013@smallexample
26014-exec-jump foo.c:10
26015*running,thread-id="all"
26016^running
26017@end smallexample
26018
922fbb7b
AC
26019
26020@subheading The @code{-exec-next} Command
26021@findex -exec-next
26022
26023@subsubheading Synopsis
26024
26025@smallexample
540aa8e7 26026 -exec-next [--reverse]
922fbb7b
AC
26027@end smallexample
26028
ef21caaf
NR
26029Resumes execution of the inferior program, stopping when the beginning
26030of the next source line is reached.
922fbb7b 26031
540aa8e7
MS
26032If the @samp{--reverse} option is specified, resumes reverse execution
26033of the inferior program, stopping at the beginning of the previous
26034source line. If you issue this command on the first line of a
26035function, it will take you back to the caller of that function, to the
26036source line where the function was called.
26037
26038
922fbb7b
AC
26039@subsubheading @value{GDBN} Command
26040
26041The corresponding @value{GDBN} command is @samp{next}.
26042
26043@subsubheading Example
26044
26045@smallexample
26046-exec-next
26047^running
594fe323 26048(gdb)
922fbb7b 26049*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 26050(gdb)
922fbb7b
AC
26051@end smallexample
26052
26053
26054@subheading The @code{-exec-next-instruction} Command
26055@findex -exec-next-instruction
26056
26057@subsubheading Synopsis
26058
26059@smallexample
540aa8e7 26060 -exec-next-instruction [--reverse]
922fbb7b
AC
26061@end smallexample
26062
ef21caaf
NR
26063Executes one machine instruction. If the instruction is a function
26064call, continues until the function returns. If the program stops at an
26065instruction in the middle of a source line, the address will be
26066printed as well.
922fbb7b 26067
540aa8e7
MS
26068If the @samp{--reverse} option is specified, resumes reverse execution
26069of the inferior program, stopping at the previous instruction. If the
26070previously executed instruction was a return from another function,
26071it will continue to execute in reverse until the call to that function
26072(from the current stack frame) is reached.
26073
922fbb7b
AC
26074@subsubheading @value{GDBN} Command
26075
26076The corresponding @value{GDBN} command is @samp{nexti}.
26077
26078@subsubheading Example
26079
26080@smallexample
594fe323 26081(gdb)
922fbb7b
AC
26082-exec-next-instruction
26083^running
26084
594fe323 26085(gdb)
922fbb7b
AC
26086*stopped,reason="end-stepping-range",
26087addr="0x000100d4",line="5",file="hello.c"
594fe323 26088(gdb)
922fbb7b
AC
26089@end smallexample
26090
26091
26092@subheading The @code{-exec-return} Command
26093@findex -exec-return
26094
26095@subsubheading Synopsis
26096
26097@smallexample
26098 -exec-return
26099@end smallexample
26100
26101Makes current function return immediately. Doesn't execute the inferior.
26102Displays the new current frame.
26103
26104@subsubheading @value{GDBN} Command
26105
26106The corresponding @value{GDBN} command is @samp{return}.
26107
26108@subsubheading Example
26109
26110@smallexample
594fe323 26111(gdb)
922fbb7b
AC
26112200-break-insert callee4
26113200^done,bkpt=@{number="1",addr="0x00010734",
26114file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 26115(gdb)
922fbb7b
AC
26116000-exec-run
26117000^running
594fe323 26118(gdb)
a47ec5fe 26119000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 26120frame=@{func="callee4",args=[],
76ff342d
DJ
26121file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26122fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 26123(gdb)
922fbb7b
AC
26124205-break-delete
26125205^done
594fe323 26126(gdb)
922fbb7b
AC
26127111-exec-return
26128111^done,frame=@{level="0",func="callee3",
26129args=[@{name="strarg",
26130value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
26131file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26132fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 26133(gdb)
922fbb7b
AC
26134@end smallexample
26135
26136
26137@subheading The @code{-exec-run} Command
26138@findex -exec-run
26139
26140@subsubheading Synopsis
26141
26142@smallexample
a79b8f6e 26143 -exec-run [--all | --thread-group N]
922fbb7b
AC
26144@end smallexample
26145
ef21caaf
NR
26146Starts execution of the inferior from the beginning. The inferior
26147executes until either a breakpoint is encountered or the program
26148exits. In the latter case the output will include an exit code, if
26149the program has exited exceptionally.
922fbb7b 26150
a79b8f6e
VP
26151When no option is specified, the current inferior is started. If the
26152@samp{--thread-group} option is specified, it should refer to a thread
26153group of type @samp{process}, and that thread group will be started.
26154If the @samp{--all} option is specified, then all inferiors will be started.
26155
922fbb7b
AC
26156@subsubheading @value{GDBN} Command
26157
26158The corresponding @value{GDBN} command is @samp{run}.
26159
ef21caaf 26160@subsubheading Examples
922fbb7b
AC
26161
26162@smallexample
594fe323 26163(gdb)
922fbb7b
AC
26164-break-insert main
26165^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 26166(gdb)
922fbb7b
AC
26167-exec-run
26168^running
594fe323 26169(gdb)
a47ec5fe 26170*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 26171frame=@{func="main",args=[],file="recursive2.c",
948d5102 26172fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 26173(gdb)
922fbb7b
AC
26174@end smallexample
26175
ef21caaf
NR
26176@noindent
26177Program exited normally:
26178
26179@smallexample
594fe323 26180(gdb)
ef21caaf
NR
26181-exec-run
26182^running
594fe323 26183(gdb)
ef21caaf
NR
26184x = 55
26185*stopped,reason="exited-normally"
594fe323 26186(gdb)
ef21caaf
NR
26187@end smallexample
26188
26189@noindent
26190Program exited exceptionally:
26191
26192@smallexample
594fe323 26193(gdb)
ef21caaf
NR
26194-exec-run
26195^running
594fe323 26196(gdb)
ef21caaf
NR
26197x = 55
26198*stopped,reason="exited",exit-code="01"
594fe323 26199(gdb)
ef21caaf
NR
26200@end smallexample
26201
26202Another way the program can terminate is if it receives a signal such as
26203@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
26204
26205@smallexample
594fe323 26206(gdb)
ef21caaf
NR
26207*stopped,reason="exited-signalled",signal-name="SIGINT",
26208signal-meaning="Interrupt"
26209@end smallexample
26210
922fbb7b 26211
a2c02241
NR
26212@c @subheading -exec-signal
26213
26214
26215@subheading The @code{-exec-step} Command
26216@findex -exec-step
922fbb7b
AC
26217
26218@subsubheading Synopsis
26219
26220@smallexample
540aa8e7 26221 -exec-step [--reverse]
922fbb7b
AC
26222@end smallexample
26223
a2c02241
NR
26224Resumes execution of the inferior program, stopping when the beginning
26225of the next source line is reached, if the next source line is not a
26226function call. If it is, stop at the first instruction of the called
540aa8e7
MS
26227function. If the @samp{--reverse} option is specified, resumes reverse
26228execution of the inferior program, stopping at the beginning of the
26229previously executed source line.
922fbb7b
AC
26230
26231@subsubheading @value{GDBN} Command
26232
a2c02241 26233The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
26234
26235@subsubheading Example
26236
26237Stepping into a function:
26238
26239@smallexample
26240-exec-step
26241^running
594fe323 26242(gdb)
922fbb7b
AC
26243*stopped,reason="end-stepping-range",
26244frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 26245@{name="b",value="0"@}],file="recursive2.c",
948d5102 26246fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 26247(gdb)
922fbb7b
AC
26248@end smallexample
26249
26250Regular stepping:
26251
26252@smallexample
26253-exec-step
26254^running
594fe323 26255(gdb)
922fbb7b 26256*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 26257(gdb)
922fbb7b
AC
26258@end smallexample
26259
26260
26261@subheading The @code{-exec-step-instruction} Command
26262@findex -exec-step-instruction
26263
26264@subsubheading Synopsis
26265
26266@smallexample
540aa8e7 26267 -exec-step-instruction [--reverse]
922fbb7b
AC
26268@end smallexample
26269
540aa8e7
MS
26270Resumes the inferior which executes one machine instruction. If the
26271@samp{--reverse} option is specified, resumes reverse execution of the
26272inferior program, stopping at the previously executed instruction.
26273The output, once @value{GDBN} has stopped, will vary depending on
26274whether we have stopped in the middle of a source line or not. In the
26275former case, the address at which the program stopped will be printed
26276as well.
922fbb7b
AC
26277
26278@subsubheading @value{GDBN} Command
26279
26280The corresponding @value{GDBN} command is @samp{stepi}.
26281
26282@subsubheading Example
26283
26284@smallexample
594fe323 26285(gdb)
922fbb7b
AC
26286-exec-step-instruction
26287^running
26288
594fe323 26289(gdb)
922fbb7b 26290*stopped,reason="end-stepping-range",
76ff342d 26291frame=@{func="foo",args=[],file="try.c",
948d5102 26292fullname="/home/foo/bar/try.c",line="10"@}
594fe323 26293(gdb)
922fbb7b
AC
26294-exec-step-instruction
26295^running
26296
594fe323 26297(gdb)
922fbb7b 26298*stopped,reason="end-stepping-range",
76ff342d 26299frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 26300fullname="/home/foo/bar/try.c",line="10"@}
594fe323 26301(gdb)
922fbb7b
AC
26302@end smallexample
26303
26304
26305@subheading The @code{-exec-until} Command
26306@findex -exec-until
26307
26308@subsubheading Synopsis
26309
26310@smallexample
26311 -exec-until [ @var{location} ]
26312@end smallexample
26313
ef21caaf
NR
26314Executes the inferior until the @var{location} specified in the
26315argument is reached. If there is no argument, the inferior executes
26316until a source line greater than the current one is reached. The
26317reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
26318
26319@subsubheading @value{GDBN} Command
26320
26321The corresponding @value{GDBN} command is @samp{until}.
26322
26323@subsubheading Example
26324
26325@smallexample
594fe323 26326(gdb)
922fbb7b
AC
26327-exec-until recursive2.c:6
26328^running
594fe323 26329(gdb)
922fbb7b
AC
26330x = 55
26331*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 26332file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 26333(gdb)
922fbb7b
AC
26334@end smallexample
26335
26336@ignore
26337@subheading -file-clear
26338Is this going away????
26339@end ignore
26340
351ff01a 26341@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
26342@node GDB/MI Stack Manipulation
26343@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 26344
922fbb7b 26345
a2c02241
NR
26346@subheading The @code{-stack-info-frame} Command
26347@findex -stack-info-frame
922fbb7b
AC
26348
26349@subsubheading Synopsis
26350
26351@smallexample
a2c02241 26352 -stack-info-frame
922fbb7b
AC
26353@end smallexample
26354
a2c02241 26355Get info on the selected frame.
922fbb7b
AC
26356
26357@subsubheading @value{GDBN} Command
26358
a2c02241
NR
26359The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
26360(without arguments).
922fbb7b
AC
26361
26362@subsubheading Example
26363
26364@smallexample
594fe323 26365(gdb)
a2c02241
NR
26366-stack-info-frame
26367^done,frame=@{level="1",addr="0x0001076c",func="callee3",
26368file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26369fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 26370(gdb)
922fbb7b
AC
26371@end smallexample
26372
a2c02241
NR
26373@subheading The @code{-stack-info-depth} Command
26374@findex -stack-info-depth
922fbb7b
AC
26375
26376@subsubheading Synopsis
26377
26378@smallexample
a2c02241 26379 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
26380@end smallexample
26381
a2c02241
NR
26382Return the depth of the stack. If the integer argument @var{max-depth}
26383is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
26384
26385@subsubheading @value{GDBN} Command
26386
a2c02241 26387There's no equivalent @value{GDBN} command.
922fbb7b
AC
26388
26389@subsubheading Example
26390
a2c02241
NR
26391For a stack with frame levels 0 through 11:
26392
922fbb7b 26393@smallexample
594fe323 26394(gdb)
a2c02241
NR
26395-stack-info-depth
26396^done,depth="12"
594fe323 26397(gdb)
a2c02241
NR
26398-stack-info-depth 4
26399^done,depth="4"
594fe323 26400(gdb)
a2c02241
NR
26401-stack-info-depth 12
26402^done,depth="12"
594fe323 26403(gdb)
a2c02241
NR
26404-stack-info-depth 11
26405^done,depth="11"
594fe323 26406(gdb)
a2c02241
NR
26407-stack-info-depth 13
26408^done,depth="12"
594fe323 26409(gdb)
922fbb7b
AC
26410@end smallexample
26411
a2c02241
NR
26412@subheading The @code{-stack-list-arguments} Command
26413@findex -stack-list-arguments
922fbb7b
AC
26414
26415@subsubheading Synopsis
26416
26417@smallexample
3afae151 26418 -stack-list-arguments @var{print-values}
a2c02241 26419 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
26420@end smallexample
26421
a2c02241
NR
26422Display a list of the arguments for the frames between @var{low-frame}
26423and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
26424@var{high-frame} are not provided, list the arguments for the whole
26425call stack. If the two arguments are equal, show the single frame
26426at the corresponding level. It is an error if @var{low-frame} is
26427larger than the actual number of frames. On the other hand,
26428@var{high-frame} may be larger than the actual number of frames, in
26429which case only existing frames will be returned.
a2c02241 26430
3afae151
VP
26431If @var{print-values} is 0 or @code{--no-values}, print only the names of
26432the variables; if it is 1 or @code{--all-values}, print also their
26433values; and if it is 2 or @code{--simple-values}, print the name,
26434type and value for simple data types, and the name and type for arrays,
26435structures and unions.
922fbb7b 26436
b3372f91
VP
26437Use of this command to obtain arguments in a single frame is
26438deprecated in favor of the @samp{-stack-list-variables} command.
26439
922fbb7b
AC
26440@subsubheading @value{GDBN} Command
26441
a2c02241
NR
26442@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
26443@samp{gdb_get_args} command which partially overlaps with the
26444functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
26445
26446@subsubheading Example
922fbb7b 26447
a2c02241 26448@smallexample
594fe323 26449(gdb)
a2c02241
NR
26450-stack-list-frames
26451^done,
26452stack=[
26453frame=@{level="0",addr="0x00010734",func="callee4",
26454file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26455fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
26456frame=@{level="1",addr="0x0001076c",func="callee3",
26457file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26458fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
26459frame=@{level="2",addr="0x0001078c",func="callee2",
26460file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26461fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
26462frame=@{level="3",addr="0x000107b4",func="callee1",
26463file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26464fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
26465frame=@{level="4",addr="0x000107e0",func="main",
26466file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26467fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 26468(gdb)
a2c02241
NR
26469-stack-list-arguments 0
26470^done,
26471stack-args=[
26472frame=@{level="0",args=[]@},
26473frame=@{level="1",args=[name="strarg"]@},
26474frame=@{level="2",args=[name="intarg",name="strarg"]@},
26475frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
26476frame=@{level="4",args=[]@}]
594fe323 26477(gdb)
a2c02241
NR
26478-stack-list-arguments 1
26479^done,
26480stack-args=[
26481frame=@{level="0",args=[]@},
26482frame=@{level="1",
26483 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
26484frame=@{level="2",args=[
26485@{name="intarg",value="2"@},
26486@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
26487@{frame=@{level="3",args=[
26488@{name="intarg",value="2"@},
26489@{name="strarg",value="0x11940 \"A string argument.\""@},
26490@{name="fltarg",value="3.5"@}]@},
26491frame=@{level="4",args=[]@}]
594fe323 26492(gdb)
a2c02241
NR
26493-stack-list-arguments 0 2 2
26494^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 26495(gdb)
a2c02241
NR
26496-stack-list-arguments 1 2 2
26497^done,stack-args=[frame=@{level="2",
26498args=[@{name="intarg",value="2"@},
26499@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 26500(gdb)
a2c02241
NR
26501@end smallexample
26502
26503@c @subheading -stack-list-exception-handlers
922fbb7b 26504
a2c02241
NR
26505
26506@subheading The @code{-stack-list-frames} Command
26507@findex -stack-list-frames
1abaf70c
BR
26508
26509@subsubheading Synopsis
26510
26511@smallexample
a2c02241 26512 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
26513@end smallexample
26514
a2c02241
NR
26515List the frames currently on the stack. For each frame it displays the
26516following info:
26517
26518@table @samp
26519@item @var{level}
d3e8051b 26520The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
26521@item @var{addr}
26522The @code{$pc} value for that frame.
26523@item @var{func}
26524Function name.
26525@item @var{file}
26526File name of the source file where the function lives.
7d288aaa
TT
26527@item @var{fullname}
26528The full file name of the source file where the function lives.
a2c02241
NR
26529@item @var{line}
26530Line number corresponding to the @code{$pc}.
7d288aaa
TT
26531@item @var{from}
26532The shared library where this function is defined. This is only given
26533if the frame's function is not known.
a2c02241
NR
26534@end table
26535
26536If invoked without arguments, this command prints a backtrace for the
26537whole stack. If given two integer arguments, it shows the frames whose
26538levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
26539are equal, it shows the single frame at the corresponding level. It is
26540an error if @var{low-frame} is larger than the actual number of
a5451f4e 26541frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 26542actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
26543
26544@subsubheading @value{GDBN} Command
26545
a2c02241 26546The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
26547
26548@subsubheading Example
26549
a2c02241
NR
26550Full stack backtrace:
26551
1abaf70c 26552@smallexample
594fe323 26553(gdb)
a2c02241
NR
26554-stack-list-frames
26555^done,stack=
26556[frame=@{level="0",addr="0x0001076c",func="foo",
26557 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
26558frame=@{level="1",addr="0x000107a4",func="foo",
26559 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26560frame=@{level="2",addr="0x000107a4",func="foo",
26561 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26562frame=@{level="3",addr="0x000107a4",func="foo",
26563 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26564frame=@{level="4",addr="0x000107a4",func="foo",
26565 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26566frame=@{level="5",addr="0x000107a4",func="foo",
26567 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26568frame=@{level="6",addr="0x000107a4",func="foo",
26569 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26570frame=@{level="7",addr="0x000107a4",func="foo",
26571 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26572frame=@{level="8",addr="0x000107a4",func="foo",
26573 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26574frame=@{level="9",addr="0x000107a4",func="foo",
26575 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26576frame=@{level="10",addr="0x000107a4",func="foo",
26577 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26578frame=@{level="11",addr="0x00010738",func="main",
26579 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 26580(gdb)
1abaf70c
BR
26581@end smallexample
26582
a2c02241 26583Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 26584
a2c02241 26585@smallexample
594fe323 26586(gdb)
a2c02241
NR
26587-stack-list-frames 3 5
26588^done,stack=
26589[frame=@{level="3",addr="0x000107a4",func="foo",
26590 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26591frame=@{level="4",addr="0x000107a4",func="foo",
26592 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
26593frame=@{level="5",addr="0x000107a4",func="foo",
26594 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 26595(gdb)
a2c02241 26596@end smallexample
922fbb7b 26597
a2c02241 26598Show a single frame:
922fbb7b
AC
26599
26600@smallexample
594fe323 26601(gdb)
a2c02241
NR
26602-stack-list-frames 3 3
26603^done,stack=
26604[frame=@{level="3",addr="0x000107a4",func="foo",
26605 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 26606(gdb)
922fbb7b
AC
26607@end smallexample
26608
922fbb7b 26609
a2c02241
NR
26610@subheading The @code{-stack-list-locals} Command
26611@findex -stack-list-locals
57c22c6c 26612
a2c02241 26613@subsubheading Synopsis
922fbb7b
AC
26614
26615@smallexample
a2c02241 26616 -stack-list-locals @var{print-values}
922fbb7b
AC
26617@end smallexample
26618
a2c02241
NR
26619Display the local variable names for the selected frame. If
26620@var{print-values} is 0 or @code{--no-values}, print only the names of
26621the variables; if it is 1 or @code{--all-values}, print also their
26622values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 26623type and value for simple data types, and the name and type for arrays,
a2c02241
NR
26624structures and unions. In this last case, a frontend can immediately
26625display the value of simple data types and create variable objects for
d3e8051b 26626other data types when the user wishes to explore their values in
a2c02241 26627more detail.
922fbb7b 26628
b3372f91
VP
26629This command is deprecated in favor of the
26630@samp{-stack-list-variables} command.
26631
922fbb7b
AC
26632@subsubheading @value{GDBN} Command
26633
a2c02241 26634@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
26635
26636@subsubheading Example
922fbb7b
AC
26637
26638@smallexample
594fe323 26639(gdb)
a2c02241
NR
26640-stack-list-locals 0
26641^done,locals=[name="A",name="B",name="C"]
594fe323 26642(gdb)
a2c02241
NR
26643-stack-list-locals --all-values
26644^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
26645 @{name="C",value="@{1, 2, 3@}"@}]
26646-stack-list-locals --simple-values
26647^done,locals=[@{name="A",type="int",value="1"@},
26648 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 26649(gdb)
922fbb7b
AC
26650@end smallexample
26651
b3372f91
VP
26652@subheading The @code{-stack-list-variables} Command
26653@findex -stack-list-variables
26654
26655@subsubheading Synopsis
26656
26657@smallexample
26658 -stack-list-variables @var{print-values}
26659@end smallexample
26660
26661Display the names of local variables and function arguments for the selected frame. If
26662@var{print-values} is 0 or @code{--no-values}, print only the names of
26663the variables; if it is 1 or @code{--all-values}, print also their
26664values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 26665type and value for simple data types, and the name and type for arrays,
b3372f91
VP
26666structures and unions.
26667
26668@subsubheading Example
26669
26670@smallexample
26671(gdb)
26672-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 26673^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
26674(gdb)
26675@end smallexample
26676
922fbb7b 26677
a2c02241
NR
26678@subheading The @code{-stack-select-frame} Command
26679@findex -stack-select-frame
922fbb7b
AC
26680
26681@subsubheading Synopsis
26682
26683@smallexample
a2c02241 26684 -stack-select-frame @var{framenum}
922fbb7b
AC
26685@end smallexample
26686
a2c02241
NR
26687Change the selected frame. Select a different frame @var{framenum} on
26688the stack.
922fbb7b 26689
c3b108f7
VP
26690This command in deprecated in favor of passing the @samp{--frame}
26691option to every command.
26692
922fbb7b
AC
26693@subsubheading @value{GDBN} Command
26694
a2c02241
NR
26695The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
26696@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
26697
26698@subsubheading Example
26699
26700@smallexample
594fe323 26701(gdb)
a2c02241 26702-stack-select-frame 2
922fbb7b 26703^done
594fe323 26704(gdb)
922fbb7b
AC
26705@end smallexample
26706
26707@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
26708@node GDB/MI Variable Objects
26709@section @sc{gdb/mi} Variable Objects
922fbb7b 26710
a1b5960f 26711@ignore
922fbb7b 26712
a2c02241 26713@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 26714
a2c02241
NR
26715For the implementation of a variable debugger window (locals, watched
26716expressions, etc.), we are proposing the adaptation of the existing code
26717used by @code{Insight}.
922fbb7b 26718
a2c02241 26719The two main reasons for that are:
922fbb7b 26720
a2c02241
NR
26721@enumerate 1
26722@item
26723It has been proven in practice (it is already on its second generation).
922fbb7b 26724
a2c02241
NR
26725@item
26726It will shorten development time (needless to say how important it is
26727now).
26728@end enumerate
922fbb7b 26729
a2c02241
NR
26730The original interface was designed to be used by Tcl code, so it was
26731slightly changed so it could be used through @sc{gdb/mi}. This section
26732describes the @sc{gdb/mi} operations that will be available and gives some
26733hints about their use.
922fbb7b 26734
a2c02241
NR
26735@emph{Note}: In addition to the set of operations described here, we
26736expect the @sc{gui} implementation of a variable window to require, at
26737least, the following operations:
922fbb7b 26738
a2c02241
NR
26739@itemize @bullet
26740@item @code{-gdb-show} @code{output-radix}
26741@item @code{-stack-list-arguments}
26742@item @code{-stack-list-locals}
26743@item @code{-stack-select-frame}
26744@end itemize
922fbb7b 26745
a1b5960f
VP
26746@end ignore
26747
c8b2f53c 26748@subheading Introduction to Variable Objects
922fbb7b 26749
a2c02241 26750@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
26751
26752Variable objects are "object-oriented" MI interface for examining and
26753changing values of expressions. Unlike some other MI interfaces that
26754work with expressions, variable objects are specifically designed for
26755simple and efficient presentation in the frontend. A variable object
26756is identified by string name. When a variable object is created, the
26757frontend specifies the expression for that variable object. The
26758expression can be a simple variable, or it can be an arbitrary complex
26759expression, and can even involve CPU registers. After creating a
26760variable object, the frontend can invoke other variable object
26761operations---for example to obtain or change the value of a variable
26762object, or to change display format.
26763
26764Variable objects have hierarchical tree structure. Any variable object
26765that corresponds to a composite type, such as structure in C, has
26766a number of child variable objects, for example corresponding to each
26767element of a structure. A child variable object can itself have
26768children, recursively. Recursion ends when we reach
25d5ea92
VP
26769leaf variable objects, which always have built-in types. Child variable
26770objects are created only by explicit request, so if a frontend
26771is not interested in the children of a particular variable object, no
26772child will be created.
c8b2f53c
VP
26773
26774For a leaf variable object it is possible to obtain its value as a
26775string, or set the value from a string. String value can be also
26776obtained for a non-leaf variable object, but it's generally a string
26777that only indicates the type of the object, and does not list its
26778contents. Assignment to a non-leaf variable object is not allowed.
26779
26780A frontend does not need to read the values of all variable objects each time
26781the program stops. Instead, MI provides an update command that lists all
26782variable objects whose values has changed since the last update
26783operation. This considerably reduces the amount of data that must
25d5ea92
VP
26784be transferred to the frontend. As noted above, children variable
26785objects are created on demand, and only leaf variable objects have a
26786real value. As result, gdb will read target memory only for leaf
26787variables that frontend has created.
26788
26789The automatic update is not always desirable. For example, a frontend
26790might want to keep a value of some expression for future reference,
26791and never update it. For another example, fetching memory is
26792relatively slow for embedded targets, so a frontend might want
26793to disable automatic update for the variables that are either not
26794visible on the screen, or ``closed''. This is possible using so
26795called ``frozen variable objects''. Such variable objects are never
26796implicitly updated.
922fbb7b 26797
c3b108f7
VP
26798Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
26799fixed variable object, the expression is parsed when the variable
26800object is created, including associating identifiers to specific
26801variables. The meaning of expression never changes. For a floating
26802variable object the values of variables whose names appear in the
26803expressions are re-evaluated every time in the context of the current
26804frame. Consider this example:
26805
26806@smallexample
26807void do_work(...)
26808@{
26809 struct work_state state;
26810
26811 if (...)
26812 do_work(...);
26813@}
26814@end smallexample
26815
26816If a fixed variable object for the @code{state} variable is created in
26817this function, and we enter the recursive call, the the variable
26818object will report the value of @code{state} in the top-level
26819@code{do_work} invocation. On the other hand, a floating variable
26820object will report the value of @code{state} in the current frame.
26821
26822If an expression specified when creating a fixed variable object
26823refers to a local variable, the variable object becomes bound to the
26824thread and frame in which the variable object is created. When such
26825variable object is updated, @value{GDBN} makes sure that the
26826thread/frame combination the variable object is bound to still exists,
26827and re-evaluates the variable object in context of that thread/frame.
26828
a2c02241
NR
26829The following is the complete set of @sc{gdb/mi} operations defined to
26830access this functionality:
922fbb7b 26831
a2c02241
NR
26832@multitable @columnfractions .4 .6
26833@item @strong{Operation}
26834@tab @strong{Description}
922fbb7b 26835
0cc7d26f
TT
26836@item @code{-enable-pretty-printing}
26837@tab enable Python-based pretty-printing
a2c02241
NR
26838@item @code{-var-create}
26839@tab create a variable object
26840@item @code{-var-delete}
22d8a470 26841@tab delete the variable object and/or its children
a2c02241
NR
26842@item @code{-var-set-format}
26843@tab set the display format of this variable
26844@item @code{-var-show-format}
26845@tab show the display format of this variable
26846@item @code{-var-info-num-children}
26847@tab tells how many children this object has
26848@item @code{-var-list-children}
26849@tab return a list of the object's children
26850@item @code{-var-info-type}
26851@tab show the type of this variable object
26852@item @code{-var-info-expression}
02142340
VP
26853@tab print parent-relative expression that this variable object represents
26854@item @code{-var-info-path-expression}
26855@tab print full expression that this variable object represents
a2c02241
NR
26856@item @code{-var-show-attributes}
26857@tab is this variable editable? does it exist here?
26858@item @code{-var-evaluate-expression}
26859@tab get the value of this variable
26860@item @code{-var-assign}
26861@tab set the value of this variable
26862@item @code{-var-update}
26863@tab update the variable and its children
25d5ea92
VP
26864@item @code{-var-set-frozen}
26865@tab set frozeness attribute
0cc7d26f
TT
26866@item @code{-var-set-update-range}
26867@tab set range of children to display on update
a2c02241 26868@end multitable
922fbb7b 26869
a2c02241
NR
26870In the next subsection we describe each operation in detail and suggest
26871how it can be used.
922fbb7b 26872
a2c02241 26873@subheading Description And Use of Operations on Variable Objects
922fbb7b 26874
0cc7d26f
TT
26875@subheading The @code{-enable-pretty-printing} Command
26876@findex -enable-pretty-printing
26877
26878@smallexample
26879-enable-pretty-printing
26880@end smallexample
26881
26882@value{GDBN} allows Python-based visualizers to affect the output of the
26883MI variable object commands. However, because there was no way to
26884implement this in a fully backward-compatible way, a front end must
26885request that this functionality be enabled.
26886
26887Once enabled, this feature cannot be disabled.
26888
26889Note that if Python support has not been compiled into @value{GDBN},
26890this command will still succeed (and do nothing).
26891
f43030c4
TT
26892This feature is currently (as of @value{GDBN} 7.0) experimental, and
26893may work differently in future versions of @value{GDBN}.
26894
a2c02241
NR
26895@subheading The @code{-var-create} Command
26896@findex -var-create
ef21caaf 26897
a2c02241 26898@subsubheading Synopsis
ef21caaf 26899
a2c02241
NR
26900@smallexample
26901 -var-create @{@var{name} | "-"@}
c3b108f7 26902 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
26903@end smallexample
26904
26905This operation creates a variable object, which allows the monitoring of
26906a variable, the result of an expression, a memory cell or a CPU
26907register.
ef21caaf 26908
a2c02241
NR
26909The @var{name} parameter is the string by which the object can be
26910referenced. It must be unique. If @samp{-} is specified, the varobj
26911system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 26912unique provided that one does not specify @var{name} of that format.
a2c02241 26913The command fails if a duplicate name is found.
ef21caaf 26914
a2c02241
NR
26915The frame under which the expression should be evaluated can be
26916specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
26917frame should be used. A @samp{@@} indicates that a floating variable
26918object must be created.
922fbb7b 26919
a2c02241
NR
26920@var{expression} is any expression valid on the current language set (must not
26921begin with a @samp{*}), or one of the following:
922fbb7b 26922
a2c02241
NR
26923@itemize @bullet
26924@item
26925@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 26926
a2c02241
NR
26927@item
26928@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 26929
a2c02241
NR
26930@item
26931@samp{$@var{regname}} --- a CPU register name
26932@end itemize
922fbb7b 26933
0cc7d26f
TT
26934@cindex dynamic varobj
26935A varobj's contents may be provided by a Python-based pretty-printer. In this
26936case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
26937have slightly different semantics in some cases. If the
26938@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
26939will never create a dynamic varobj. This ensures backward
26940compatibility for existing clients.
26941
a2c02241 26942@subsubheading Result
922fbb7b 26943
0cc7d26f
TT
26944This operation returns attributes of the newly-created varobj. These
26945are:
26946
26947@table @samp
26948@item name
26949The name of the varobj.
26950
26951@item numchild
26952The number of children of the varobj. This number is not necessarily
26953reliable for a dynamic varobj. Instead, you must examine the
26954@samp{has_more} attribute.
26955
26956@item value
26957The varobj's scalar value. For a varobj whose type is some sort of
26958aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
26959will not be interesting.
26960
26961@item type
26962The varobj's type. This is a string representation of the type, as
26963would be printed by the @value{GDBN} CLI.
26964
26965@item thread-id
26966If a variable object is bound to a specific thread, then this is the
26967thread's identifier.
26968
26969@item has_more
26970For a dynamic varobj, this indicates whether there appear to be any
26971children available. For a non-dynamic varobj, this will be 0.
26972
26973@item dynamic
26974This attribute will be present and have the value @samp{1} if the
26975varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
26976then this attribute will not be present.
26977
26978@item displayhint
26979A dynamic varobj can supply a display hint to the front end. The
26980value comes directly from the Python pretty-printer object's
4c374409 26981@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
26982@end table
26983
26984Typical output will look like this:
922fbb7b
AC
26985
26986@smallexample
0cc7d26f
TT
26987 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
26988 has_more="@var{has_more}"
dcaaae04
NR
26989@end smallexample
26990
a2c02241
NR
26991
26992@subheading The @code{-var-delete} Command
26993@findex -var-delete
922fbb7b
AC
26994
26995@subsubheading Synopsis
26996
26997@smallexample
22d8a470 26998 -var-delete [ -c ] @var{name}
922fbb7b
AC
26999@end smallexample
27000
a2c02241 27001Deletes a previously created variable object and all of its children.
22d8a470 27002With the @samp{-c} option, just deletes the children.
922fbb7b 27003
a2c02241 27004Returns an error if the object @var{name} is not found.
922fbb7b 27005
922fbb7b 27006
a2c02241
NR
27007@subheading The @code{-var-set-format} Command
27008@findex -var-set-format
922fbb7b 27009
a2c02241 27010@subsubheading Synopsis
922fbb7b
AC
27011
27012@smallexample
a2c02241 27013 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
27014@end smallexample
27015
a2c02241
NR
27016Sets the output format for the value of the object @var{name} to be
27017@var{format-spec}.
27018
de051565 27019@anchor{-var-set-format}
a2c02241
NR
27020The syntax for the @var{format-spec} is as follows:
27021
27022@smallexample
27023 @var{format-spec} @expansion{}
27024 @{binary | decimal | hexadecimal | octal | natural@}
27025@end smallexample
27026
c8b2f53c
VP
27027The natural format is the default format choosen automatically
27028based on the variable type (like decimal for an @code{int}, hex
27029for pointers, etc.).
27030
27031For a variable with children, the format is set only on the
27032variable itself, and the children are not affected.
a2c02241
NR
27033
27034@subheading The @code{-var-show-format} Command
27035@findex -var-show-format
922fbb7b
AC
27036
27037@subsubheading Synopsis
27038
27039@smallexample
a2c02241 27040 -var-show-format @var{name}
922fbb7b
AC
27041@end smallexample
27042
a2c02241 27043Returns the format used to display the value of the object @var{name}.
922fbb7b 27044
a2c02241
NR
27045@smallexample
27046 @var{format} @expansion{}
27047 @var{format-spec}
27048@end smallexample
922fbb7b 27049
922fbb7b 27050
a2c02241
NR
27051@subheading The @code{-var-info-num-children} Command
27052@findex -var-info-num-children
27053
27054@subsubheading Synopsis
27055
27056@smallexample
27057 -var-info-num-children @var{name}
27058@end smallexample
27059
27060Returns the number of children of a variable object @var{name}:
27061
27062@smallexample
27063 numchild=@var{n}
27064@end smallexample
27065
0cc7d26f
TT
27066Note that this number is not completely reliable for a dynamic varobj.
27067It will return the current number of children, but more children may
27068be available.
27069
a2c02241
NR
27070
27071@subheading The @code{-var-list-children} Command
27072@findex -var-list-children
27073
27074@subsubheading Synopsis
27075
27076@smallexample
0cc7d26f 27077 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 27078@end smallexample
b569d230 27079@anchor{-var-list-children}
a2c02241
NR
27080
27081Return a list of the children of the specified variable object and
27082create variable objects for them, if they do not already exist. With
f5011d11 27083a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
27084@code{--no-values}, print only the names of the variables; if
27085@var{print-values} is 1 or @code{--all-values}, also print their
27086values; and if it is 2 or @code{--simple-values} print the name and
27087value for simple data types and just the name for arrays, structures
27088and unions.
922fbb7b 27089
0cc7d26f
TT
27090@var{from} and @var{to}, if specified, indicate the range of children
27091to report. If @var{from} or @var{to} is less than zero, the range is
27092reset and all children will be reported. Otherwise, children starting
27093at @var{from} (zero-based) and up to and excluding @var{to} will be
27094reported.
27095
27096If a child range is requested, it will only affect the current call to
27097@code{-var-list-children}, but not future calls to @code{-var-update}.
27098For this, you must instead use @code{-var-set-update-range}. The
27099intent of this approach is to enable a front end to implement any
27100update approach it likes; for example, scrolling a view may cause the
27101front end to request more children with @code{-var-list-children}, and
27102then the front end could call @code{-var-set-update-range} with a
27103different range to ensure that future updates are restricted to just
27104the visible items.
27105
b569d230
EZ
27106For each child the following results are returned:
27107
27108@table @var
27109
27110@item name
27111Name of the variable object created for this child.
27112
27113@item exp
27114The expression to be shown to the user by the front end to designate this child.
27115For example this may be the name of a structure member.
27116
0cc7d26f
TT
27117For a dynamic varobj, this value cannot be used to form an
27118expression. There is no way to do this at all with a dynamic varobj.
27119
b569d230
EZ
27120For C/C@t{++} structures there are several pseudo children returned to
27121designate access qualifiers. For these pseudo children @var{exp} is
27122@samp{public}, @samp{private}, or @samp{protected}. In this case the
27123type and value are not present.
27124
0cc7d26f
TT
27125A dynamic varobj will not report the access qualifying
27126pseudo-children, regardless of the language. This information is not
27127available at all with a dynamic varobj.
27128
b569d230 27129@item numchild
0cc7d26f
TT
27130Number of children this child has. For a dynamic varobj, this will be
271310.
b569d230
EZ
27132
27133@item type
27134The type of the child.
27135
27136@item value
27137If values were requested, this is the value.
27138
27139@item thread-id
27140If this variable object is associated with a thread, this is the thread id.
27141Otherwise this result is not present.
27142
27143@item frozen
27144If the variable object is frozen, this variable will be present with a value of 1.
27145@end table
27146
0cc7d26f
TT
27147The result may have its own attributes:
27148
27149@table @samp
27150@item displayhint
27151A dynamic varobj can supply a display hint to the front end. The
27152value comes directly from the Python pretty-printer object's
4c374409 27153@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
27154
27155@item has_more
27156This is an integer attribute which is nonzero if there are children
27157remaining after the end of the selected range.
27158@end table
27159
922fbb7b
AC
27160@subsubheading Example
27161
27162@smallexample
594fe323 27163(gdb)
a2c02241 27164 -var-list-children n
b569d230 27165 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 27166 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 27167(gdb)
a2c02241 27168 -var-list-children --all-values n
b569d230 27169 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 27170 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
27171@end smallexample
27172
922fbb7b 27173
a2c02241
NR
27174@subheading The @code{-var-info-type} Command
27175@findex -var-info-type
922fbb7b 27176
a2c02241
NR
27177@subsubheading Synopsis
27178
27179@smallexample
27180 -var-info-type @var{name}
27181@end smallexample
27182
27183Returns the type of the specified variable @var{name}. The type is
27184returned as a string in the same format as it is output by the
27185@value{GDBN} CLI:
27186
27187@smallexample
27188 type=@var{typename}
27189@end smallexample
27190
27191
27192@subheading The @code{-var-info-expression} Command
27193@findex -var-info-expression
922fbb7b
AC
27194
27195@subsubheading Synopsis
27196
27197@smallexample
a2c02241 27198 -var-info-expression @var{name}
922fbb7b
AC
27199@end smallexample
27200
02142340
VP
27201Returns a string that is suitable for presenting this
27202variable object in user interface. The string is generally
27203not valid expression in the current language, and cannot be evaluated.
27204
27205For example, if @code{a} is an array, and variable object
27206@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 27207
a2c02241 27208@smallexample
02142340
VP
27209(gdb) -var-info-expression A.1
27210^done,lang="C",exp="1"
a2c02241 27211@end smallexample
922fbb7b 27212
a2c02241 27213@noindent
02142340
VP
27214Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
27215
27216Note that the output of the @code{-var-list-children} command also
27217includes those expressions, so the @code{-var-info-expression} command
27218is of limited use.
27219
27220@subheading The @code{-var-info-path-expression} Command
27221@findex -var-info-path-expression
27222
27223@subsubheading Synopsis
27224
27225@smallexample
27226 -var-info-path-expression @var{name}
27227@end smallexample
27228
27229Returns an expression that can be evaluated in the current
27230context and will yield the same value that a variable object has.
27231Compare this with the @code{-var-info-expression} command, which
27232result can be used only for UI presentation. Typical use of
27233the @code{-var-info-path-expression} command is creating a
27234watchpoint from a variable object.
27235
0cc7d26f
TT
27236This command is currently not valid for children of a dynamic varobj,
27237and will give an error when invoked on one.
27238
02142340
VP
27239For example, suppose @code{C} is a C@t{++} class, derived from class
27240@code{Base}, and that the @code{Base} class has a member called
27241@code{m_size}. Assume a variable @code{c} is has the type of
27242@code{C} and a variable object @code{C} was created for variable
27243@code{c}. Then, we'll get this output:
27244@smallexample
27245(gdb) -var-info-path-expression C.Base.public.m_size
27246^done,path_expr=((Base)c).m_size)
27247@end smallexample
922fbb7b 27248
a2c02241
NR
27249@subheading The @code{-var-show-attributes} Command
27250@findex -var-show-attributes
922fbb7b 27251
a2c02241 27252@subsubheading Synopsis
922fbb7b 27253
a2c02241
NR
27254@smallexample
27255 -var-show-attributes @var{name}
27256@end smallexample
922fbb7b 27257
a2c02241 27258List attributes of the specified variable object @var{name}:
922fbb7b
AC
27259
27260@smallexample
a2c02241 27261 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
27262@end smallexample
27263
a2c02241
NR
27264@noindent
27265where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
27266
27267@subheading The @code{-var-evaluate-expression} Command
27268@findex -var-evaluate-expression
27269
27270@subsubheading Synopsis
27271
27272@smallexample
de051565 27273 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
27274@end smallexample
27275
27276Evaluates the expression that is represented by the specified variable
de051565
MK
27277object and returns its value as a string. The format of the string
27278can be specified with the @samp{-f} option. The possible values of
27279this option are the same as for @code{-var-set-format}
27280(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
27281the current display format will be used. The current display format
27282can be changed using the @code{-var-set-format} command.
a2c02241
NR
27283
27284@smallexample
27285 value=@var{value}
27286@end smallexample
27287
27288Note that one must invoke @code{-var-list-children} for a variable
27289before the value of a child variable can be evaluated.
27290
27291@subheading The @code{-var-assign} Command
27292@findex -var-assign
27293
27294@subsubheading Synopsis
27295
27296@smallexample
27297 -var-assign @var{name} @var{expression}
27298@end smallexample
27299
27300Assigns the value of @var{expression} to the variable object specified
27301by @var{name}. The object must be @samp{editable}. If the variable's
27302value is altered by the assign, the variable will show up in any
27303subsequent @code{-var-update} list.
27304
27305@subsubheading Example
922fbb7b
AC
27306
27307@smallexample
594fe323 27308(gdb)
a2c02241
NR
27309-var-assign var1 3
27310^done,value="3"
594fe323 27311(gdb)
a2c02241
NR
27312-var-update *
27313^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 27314(gdb)
922fbb7b
AC
27315@end smallexample
27316
a2c02241
NR
27317@subheading The @code{-var-update} Command
27318@findex -var-update
27319
27320@subsubheading Synopsis
27321
27322@smallexample
27323 -var-update [@var{print-values}] @{@var{name} | "*"@}
27324@end smallexample
27325
c8b2f53c
VP
27326Reevaluate the expressions corresponding to the variable object
27327@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
27328list of variable objects whose values have changed; @var{name} must
27329be a root variable object. Here, ``changed'' means that the result of
27330@code{-var-evaluate-expression} before and after the
27331@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
27332object names, all existing variable objects are updated, except
27333for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 27334@var{print-values} determines whether both names and values, or just
de051565 27335names are printed. The possible values of this option are the same
36ece8b3
NR
27336as for @code{-var-list-children} (@pxref{-var-list-children}). It is
27337recommended to use the @samp{--all-values} option, to reduce the
27338number of MI commands needed on each program stop.
c8b2f53c 27339
c3b108f7
VP
27340With the @samp{*} parameter, if a variable object is bound to a
27341currently running thread, it will not be updated, without any
27342diagnostic.
a2c02241 27343
0cc7d26f
TT
27344If @code{-var-set-update-range} was previously used on a varobj, then
27345only the selected range of children will be reported.
922fbb7b 27346
0cc7d26f
TT
27347@code{-var-update} reports all the changed varobjs in a tuple named
27348@samp{changelist}.
27349
27350Each item in the change list is itself a tuple holding:
27351
27352@table @samp
27353@item name
27354The name of the varobj.
27355
27356@item value
27357If values were requested for this update, then this field will be
27358present and will hold the value of the varobj.
922fbb7b 27359
0cc7d26f 27360@item in_scope
9f708cb2 27361@anchor{-var-update}
0cc7d26f 27362This field is a string which may take one of three values:
36ece8b3
NR
27363
27364@table @code
27365@item "true"
27366The variable object's current value is valid.
27367
27368@item "false"
27369The variable object does not currently hold a valid value but it may
27370hold one in the future if its associated expression comes back into
27371scope.
27372
27373@item "invalid"
27374The variable object no longer holds a valid value.
27375This can occur when the executable file being debugged has changed,
27376either through recompilation or by using the @value{GDBN} @code{file}
27377command. The front end should normally choose to delete these variable
27378objects.
27379@end table
27380
27381In the future new values may be added to this list so the front should
27382be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
27383
0cc7d26f
TT
27384@item type_changed
27385This is only present if the varobj is still valid. If the type
27386changed, then this will be the string @samp{true}; otherwise it will
27387be @samp{false}.
27388
27389@item new_type
27390If the varobj's type changed, then this field will be present and will
27391hold the new type.
27392
27393@item new_num_children
27394For a dynamic varobj, if the number of children changed, or if the
27395type changed, this will be the new number of children.
27396
27397The @samp{numchild} field in other varobj responses is generally not
27398valid for a dynamic varobj -- it will show the number of children that
27399@value{GDBN} knows about, but because dynamic varobjs lazily
27400instantiate their children, this will not reflect the number of
27401children which may be available.
27402
27403The @samp{new_num_children} attribute only reports changes to the
27404number of children known by @value{GDBN}. This is the only way to
27405detect whether an update has removed children (which necessarily can
27406only happen at the end of the update range).
27407
27408@item displayhint
27409The display hint, if any.
27410
27411@item has_more
27412This is an integer value, which will be 1 if there are more children
27413available outside the varobj's update range.
27414
27415@item dynamic
27416This attribute will be present and have the value @samp{1} if the
27417varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
27418then this attribute will not be present.
27419
27420@item new_children
27421If new children were added to a dynamic varobj within the selected
27422update range (as set by @code{-var-set-update-range}), then they will
27423be listed in this attribute.
27424@end table
27425
27426@subsubheading Example
27427
27428@smallexample
27429(gdb)
27430-var-assign var1 3
27431^done,value="3"
27432(gdb)
27433-var-update --all-values var1
27434^done,changelist=[@{name="var1",value="3",in_scope="true",
27435type_changed="false"@}]
27436(gdb)
27437@end smallexample
27438
25d5ea92
VP
27439@subheading The @code{-var-set-frozen} Command
27440@findex -var-set-frozen
9f708cb2 27441@anchor{-var-set-frozen}
25d5ea92
VP
27442
27443@subsubheading Synopsis
27444
27445@smallexample
9f708cb2 27446 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
27447@end smallexample
27448
9f708cb2 27449Set the frozenness flag on the variable object @var{name}. The
25d5ea92 27450@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 27451frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 27452frozen, then neither itself, nor any of its children, are
9f708cb2 27453implicitly updated by @code{-var-update} of
25d5ea92
VP
27454a parent variable or by @code{-var-update *}. Only
27455@code{-var-update} of the variable itself will update its value and
27456values of its children. After a variable object is unfrozen, it is
27457implicitly updated by all subsequent @code{-var-update} operations.
27458Unfreezing a variable does not update it, only subsequent
27459@code{-var-update} does.
27460
27461@subsubheading Example
27462
27463@smallexample
27464(gdb)
27465-var-set-frozen V 1
27466^done
27467(gdb)
27468@end smallexample
27469
0cc7d26f
TT
27470@subheading The @code{-var-set-update-range} command
27471@findex -var-set-update-range
27472@anchor{-var-set-update-range}
27473
27474@subsubheading Synopsis
27475
27476@smallexample
27477 -var-set-update-range @var{name} @var{from} @var{to}
27478@end smallexample
27479
27480Set the range of children to be returned by future invocations of
27481@code{-var-update}.
27482
27483@var{from} and @var{to} indicate the range of children to report. If
27484@var{from} or @var{to} is less than zero, the range is reset and all
27485children will be reported. Otherwise, children starting at @var{from}
27486(zero-based) and up to and excluding @var{to} will be reported.
27487
27488@subsubheading Example
27489
27490@smallexample
27491(gdb)
27492-var-set-update-range V 1 2
27493^done
27494@end smallexample
27495
b6313243
TT
27496@subheading The @code{-var-set-visualizer} command
27497@findex -var-set-visualizer
27498@anchor{-var-set-visualizer}
27499
27500@subsubheading Synopsis
27501
27502@smallexample
27503 -var-set-visualizer @var{name} @var{visualizer}
27504@end smallexample
27505
27506Set a visualizer for the variable object @var{name}.
27507
27508@var{visualizer} is the visualizer to use. The special value
27509@samp{None} means to disable any visualizer in use.
27510
27511If not @samp{None}, @var{visualizer} must be a Python expression.
27512This expression must evaluate to a callable object which accepts a
27513single argument. @value{GDBN} will call this object with the value of
27514the varobj @var{name} as an argument (this is done so that the same
27515Python pretty-printing code can be used for both the CLI and MI).
27516When called, this object must return an object which conforms to the
4c374409 27517pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
27518
27519The pre-defined function @code{gdb.default_visualizer} may be used to
27520select a visualizer by following the built-in process
27521(@pxref{Selecting Pretty-Printers}). This is done automatically when
27522a varobj is created, and so ordinarily is not needed.
27523
27524This feature is only available if Python support is enabled. The MI
27525command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
27526can be used to check this.
27527
27528@subsubheading Example
27529
27530Resetting the visualizer:
27531
27532@smallexample
27533(gdb)
27534-var-set-visualizer V None
27535^done
27536@end smallexample
27537
27538Reselecting the default (type-based) visualizer:
27539
27540@smallexample
27541(gdb)
27542-var-set-visualizer V gdb.default_visualizer
27543^done
27544@end smallexample
27545
27546Suppose @code{SomeClass} is a visualizer class. A lambda expression
27547can be used to instantiate this class for a varobj:
27548
27549@smallexample
27550(gdb)
27551-var-set-visualizer V "lambda val: SomeClass()"
27552^done
27553@end smallexample
25d5ea92 27554
a2c02241
NR
27555@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27556@node GDB/MI Data Manipulation
27557@section @sc{gdb/mi} Data Manipulation
922fbb7b 27558
a2c02241
NR
27559@cindex data manipulation, in @sc{gdb/mi}
27560@cindex @sc{gdb/mi}, data manipulation
27561This section describes the @sc{gdb/mi} commands that manipulate data:
27562examine memory and registers, evaluate expressions, etc.
27563
27564@c REMOVED FROM THE INTERFACE.
27565@c @subheading -data-assign
27566@c Change the value of a program variable. Plenty of side effects.
79a6e687 27567@c @subsubheading GDB Command
a2c02241
NR
27568@c set variable
27569@c @subsubheading Example
27570@c N.A.
27571
27572@subheading The @code{-data-disassemble} Command
27573@findex -data-disassemble
922fbb7b
AC
27574
27575@subsubheading Synopsis
27576
27577@smallexample
a2c02241
NR
27578 -data-disassemble
27579 [ -s @var{start-addr} -e @var{end-addr} ]
27580 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
27581 -- @var{mode}
922fbb7b
AC
27582@end smallexample
27583
a2c02241
NR
27584@noindent
27585Where:
27586
27587@table @samp
27588@item @var{start-addr}
27589is the beginning address (or @code{$pc})
27590@item @var{end-addr}
27591is the end address
27592@item @var{filename}
27593is the name of the file to disassemble
27594@item @var{linenum}
27595is the line number to disassemble around
27596@item @var{lines}
d3e8051b 27597is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
27598the whole function will be disassembled, in case no @var{end-addr} is
27599specified. If @var{end-addr} is specified as a non-zero value, and
27600@var{lines} is lower than the number of disassembly lines between
27601@var{start-addr} and @var{end-addr}, only @var{lines} lines are
27602displayed; if @var{lines} is higher than the number of lines between
27603@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
27604are displayed.
27605@item @var{mode}
27606is either 0 (meaning only disassembly) or 1 (meaning mixed source and
27607disassembly).
27608@end table
27609
27610@subsubheading Result
27611
27612The output for each instruction is composed of four fields:
27613
27614@itemize @bullet
27615@item Address
27616@item Func-name
27617@item Offset
27618@item Instruction
27619@end itemize
27620
27621Note that whatever included in the instruction field, is not manipulated
d3e8051b 27622directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
922fbb7b
AC
27623
27624@subsubheading @value{GDBN} Command
27625
a2c02241 27626There's no direct mapping from this command to the CLI.
922fbb7b
AC
27627
27628@subsubheading Example
27629
a2c02241
NR
27630Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
27631
922fbb7b 27632@smallexample
594fe323 27633(gdb)
a2c02241
NR
27634-data-disassemble -s $pc -e "$pc + 20" -- 0
27635^done,
27636asm_insns=[
27637@{address="0x000107c0",func-name="main",offset="4",
27638inst="mov 2, %o0"@},
27639@{address="0x000107c4",func-name="main",offset="8",
27640inst="sethi %hi(0x11800), %o2"@},
27641@{address="0x000107c8",func-name="main",offset="12",
27642inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
27643@{address="0x000107cc",func-name="main",offset="16",
27644inst="sethi %hi(0x11800), %o2"@},
27645@{address="0x000107d0",func-name="main",offset="20",
27646inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 27647(gdb)
a2c02241
NR
27648@end smallexample
27649
27650Disassemble the whole @code{main} function. Line 32 is part of
27651@code{main}.
27652
27653@smallexample
27654-data-disassemble -f basics.c -l 32 -- 0
27655^done,asm_insns=[
27656@{address="0x000107bc",func-name="main",offset="0",
27657inst="save %sp, -112, %sp"@},
27658@{address="0x000107c0",func-name="main",offset="4",
27659inst="mov 2, %o0"@},
27660@{address="0x000107c4",func-name="main",offset="8",
27661inst="sethi %hi(0x11800), %o2"@},
27662[@dots{}]
27663@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
27664@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 27665(gdb)
922fbb7b
AC
27666@end smallexample
27667
a2c02241 27668Disassemble 3 instructions from the start of @code{main}:
922fbb7b 27669
a2c02241 27670@smallexample
594fe323 27671(gdb)
a2c02241
NR
27672-data-disassemble -f basics.c -l 32 -n 3 -- 0
27673^done,asm_insns=[
27674@{address="0x000107bc",func-name="main",offset="0",
27675inst="save %sp, -112, %sp"@},
27676@{address="0x000107c0",func-name="main",offset="4",
27677inst="mov 2, %o0"@},
27678@{address="0x000107c4",func-name="main",offset="8",
27679inst="sethi %hi(0x11800), %o2"@}]
594fe323 27680(gdb)
a2c02241
NR
27681@end smallexample
27682
27683Disassemble 3 instructions from the start of @code{main} in mixed mode:
27684
27685@smallexample
594fe323 27686(gdb)
a2c02241
NR
27687-data-disassemble -f basics.c -l 32 -n 3 -- 1
27688^done,asm_insns=[
27689src_and_asm_line=@{line="31",
27690file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
27691 testsuite/gdb.mi/basics.c",line_asm_insn=[
27692@{address="0x000107bc",func-name="main",offset="0",
27693inst="save %sp, -112, %sp"@}]@},
27694src_and_asm_line=@{line="32",
27695file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
27696 testsuite/gdb.mi/basics.c",line_asm_insn=[
27697@{address="0x000107c0",func-name="main",offset="4",
27698inst="mov 2, %o0"@},
27699@{address="0x000107c4",func-name="main",offset="8",
27700inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 27701(gdb)
a2c02241
NR
27702@end smallexample
27703
27704
27705@subheading The @code{-data-evaluate-expression} Command
27706@findex -data-evaluate-expression
922fbb7b
AC
27707
27708@subsubheading Synopsis
27709
27710@smallexample
a2c02241 27711 -data-evaluate-expression @var{expr}
922fbb7b
AC
27712@end smallexample
27713
a2c02241
NR
27714Evaluate @var{expr} as an expression. The expression could contain an
27715inferior function call. The function call will execute synchronously.
27716If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
27717
27718@subsubheading @value{GDBN} Command
27719
a2c02241
NR
27720The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
27721@samp{call}. In @code{gdbtk} only, there's a corresponding
27722@samp{gdb_eval} command.
922fbb7b
AC
27723
27724@subsubheading Example
27725
a2c02241
NR
27726In the following example, the numbers that precede the commands are the
27727@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
27728Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
27729output.
27730
922fbb7b 27731@smallexample
a2c02241
NR
27732211-data-evaluate-expression A
27733211^done,value="1"
594fe323 27734(gdb)
a2c02241
NR
27735311-data-evaluate-expression &A
27736311^done,value="0xefffeb7c"
594fe323 27737(gdb)
a2c02241
NR
27738411-data-evaluate-expression A+3
27739411^done,value="4"
594fe323 27740(gdb)
a2c02241
NR
27741511-data-evaluate-expression "A + 3"
27742511^done,value="4"
594fe323 27743(gdb)
a2c02241 27744@end smallexample
922fbb7b
AC
27745
27746
a2c02241
NR
27747@subheading The @code{-data-list-changed-registers} Command
27748@findex -data-list-changed-registers
922fbb7b
AC
27749
27750@subsubheading Synopsis
27751
27752@smallexample
a2c02241 27753 -data-list-changed-registers
922fbb7b
AC
27754@end smallexample
27755
a2c02241 27756Display a list of the registers that have changed.
922fbb7b
AC
27757
27758@subsubheading @value{GDBN} Command
27759
a2c02241
NR
27760@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
27761has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
27762
27763@subsubheading Example
922fbb7b 27764
a2c02241 27765On a PPC MBX board:
922fbb7b
AC
27766
27767@smallexample
594fe323 27768(gdb)
a2c02241
NR
27769-exec-continue
27770^running
922fbb7b 27771
594fe323 27772(gdb)
a47ec5fe
AR
27773*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
27774func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
27775line="5"@}
594fe323 27776(gdb)
a2c02241
NR
27777-data-list-changed-registers
27778^done,changed-registers=["0","1","2","4","5","6","7","8","9",
27779"10","11","13","14","15","16","17","18","19","20","21","22","23",
27780"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 27781(gdb)
a2c02241 27782@end smallexample
922fbb7b
AC
27783
27784
a2c02241
NR
27785@subheading The @code{-data-list-register-names} Command
27786@findex -data-list-register-names
922fbb7b
AC
27787
27788@subsubheading Synopsis
27789
27790@smallexample
a2c02241 27791 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
27792@end smallexample
27793
a2c02241
NR
27794Show a list of register names for the current target. If no arguments
27795are given, it shows a list of the names of all the registers. If
27796integer numbers are given as arguments, it will print a list of the
27797names of the registers corresponding to the arguments. To ensure
27798consistency between a register name and its number, the output list may
27799include empty register names.
922fbb7b
AC
27800
27801@subsubheading @value{GDBN} Command
27802
a2c02241
NR
27803@value{GDBN} does not have a command which corresponds to
27804@samp{-data-list-register-names}. In @code{gdbtk} there is a
27805corresponding command @samp{gdb_regnames}.
922fbb7b
AC
27806
27807@subsubheading Example
922fbb7b 27808
a2c02241
NR
27809For the PPC MBX board:
27810@smallexample
594fe323 27811(gdb)
a2c02241
NR
27812-data-list-register-names
27813^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
27814"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
27815"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
27816"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
27817"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
27818"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
27819"", "pc","ps","cr","lr","ctr","xer"]
594fe323 27820(gdb)
a2c02241
NR
27821-data-list-register-names 1 2 3
27822^done,register-names=["r1","r2","r3"]
594fe323 27823(gdb)
a2c02241 27824@end smallexample
922fbb7b 27825
a2c02241
NR
27826@subheading The @code{-data-list-register-values} Command
27827@findex -data-list-register-values
922fbb7b
AC
27828
27829@subsubheading Synopsis
27830
27831@smallexample
a2c02241 27832 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
27833@end smallexample
27834
a2c02241
NR
27835Display the registers' contents. @var{fmt} is the format according to
27836which the registers' contents are to be returned, followed by an optional
27837list of numbers specifying the registers to display. A missing list of
27838numbers indicates that the contents of all the registers must be returned.
27839
27840Allowed formats for @var{fmt} are:
27841
27842@table @code
27843@item x
27844Hexadecimal
27845@item o
27846Octal
27847@item t
27848Binary
27849@item d
27850Decimal
27851@item r
27852Raw
27853@item N
27854Natural
27855@end table
922fbb7b
AC
27856
27857@subsubheading @value{GDBN} Command
27858
a2c02241
NR
27859The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
27860all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
27861
27862@subsubheading Example
922fbb7b 27863
a2c02241
NR
27864For a PPC MBX board (note: line breaks are for readability only, they
27865don't appear in the actual output):
27866
27867@smallexample
594fe323 27868(gdb)
a2c02241
NR
27869-data-list-register-values r 64 65
27870^done,register-values=[@{number="64",value="0xfe00a300"@},
27871@{number="65",value="0x00029002"@}]
594fe323 27872(gdb)
a2c02241
NR
27873-data-list-register-values x
27874^done,register-values=[@{number="0",value="0xfe0043c8"@},
27875@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
27876@{number="3",value="0x0"@},@{number="4",value="0xa"@},
27877@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
27878@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
27879@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
27880@{number="11",value="0x1"@},@{number="12",value="0x0"@},
27881@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
27882@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
27883@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
27884@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
27885@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
27886@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
27887@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
27888@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
27889@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
27890@{number="31",value="0x0"@},@{number="32",value="0x0"@},
27891@{number="33",value="0x0"@},@{number="34",value="0x0"@},
27892@{number="35",value="0x0"@},@{number="36",value="0x0"@},
27893@{number="37",value="0x0"@},@{number="38",value="0x0"@},
27894@{number="39",value="0x0"@},@{number="40",value="0x0"@},
27895@{number="41",value="0x0"@},@{number="42",value="0x0"@},
27896@{number="43",value="0x0"@},@{number="44",value="0x0"@},
27897@{number="45",value="0x0"@},@{number="46",value="0x0"@},
27898@{number="47",value="0x0"@},@{number="48",value="0x0"@},
27899@{number="49",value="0x0"@},@{number="50",value="0x0"@},
27900@{number="51",value="0x0"@},@{number="52",value="0x0"@},
27901@{number="53",value="0x0"@},@{number="54",value="0x0"@},
27902@{number="55",value="0x0"@},@{number="56",value="0x0"@},
27903@{number="57",value="0x0"@},@{number="58",value="0x0"@},
27904@{number="59",value="0x0"@},@{number="60",value="0x0"@},
27905@{number="61",value="0x0"@},@{number="62",value="0x0"@},
27906@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
27907@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
27908@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
27909@{number="69",value="0x20002b03"@}]
594fe323 27910(gdb)
a2c02241 27911@end smallexample
922fbb7b 27912
a2c02241
NR
27913
27914@subheading The @code{-data-read-memory} Command
27915@findex -data-read-memory
922fbb7b 27916
8dedea02
VP
27917This command is deprecated, use @code{-data-read-memory-bytes} instead.
27918
922fbb7b
AC
27919@subsubheading Synopsis
27920
27921@smallexample
a2c02241
NR
27922 -data-read-memory [ -o @var{byte-offset} ]
27923 @var{address} @var{word-format} @var{word-size}
27924 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
27925@end smallexample
27926
a2c02241
NR
27927@noindent
27928where:
922fbb7b 27929
a2c02241
NR
27930@table @samp
27931@item @var{address}
27932An expression specifying the address of the first memory word to be
27933read. Complex expressions containing embedded white space should be
27934quoted using the C convention.
922fbb7b 27935
a2c02241
NR
27936@item @var{word-format}
27937The format to be used to print the memory words. The notation is the
27938same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 27939,Output Formats}).
922fbb7b 27940
a2c02241
NR
27941@item @var{word-size}
27942The size of each memory word in bytes.
922fbb7b 27943
a2c02241
NR
27944@item @var{nr-rows}
27945The number of rows in the output table.
922fbb7b 27946
a2c02241
NR
27947@item @var{nr-cols}
27948The number of columns in the output table.
922fbb7b 27949
a2c02241
NR
27950@item @var{aschar}
27951If present, indicates that each row should include an @sc{ascii} dump. The
27952value of @var{aschar} is used as a padding character when a byte is not a
27953member of the printable @sc{ascii} character set (printable @sc{ascii}
27954characters are those whose code is between 32 and 126, inclusively).
922fbb7b 27955
a2c02241
NR
27956@item @var{byte-offset}
27957An offset to add to the @var{address} before fetching memory.
27958@end table
922fbb7b 27959
a2c02241
NR
27960This command displays memory contents as a table of @var{nr-rows} by
27961@var{nr-cols} words, each word being @var{word-size} bytes. In total,
27962@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
27963(returned as @samp{total-bytes}). Should less than the requested number
27964of bytes be returned by the target, the missing words are identified
27965using @samp{N/A}. The number of bytes read from the target is returned
27966in @samp{nr-bytes} and the starting address used to read memory in
27967@samp{addr}.
27968
27969The address of the next/previous row or page is available in
27970@samp{next-row} and @samp{prev-row}, @samp{next-page} and
27971@samp{prev-page}.
922fbb7b
AC
27972
27973@subsubheading @value{GDBN} Command
27974
a2c02241
NR
27975The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
27976@samp{gdb_get_mem} memory read command.
922fbb7b
AC
27977
27978@subsubheading Example
32e7087d 27979
a2c02241
NR
27980Read six bytes of memory starting at @code{bytes+6} but then offset by
27981@code{-6} bytes. Format as three rows of two columns. One byte per
27982word. Display each word in hex.
32e7087d
JB
27983
27984@smallexample
594fe323 27985(gdb)
a2c02241
NR
279869-data-read-memory -o -6 -- bytes+6 x 1 3 2
279879^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
27988next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
27989prev-page="0x0000138a",memory=[
27990@{addr="0x00001390",data=["0x00","0x01"]@},
27991@{addr="0x00001392",data=["0x02","0x03"]@},
27992@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 27993(gdb)
32e7087d
JB
27994@end smallexample
27995
a2c02241
NR
27996Read two bytes of memory starting at address @code{shorts + 64} and
27997display as a single word formatted in decimal.
32e7087d 27998
32e7087d 27999@smallexample
594fe323 28000(gdb)
a2c02241
NR
280015-data-read-memory shorts+64 d 2 1 1
280025^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
28003next-row="0x00001512",prev-row="0x0000150e",
28004next-page="0x00001512",prev-page="0x0000150e",memory=[
28005@{addr="0x00001510",data=["128"]@}]
594fe323 28006(gdb)
32e7087d
JB
28007@end smallexample
28008
a2c02241
NR
28009Read thirty two bytes of memory starting at @code{bytes+16} and format
28010as eight rows of four columns. Include a string encoding with @samp{x}
28011used as the non-printable character.
922fbb7b
AC
28012
28013@smallexample
594fe323 28014(gdb)
a2c02241
NR
280154-data-read-memory bytes+16 x 1 8 4 x
280164^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
28017next-row="0x000013c0",prev-row="0x0000139c",
28018next-page="0x000013c0",prev-page="0x00001380",memory=[
28019@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
28020@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
28021@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
28022@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
28023@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
28024@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
28025@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
28026@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 28027(gdb)
922fbb7b
AC
28028@end smallexample
28029
8dedea02
VP
28030@subheading The @code{-data-read-memory-bytes} Command
28031@findex -data-read-memory-bytes
28032
28033@subsubheading Synopsis
28034
28035@smallexample
28036 -data-read-memory-bytes [ -o @var{byte-offset} ]
28037 @var{address} @var{count}
28038@end smallexample
28039
28040@noindent
28041where:
28042
28043@table @samp
28044@item @var{address}
28045An expression specifying the address of the first memory word to be
28046read. Complex expressions containing embedded white space should be
28047quoted using the C convention.
28048
28049@item @var{count}
28050The number of bytes to read. This should be an integer literal.
28051
28052@item @var{byte-offset}
28053The offsets in bytes relative to @var{address} at which to start
28054reading. This should be an integer literal. This option is provided
28055so that a frontend is not required to first evaluate address and then
28056perform address arithmetics itself.
28057
28058@end table
28059
28060This command attempts to read all accessible memory regions in the
28061specified range. First, all regions marked as unreadable in the memory
28062map (if one is defined) will be skipped. @xref{Memory Region
28063Attributes}. Second, @value{GDBN} will attempt to read the remaining
28064regions. For each one, if reading full region results in an errors,
28065@value{GDBN} will try to read a subset of the region.
28066
28067In general, every single byte in the region may be readable or not,
28068and the only way to read every readable byte is to try a read at
28069every address, which is not practical. Therefore, @value{GDBN} will
28070attempt to read all accessible bytes at either beginning or the end
28071of the region, using a binary division scheme. This heuristic works
28072well for reading accross a memory map boundary. Note that if a region
28073has a readable range that is neither at the beginning or the end,
28074@value{GDBN} will not read it.
28075
28076The result record (@pxref{GDB/MI Result Records}) that is output of
28077the command includes a field named @samp{memory} whose content is a
28078list of tuples. Each tuple represent a successfully read memory block
28079and has the following fields:
28080
28081@table @code
28082@item begin
28083The start address of the memory block, as hexadecimal literal.
28084
28085@item end
28086The end address of the memory block, as hexadecimal literal.
28087
28088@item offset
28089The offset of the memory block, as hexadecimal literal, relative to
28090the start address passed to @code{-data-read-memory-bytes}.
28091
28092@item contents
28093The contents of the memory block, in hex.
28094
28095@end table
28096
28097
28098
28099@subsubheading @value{GDBN} Command
28100
28101The corresponding @value{GDBN} command is @samp{x}.
28102
28103@subsubheading Example
28104
28105@smallexample
28106(gdb)
28107-data-read-memory-bytes &a 10
28108^done,memory=[@{begin="0xbffff154",offset="0x00000000",
28109 end="0xbffff15e",
28110 contents="01000000020000000300"@}]
28111(gdb)
28112@end smallexample
28113
28114
28115@subheading The @code{-data-write-memory-bytes} Command
28116@findex -data-write-memory-bytes
28117
28118@subsubheading Synopsis
28119
28120@smallexample
28121 -data-write-memory-bytes @var{address} @var{contents}
28122@end smallexample
28123
28124@noindent
28125where:
28126
28127@table @samp
28128@item @var{address}
28129An expression specifying the address of the first memory word to be
28130read. Complex expressions containing embedded white space should be
28131quoted using the C convention.
28132
28133@item @var{contents}
28134The hex-encoded bytes to write.
28135
28136@end table
28137
28138@subsubheading @value{GDBN} Command
28139
28140There's no corresponding @value{GDBN} command.
28141
28142@subsubheading Example
28143
28144@smallexample
28145(gdb)
28146-data-write-memory-bytes &a "aabbccdd"
28147^done
28148(gdb)
28149@end smallexample
28150
28151
a2c02241
NR
28152@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28153@node GDB/MI Tracepoint Commands
28154@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 28155
18148017
VP
28156The commands defined in this section implement MI support for
28157tracepoints. For detailed introduction, see @ref{Tracepoints}.
28158
28159@subheading The @code{-trace-find} Command
28160@findex -trace-find
28161
28162@subsubheading Synopsis
28163
28164@smallexample
28165 -trace-find @var{mode} [@var{parameters}@dots{}]
28166@end smallexample
28167
28168Find a trace frame using criteria defined by @var{mode} and
28169@var{parameters}. The following table lists permissible
28170modes and their parameters. For details of operation, see @ref{tfind}.
28171
28172@table @samp
28173
28174@item none
28175No parameters are required. Stops examining trace frames.
28176
28177@item frame-number
28178An integer is required as parameter. Selects tracepoint frame with
28179that index.
28180
28181@item tracepoint-number
28182An integer is required as parameter. Finds next
28183trace frame that corresponds to tracepoint with the specified number.
28184
28185@item pc
28186An address is required as parameter. Finds
28187next trace frame that corresponds to any tracepoint at the specified
28188address.
28189
28190@item pc-inside-range
28191Two addresses are required as parameters. Finds next trace
28192frame that corresponds to a tracepoint at an address inside the
28193specified range. Both bounds are considered to be inside the range.
28194
28195@item pc-outside-range
28196Two addresses are required as parameters. Finds
28197next trace frame that corresponds to a tracepoint at an address outside
28198the specified range. Both bounds are considered to be inside the range.
28199
28200@item line
28201Line specification is required as parameter. @xref{Specify Location}.
28202Finds next trace frame that corresponds to a tracepoint at
28203the specified location.
28204
28205@end table
28206
28207If @samp{none} was passed as @var{mode}, the response does not
28208have fields. Otherwise, the response may have the following fields:
28209
28210@table @samp
28211@item found
28212This field has either @samp{0} or @samp{1} as the value, depending
28213on whether a matching tracepoint was found.
28214
28215@item traceframe
28216The index of the found traceframe. This field is present iff
28217the @samp{found} field has value of @samp{1}.
28218
28219@item tracepoint
28220The index of the found tracepoint. This field is present iff
28221the @samp{found} field has value of @samp{1}.
28222
28223@item frame
28224The information about the frame corresponding to the found trace
28225frame. This field is present only if a trace frame was found.
cd64ee31 28226@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
28227
28228@end table
28229
7d13fe92
SS
28230@subsubheading @value{GDBN} Command
28231
28232The corresponding @value{GDBN} command is @samp{tfind}.
28233
18148017
VP
28234@subheading -trace-define-variable
28235@findex -trace-define-variable
28236
28237@subsubheading Synopsis
28238
28239@smallexample
28240 -trace-define-variable @var{name} [ @var{value} ]
28241@end smallexample
28242
28243Create trace variable @var{name} if it does not exist. If
28244@var{value} is specified, sets the initial value of the specified
28245trace variable to that value. Note that the @var{name} should start
28246with the @samp{$} character.
28247
7d13fe92
SS
28248@subsubheading @value{GDBN} Command
28249
28250The corresponding @value{GDBN} command is @samp{tvariable}.
28251
18148017
VP
28252@subheading -trace-list-variables
28253@findex -trace-list-variables
922fbb7b 28254
18148017 28255@subsubheading Synopsis
922fbb7b 28256
18148017
VP
28257@smallexample
28258 -trace-list-variables
28259@end smallexample
922fbb7b 28260
18148017
VP
28261Return a table of all defined trace variables. Each element of the
28262table has the following fields:
922fbb7b 28263
18148017
VP
28264@table @samp
28265@item name
28266The name of the trace variable. This field is always present.
922fbb7b 28267
18148017
VP
28268@item initial
28269The initial value. This is a 64-bit signed integer. This
28270field is always present.
922fbb7b 28271
18148017
VP
28272@item current
28273The value the trace variable has at the moment. This is a 64-bit
28274signed integer. This field is absent iff current value is
28275not defined, for example if the trace was never run, or is
28276presently running.
922fbb7b 28277
18148017 28278@end table
922fbb7b 28279
7d13fe92
SS
28280@subsubheading @value{GDBN} Command
28281
28282The corresponding @value{GDBN} command is @samp{tvariables}.
28283
18148017 28284@subsubheading Example
922fbb7b 28285
18148017
VP
28286@smallexample
28287(gdb)
28288-trace-list-variables
28289^done,trace-variables=@{nr_rows="1",nr_cols="3",
28290hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
28291 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
28292 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
28293body=[variable=@{name="$trace_timestamp",initial="0"@}
28294 variable=@{name="$foo",initial="10",current="15"@}]@}
28295(gdb)
28296@end smallexample
922fbb7b 28297
18148017
VP
28298@subheading -trace-save
28299@findex -trace-save
922fbb7b 28300
18148017
VP
28301@subsubheading Synopsis
28302
28303@smallexample
28304 -trace-save [-r ] @var{filename}
28305@end smallexample
28306
28307Saves the collected trace data to @var{filename}. Without the
28308@samp{-r} option, the data is downloaded from the target and saved
28309in a local file. With the @samp{-r} option the target is asked
28310to perform the save.
28311
7d13fe92
SS
28312@subsubheading @value{GDBN} Command
28313
28314The corresponding @value{GDBN} command is @samp{tsave}.
28315
18148017
VP
28316
28317@subheading -trace-start
28318@findex -trace-start
28319
28320@subsubheading Synopsis
28321
28322@smallexample
28323 -trace-start
28324@end smallexample
922fbb7b 28325
18148017
VP
28326Starts a tracing experiments. The result of this command does not
28327have any fields.
922fbb7b 28328
7d13fe92
SS
28329@subsubheading @value{GDBN} Command
28330
28331The corresponding @value{GDBN} command is @samp{tstart}.
28332
18148017
VP
28333@subheading -trace-status
28334@findex -trace-status
922fbb7b 28335
18148017
VP
28336@subsubheading Synopsis
28337
28338@smallexample
28339 -trace-status
28340@end smallexample
28341
a97153c7 28342Obtains the status of a tracing experiment. The result may include
18148017
VP
28343the following fields:
28344
28345@table @samp
28346
28347@item supported
28348May have a value of either @samp{0}, when no tracing operations are
28349supported, @samp{1}, when all tracing operations are supported, or
28350@samp{file} when examining trace file. In the latter case, examining
28351of trace frame is possible but new tracing experiement cannot be
28352started. This field is always present.
28353
28354@item running
28355May have a value of either @samp{0} or @samp{1} depending on whether
28356tracing experiement is in progress on target. This field is present
28357if @samp{supported} field is not @samp{0}.
28358
28359@item stop-reason
28360Report the reason why the tracing was stopped last time. This field
28361may be absent iff tracing was never stopped on target yet. The
28362value of @samp{request} means the tracing was stopped as result of
28363the @code{-trace-stop} command. The value of @samp{overflow} means
28364the tracing buffer is full. The value of @samp{disconnection} means
28365tracing was automatically stopped when @value{GDBN} has disconnected.
28366The value of @samp{passcount} means tracing was stopped when a
28367tracepoint was passed a maximal number of times for that tracepoint.
28368This field is present if @samp{supported} field is not @samp{0}.
28369
28370@item stopping-tracepoint
28371The number of tracepoint whose passcount as exceeded. This field is
28372present iff the @samp{stop-reason} field has the value of
28373@samp{passcount}.
28374
28375@item frames
87290684
SS
28376@itemx frames-created
28377The @samp{frames} field is a count of the total number of trace frames
28378in the trace buffer, while @samp{frames-created} is the total created
28379during the run, including ones that were discarded, such as when a
28380circular trace buffer filled up. Both fields are optional.
18148017
VP
28381
28382@item buffer-size
28383@itemx buffer-free
28384These fields tell the current size of the tracing buffer and the
87290684 28385remaining space. These fields are optional.
18148017 28386
a97153c7
PA
28387@item circular
28388The value of the circular trace buffer flag. @code{1} means that the
28389trace buffer is circular and old trace frames will be discarded if
28390necessary to make room, @code{0} means that the trace buffer is linear
28391and may fill up.
28392
28393@item disconnected
28394The value of the disconnected tracing flag. @code{1} means that
28395tracing will continue after @value{GDBN} disconnects, @code{0} means
28396that the trace run will stop.
28397
18148017
VP
28398@end table
28399
7d13fe92
SS
28400@subsubheading @value{GDBN} Command
28401
28402The corresponding @value{GDBN} command is @samp{tstatus}.
28403
18148017
VP
28404@subheading -trace-stop
28405@findex -trace-stop
28406
28407@subsubheading Synopsis
28408
28409@smallexample
28410 -trace-stop
28411@end smallexample
922fbb7b 28412
18148017
VP
28413Stops a tracing experiment. The result of this command has the same
28414fields as @code{-trace-status}, except that the @samp{supported} and
28415@samp{running} fields are not output.
922fbb7b 28416
7d13fe92
SS
28417@subsubheading @value{GDBN} Command
28418
28419The corresponding @value{GDBN} command is @samp{tstop}.
28420
922fbb7b 28421
a2c02241
NR
28422@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28423@node GDB/MI Symbol Query
28424@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
28425
28426
9901a55b 28427@ignore
a2c02241
NR
28428@subheading The @code{-symbol-info-address} Command
28429@findex -symbol-info-address
922fbb7b
AC
28430
28431@subsubheading Synopsis
28432
28433@smallexample
a2c02241 28434 -symbol-info-address @var{symbol}
922fbb7b
AC
28435@end smallexample
28436
a2c02241 28437Describe where @var{symbol} is stored.
922fbb7b
AC
28438
28439@subsubheading @value{GDBN} Command
28440
a2c02241 28441The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
28442
28443@subsubheading Example
28444N.A.
28445
28446
a2c02241
NR
28447@subheading The @code{-symbol-info-file} Command
28448@findex -symbol-info-file
922fbb7b
AC
28449
28450@subsubheading Synopsis
28451
28452@smallexample
a2c02241 28453 -symbol-info-file
922fbb7b
AC
28454@end smallexample
28455
a2c02241 28456Show the file for the symbol.
922fbb7b 28457
a2c02241 28458@subsubheading @value{GDBN} Command
922fbb7b 28459
a2c02241
NR
28460There's no equivalent @value{GDBN} command. @code{gdbtk} has
28461@samp{gdb_find_file}.
922fbb7b
AC
28462
28463@subsubheading Example
28464N.A.
28465
28466
a2c02241
NR
28467@subheading The @code{-symbol-info-function} Command
28468@findex -symbol-info-function
922fbb7b
AC
28469
28470@subsubheading Synopsis
28471
28472@smallexample
a2c02241 28473 -symbol-info-function
922fbb7b
AC
28474@end smallexample
28475
a2c02241 28476Show which function the symbol lives in.
922fbb7b
AC
28477
28478@subsubheading @value{GDBN} Command
28479
a2c02241 28480@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
28481
28482@subsubheading Example
28483N.A.
28484
28485
a2c02241
NR
28486@subheading The @code{-symbol-info-line} Command
28487@findex -symbol-info-line
922fbb7b
AC
28488
28489@subsubheading Synopsis
28490
28491@smallexample
a2c02241 28492 -symbol-info-line
922fbb7b
AC
28493@end smallexample
28494
a2c02241 28495Show the core addresses of the code for a source line.
922fbb7b 28496
a2c02241 28497@subsubheading @value{GDBN} Command
922fbb7b 28498
a2c02241
NR
28499The corresponding @value{GDBN} command is @samp{info line}.
28500@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
28501
28502@subsubheading Example
a2c02241 28503N.A.
922fbb7b
AC
28504
28505
a2c02241
NR
28506@subheading The @code{-symbol-info-symbol} Command
28507@findex -symbol-info-symbol
07f31aa6
DJ
28508
28509@subsubheading Synopsis
28510
a2c02241
NR
28511@smallexample
28512 -symbol-info-symbol @var{addr}
28513@end smallexample
07f31aa6 28514
a2c02241 28515Describe what symbol is at location @var{addr}.
07f31aa6 28516
a2c02241 28517@subsubheading @value{GDBN} Command
07f31aa6 28518
a2c02241 28519The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
28520
28521@subsubheading Example
a2c02241 28522N.A.
07f31aa6
DJ
28523
28524
a2c02241
NR
28525@subheading The @code{-symbol-list-functions} Command
28526@findex -symbol-list-functions
922fbb7b
AC
28527
28528@subsubheading Synopsis
28529
28530@smallexample
a2c02241 28531 -symbol-list-functions
922fbb7b
AC
28532@end smallexample
28533
a2c02241 28534List the functions in the executable.
922fbb7b
AC
28535
28536@subsubheading @value{GDBN} Command
28537
a2c02241
NR
28538@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
28539@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
28540
28541@subsubheading Example
a2c02241 28542N.A.
9901a55b 28543@end ignore
922fbb7b
AC
28544
28545
a2c02241
NR
28546@subheading The @code{-symbol-list-lines} Command
28547@findex -symbol-list-lines
922fbb7b
AC
28548
28549@subsubheading Synopsis
28550
28551@smallexample
a2c02241 28552 -symbol-list-lines @var{filename}
922fbb7b
AC
28553@end smallexample
28554
a2c02241
NR
28555Print the list of lines that contain code and their associated program
28556addresses for the given source filename. The entries are sorted in
28557ascending PC order.
922fbb7b
AC
28558
28559@subsubheading @value{GDBN} Command
28560
a2c02241 28561There is no corresponding @value{GDBN} command.
922fbb7b
AC
28562
28563@subsubheading Example
a2c02241 28564@smallexample
594fe323 28565(gdb)
a2c02241
NR
28566-symbol-list-lines basics.c
28567^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 28568(gdb)
a2c02241 28569@end smallexample
922fbb7b
AC
28570
28571
9901a55b 28572@ignore
a2c02241
NR
28573@subheading The @code{-symbol-list-types} Command
28574@findex -symbol-list-types
922fbb7b
AC
28575
28576@subsubheading Synopsis
28577
28578@smallexample
a2c02241 28579 -symbol-list-types
922fbb7b
AC
28580@end smallexample
28581
a2c02241 28582List all the type names.
922fbb7b
AC
28583
28584@subsubheading @value{GDBN} Command
28585
a2c02241
NR
28586The corresponding commands are @samp{info types} in @value{GDBN},
28587@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
28588
28589@subsubheading Example
28590N.A.
28591
28592
a2c02241
NR
28593@subheading The @code{-symbol-list-variables} Command
28594@findex -symbol-list-variables
922fbb7b
AC
28595
28596@subsubheading Synopsis
28597
28598@smallexample
a2c02241 28599 -symbol-list-variables
922fbb7b
AC
28600@end smallexample
28601
a2c02241 28602List all the global and static variable names.
922fbb7b
AC
28603
28604@subsubheading @value{GDBN} Command
28605
a2c02241 28606@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
28607
28608@subsubheading Example
28609N.A.
28610
28611
a2c02241
NR
28612@subheading The @code{-symbol-locate} Command
28613@findex -symbol-locate
922fbb7b
AC
28614
28615@subsubheading Synopsis
28616
28617@smallexample
a2c02241 28618 -symbol-locate
922fbb7b
AC
28619@end smallexample
28620
922fbb7b
AC
28621@subsubheading @value{GDBN} Command
28622
a2c02241 28623@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
28624
28625@subsubheading Example
28626N.A.
28627
28628
a2c02241
NR
28629@subheading The @code{-symbol-type} Command
28630@findex -symbol-type
922fbb7b
AC
28631
28632@subsubheading Synopsis
28633
28634@smallexample
a2c02241 28635 -symbol-type @var{variable}
922fbb7b
AC
28636@end smallexample
28637
a2c02241 28638Show type of @var{variable}.
922fbb7b 28639
a2c02241 28640@subsubheading @value{GDBN} Command
922fbb7b 28641
a2c02241
NR
28642The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
28643@samp{gdb_obj_variable}.
28644
28645@subsubheading Example
28646N.A.
9901a55b 28647@end ignore
a2c02241
NR
28648
28649
28650@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28651@node GDB/MI File Commands
28652@section @sc{gdb/mi} File Commands
28653
28654This section describes the GDB/MI commands to specify executable file names
28655and to read in and obtain symbol table information.
28656
28657@subheading The @code{-file-exec-and-symbols} Command
28658@findex -file-exec-and-symbols
28659
28660@subsubheading Synopsis
922fbb7b
AC
28661
28662@smallexample
a2c02241 28663 -file-exec-and-symbols @var{file}
922fbb7b
AC
28664@end smallexample
28665
a2c02241
NR
28666Specify the executable file to be debugged. This file is the one from
28667which the symbol table is also read. If no file is specified, the
28668command clears the executable and symbol information. If breakpoints
28669are set when using this command with no arguments, @value{GDBN} will produce
28670error messages. Otherwise, no output is produced, except a completion
28671notification.
28672
922fbb7b
AC
28673@subsubheading @value{GDBN} Command
28674
a2c02241 28675The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
28676
28677@subsubheading Example
28678
28679@smallexample
594fe323 28680(gdb)
a2c02241
NR
28681-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
28682^done
594fe323 28683(gdb)
922fbb7b
AC
28684@end smallexample
28685
922fbb7b 28686
a2c02241
NR
28687@subheading The @code{-file-exec-file} Command
28688@findex -file-exec-file
922fbb7b
AC
28689
28690@subsubheading Synopsis
28691
28692@smallexample
a2c02241 28693 -file-exec-file @var{file}
922fbb7b
AC
28694@end smallexample
28695
a2c02241
NR
28696Specify the executable file to be debugged. Unlike
28697@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
28698from this file. If used without argument, @value{GDBN} clears the information
28699about the executable file. No output is produced, except a completion
28700notification.
922fbb7b 28701
a2c02241
NR
28702@subsubheading @value{GDBN} Command
28703
28704The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
28705
28706@subsubheading Example
a2c02241
NR
28707
28708@smallexample
594fe323 28709(gdb)
a2c02241
NR
28710-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
28711^done
594fe323 28712(gdb)
a2c02241 28713@end smallexample
922fbb7b
AC
28714
28715
9901a55b 28716@ignore
a2c02241
NR
28717@subheading The @code{-file-list-exec-sections} Command
28718@findex -file-list-exec-sections
922fbb7b
AC
28719
28720@subsubheading Synopsis
28721
28722@smallexample
a2c02241 28723 -file-list-exec-sections
922fbb7b
AC
28724@end smallexample
28725
a2c02241
NR
28726List the sections of the current executable file.
28727
922fbb7b
AC
28728@subsubheading @value{GDBN} Command
28729
a2c02241
NR
28730The @value{GDBN} command @samp{info file} shows, among the rest, the same
28731information as this command. @code{gdbtk} has a corresponding command
28732@samp{gdb_load_info}.
922fbb7b
AC
28733
28734@subsubheading Example
28735N.A.
9901a55b 28736@end ignore
922fbb7b
AC
28737
28738
a2c02241
NR
28739@subheading The @code{-file-list-exec-source-file} Command
28740@findex -file-list-exec-source-file
922fbb7b
AC
28741
28742@subsubheading Synopsis
28743
28744@smallexample
a2c02241 28745 -file-list-exec-source-file
922fbb7b
AC
28746@end smallexample
28747
a2c02241 28748List the line number, the current source file, and the absolute path
44288b44
NR
28749to the current source file for the current executable. The macro
28750information field has a value of @samp{1} or @samp{0} depending on
28751whether or not the file includes preprocessor macro information.
922fbb7b
AC
28752
28753@subsubheading @value{GDBN} Command
28754
a2c02241 28755The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
28756
28757@subsubheading Example
28758
922fbb7b 28759@smallexample
594fe323 28760(gdb)
a2c02241 28761123-file-list-exec-source-file
44288b44 28762123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 28763(gdb)
922fbb7b
AC
28764@end smallexample
28765
28766
a2c02241
NR
28767@subheading The @code{-file-list-exec-source-files} Command
28768@findex -file-list-exec-source-files
922fbb7b
AC
28769
28770@subsubheading Synopsis
28771
28772@smallexample
a2c02241 28773 -file-list-exec-source-files
922fbb7b
AC
28774@end smallexample
28775
a2c02241
NR
28776List the source files for the current executable.
28777
3f94c067
BW
28778It will always output the filename, but only when @value{GDBN} can find
28779the absolute file name of a source file, will it output the fullname.
922fbb7b
AC
28780
28781@subsubheading @value{GDBN} Command
28782
a2c02241
NR
28783The @value{GDBN} equivalent is @samp{info sources}.
28784@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
28785
28786@subsubheading Example
922fbb7b 28787@smallexample
594fe323 28788(gdb)
a2c02241
NR
28789-file-list-exec-source-files
28790^done,files=[
28791@{file=foo.c,fullname=/home/foo.c@},
28792@{file=/home/bar.c,fullname=/home/bar.c@},
28793@{file=gdb_could_not_find_fullpath.c@}]
594fe323 28794(gdb)
922fbb7b
AC
28795@end smallexample
28796
9901a55b 28797@ignore
a2c02241
NR
28798@subheading The @code{-file-list-shared-libraries} Command
28799@findex -file-list-shared-libraries
922fbb7b 28800
a2c02241 28801@subsubheading Synopsis
922fbb7b 28802
a2c02241
NR
28803@smallexample
28804 -file-list-shared-libraries
28805@end smallexample
922fbb7b 28806
a2c02241 28807List the shared libraries in the program.
922fbb7b 28808
a2c02241 28809@subsubheading @value{GDBN} Command
922fbb7b 28810
a2c02241 28811The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 28812
a2c02241
NR
28813@subsubheading Example
28814N.A.
922fbb7b
AC
28815
28816
a2c02241
NR
28817@subheading The @code{-file-list-symbol-files} Command
28818@findex -file-list-symbol-files
922fbb7b 28819
a2c02241 28820@subsubheading Synopsis
922fbb7b 28821
a2c02241
NR
28822@smallexample
28823 -file-list-symbol-files
28824@end smallexample
922fbb7b 28825
a2c02241 28826List symbol files.
922fbb7b 28827
a2c02241 28828@subsubheading @value{GDBN} Command
922fbb7b 28829
a2c02241 28830The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 28831
a2c02241
NR
28832@subsubheading Example
28833N.A.
9901a55b 28834@end ignore
922fbb7b 28835
922fbb7b 28836
a2c02241
NR
28837@subheading The @code{-file-symbol-file} Command
28838@findex -file-symbol-file
922fbb7b 28839
a2c02241 28840@subsubheading Synopsis
922fbb7b 28841
a2c02241
NR
28842@smallexample
28843 -file-symbol-file @var{file}
28844@end smallexample
922fbb7b 28845
a2c02241
NR
28846Read symbol table info from the specified @var{file} argument. When
28847used without arguments, clears @value{GDBN}'s symbol table info. No output is
28848produced, except for a completion notification.
922fbb7b 28849
a2c02241 28850@subsubheading @value{GDBN} Command
922fbb7b 28851
a2c02241 28852The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 28853
a2c02241 28854@subsubheading Example
922fbb7b 28855
a2c02241 28856@smallexample
594fe323 28857(gdb)
a2c02241
NR
28858-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
28859^done
594fe323 28860(gdb)
a2c02241 28861@end smallexample
922fbb7b 28862
a2c02241 28863@ignore
a2c02241
NR
28864@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28865@node GDB/MI Memory Overlay Commands
28866@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 28867
a2c02241 28868The memory overlay commands are not implemented.
922fbb7b 28869
a2c02241 28870@c @subheading -overlay-auto
922fbb7b 28871
a2c02241 28872@c @subheading -overlay-list-mapping-state
922fbb7b 28873
a2c02241 28874@c @subheading -overlay-list-overlays
922fbb7b 28875
a2c02241 28876@c @subheading -overlay-map
922fbb7b 28877
a2c02241 28878@c @subheading -overlay-off
922fbb7b 28879
a2c02241 28880@c @subheading -overlay-on
922fbb7b 28881
a2c02241 28882@c @subheading -overlay-unmap
922fbb7b 28883
a2c02241
NR
28884@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28885@node GDB/MI Signal Handling Commands
28886@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 28887
a2c02241 28888Signal handling commands are not implemented.
922fbb7b 28889
a2c02241 28890@c @subheading -signal-handle
922fbb7b 28891
a2c02241 28892@c @subheading -signal-list-handle-actions
922fbb7b 28893
a2c02241
NR
28894@c @subheading -signal-list-signal-types
28895@end ignore
922fbb7b 28896
922fbb7b 28897
a2c02241
NR
28898@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28899@node GDB/MI Target Manipulation
28900@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
28901
28902
a2c02241
NR
28903@subheading The @code{-target-attach} Command
28904@findex -target-attach
922fbb7b
AC
28905
28906@subsubheading Synopsis
28907
28908@smallexample
c3b108f7 28909 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
28910@end smallexample
28911
c3b108f7
VP
28912Attach to a process @var{pid} or a file @var{file} outside of
28913@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
28914group, the id previously returned by
28915@samp{-list-thread-groups --available} must be used.
922fbb7b 28916
79a6e687 28917@subsubheading @value{GDBN} Command
922fbb7b 28918
a2c02241 28919The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 28920
a2c02241 28921@subsubheading Example
b56e7235
VP
28922@smallexample
28923(gdb)
28924-target-attach 34
28925=thread-created,id="1"
5ae4183a 28926*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
28927^done
28928(gdb)
28929@end smallexample
a2c02241 28930
9901a55b 28931@ignore
a2c02241
NR
28932@subheading The @code{-target-compare-sections} Command
28933@findex -target-compare-sections
922fbb7b
AC
28934
28935@subsubheading Synopsis
28936
28937@smallexample
a2c02241 28938 -target-compare-sections [ @var{section} ]
922fbb7b
AC
28939@end smallexample
28940
a2c02241
NR
28941Compare data of section @var{section} on target to the exec file.
28942Without the argument, all sections are compared.
922fbb7b 28943
a2c02241 28944@subsubheading @value{GDBN} Command
922fbb7b 28945
a2c02241 28946The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 28947
a2c02241
NR
28948@subsubheading Example
28949N.A.
9901a55b 28950@end ignore
a2c02241
NR
28951
28952
28953@subheading The @code{-target-detach} Command
28954@findex -target-detach
922fbb7b
AC
28955
28956@subsubheading Synopsis
28957
28958@smallexample
c3b108f7 28959 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
28960@end smallexample
28961
a2c02241 28962Detach from the remote target which normally resumes its execution.
c3b108f7
VP
28963If either @var{pid} or @var{gid} is specified, detaches from either
28964the specified process, or specified thread group. There's no output.
a2c02241 28965
79a6e687 28966@subsubheading @value{GDBN} Command
a2c02241
NR
28967
28968The corresponding @value{GDBN} command is @samp{detach}.
28969
28970@subsubheading Example
922fbb7b
AC
28971
28972@smallexample
594fe323 28973(gdb)
a2c02241
NR
28974-target-detach
28975^done
594fe323 28976(gdb)
922fbb7b
AC
28977@end smallexample
28978
28979
a2c02241
NR
28980@subheading The @code{-target-disconnect} Command
28981@findex -target-disconnect
922fbb7b
AC
28982
28983@subsubheading Synopsis
28984
123dc839 28985@smallexample
a2c02241 28986 -target-disconnect
123dc839 28987@end smallexample
922fbb7b 28988
a2c02241
NR
28989Disconnect from the remote target. There's no output and the target is
28990generally not resumed.
28991
79a6e687 28992@subsubheading @value{GDBN} Command
a2c02241
NR
28993
28994The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
28995
28996@subsubheading Example
922fbb7b
AC
28997
28998@smallexample
594fe323 28999(gdb)
a2c02241
NR
29000-target-disconnect
29001^done
594fe323 29002(gdb)
922fbb7b
AC
29003@end smallexample
29004
29005
a2c02241
NR
29006@subheading The @code{-target-download} Command
29007@findex -target-download
922fbb7b
AC
29008
29009@subsubheading Synopsis
29010
29011@smallexample
a2c02241 29012 -target-download
922fbb7b
AC
29013@end smallexample
29014
a2c02241
NR
29015Loads the executable onto the remote target.
29016It prints out an update message every half second, which includes the fields:
29017
29018@table @samp
29019@item section
29020The name of the section.
29021@item section-sent
29022The size of what has been sent so far for that section.
29023@item section-size
29024The size of the section.
29025@item total-sent
29026The total size of what was sent so far (the current and the previous sections).
29027@item total-size
29028The size of the overall executable to download.
29029@end table
29030
29031@noindent
29032Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
29033@sc{gdb/mi} Output Syntax}).
29034
29035In addition, it prints the name and size of the sections, as they are
29036downloaded. These messages include the following fields:
29037
29038@table @samp
29039@item section
29040The name of the section.
29041@item section-size
29042The size of the section.
29043@item total-size
29044The size of the overall executable to download.
29045@end table
29046
29047@noindent
29048At the end, a summary is printed.
29049
29050@subsubheading @value{GDBN} Command
29051
29052The corresponding @value{GDBN} command is @samp{load}.
29053
29054@subsubheading Example
29055
29056Note: each status message appears on a single line. Here the messages
29057have been broken down so that they can fit onto a page.
922fbb7b
AC
29058
29059@smallexample
594fe323 29060(gdb)
a2c02241
NR
29061-target-download
29062+download,@{section=".text",section-size="6668",total-size="9880"@}
29063+download,@{section=".text",section-sent="512",section-size="6668",
29064total-sent="512",total-size="9880"@}
29065+download,@{section=".text",section-sent="1024",section-size="6668",
29066total-sent="1024",total-size="9880"@}
29067+download,@{section=".text",section-sent="1536",section-size="6668",
29068total-sent="1536",total-size="9880"@}
29069+download,@{section=".text",section-sent="2048",section-size="6668",
29070total-sent="2048",total-size="9880"@}
29071+download,@{section=".text",section-sent="2560",section-size="6668",
29072total-sent="2560",total-size="9880"@}
29073+download,@{section=".text",section-sent="3072",section-size="6668",
29074total-sent="3072",total-size="9880"@}
29075+download,@{section=".text",section-sent="3584",section-size="6668",
29076total-sent="3584",total-size="9880"@}
29077+download,@{section=".text",section-sent="4096",section-size="6668",
29078total-sent="4096",total-size="9880"@}
29079+download,@{section=".text",section-sent="4608",section-size="6668",
29080total-sent="4608",total-size="9880"@}
29081+download,@{section=".text",section-sent="5120",section-size="6668",
29082total-sent="5120",total-size="9880"@}
29083+download,@{section=".text",section-sent="5632",section-size="6668",
29084total-sent="5632",total-size="9880"@}
29085+download,@{section=".text",section-sent="6144",section-size="6668",
29086total-sent="6144",total-size="9880"@}
29087+download,@{section=".text",section-sent="6656",section-size="6668",
29088total-sent="6656",total-size="9880"@}
29089+download,@{section=".init",section-size="28",total-size="9880"@}
29090+download,@{section=".fini",section-size="28",total-size="9880"@}
29091+download,@{section=".data",section-size="3156",total-size="9880"@}
29092+download,@{section=".data",section-sent="512",section-size="3156",
29093total-sent="7236",total-size="9880"@}
29094+download,@{section=".data",section-sent="1024",section-size="3156",
29095total-sent="7748",total-size="9880"@}
29096+download,@{section=".data",section-sent="1536",section-size="3156",
29097total-sent="8260",total-size="9880"@}
29098+download,@{section=".data",section-sent="2048",section-size="3156",
29099total-sent="8772",total-size="9880"@}
29100+download,@{section=".data",section-sent="2560",section-size="3156",
29101total-sent="9284",total-size="9880"@}
29102+download,@{section=".data",section-sent="3072",section-size="3156",
29103total-sent="9796",total-size="9880"@}
29104^done,address="0x10004",load-size="9880",transfer-rate="6586",
29105write-rate="429"
594fe323 29106(gdb)
922fbb7b
AC
29107@end smallexample
29108
29109
9901a55b 29110@ignore
a2c02241
NR
29111@subheading The @code{-target-exec-status} Command
29112@findex -target-exec-status
922fbb7b
AC
29113
29114@subsubheading Synopsis
29115
29116@smallexample
a2c02241 29117 -target-exec-status
922fbb7b
AC
29118@end smallexample
29119
a2c02241
NR
29120Provide information on the state of the target (whether it is running or
29121not, for instance).
922fbb7b 29122
a2c02241 29123@subsubheading @value{GDBN} Command
922fbb7b 29124
a2c02241
NR
29125There's no equivalent @value{GDBN} command.
29126
29127@subsubheading Example
29128N.A.
922fbb7b 29129
a2c02241
NR
29130
29131@subheading The @code{-target-list-available-targets} Command
29132@findex -target-list-available-targets
922fbb7b
AC
29133
29134@subsubheading Synopsis
29135
29136@smallexample
a2c02241 29137 -target-list-available-targets
922fbb7b
AC
29138@end smallexample
29139
a2c02241 29140List the possible targets to connect to.
922fbb7b 29141
a2c02241 29142@subsubheading @value{GDBN} Command
922fbb7b 29143
a2c02241 29144The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 29145
a2c02241
NR
29146@subsubheading Example
29147N.A.
29148
29149
29150@subheading The @code{-target-list-current-targets} Command
29151@findex -target-list-current-targets
922fbb7b
AC
29152
29153@subsubheading Synopsis
29154
29155@smallexample
a2c02241 29156 -target-list-current-targets
922fbb7b
AC
29157@end smallexample
29158
a2c02241 29159Describe the current target.
922fbb7b 29160
a2c02241 29161@subsubheading @value{GDBN} Command
922fbb7b 29162
a2c02241
NR
29163The corresponding information is printed by @samp{info file} (among
29164other things).
922fbb7b 29165
a2c02241
NR
29166@subsubheading Example
29167N.A.
29168
29169
29170@subheading The @code{-target-list-parameters} Command
29171@findex -target-list-parameters
922fbb7b
AC
29172
29173@subsubheading Synopsis
29174
29175@smallexample
a2c02241 29176 -target-list-parameters
922fbb7b
AC
29177@end smallexample
29178
a2c02241 29179@c ????
9901a55b 29180@end ignore
a2c02241
NR
29181
29182@subsubheading @value{GDBN} Command
29183
29184No equivalent.
922fbb7b
AC
29185
29186@subsubheading Example
a2c02241
NR
29187N.A.
29188
29189
29190@subheading The @code{-target-select} Command
29191@findex -target-select
29192
29193@subsubheading Synopsis
922fbb7b
AC
29194
29195@smallexample
a2c02241 29196 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
29197@end smallexample
29198
a2c02241 29199Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 29200
a2c02241
NR
29201@table @samp
29202@item @var{type}
75c99385 29203The type of target, for instance @samp{remote}, etc.
a2c02241
NR
29204@item @var{parameters}
29205Device names, host names and the like. @xref{Target Commands, ,
79a6e687 29206Commands for Managing Targets}, for more details.
a2c02241
NR
29207@end table
29208
29209The output is a connection notification, followed by the address at
29210which the target program is, in the following form:
922fbb7b
AC
29211
29212@smallexample
a2c02241
NR
29213^connected,addr="@var{address}",func="@var{function name}",
29214 args=[@var{arg list}]
922fbb7b
AC
29215@end smallexample
29216
a2c02241
NR
29217@subsubheading @value{GDBN} Command
29218
29219The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
29220
29221@subsubheading Example
922fbb7b 29222
265eeb58 29223@smallexample
594fe323 29224(gdb)
75c99385 29225-target-select remote /dev/ttya
a2c02241 29226^connected,addr="0xfe00a300",func="??",args=[]
594fe323 29227(gdb)
265eeb58 29228@end smallexample
ef21caaf 29229
a6b151f1
DJ
29230@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29231@node GDB/MI File Transfer Commands
29232@section @sc{gdb/mi} File Transfer Commands
29233
29234
29235@subheading The @code{-target-file-put} Command
29236@findex -target-file-put
29237
29238@subsubheading Synopsis
29239
29240@smallexample
29241 -target-file-put @var{hostfile} @var{targetfile}
29242@end smallexample
29243
29244Copy file @var{hostfile} from the host system (the machine running
29245@value{GDBN}) to @var{targetfile} on the target system.
29246
29247@subsubheading @value{GDBN} Command
29248
29249The corresponding @value{GDBN} command is @samp{remote put}.
29250
29251@subsubheading Example
29252
29253@smallexample
29254(gdb)
29255-target-file-put localfile remotefile
29256^done
29257(gdb)
29258@end smallexample
29259
29260
1763a388 29261@subheading The @code{-target-file-get} Command
a6b151f1
DJ
29262@findex -target-file-get
29263
29264@subsubheading Synopsis
29265
29266@smallexample
29267 -target-file-get @var{targetfile} @var{hostfile}
29268@end smallexample
29269
29270Copy file @var{targetfile} from the target system to @var{hostfile}
29271on the host system.
29272
29273@subsubheading @value{GDBN} Command
29274
29275The corresponding @value{GDBN} command is @samp{remote get}.
29276
29277@subsubheading Example
29278
29279@smallexample
29280(gdb)
29281-target-file-get remotefile localfile
29282^done
29283(gdb)
29284@end smallexample
29285
29286
29287@subheading The @code{-target-file-delete} Command
29288@findex -target-file-delete
29289
29290@subsubheading Synopsis
29291
29292@smallexample
29293 -target-file-delete @var{targetfile}
29294@end smallexample
29295
29296Delete @var{targetfile} from the target system.
29297
29298@subsubheading @value{GDBN} Command
29299
29300The corresponding @value{GDBN} command is @samp{remote delete}.
29301
29302@subsubheading Example
29303
29304@smallexample
29305(gdb)
29306-target-file-delete remotefile
29307^done
29308(gdb)
29309@end smallexample
29310
29311
ef21caaf
NR
29312@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29313@node GDB/MI Miscellaneous Commands
29314@section Miscellaneous @sc{gdb/mi} Commands
29315
29316@c @subheading -gdb-complete
29317
29318@subheading The @code{-gdb-exit} Command
29319@findex -gdb-exit
29320
29321@subsubheading Synopsis
29322
29323@smallexample
29324 -gdb-exit
29325@end smallexample
29326
29327Exit @value{GDBN} immediately.
29328
29329@subsubheading @value{GDBN} Command
29330
29331Approximately corresponds to @samp{quit}.
29332
29333@subsubheading Example
29334
29335@smallexample
594fe323 29336(gdb)
ef21caaf
NR
29337-gdb-exit
29338^exit
29339@end smallexample
29340
a2c02241 29341
9901a55b 29342@ignore
a2c02241
NR
29343@subheading The @code{-exec-abort} Command
29344@findex -exec-abort
29345
29346@subsubheading Synopsis
29347
29348@smallexample
29349 -exec-abort
29350@end smallexample
29351
29352Kill the inferior running program.
29353
29354@subsubheading @value{GDBN} Command
29355
29356The corresponding @value{GDBN} command is @samp{kill}.
29357
29358@subsubheading Example
29359N.A.
9901a55b 29360@end ignore
a2c02241
NR
29361
29362
ef21caaf
NR
29363@subheading The @code{-gdb-set} Command
29364@findex -gdb-set
29365
29366@subsubheading Synopsis
29367
29368@smallexample
29369 -gdb-set
29370@end smallexample
29371
29372Set an internal @value{GDBN} variable.
29373@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
29374
29375@subsubheading @value{GDBN} Command
29376
29377The corresponding @value{GDBN} command is @samp{set}.
29378
29379@subsubheading Example
29380
29381@smallexample
594fe323 29382(gdb)
ef21caaf
NR
29383-gdb-set $foo=3
29384^done
594fe323 29385(gdb)
ef21caaf
NR
29386@end smallexample
29387
29388
29389@subheading The @code{-gdb-show} Command
29390@findex -gdb-show
29391
29392@subsubheading Synopsis
29393
29394@smallexample
29395 -gdb-show
29396@end smallexample
29397
29398Show the current value of a @value{GDBN} variable.
29399
79a6e687 29400@subsubheading @value{GDBN} Command
ef21caaf
NR
29401
29402The corresponding @value{GDBN} command is @samp{show}.
29403
29404@subsubheading Example
29405
29406@smallexample
594fe323 29407(gdb)
ef21caaf
NR
29408-gdb-show annotate
29409^done,value="0"
594fe323 29410(gdb)
ef21caaf
NR
29411@end smallexample
29412
29413@c @subheading -gdb-source
29414
29415
29416@subheading The @code{-gdb-version} Command
29417@findex -gdb-version
29418
29419@subsubheading Synopsis
29420
29421@smallexample
29422 -gdb-version
29423@end smallexample
29424
29425Show version information for @value{GDBN}. Used mostly in testing.
29426
29427@subsubheading @value{GDBN} Command
29428
29429The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
29430default shows this information when you start an interactive session.
29431
29432@subsubheading Example
29433
29434@c This example modifies the actual output from GDB to avoid overfull
29435@c box in TeX.
29436@smallexample
594fe323 29437(gdb)
ef21caaf
NR
29438-gdb-version
29439~GNU gdb 5.2.1
29440~Copyright 2000 Free Software Foundation, Inc.
29441~GDB is free software, covered by the GNU General Public License, and
29442~you are welcome to change it and/or distribute copies of it under
29443~ certain conditions.
29444~Type "show copying" to see the conditions.
29445~There is absolutely no warranty for GDB. Type "show warranty" for
29446~ details.
29447~This GDB was configured as
29448 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
29449^done
594fe323 29450(gdb)
ef21caaf
NR
29451@end smallexample
29452
084344da
VP
29453@subheading The @code{-list-features} Command
29454@findex -list-features
29455
29456Returns a list of particular features of the MI protocol that
29457this version of gdb implements. A feature can be a command,
29458or a new field in an output of some command, or even an
29459important bugfix. While a frontend can sometimes detect presence
29460of a feature at runtime, it is easier to perform detection at debugger
29461startup.
29462
29463The command returns a list of strings, with each string naming an
29464available feature. Each returned string is just a name, it does not
29465have any internal structure. The list of possible feature names
29466is given below.
29467
29468Example output:
29469
29470@smallexample
29471(gdb) -list-features
29472^done,result=["feature1","feature2"]
29473@end smallexample
29474
29475The current list of features is:
29476
30e026bb
VP
29477@table @samp
29478@item frozen-varobjs
29479Indicates presence of the @code{-var-set-frozen} command, as well
29480as possible presense of the @code{frozen} field in the output
29481of @code{-varobj-create}.
29482@item pending-breakpoints
29483Indicates presence of the @option{-f} option to the @code{-break-insert} command.
b6313243
TT
29484@item python
29485Indicates presence of Python scripting support, Python-based
29486pretty-printing commands, and possible presence of the
29487@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb
VP
29488@item thread-info
29489Indicates presence of the @code{-thread-info} command.
8dedea02
VP
29490@item data-read-memory-bytes
29491Indicates presense of the @code{-data-read-memory-bytes} and the
29492@code{-data-write-memory-bytes} commands.
8b4ed427 29493
30e026bb 29494@end table
084344da 29495
c6ebd6cf
VP
29496@subheading The @code{-list-target-features} Command
29497@findex -list-target-features
29498
29499Returns a list of particular features that are supported by the
29500target. Those features affect the permitted MI commands, but
29501unlike the features reported by the @code{-list-features} command, the
29502features depend on which target GDB is using at the moment. Whenever
29503a target can change, due to commands such as @code{-target-select},
29504@code{-target-attach} or @code{-exec-run}, the list of target features
29505may change, and the frontend should obtain it again.
29506Example output:
29507
29508@smallexample
29509(gdb) -list-features
29510^done,result=["async"]
29511@end smallexample
29512
29513The current list of features is:
29514
29515@table @samp
29516@item async
29517Indicates that the target is capable of asynchronous command
29518execution, which means that @value{GDBN} will accept further commands
29519while the target is running.
29520
f75d858b
MK
29521@item reverse
29522Indicates that the target is capable of reverse execution.
29523@xref{Reverse Execution}, for more information.
29524
c6ebd6cf
VP
29525@end table
29526
c3b108f7
VP
29527@subheading The @code{-list-thread-groups} Command
29528@findex -list-thread-groups
29529
29530@subheading Synopsis
29531
29532@smallexample
dc146f7c 29533-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
29534@end smallexample
29535
dc146f7c
VP
29536Lists thread groups (@pxref{Thread groups}). When a single thread
29537group is passed as the argument, lists the children of that group.
29538When several thread group are passed, lists information about those
29539thread groups. Without any parameters, lists information about all
29540top-level thread groups.
29541
29542Normally, thread groups that are being debugged are reported.
29543With the @samp{--available} option, @value{GDBN} reports thread groups
29544available on the target.
29545
29546The output of this command may have either a @samp{threads} result or
29547a @samp{groups} result. The @samp{thread} result has a list of tuples
29548as value, with each tuple describing a thread (@pxref{GDB/MI Thread
29549Information}). The @samp{groups} result has a list of tuples as value,
29550each tuple describing a thread group. If top-level groups are
29551requested (that is, no parameter is passed), or when several groups
29552are passed, the output always has a @samp{groups} result. The format
29553of the @samp{group} result is described below.
29554
29555To reduce the number of roundtrips it's possible to list thread groups
29556together with their children, by passing the @samp{--recurse} option
29557and the recursion depth. Presently, only recursion depth of 1 is
29558permitted. If this option is present, then every reported thread group
29559will also include its children, either as @samp{group} or
29560@samp{threads} field.
29561
29562In general, any combination of option and parameters is permitted, with
29563the following caveats:
29564
29565@itemize @bullet
29566@item
29567When a single thread group is passed, the output will typically
29568be the @samp{threads} result. Because threads may not contain
29569anything, the @samp{recurse} option will be ignored.
29570
29571@item
29572When the @samp{--available} option is passed, limited information may
29573be available. In particular, the list of threads of a process might
29574be inaccessible. Further, specifying specific thread groups might
29575not give any performance advantage over listing all thread groups.
29576The frontend should assume that @samp{-list-thread-groups --available}
29577is always an expensive operation and cache the results.
29578
29579@end itemize
29580
29581The @samp{groups} result is a list of tuples, where each tuple may
29582have the following fields:
29583
29584@table @code
29585@item id
29586Identifier of the thread group. This field is always present.
a79b8f6e
VP
29587The identifier is an opaque string; frontends should not try to
29588convert it to an integer, even though it might look like one.
dc146f7c
VP
29589
29590@item type
29591The type of the thread group. At present, only @samp{process} is a
29592valid type.
29593
29594@item pid
29595The target-specific process identifier. This field is only present
a79b8f6e 29596for thread groups of type @samp{process} and only if the process exists.
c3b108f7 29597
dc146f7c
VP
29598@item num_children
29599The number of children this thread group has. This field may be
29600absent for an available thread group.
29601
29602@item threads
29603This field has a list of tuples as value, each tuple describing a
29604thread. It may be present if the @samp{--recurse} option is
29605specified, and it's actually possible to obtain the threads.
29606
29607@item cores
29608This field is a list of integers, each identifying a core that one
29609thread of the group is running on. This field may be absent if
29610such information is not available.
29611
a79b8f6e
VP
29612@item executable
29613The name of the executable file that corresponds to this thread group.
29614The field is only present for thread groups of type @samp{process},
29615and only if there is a corresponding executable file.
29616
dc146f7c 29617@end table
c3b108f7
VP
29618
29619@subheading Example
29620
29621@smallexample
29622@value{GDBP}
29623-list-thread-groups
29624^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
29625-list-thread-groups 17
29626^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
29627 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
29628@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
29629 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
29630 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
dc146f7c
VP
29631-list-thread-groups --available
29632^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
29633-list-thread-groups --available --recurse 1
29634 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
29635 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
29636 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
29637-list-thread-groups --available --recurse 1 17 18
29638^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
29639 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
29640 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 29641@end smallexample
c6ebd6cf 29642
a79b8f6e
VP
29643
29644@subheading The @code{-add-inferior} Command
29645@findex -add-inferior
29646
29647@subheading Synopsis
29648
29649@smallexample
29650-add-inferior
29651@end smallexample
29652
29653Creates a new inferior (@pxref{Inferiors and Programs}). The created
29654inferior is not associated with any executable. Such association may
29655be established with the @samp{-file-exec-and-symbols} command
29656(@pxref{GDB/MI File Commands}). The command response has a single
29657field, @samp{thread-group}, whose value is the identifier of the
29658thread group corresponding to the new inferior.
29659
29660@subheading Example
29661
29662@smallexample
29663@value{GDBP}
29664-add-inferior
29665^done,thread-group="i3"
29666@end smallexample
29667
ef21caaf
NR
29668@subheading The @code{-interpreter-exec} Command
29669@findex -interpreter-exec
29670
29671@subheading Synopsis
29672
29673@smallexample
29674-interpreter-exec @var{interpreter} @var{command}
29675@end smallexample
a2c02241 29676@anchor{-interpreter-exec}
ef21caaf
NR
29677
29678Execute the specified @var{command} in the given @var{interpreter}.
29679
29680@subheading @value{GDBN} Command
29681
29682The corresponding @value{GDBN} command is @samp{interpreter-exec}.
29683
29684@subheading Example
29685
29686@smallexample
594fe323 29687(gdb)
ef21caaf
NR
29688-interpreter-exec console "break main"
29689&"During symbol reading, couldn't parse type; debugger out of date?.\n"
29690&"During symbol reading, bad structure-type format.\n"
29691~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
29692^done
594fe323 29693(gdb)
ef21caaf
NR
29694@end smallexample
29695
29696@subheading The @code{-inferior-tty-set} Command
29697@findex -inferior-tty-set
29698
29699@subheading Synopsis
29700
29701@smallexample
29702-inferior-tty-set /dev/pts/1
29703@end smallexample
29704
29705Set terminal for future runs of the program being debugged.
29706
29707@subheading @value{GDBN} Command
29708
29709The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
29710
29711@subheading Example
29712
29713@smallexample
594fe323 29714(gdb)
ef21caaf
NR
29715-inferior-tty-set /dev/pts/1
29716^done
594fe323 29717(gdb)
ef21caaf
NR
29718@end smallexample
29719
29720@subheading The @code{-inferior-tty-show} Command
29721@findex -inferior-tty-show
29722
29723@subheading Synopsis
29724
29725@smallexample
29726-inferior-tty-show
29727@end smallexample
29728
29729Show terminal for future runs of program being debugged.
29730
29731@subheading @value{GDBN} Command
29732
29733The corresponding @value{GDBN} command is @samp{show inferior-tty}.
29734
29735@subheading Example
29736
29737@smallexample
594fe323 29738(gdb)
ef21caaf
NR
29739-inferior-tty-set /dev/pts/1
29740^done
594fe323 29741(gdb)
ef21caaf
NR
29742-inferior-tty-show
29743^done,inferior_tty_terminal="/dev/pts/1"
594fe323 29744(gdb)
ef21caaf 29745@end smallexample
922fbb7b 29746
a4eefcd8
NR
29747@subheading The @code{-enable-timings} Command
29748@findex -enable-timings
29749
29750@subheading Synopsis
29751
29752@smallexample
29753-enable-timings [yes | no]
29754@end smallexample
29755
29756Toggle the printing of the wallclock, user and system times for an MI
29757command as a field in its output. This command is to help frontend
29758developers optimize the performance of their code. No argument is
29759equivalent to @samp{yes}.
29760
29761@subheading @value{GDBN} Command
29762
29763No equivalent.
29764
29765@subheading Example
29766
29767@smallexample
29768(gdb)
29769-enable-timings
29770^done
29771(gdb)
29772-break-insert main
29773^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29774addr="0x080484ed",func="main",file="myprog.c",
29775fullname="/home/nickrob/myprog.c",line="73",times="0"@},
29776time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
29777(gdb)
29778-enable-timings no
29779^done
29780(gdb)
29781-exec-run
29782^running
29783(gdb)
a47ec5fe 29784*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
29785frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
29786@{name="argv",value="0xbfb60364"@}],file="myprog.c",
29787fullname="/home/nickrob/myprog.c",line="73"@}
29788(gdb)
29789@end smallexample
29790
922fbb7b
AC
29791@node Annotations
29792@chapter @value{GDBN} Annotations
29793
086432e2
AC
29794This chapter describes annotations in @value{GDBN}. Annotations were
29795designed to interface @value{GDBN} to graphical user interfaces or other
29796similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
29797relatively high level.
29798
d3e8051b 29799The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
29800(@pxref{GDB/MI}).
29801
922fbb7b
AC
29802@ignore
29803This is Edition @value{EDITION}, @value{DATE}.
29804@end ignore
29805
29806@menu
29807* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 29808* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
29809* Prompting:: Annotations marking @value{GDBN}'s need for input.
29810* Errors:: Annotations for error messages.
922fbb7b
AC
29811* Invalidation:: Some annotations describe things now invalid.
29812* Annotations for Running::
29813 Whether the program is running, how it stopped, etc.
29814* Source Annotations:: Annotations describing source code.
922fbb7b
AC
29815@end menu
29816
29817@node Annotations Overview
29818@section What is an Annotation?
29819@cindex annotations
29820
922fbb7b
AC
29821Annotations start with a newline character, two @samp{control-z}
29822characters, and the name of the annotation. If there is no additional
29823information associated with this annotation, the name of the annotation
29824is followed immediately by a newline. If there is additional
29825information, the name of the annotation is followed by a space, the
29826additional information, and a newline. The additional information
29827cannot contain newline characters.
29828
29829Any output not beginning with a newline and two @samp{control-z}
29830characters denotes literal output from @value{GDBN}. Currently there is
29831no need for @value{GDBN} to output a newline followed by two
29832@samp{control-z} characters, but if there was such a need, the
29833annotations could be extended with an @samp{escape} annotation which
29834means those three characters as output.
29835
086432e2
AC
29836The annotation @var{level}, which is specified using the
29837@option{--annotate} command line option (@pxref{Mode Options}), controls
29838how much information @value{GDBN} prints together with its prompt,
29839values of expressions, source lines, and other types of output. Level 0
d3e8051b 29840is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
29841subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
29842for programs that control @value{GDBN}, and level 2 annotations have
29843been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
29844Interface, annotate, GDB's Obsolete Annotations}).
29845
29846@table @code
29847@kindex set annotate
29848@item set annotate @var{level}
e09f16f9 29849The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 29850annotations to the specified @var{level}.
9c16f35a
EZ
29851
29852@item show annotate
29853@kindex show annotate
29854Show the current annotation level.
09d4efe1
EZ
29855@end table
29856
29857This chapter describes level 3 annotations.
086432e2 29858
922fbb7b
AC
29859A simple example of starting up @value{GDBN} with annotations is:
29860
29861@smallexample
086432e2
AC
29862$ @kbd{gdb --annotate=3}
29863GNU gdb 6.0
29864Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
29865GDB is free software, covered by the GNU General Public License,
29866and you are welcome to change it and/or distribute copies of it
29867under certain conditions.
29868Type "show copying" to see the conditions.
29869There is absolutely no warranty for GDB. Type "show warranty"
29870for details.
086432e2 29871This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
29872
29873^Z^Zpre-prompt
f7dc1244 29874(@value{GDBP})
922fbb7b 29875^Z^Zprompt
086432e2 29876@kbd{quit}
922fbb7b
AC
29877
29878^Z^Zpost-prompt
b383017d 29879$
922fbb7b
AC
29880@end smallexample
29881
29882Here @samp{quit} is input to @value{GDBN}; the rest is output from
29883@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
29884denotes a @samp{control-z} character) are annotations; the rest is
29885output from @value{GDBN}.
29886
9e6c4bd5
NR
29887@node Server Prefix
29888@section The Server Prefix
29889@cindex server prefix
29890
29891If you prefix a command with @samp{server } then it will not affect
29892the command history, nor will it affect @value{GDBN}'s notion of which
29893command to repeat if @key{RET} is pressed on a line by itself. This
29894means that commands can be run behind a user's back by a front-end in
29895a transparent manner.
29896
d837706a
NR
29897The @code{server } prefix does not affect the recording of values into
29898the value history; to print a value without recording it into the
29899value history, use the @code{output} command instead of the
29900@code{print} command.
29901
29902Using this prefix also disables confirmation requests
29903(@pxref{confirmation requests}).
9e6c4bd5 29904
922fbb7b
AC
29905@node Prompting
29906@section Annotation for @value{GDBN} Input
29907
29908@cindex annotations for prompts
29909When @value{GDBN} prompts for input, it annotates this fact so it is possible
29910to know when to send output, when the output from a given command is
29911over, etc.
29912
29913Different kinds of input each have a different @dfn{input type}. Each
29914input type has three annotations: a @code{pre-} annotation, which
29915denotes the beginning of any prompt which is being output, a plain
29916annotation, which denotes the end of the prompt, and then a @code{post-}
29917annotation which denotes the end of any echo which may (or may not) be
29918associated with the input. For example, the @code{prompt} input type
29919features the following annotations:
29920
29921@smallexample
29922^Z^Zpre-prompt
29923^Z^Zprompt
29924^Z^Zpost-prompt
29925@end smallexample
29926
29927The input types are
29928
29929@table @code
e5ac9b53
EZ
29930@findex pre-prompt annotation
29931@findex prompt annotation
29932@findex post-prompt annotation
922fbb7b
AC
29933@item prompt
29934When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
29935
e5ac9b53
EZ
29936@findex pre-commands annotation
29937@findex commands annotation
29938@findex post-commands annotation
922fbb7b
AC
29939@item commands
29940When @value{GDBN} prompts for a set of commands, like in the @code{commands}
29941command. The annotations are repeated for each command which is input.
29942
e5ac9b53
EZ
29943@findex pre-overload-choice annotation
29944@findex overload-choice annotation
29945@findex post-overload-choice annotation
922fbb7b
AC
29946@item overload-choice
29947When @value{GDBN} wants the user to select between various overloaded functions.
29948
e5ac9b53
EZ
29949@findex pre-query annotation
29950@findex query annotation
29951@findex post-query annotation
922fbb7b
AC
29952@item query
29953When @value{GDBN} wants the user to confirm a potentially dangerous operation.
29954
e5ac9b53
EZ
29955@findex pre-prompt-for-continue annotation
29956@findex prompt-for-continue annotation
29957@findex post-prompt-for-continue annotation
922fbb7b
AC
29958@item prompt-for-continue
29959When @value{GDBN} is asking the user to press return to continue. Note: Don't
29960expect this to work well; instead use @code{set height 0} to disable
29961prompting. This is because the counting of lines is buggy in the
29962presence of annotations.
29963@end table
29964
29965@node Errors
29966@section Errors
29967@cindex annotations for errors, warnings and interrupts
29968
e5ac9b53 29969@findex quit annotation
922fbb7b
AC
29970@smallexample
29971^Z^Zquit
29972@end smallexample
29973
29974This annotation occurs right before @value{GDBN} responds to an interrupt.
29975
e5ac9b53 29976@findex error annotation
922fbb7b
AC
29977@smallexample
29978^Z^Zerror
29979@end smallexample
29980
29981This annotation occurs right before @value{GDBN} responds to an error.
29982
29983Quit and error annotations indicate that any annotations which @value{GDBN} was
29984in the middle of may end abruptly. For example, if a
29985@code{value-history-begin} annotation is followed by a @code{error}, one
29986cannot expect to receive the matching @code{value-history-end}. One
29987cannot expect not to receive it either, however; an error annotation
29988does not necessarily mean that @value{GDBN} is immediately returning all the way
29989to the top level.
29990
e5ac9b53 29991@findex error-begin annotation
922fbb7b
AC
29992A quit or error annotation may be preceded by
29993
29994@smallexample
29995^Z^Zerror-begin
29996@end smallexample
29997
29998Any output between that and the quit or error annotation is the error
29999message.
30000
30001Warning messages are not yet annotated.
30002@c If we want to change that, need to fix warning(), type_error(),
30003@c range_error(), and possibly other places.
30004
922fbb7b
AC
30005@node Invalidation
30006@section Invalidation Notices
30007
30008@cindex annotations for invalidation messages
30009The following annotations say that certain pieces of state may have
30010changed.
30011
30012@table @code
e5ac9b53 30013@findex frames-invalid annotation
922fbb7b
AC
30014@item ^Z^Zframes-invalid
30015
30016The frames (for example, output from the @code{backtrace} command) may
30017have changed.
30018
e5ac9b53 30019@findex breakpoints-invalid annotation
922fbb7b
AC
30020@item ^Z^Zbreakpoints-invalid
30021
30022The breakpoints may have changed. For example, the user just added or
30023deleted a breakpoint.
30024@end table
30025
30026@node Annotations for Running
30027@section Running the Program
30028@cindex annotations for running programs
30029
e5ac9b53
EZ
30030@findex starting annotation
30031@findex stopping annotation
922fbb7b 30032When the program starts executing due to a @value{GDBN} command such as
b383017d 30033@code{step} or @code{continue},
922fbb7b
AC
30034
30035@smallexample
30036^Z^Zstarting
30037@end smallexample
30038
b383017d 30039is output. When the program stops,
922fbb7b
AC
30040
30041@smallexample
30042^Z^Zstopped
30043@end smallexample
30044
30045is output. Before the @code{stopped} annotation, a variety of
30046annotations describe how the program stopped.
30047
30048@table @code
e5ac9b53 30049@findex exited annotation
922fbb7b
AC
30050@item ^Z^Zexited @var{exit-status}
30051The program exited, and @var{exit-status} is the exit status (zero for
30052successful exit, otherwise nonzero).
30053
e5ac9b53
EZ
30054@findex signalled annotation
30055@findex signal-name annotation
30056@findex signal-name-end annotation
30057@findex signal-string annotation
30058@findex signal-string-end annotation
922fbb7b
AC
30059@item ^Z^Zsignalled
30060The program exited with a signal. After the @code{^Z^Zsignalled}, the
30061annotation continues:
30062
30063@smallexample
30064@var{intro-text}
30065^Z^Zsignal-name
30066@var{name}
30067^Z^Zsignal-name-end
30068@var{middle-text}
30069^Z^Zsignal-string
30070@var{string}
30071^Z^Zsignal-string-end
30072@var{end-text}
30073@end smallexample
30074
30075@noindent
30076where @var{name} is the name of the signal, such as @code{SIGILL} or
30077@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
30078as @code{Illegal Instruction} or @code{Segmentation fault}.
30079@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
30080user's benefit and have no particular format.
30081
e5ac9b53 30082@findex signal annotation
922fbb7b
AC
30083@item ^Z^Zsignal
30084The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
30085just saying that the program received the signal, not that it was
30086terminated with it.
30087
e5ac9b53 30088@findex breakpoint annotation
922fbb7b
AC
30089@item ^Z^Zbreakpoint @var{number}
30090The program hit breakpoint number @var{number}.
30091
e5ac9b53 30092@findex watchpoint annotation
922fbb7b
AC
30093@item ^Z^Zwatchpoint @var{number}
30094The program hit watchpoint number @var{number}.
30095@end table
30096
30097@node Source Annotations
30098@section Displaying Source
30099@cindex annotations for source display
30100
e5ac9b53 30101@findex source annotation
922fbb7b
AC
30102The following annotation is used instead of displaying source code:
30103
30104@smallexample
30105^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
30106@end smallexample
30107
30108where @var{filename} is an absolute file name indicating which source
30109file, @var{line} is the line number within that file (where 1 is the
30110first line in the file), @var{character} is the character position
30111within the file (where 0 is the first character in the file) (for most
30112debug formats this will necessarily point to the beginning of a line),
30113@var{middle} is @samp{middle} if @var{addr} is in the middle of the
30114line, or @samp{beg} if @var{addr} is at the beginning of the line, and
30115@var{addr} is the address in the target program associated with the
30116source which is being displayed. @var{addr} is in the form @samp{0x}
30117followed by one or more lowercase hex digits (note that this does not
30118depend on the language).
30119
4efc6507
DE
30120@node JIT Interface
30121@chapter JIT Compilation Interface
30122@cindex just-in-time compilation
30123@cindex JIT compilation interface
30124
30125This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
30126interface. A JIT compiler is a program or library that generates native
30127executable code at runtime and executes it, usually in order to achieve good
30128performance while maintaining platform independence.
30129
30130Programs that use JIT compilation are normally difficult to debug because
30131portions of their code are generated at runtime, instead of being loaded from
30132object files, which is where @value{GDBN} normally finds the program's symbols
30133and debug information. In order to debug programs that use JIT compilation,
30134@value{GDBN} has an interface that allows the program to register in-memory
30135symbol files with @value{GDBN} at runtime.
30136
30137If you are using @value{GDBN} to debug a program that uses this interface, then
30138it should work transparently so long as you have not stripped the binary. If
30139you are developing a JIT compiler, then the interface is documented in the rest
30140of this chapter. At this time, the only known client of this interface is the
30141LLVM JIT.
30142
30143Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
30144JIT compiler communicates with @value{GDBN} by writing data into a global
30145variable and calling a fuction at a well-known symbol. When @value{GDBN}
30146attaches, it reads a linked list of symbol files from the global variable to
30147find existing code, and puts a breakpoint in the function so that it can find
30148out about additional code.
30149
30150@menu
30151* Declarations:: Relevant C struct declarations
30152* Registering Code:: Steps to register code
30153* Unregistering Code:: Steps to unregister code
30154@end menu
30155
30156@node Declarations
30157@section JIT Declarations
30158
30159These are the relevant struct declarations that a C program should include to
30160implement the interface:
30161
30162@smallexample
30163typedef enum
30164@{
30165 JIT_NOACTION = 0,
30166 JIT_REGISTER_FN,
30167 JIT_UNREGISTER_FN
30168@} jit_actions_t;
30169
30170struct jit_code_entry
30171@{
30172 struct jit_code_entry *next_entry;
30173 struct jit_code_entry *prev_entry;
30174 const char *symfile_addr;
30175 uint64_t symfile_size;
30176@};
30177
30178struct jit_descriptor
30179@{
30180 uint32_t version;
30181 /* This type should be jit_actions_t, but we use uint32_t
30182 to be explicit about the bitwidth. */
30183 uint32_t action_flag;
30184 struct jit_code_entry *relevant_entry;
30185 struct jit_code_entry *first_entry;
30186@};
30187
30188/* GDB puts a breakpoint in this function. */
30189void __attribute__((noinline)) __jit_debug_register_code() @{ @};
30190
30191/* Make sure to specify the version statically, because the
30192 debugger may check the version before we can set it. */
30193struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
30194@end smallexample
30195
30196If the JIT is multi-threaded, then it is important that the JIT synchronize any
30197modifications to this global data properly, which can easily be done by putting
30198a global mutex around modifications to these structures.
30199
30200@node Registering Code
30201@section Registering Code
30202
30203To register code with @value{GDBN}, the JIT should follow this protocol:
30204
30205@itemize @bullet
30206@item
30207Generate an object file in memory with symbols and other desired debug
30208information. The file must include the virtual addresses of the sections.
30209
30210@item
30211Create a code entry for the file, which gives the start and size of the symbol
30212file.
30213
30214@item
30215Add it to the linked list in the JIT descriptor.
30216
30217@item
30218Point the relevant_entry field of the descriptor at the entry.
30219
30220@item
30221Set @code{action_flag} to @code{JIT_REGISTER} and call
30222@code{__jit_debug_register_code}.
30223@end itemize
30224
30225When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
30226@code{relevant_entry} pointer so it doesn't have to walk the list looking for
30227new code. However, the linked list must still be maintained in order to allow
30228@value{GDBN} to attach to a running process and still find the symbol files.
30229
30230@node Unregistering Code
30231@section Unregistering Code
30232
30233If code is freed, then the JIT should use the following protocol:
30234
30235@itemize @bullet
30236@item
30237Remove the code entry corresponding to the code from the linked list.
30238
30239@item
30240Point the @code{relevant_entry} field of the descriptor at the code entry.
30241
30242@item
30243Set @code{action_flag} to @code{JIT_UNREGISTER} and call
30244@code{__jit_debug_register_code}.
30245@end itemize
30246
30247If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
30248and the JIT will leak the memory used for the associated symbol files.
30249
8e04817f
AC
30250@node GDB Bugs
30251@chapter Reporting Bugs in @value{GDBN}
30252@cindex bugs in @value{GDBN}
30253@cindex reporting bugs in @value{GDBN}
c906108c 30254
8e04817f 30255Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 30256
8e04817f
AC
30257Reporting a bug may help you by bringing a solution to your problem, or it
30258may not. But in any case the principal function of a bug report is to help
30259the entire community by making the next version of @value{GDBN} work better. Bug
30260reports are your contribution to the maintenance of @value{GDBN}.
c906108c 30261
8e04817f
AC
30262In order for a bug report to serve its purpose, you must include the
30263information that enables us to fix the bug.
c4555f82
SC
30264
30265@menu
8e04817f
AC
30266* Bug Criteria:: Have you found a bug?
30267* Bug Reporting:: How to report bugs
c4555f82
SC
30268@end menu
30269
8e04817f 30270@node Bug Criteria
79a6e687 30271@section Have You Found a Bug?
8e04817f 30272@cindex bug criteria
c4555f82 30273
8e04817f 30274If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
30275
30276@itemize @bullet
8e04817f
AC
30277@cindex fatal signal
30278@cindex debugger crash
30279@cindex crash of debugger
c4555f82 30280@item
8e04817f
AC
30281If the debugger gets a fatal signal, for any input whatever, that is a
30282@value{GDBN} bug. Reliable debuggers never crash.
30283
30284@cindex error on valid input
30285@item
30286If @value{GDBN} produces an error message for valid input, that is a
30287bug. (Note that if you're cross debugging, the problem may also be
30288somewhere in the connection to the target.)
c4555f82 30289
8e04817f 30290@cindex invalid input
c4555f82 30291@item
8e04817f
AC
30292If @value{GDBN} does not produce an error message for invalid input,
30293that is a bug. However, you should note that your idea of
30294``invalid input'' might be our idea of ``an extension'' or ``support
30295for traditional practice''.
30296
30297@item
30298If you are an experienced user of debugging tools, your suggestions
30299for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
30300@end itemize
30301
8e04817f 30302@node Bug Reporting
79a6e687 30303@section How to Report Bugs
8e04817f
AC
30304@cindex bug reports
30305@cindex @value{GDBN} bugs, reporting
30306
30307A number of companies and individuals offer support for @sc{gnu} products.
30308If you obtained @value{GDBN} from a support organization, we recommend you
30309contact that organization first.
30310
30311You can find contact information for many support companies and
30312individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
30313distribution.
30314@c should add a web page ref...
30315
c16158bc
JM
30316@ifset BUGURL
30317@ifset BUGURL_DEFAULT
129188f6 30318In any event, we also recommend that you submit bug reports for
d3e8051b 30319@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
30320@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
30321page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
30322be used.
8e04817f
AC
30323
30324@strong{Do not send bug reports to @samp{info-gdb}, or to
30325@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
30326not want to receive bug reports. Those that do have arranged to receive
30327@samp{bug-gdb}.
30328
30329The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
30330serves as a repeater. The mailing list and the newsgroup carry exactly
30331the same messages. Often people think of posting bug reports to the
30332newsgroup instead of mailing them. This appears to work, but it has one
30333problem which can be crucial: a newsgroup posting often lacks a mail
30334path back to the sender. Thus, if we need to ask for more information,
30335we may be unable to reach you. For this reason, it is better to send
30336bug reports to the mailing list.
c16158bc
JM
30337@end ifset
30338@ifclear BUGURL_DEFAULT
30339In any event, we also recommend that you submit bug reports for
30340@value{GDBN} to @value{BUGURL}.
30341@end ifclear
30342@end ifset
c4555f82 30343
8e04817f
AC
30344The fundamental principle of reporting bugs usefully is this:
30345@strong{report all the facts}. If you are not sure whether to state a
30346fact or leave it out, state it!
c4555f82 30347
8e04817f
AC
30348Often people omit facts because they think they know what causes the
30349problem and assume that some details do not matter. Thus, you might
30350assume that the name of the variable you use in an example does not matter.
30351Well, probably it does not, but one cannot be sure. Perhaps the bug is a
30352stray memory reference which happens to fetch from the location where that
30353name is stored in memory; perhaps, if the name were different, the contents
30354of that location would fool the debugger into doing the right thing despite
30355the bug. Play it safe and give a specific, complete example. That is the
30356easiest thing for you to do, and the most helpful.
c4555f82 30357
8e04817f
AC
30358Keep in mind that the purpose of a bug report is to enable us to fix the
30359bug. It may be that the bug has been reported previously, but neither
30360you nor we can know that unless your bug report is complete and
30361self-contained.
c4555f82 30362
8e04817f
AC
30363Sometimes people give a few sketchy facts and ask, ``Does this ring a
30364bell?'' Those bug reports are useless, and we urge everyone to
30365@emph{refuse to respond to them} except to chide the sender to report
30366bugs properly.
30367
30368To enable us to fix the bug, you should include all these things:
c4555f82
SC
30369
30370@itemize @bullet
30371@item
8e04817f
AC
30372The version of @value{GDBN}. @value{GDBN} announces it if you start
30373with no arguments; you can also print it at any time using @code{show
30374version}.
c4555f82 30375
8e04817f
AC
30376Without this, we will not know whether there is any point in looking for
30377the bug in the current version of @value{GDBN}.
c4555f82
SC
30378
30379@item
8e04817f
AC
30380The type of machine you are using, and the operating system name and
30381version number.
c4555f82
SC
30382
30383@item
c1468174 30384What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 30385``@value{GCC}--2.8.1''.
c4555f82
SC
30386
30387@item
8e04817f 30388What compiler (and its version) was used to compile the program you are
c1468174 30389debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
30390C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
30391to get this information; for other compilers, see the documentation for
30392those compilers.
c4555f82 30393
8e04817f
AC
30394@item
30395The command arguments you gave the compiler to compile your example and
30396observe the bug. For example, did you use @samp{-O}? To guarantee
30397you will not omit something important, list them all. A copy of the
30398Makefile (or the output from make) is sufficient.
c4555f82 30399
8e04817f
AC
30400If we were to try to guess the arguments, we would probably guess wrong
30401and then we might not encounter the bug.
c4555f82 30402
8e04817f
AC
30403@item
30404A complete input script, and all necessary source files, that will
30405reproduce the bug.
c4555f82 30406
8e04817f
AC
30407@item
30408A description of what behavior you observe that you believe is
30409incorrect. For example, ``It gets a fatal signal.''
c4555f82 30410
8e04817f
AC
30411Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
30412will certainly notice it. But if the bug is incorrect output, we might
30413not notice unless it is glaringly wrong. You might as well not give us
30414a chance to make a mistake.
c4555f82 30415
8e04817f
AC
30416Even if the problem you experience is a fatal signal, you should still
30417say so explicitly. Suppose something strange is going on, such as, your
30418copy of @value{GDBN} is out of synch, or you have encountered a bug in
30419the C library on your system. (This has happened!) Your copy might
30420crash and ours would not. If you told us to expect a crash, then when
30421ours fails to crash, we would know that the bug was not happening for
30422us. If you had not told us to expect a crash, then we would not be able
30423to draw any conclusion from our observations.
c4555f82 30424
e0c07bf0
MC
30425@pindex script
30426@cindex recording a session script
30427To collect all this information, you can use a session recording program
30428such as @command{script}, which is available on many Unix systems.
30429Just run your @value{GDBN} session inside @command{script} and then
30430include the @file{typescript} file with your bug report.
30431
30432Another way to record a @value{GDBN} session is to run @value{GDBN}
30433inside Emacs and then save the entire buffer to a file.
30434
8e04817f
AC
30435@item
30436If you wish to suggest changes to the @value{GDBN} source, send us context
30437diffs. If you even discuss something in the @value{GDBN} source, refer to
30438it by context, not by line number.
c4555f82 30439
8e04817f
AC
30440The line numbers in our development sources will not match those in your
30441sources. Your line numbers would convey no useful information to us.
c4555f82 30442
8e04817f 30443@end itemize
c4555f82 30444
8e04817f 30445Here are some things that are not necessary:
c4555f82 30446
8e04817f
AC
30447@itemize @bullet
30448@item
30449A description of the envelope of the bug.
c4555f82 30450
8e04817f
AC
30451Often people who encounter a bug spend a lot of time investigating
30452which changes to the input file will make the bug go away and which
30453changes will not affect it.
c4555f82 30454
8e04817f
AC
30455This is often time consuming and not very useful, because the way we
30456will find the bug is by running a single example under the debugger
30457with breakpoints, not by pure deduction from a series of examples.
30458We recommend that you save your time for something else.
c4555f82 30459
8e04817f
AC
30460Of course, if you can find a simpler example to report @emph{instead}
30461of the original one, that is a convenience for us. Errors in the
30462output will be easier to spot, running under the debugger will take
30463less time, and so on.
c4555f82 30464
8e04817f
AC
30465However, simplification is not vital; if you do not want to do this,
30466report the bug anyway and send us the entire test case you used.
c4555f82 30467
8e04817f
AC
30468@item
30469A patch for the bug.
c4555f82 30470
8e04817f
AC
30471A patch for the bug does help us if it is a good one. But do not omit
30472the necessary information, such as the test case, on the assumption that
30473a patch is all we need. We might see problems with your patch and decide
30474to fix the problem another way, or we might not understand it at all.
c4555f82 30475
8e04817f
AC
30476Sometimes with a program as complicated as @value{GDBN} it is very hard to
30477construct an example that will make the program follow a certain path
30478through the code. If you do not send us the example, we will not be able
30479to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 30480
8e04817f
AC
30481And if we cannot understand what bug you are trying to fix, or why your
30482patch should be an improvement, we will not install it. A test case will
30483help us to understand.
c4555f82 30484
8e04817f
AC
30485@item
30486A guess about what the bug is or what it depends on.
c4555f82 30487
8e04817f
AC
30488Such guesses are usually wrong. Even we cannot guess right about such
30489things without first using the debugger to find the facts.
30490@end itemize
c4555f82 30491
8e04817f
AC
30492@c The readline documentation is distributed with the readline code
30493@c and consists of the two following files:
30494@c rluser.texinfo
30495@c inc-hist.texinfo
30496@c Use -I with makeinfo to point to the appropriate directory,
30497@c environment var TEXINPUTS with TeX.
39037522 30498@ifclear SYSTEM_READLINE
5bdf8622 30499@include rluser.texi
8e04817f 30500@include inc-hist.texinfo
39037522 30501@end ifclear
c4555f82 30502
c4555f82 30503
8e04817f
AC
30504@node Formatting Documentation
30505@appendix Formatting Documentation
c4555f82 30506
8e04817f
AC
30507@cindex @value{GDBN} reference card
30508@cindex reference card
30509The @value{GDBN} 4 release includes an already-formatted reference card, ready
30510for printing with PostScript or Ghostscript, in the @file{gdb}
30511subdirectory of the main source directory@footnote{In
30512@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
30513release.}. If you can use PostScript or Ghostscript with your printer,
30514you can print the reference card immediately with @file{refcard.ps}.
c4555f82 30515
8e04817f
AC
30516The release also includes the source for the reference card. You
30517can format it, using @TeX{}, by typing:
c4555f82 30518
474c8240 30519@smallexample
8e04817f 30520make refcard.dvi
474c8240 30521@end smallexample
c4555f82 30522
8e04817f
AC
30523The @value{GDBN} reference card is designed to print in @dfn{landscape}
30524mode on US ``letter'' size paper;
30525that is, on a sheet 11 inches wide by 8.5 inches
30526high. You will need to specify this form of printing as an option to
30527your @sc{dvi} output program.
c4555f82 30528
8e04817f 30529@cindex documentation
c4555f82 30530
8e04817f
AC
30531All the documentation for @value{GDBN} comes as part of the machine-readable
30532distribution. The documentation is written in Texinfo format, which is
30533a documentation system that uses a single source file to produce both
30534on-line information and a printed manual. You can use one of the Info
30535formatting commands to create the on-line version of the documentation
30536and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 30537
8e04817f
AC
30538@value{GDBN} includes an already formatted copy of the on-line Info
30539version of this manual in the @file{gdb} subdirectory. The main Info
30540file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
30541subordinate files matching @samp{gdb.info*} in the same directory. If
30542necessary, you can print out these files, or read them with any editor;
30543but they are easier to read using the @code{info} subsystem in @sc{gnu}
30544Emacs or the standalone @code{info} program, available as part of the
30545@sc{gnu} Texinfo distribution.
c4555f82 30546
8e04817f
AC
30547If you want to format these Info files yourself, you need one of the
30548Info formatting programs, such as @code{texinfo-format-buffer} or
30549@code{makeinfo}.
c4555f82 30550
8e04817f
AC
30551If you have @code{makeinfo} installed, and are in the top level
30552@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
30553version @value{GDBVN}), you can make the Info file by typing:
c4555f82 30554
474c8240 30555@smallexample
8e04817f
AC
30556cd gdb
30557make gdb.info
474c8240 30558@end smallexample
c4555f82 30559
8e04817f
AC
30560If you want to typeset and print copies of this manual, you need @TeX{},
30561a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
30562Texinfo definitions file.
c4555f82 30563
8e04817f
AC
30564@TeX{} is a typesetting program; it does not print files directly, but
30565produces output files called @sc{dvi} files. To print a typeset
30566document, you need a program to print @sc{dvi} files. If your system
30567has @TeX{} installed, chances are it has such a program. The precise
30568command to use depends on your system; @kbd{lpr -d} is common; another
30569(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
30570require a file name without any extension or a @samp{.dvi} extension.
c4555f82 30571
8e04817f
AC
30572@TeX{} also requires a macro definitions file called
30573@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
30574written in Texinfo format. On its own, @TeX{} cannot either read or
30575typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
30576and is located in the @file{gdb-@var{version-number}/texinfo}
30577directory.
c4555f82 30578
8e04817f 30579If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 30580typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
30581subdirectory of the main source directory (for example, to
30582@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 30583
474c8240 30584@smallexample
8e04817f 30585make gdb.dvi
474c8240 30586@end smallexample
c4555f82 30587
8e04817f 30588Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 30589
8e04817f
AC
30590@node Installing GDB
30591@appendix Installing @value{GDBN}
8e04817f 30592@cindex installation
c4555f82 30593
7fa2210b
DJ
30594@menu
30595* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 30596* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
30597* Separate Objdir:: Compiling @value{GDBN} in another directory
30598* Config Names:: Specifying names for hosts and targets
30599* Configure Options:: Summary of options for configure
098b41a6 30600* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
30601@end menu
30602
30603@node Requirements
79a6e687 30604@section Requirements for Building @value{GDBN}
7fa2210b
DJ
30605@cindex building @value{GDBN}, requirements for
30606
30607Building @value{GDBN} requires various tools and packages to be available.
30608Other packages will be used only if they are found.
30609
79a6e687 30610@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
30611@table @asis
30612@item ISO C90 compiler
30613@value{GDBN} is written in ISO C90. It should be buildable with any
30614working C90 compiler, e.g.@: GCC.
30615
30616@end table
30617
79a6e687 30618@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
30619@table @asis
30620@item Expat
123dc839 30621@anchor{Expat}
7fa2210b
DJ
30622@value{GDBN} can use the Expat XML parsing library. This library may be
30623included with your operating system distribution; if it is not, you
30624can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 30625The @file{configure} script will search for this library in several
7fa2210b
DJ
30626standard locations; if it is installed in an unusual path, you can
30627use the @option{--with-libexpat-prefix} option to specify its location.
30628
9cceb671
DJ
30629Expat is used for:
30630
30631@itemize @bullet
30632@item
30633Remote protocol memory maps (@pxref{Memory Map Format})
30634@item
30635Target descriptions (@pxref{Target Descriptions})
30636@item
30637Remote shared library lists (@pxref{Library List Format})
30638@item
30639MS-Windows shared libraries (@pxref{Shared Libraries})
30640@end itemize
7fa2210b 30641
31fffb02
CS
30642@item zlib
30643@cindex compressed debug sections
30644@value{GDBN} will use the @samp{zlib} library, if available, to read
30645compressed debug sections. Some linkers, such as GNU gold, are capable
30646of producing binaries with compressed debug sections. If @value{GDBN}
30647is compiled with @samp{zlib}, it will be able to read the debug
30648information in such binaries.
30649
30650The @samp{zlib} library is likely included with your operating system
30651distribution; if it is not, you can get the latest version from
30652@url{http://zlib.net}.
30653
6c7a06a3
TT
30654@item iconv
30655@value{GDBN}'s features related to character sets (@pxref{Character
30656Sets}) require a functioning @code{iconv} implementation. If you are
30657on a GNU system, then this is provided by the GNU C Library. Some
30658other systems also provide a working @code{iconv}.
30659
30660On systems with @code{iconv}, you can install GNU Libiconv. If you
30661have previously installed Libiconv, you can use the
30662@option{--with-libiconv-prefix} option to configure.
30663
30664@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
30665arrange to build Libiconv if a directory named @file{libiconv} appears
30666in the top-most source directory. If Libiconv is built this way, and
30667if the operating system does not provide a suitable @code{iconv}
30668implementation, then the just-built library will automatically be used
30669by @value{GDBN}. One easy way to set this up is to download GNU
30670Libiconv, unpack it, and then rename the directory holding the
30671Libiconv source code to @samp{libiconv}.
7fa2210b
DJ
30672@end table
30673
30674@node Running Configure
db2e3e2e 30675@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 30676@cindex configuring @value{GDBN}
db2e3e2e 30677@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
30678of preparing @value{GDBN} for installation; you can then use @code{make} to
30679build the @code{gdb} program.
30680@iftex
30681@c irrelevant in info file; it's as current as the code it lives with.
30682@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
30683look at the @file{README} file in the sources; we may have improved the
30684installation procedures since publishing this manual.}
30685@end iftex
c4555f82 30686
8e04817f
AC
30687The @value{GDBN} distribution includes all the source code you need for
30688@value{GDBN} in a single directory, whose name is usually composed by
30689appending the version number to @samp{gdb}.
c4555f82 30690
8e04817f
AC
30691For example, the @value{GDBN} version @value{GDBVN} distribution is in the
30692@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 30693
8e04817f
AC
30694@table @code
30695@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
30696script for configuring @value{GDBN} and all its supporting libraries
c4555f82 30697
8e04817f
AC
30698@item gdb-@value{GDBVN}/gdb
30699the source specific to @value{GDBN} itself
c4555f82 30700
8e04817f
AC
30701@item gdb-@value{GDBVN}/bfd
30702source for the Binary File Descriptor library
c906108c 30703
8e04817f
AC
30704@item gdb-@value{GDBVN}/include
30705@sc{gnu} include files
c906108c 30706
8e04817f
AC
30707@item gdb-@value{GDBVN}/libiberty
30708source for the @samp{-liberty} free software library
c906108c 30709
8e04817f
AC
30710@item gdb-@value{GDBVN}/opcodes
30711source for the library of opcode tables and disassemblers
c906108c 30712
8e04817f
AC
30713@item gdb-@value{GDBVN}/readline
30714source for the @sc{gnu} command-line interface
c906108c 30715
8e04817f
AC
30716@item gdb-@value{GDBVN}/glob
30717source for the @sc{gnu} filename pattern-matching subroutine
c906108c 30718
8e04817f
AC
30719@item gdb-@value{GDBVN}/mmalloc
30720source for the @sc{gnu} memory-mapped malloc package
30721@end table
c906108c 30722
db2e3e2e 30723The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
30724from the @file{gdb-@var{version-number}} source directory, which in
30725this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 30726
8e04817f 30727First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 30728if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
30729identifier for the platform on which @value{GDBN} will run as an
30730argument.
c906108c 30731
8e04817f 30732For example:
c906108c 30733
474c8240 30734@smallexample
8e04817f
AC
30735cd gdb-@value{GDBVN}
30736./configure @var{host}
30737make
474c8240 30738@end smallexample
c906108c 30739
8e04817f
AC
30740@noindent
30741where @var{host} is an identifier such as @samp{sun4} or
30742@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 30743(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 30744correct value by examining your system.)
c906108c 30745
8e04817f
AC
30746Running @samp{configure @var{host}} and then running @code{make} builds the
30747@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
30748libraries, then @code{gdb} itself. The configured source files, and the
30749binaries, are left in the corresponding source directories.
c906108c 30750
8e04817f 30751@need 750
db2e3e2e 30752@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
30753system does not recognize this automatically when you run a different
30754shell, you may need to run @code{sh} on it explicitly:
c906108c 30755
474c8240 30756@smallexample
8e04817f 30757sh configure @var{host}
474c8240 30758@end smallexample
c906108c 30759
db2e3e2e 30760If you run @file{configure} from a directory that contains source
8e04817f 30761directories for multiple libraries or programs, such as the
db2e3e2e
BW
30762@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
30763@file{configure}
8e04817f
AC
30764creates configuration files for every directory level underneath (unless
30765you tell it not to, with the @samp{--norecursion} option).
30766
db2e3e2e 30767You should run the @file{configure} script from the top directory in the
94e91d6d 30768source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 30769@file{configure} from one of the subdirectories, you will configure only
94e91d6d 30770that subdirectory. That is usually not what you want. In particular,
db2e3e2e 30771if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
30772of the @file{gdb-@var{version-number}} directory, you will omit the
30773configuration of @file{bfd}, @file{readline}, and other sibling
30774directories of the @file{gdb} subdirectory. This leads to build errors
30775about missing include files such as @file{bfd/bfd.h}.
c906108c 30776
8e04817f
AC
30777You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
30778However, you should make sure that the shell on your path (named by
30779the @samp{SHELL} environment variable) is publicly readable. Remember
30780that @value{GDBN} uses the shell to start your program---some systems refuse to
30781let @value{GDBN} debug child processes whose programs are not readable.
c906108c 30782
8e04817f 30783@node Separate Objdir
79a6e687 30784@section Compiling @value{GDBN} in Another Directory
c906108c 30785
8e04817f
AC
30786If you want to run @value{GDBN} versions for several host or target machines,
30787you need a different @code{gdb} compiled for each combination of
db2e3e2e 30788host and target. @file{configure} is designed to make this easy by
8e04817f
AC
30789allowing you to generate each configuration in a separate subdirectory,
30790rather than in the source directory. If your @code{make} program
30791handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
30792@code{make} in each of these directories builds the @code{gdb}
30793program specified there.
c906108c 30794
db2e3e2e 30795To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 30796with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
30797(You also need to specify a path to find @file{configure}
30798itself from your working directory. If the path to @file{configure}
8e04817f
AC
30799would be the same as the argument to @samp{--srcdir}, you can leave out
30800the @samp{--srcdir} option; it is assumed.)
c906108c 30801
8e04817f
AC
30802For example, with version @value{GDBVN}, you can build @value{GDBN} in a
30803separate directory for a Sun 4 like this:
c906108c 30804
474c8240 30805@smallexample
8e04817f
AC
30806@group
30807cd gdb-@value{GDBVN}
30808mkdir ../gdb-sun4
30809cd ../gdb-sun4
30810../gdb-@value{GDBVN}/configure sun4
30811make
30812@end group
474c8240 30813@end smallexample
c906108c 30814
db2e3e2e 30815When @file{configure} builds a configuration using a remote source
8e04817f
AC
30816directory, it creates a tree for the binaries with the same structure
30817(and using the same names) as the tree under the source directory. In
30818the example, you'd find the Sun 4 library @file{libiberty.a} in the
30819directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
30820@file{gdb-sun4/gdb}.
c906108c 30821
94e91d6d
MC
30822Make sure that your path to the @file{configure} script has just one
30823instance of @file{gdb} in it. If your path to @file{configure} looks
30824like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
30825one subdirectory of @value{GDBN}, not the whole package. This leads to
30826build errors about missing include files such as @file{bfd/bfd.h}.
30827
8e04817f
AC
30828One popular reason to build several @value{GDBN} configurations in separate
30829directories is to configure @value{GDBN} for cross-compiling (where
30830@value{GDBN} runs on one machine---the @dfn{host}---while debugging
30831programs that run on another machine---the @dfn{target}).
30832You specify a cross-debugging target by
db2e3e2e 30833giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 30834
8e04817f
AC
30835When you run @code{make} to build a program or library, you must run
30836it in a configured directory---whatever directory you were in when you
db2e3e2e 30837called @file{configure} (or one of its subdirectories).
c906108c 30838
db2e3e2e 30839The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
30840directory also runs recursively. If you type @code{make} in a source
30841directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
30842directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
30843will build all the required libraries, and then build GDB.
c906108c 30844
8e04817f
AC
30845When you have multiple hosts or targets configured in separate
30846directories, you can run @code{make} on them in parallel (for example,
30847if they are NFS-mounted on each of the hosts); they will not interfere
30848with each other.
c906108c 30849
8e04817f 30850@node Config Names
79a6e687 30851@section Specifying Names for Hosts and Targets
c906108c 30852
db2e3e2e 30853The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
30854script are based on a three-part naming scheme, but some short predefined
30855aliases are also supported. The full naming scheme encodes three pieces
30856of information in the following pattern:
c906108c 30857
474c8240 30858@smallexample
8e04817f 30859@var{architecture}-@var{vendor}-@var{os}
474c8240 30860@end smallexample
c906108c 30861
8e04817f
AC
30862For example, you can use the alias @code{sun4} as a @var{host} argument,
30863or as the value for @var{target} in a @code{--target=@var{target}}
30864option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 30865
db2e3e2e 30866The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 30867any query facility to list all supported host and target names or
db2e3e2e 30868aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
30869@code{config.sub} to map abbreviations to full names; you can read the
30870script, if you wish, or you can use it to test your guesses on
30871abbreviations---for example:
c906108c 30872
8e04817f
AC
30873@smallexample
30874% sh config.sub i386-linux
30875i386-pc-linux-gnu
30876% sh config.sub alpha-linux
30877alpha-unknown-linux-gnu
30878% sh config.sub hp9k700
30879hppa1.1-hp-hpux
30880% sh config.sub sun4
30881sparc-sun-sunos4.1.1
30882% sh config.sub sun3
30883m68k-sun-sunos4.1.1
30884% sh config.sub i986v
30885Invalid configuration `i986v': machine `i986v' not recognized
30886@end smallexample
c906108c 30887
8e04817f
AC
30888@noindent
30889@code{config.sub} is also distributed in the @value{GDBN} source
30890directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 30891
8e04817f 30892@node Configure Options
db2e3e2e 30893@section @file{configure} Options
c906108c 30894
db2e3e2e
BW
30895Here is a summary of the @file{configure} options and arguments that
30896are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 30897several other options not listed here. @inforef{What Configure
db2e3e2e 30898Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 30899
474c8240 30900@smallexample
8e04817f
AC
30901configure @r{[}--help@r{]}
30902 @r{[}--prefix=@var{dir}@r{]}
30903 @r{[}--exec-prefix=@var{dir}@r{]}
30904 @r{[}--srcdir=@var{dirname}@r{]}
30905 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
30906 @r{[}--target=@var{target}@r{]}
30907 @var{host}
474c8240 30908@end smallexample
c906108c 30909
8e04817f
AC
30910@noindent
30911You may introduce options with a single @samp{-} rather than
30912@samp{--} if you prefer; but you may abbreviate option names if you use
30913@samp{--}.
c906108c 30914
8e04817f
AC
30915@table @code
30916@item --help
db2e3e2e 30917Display a quick summary of how to invoke @file{configure}.
c906108c 30918
8e04817f
AC
30919@item --prefix=@var{dir}
30920Configure the source to install programs and files under directory
30921@file{@var{dir}}.
c906108c 30922
8e04817f
AC
30923@item --exec-prefix=@var{dir}
30924Configure the source to install programs under directory
30925@file{@var{dir}}.
c906108c 30926
8e04817f
AC
30927@c avoid splitting the warning from the explanation:
30928@need 2000
30929@item --srcdir=@var{dirname}
30930@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
30931@code{make} that implements the @code{VPATH} feature.}@*
30932Use this option to make configurations in directories separate from the
30933@value{GDBN} source directories. Among other things, you can use this to
30934build (or maintain) several configurations simultaneously, in separate
db2e3e2e 30935directories. @file{configure} writes configuration-specific files in
8e04817f 30936the current directory, but arranges for them to use the source in the
db2e3e2e 30937directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
30938the working directory in parallel to the source directories below
30939@var{dirname}.
c906108c 30940
8e04817f 30941@item --norecursion
db2e3e2e 30942Configure only the directory level where @file{configure} is executed; do not
8e04817f 30943propagate configuration to subdirectories.
c906108c 30944
8e04817f
AC
30945@item --target=@var{target}
30946Configure @value{GDBN} for cross-debugging programs running on the specified
30947@var{target}. Without this option, @value{GDBN} is configured to debug
30948programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 30949
8e04817f 30950There is no convenient way to generate a list of all available targets.
c906108c 30951
8e04817f
AC
30952@item @var{host} @dots{}
30953Configure @value{GDBN} to run on the specified @var{host}.
c906108c 30954
8e04817f
AC
30955There is no convenient way to generate a list of all available hosts.
30956@end table
c906108c 30957
8e04817f
AC
30958There are many other options available as well, but they are generally
30959needed for special purposes only.
c906108c 30960
098b41a6
JG
30961@node System-wide configuration
30962@section System-wide configuration and settings
30963@cindex system-wide init file
30964
30965@value{GDBN} can be configured to have a system-wide init file;
30966this file will be read and executed at startup (@pxref{Startup, , What
30967@value{GDBN} does during startup}).
30968
30969Here is the corresponding configure option:
30970
30971@table @code
30972@item --with-system-gdbinit=@var{file}
30973Specify that the default location of the system-wide init file is
30974@var{file}.
30975@end table
30976
30977If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
30978it may be subject to relocation. Two possible cases:
30979
30980@itemize @bullet
30981@item
30982If the default location of this init file contains @file{$prefix},
30983it will be subject to relocation. Suppose that the configure options
30984are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
30985if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
30986init file is looked for as @file{$install/etc/gdbinit} instead of
30987@file{$prefix/etc/gdbinit}.
30988
30989@item
30990By contrast, if the default location does not contain the prefix,
30991it will not be relocated. E.g.@: if @value{GDBN} has been configured with
30992@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
30993then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
30994wherever @value{GDBN} is installed.
30995@end itemize
30996
8e04817f
AC
30997@node Maintenance Commands
30998@appendix Maintenance Commands
30999@cindex maintenance commands
31000@cindex internal commands
c906108c 31001
8e04817f 31002In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
31003includes a number of commands intended for @value{GDBN} developers,
31004that are not documented elsewhere in this manual. These commands are
da316a69
EZ
31005provided here for reference. (For commands that turn on debugging
31006messages, see @ref{Debugging Output}.)
c906108c 31007
8e04817f 31008@table @code
09d4efe1 31009@kindex maint agent
782b2b07 31010@kindex maint agent-eval
09d4efe1 31011@item maint agent @var{expression}
782b2b07 31012@itemx maint agent-eval @var{expression}
09d4efe1
EZ
31013Translate the given @var{expression} into remote agent bytecodes.
31014This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
31015(@pxref{Agent Expressions}). The @samp{agent} version produces an
31016expression useful for data collection, such as by tracepoints, while
31017@samp{maint agent-eval} produces an expression that evaluates directly
31018to a result. For instance, a collection expression for @code{globa +
31019globb} will include bytecodes to record four bytes of memory at each
31020of the addresses of @code{globa} and @code{globb}, while discarding
31021the result of the addition, while an evaluation expression will do the
31022addition and return the sum.
09d4efe1 31023
8e04817f
AC
31024@kindex maint info breakpoints
31025@item @anchor{maint info breakpoints}maint info breakpoints
31026Using the same format as @samp{info breakpoints}, display both the
31027breakpoints you've set explicitly, and those @value{GDBN} is using for
31028internal purposes. Internal breakpoints are shown with negative
31029breakpoint numbers. The type column identifies what kind of breakpoint
31030is shown:
c906108c 31031
8e04817f
AC
31032@table @code
31033@item breakpoint
31034Normal, explicitly set breakpoint.
c906108c 31035
8e04817f
AC
31036@item watchpoint
31037Normal, explicitly set watchpoint.
c906108c 31038
8e04817f
AC
31039@item longjmp
31040Internal breakpoint, used to handle correctly stepping through
31041@code{longjmp} calls.
c906108c 31042
8e04817f
AC
31043@item longjmp resume
31044Internal breakpoint at the target of a @code{longjmp}.
c906108c 31045
8e04817f
AC
31046@item until
31047Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 31048
8e04817f
AC
31049@item finish
31050Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 31051
8e04817f
AC
31052@item shlib events
31053Shared library events.
c906108c 31054
8e04817f 31055@end table
c906108c 31056
fff08868
HZ
31057@kindex set displaced-stepping
31058@kindex show displaced-stepping
237fc4c9
PA
31059@cindex displaced stepping support
31060@cindex out-of-line single-stepping
fff08868
HZ
31061@item set displaced-stepping
31062@itemx show displaced-stepping
237fc4c9 31063Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
31064if the target supports it. Displaced stepping is a way to single-step
31065over breakpoints without removing them from the inferior, by executing
31066an out-of-line copy of the instruction that was originally at the
31067breakpoint location. It is also known as out-of-line single-stepping.
31068
31069@table @code
31070@item set displaced-stepping on
31071If the target architecture supports it, @value{GDBN} will use
31072displaced stepping to step over breakpoints.
31073
31074@item set displaced-stepping off
31075@value{GDBN} will not use displaced stepping to step over breakpoints,
31076even if such is supported by the target architecture.
31077
31078@cindex non-stop mode, and @samp{set displaced-stepping}
31079@item set displaced-stepping auto
31080This is the default mode. @value{GDBN} will use displaced stepping
31081only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
31082architecture supports displaced stepping.
31083@end table
237fc4c9 31084
09d4efe1
EZ
31085@kindex maint check-symtabs
31086@item maint check-symtabs
31087Check the consistency of psymtabs and symtabs.
31088
31089@kindex maint cplus first_component
31090@item maint cplus first_component @var{name}
31091Print the first C@t{++} class/namespace component of @var{name}.
31092
31093@kindex maint cplus namespace
31094@item maint cplus namespace
31095Print the list of possible C@t{++} namespaces.
31096
31097@kindex maint demangle
31098@item maint demangle @var{name}
d3e8051b 31099Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
31100
31101@kindex maint deprecate
31102@kindex maint undeprecate
31103@cindex deprecated commands
31104@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
31105@itemx maint undeprecate @var{command}
31106Deprecate or undeprecate the named @var{command}. Deprecated commands
31107cause @value{GDBN} to issue a warning when you use them. The optional
31108argument @var{replacement} says which newer command should be used in
31109favor of the deprecated one; if it is given, @value{GDBN} will mention
31110the replacement as part of the warning.
31111
31112@kindex maint dump-me
31113@item maint dump-me
721c2651 31114@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 31115Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
31116This is supported only on systems which support aborting a program
31117with the @code{SIGQUIT} signal.
09d4efe1 31118
8d30a00d
AC
31119@kindex maint internal-error
31120@kindex maint internal-warning
09d4efe1
EZ
31121@item maint internal-error @r{[}@var{message-text}@r{]}
31122@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
31123Cause @value{GDBN} to call the internal function @code{internal_error}
31124or @code{internal_warning} and hence behave as though an internal error
31125or internal warning has been detected. In addition to reporting the
31126internal problem, these functions give the user the opportunity to
31127either quit @value{GDBN} or create a core file of the current
31128@value{GDBN} session.
31129
09d4efe1
EZ
31130These commands take an optional parameter @var{message-text} that is
31131used as the text of the error or warning message.
31132
d3e8051b 31133Here's an example of using @code{internal-error}:
09d4efe1 31134
8d30a00d 31135@smallexample
f7dc1244 31136(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
31137@dots{}/maint.c:121: internal-error: testing, 1, 2
31138A problem internal to GDB has been detected. Further
31139debugging may prove unreliable.
31140Quit this debugging session? (y or n) @kbd{n}
31141Create a core file? (y or n) @kbd{n}
f7dc1244 31142(@value{GDBP})
8d30a00d
AC
31143@end smallexample
31144
3c16cced
PA
31145@cindex @value{GDBN} internal error
31146@cindex internal errors, control of @value{GDBN} behavior
31147
31148@kindex maint set internal-error
31149@kindex maint show internal-error
31150@kindex maint set internal-warning
31151@kindex maint show internal-warning
31152@item maint set internal-error @var{action} [ask|yes|no]
31153@itemx maint show internal-error @var{action}
31154@itemx maint set internal-warning @var{action} [ask|yes|no]
31155@itemx maint show internal-warning @var{action}
31156When @value{GDBN} reports an internal problem (error or warning) it
31157gives the user the opportunity to both quit @value{GDBN} and create a
31158core file of the current @value{GDBN} session. These commands let you
31159override the default behaviour for each particular @var{action},
31160described in the table below.
31161
31162@table @samp
31163@item quit
31164You can specify that @value{GDBN} should always (yes) or never (no)
31165quit. The default is to ask the user what to do.
31166
31167@item corefile
31168You can specify that @value{GDBN} should always (yes) or never (no)
31169create a core file. The default is to ask the user what to do.
31170@end table
31171
09d4efe1
EZ
31172@kindex maint packet
31173@item maint packet @var{text}
31174If @value{GDBN} is talking to an inferior via the serial protocol,
31175then this command sends the string @var{text} to the inferior, and
31176displays the response packet. @value{GDBN} supplies the initial
31177@samp{$} character, the terminating @samp{#} character, and the
31178checksum.
31179
31180@kindex maint print architecture
31181@item maint print architecture @r{[}@var{file}@r{]}
31182Print the entire architecture configuration. The optional argument
31183@var{file} names the file where the output goes.
8d30a00d 31184
81adfced
DJ
31185@kindex maint print c-tdesc
31186@item maint print c-tdesc
31187Print the current target description (@pxref{Target Descriptions}) as
31188a C source file. The created source file can be used in @value{GDBN}
31189when an XML parser is not available to parse the description.
31190
00905d52
AC
31191@kindex maint print dummy-frames
31192@item maint print dummy-frames
00905d52
AC
31193Prints the contents of @value{GDBN}'s internal dummy-frame stack.
31194
31195@smallexample
f7dc1244 31196(@value{GDBP}) @kbd{b add}
00905d52 31197@dots{}
f7dc1244 31198(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
31199Breakpoint 2, add (a=2, b=3) at @dots{}
3120058 return (a + b);
31201The program being debugged stopped while in a function called from GDB.
31202@dots{}
f7dc1244 31203(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
312040x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
31205 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
31206 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 31207(@value{GDBP})
00905d52
AC
31208@end smallexample
31209
31210Takes an optional file parameter.
31211
0680b120
AC
31212@kindex maint print registers
31213@kindex maint print raw-registers
31214@kindex maint print cooked-registers
617073a9 31215@kindex maint print register-groups
09d4efe1
EZ
31216@item maint print registers @r{[}@var{file}@r{]}
31217@itemx maint print raw-registers @r{[}@var{file}@r{]}
31218@itemx maint print cooked-registers @r{[}@var{file}@r{]}
31219@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
31220Print @value{GDBN}'s internal register data structures.
31221
617073a9
AC
31222The command @code{maint print raw-registers} includes the contents of
31223the raw register cache; the command @code{maint print cooked-registers}
5c5dcc1b
L
31224includes the (cooked) value of all registers, including registers which
31225aren't available on the target nor visible to user; and the
31226command @code{maint print register-groups} includes the groups that each
617073a9
AC
31227register is a member of. @xref{Registers,, Registers, gdbint,
31228@value{GDBN} Internals}.
0680b120 31229
09d4efe1
EZ
31230These commands take an optional parameter, a file name to which to
31231write the information.
0680b120 31232
617073a9 31233@kindex maint print reggroups
09d4efe1
EZ
31234@item maint print reggroups @r{[}@var{file}@r{]}
31235Print @value{GDBN}'s internal register group data structures. The
31236optional argument @var{file} tells to what file to write the
31237information.
617073a9 31238
09d4efe1 31239The register groups info looks like this:
617073a9
AC
31240
31241@smallexample
f7dc1244 31242(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
31243 Group Type
31244 general user
31245 float user
31246 all user
31247 vector user
31248 system user
31249 save internal
31250 restore internal
617073a9
AC
31251@end smallexample
31252
09d4efe1
EZ
31253@kindex flushregs
31254@item flushregs
31255This command forces @value{GDBN} to flush its internal register cache.
31256
31257@kindex maint print objfiles
31258@cindex info for known object files
31259@item maint print objfiles
31260Print a dump of all known object files. For each object file, this
31261command prints its name, address in memory, and all of its psymtabs
31262and symtabs.
31263
8a1ea21f
DE
31264@kindex maint print section-scripts
31265@cindex info for known .debug_gdb_scripts-loaded scripts
31266@item maint print section-scripts [@var{regexp}]
31267Print a dump of scripts specified in the @code{.debug_gdb_section} section.
31268If @var{regexp} is specified, only print scripts loaded by object files
31269matching @var{regexp}.
31270For each script, this command prints its name as specified in the objfile,
31271and the full path if known.
31272@xref{.debug_gdb_scripts section}.
31273
09d4efe1
EZ
31274@kindex maint print statistics
31275@cindex bcache statistics
31276@item maint print statistics
31277This command prints, for each object file in the program, various data
31278about that object file followed by the byte cache (@dfn{bcache})
31279statistics for the object file. The objfile data includes the number
d3e8051b 31280of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
31281defined by the objfile, the number of as yet unexpanded psym tables,
31282the number of line tables and string tables, and the amount of memory
31283used by the various tables. The bcache statistics include the counts,
31284sizes, and counts of duplicates of all and unique objects, max,
31285average, and median entry size, total memory used and its overhead and
31286savings, and various measures of the hash table size and chain
31287lengths.
31288
c7ba131e
JB
31289@kindex maint print target-stack
31290@cindex target stack description
31291@item maint print target-stack
31292A @dfn{target} is an interface between the debugger and a particular
31293kind of file or process. Targets can be stacked in @dfn{strata},
31294so that more than one target can potentially respond to a request.
31295In particular, memory accesses will walk down the stack of targets
31296until they find a target that is interested in handling that particular
31297address.
31298
31299This command prints a short description of each layer that was pushed on
31300the @dfn{target stack}, starting from the top layer down to the bottom one.
31301
09d4efe1
EZ
31302@kindex maint print type
31303@cindex type chain of a data type
31304@item maint print type @var{expr}
31305Print the type chain for a type specified by @var{expr}. The argument
31306can be either a type name or a symbol. If it is a symbol, the type of
31307that symbol is described. The type chain produced by this command is
31308a recursive definition of the data type as stored in @value{GDBN}'s
31309data structures, including its flags and contained types.
31310
9eae7c52
TT
31311@kindex maint set dwarf2 always-disassemble
31312@kindex maint show dwarf2 always-disassemble
31313@item maint set dwarf2 always-disassemble
31314@item maint show dwarf2 always-disassemble
31315Control the behavior of @code{info address} when using DWARF debugging
31316information.
31317
31318The default is @code{off}, which means that @value{GDBN} should try to
31319describe a variable's location in an easily readable format. When
31320@code{on}, @value{GDBN} will instead display the DWARF location
31321expression in an assembly-like format. Note that some locations are
31322too complex for @value{GDBN} to describe simply; in this case you will
31323always see the disassembly form.
31324
31325Here is an example of the resulting disassembly:
31326
31327@smallexample
31328(gdb) info addr argc
31329Symbol "argc" is a complex DWARF expression:
31330 1: DW_OP_fbreg 0
31331@end smallexample
31332
31333For more information on these expressions, see
31334@uref{http://www.dwarfstd.org/, the DWARF standard}.
31335
09d4efe1
EZ
31336@kindex maint set dwarf2 max-cache-age
31337@kindex maint show dwarf2 max-cache-age
31338@item maint set dwarf2 max-cache-age
31339@itemx maint show dwarf2 max-cache-age
31340Control the DWARF 2 compilation unit cache.
31341
31342@cindex DWARF 2 compilation units cache
31343In object files with inter-compilation-unit references, such as those
31344produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
31345reader needs to frequently refer to previously read compilation units.
31346This setting controls how long a compilation unit will remain in the
31347cache if it is not referenced. A higher limit means that cached
31348compilation units will be stored in memory longer, and more total
31349memory will be used. Setting it to zero disables caching, which will
31350slow down @value{GDBN} startup, but reduce memory consumption.
31351
e7ba9c65
DJ
31352@kindex maint set profile
31353@kindex maint show profile
31354@cindex profiling GDB
31355@item maint set profile
31356@itemx maint show profile
31357Control profiling of @value{GDBN}.
31358
31359Profiling will be disabled until you use the @samp{maint set profile}
31360command to enable it. When you enable profiling, the system will begin
31361collecting timing and execution count data; when you disable profiling or
31362exit @value{GDBN}, the results will be written to a log file. Remember that
31363if you use profiling, @value{GDBN} will overwrite the profiling log file
31364(often called @file{gmon.out}). If you have a record of important profiling
31365data in a @file{gmon.out} file, be sure to move it to a safe location.
31366
31367Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 31368compiled with the @samp{-pg} compiler option.
e7ba9c65 31369
cbe54154
PA
31370@kindex maint set show-debug-regs
31371@kindex maint show show-debug-regs
eac35c4e 31372@cindex hardware debug registers
cbe54154
PA
31373@item maint set show-debug-regs
31374@itemx maint show show-debug-regs
eac35c4e 31375Control whether to show variables that mirror the hardware debug
09d4efe1 31376registers. Use @code{ON} to enable, @code{OFF} to disable. If
3f94c067 31377enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
31378removes a hardware breakpoint or watchpoint, and when the inferior
31379triggers a hardware-assisted breakpoint or watchpoint.
31380
711e434b
PM
31381@kindex maint set show-all-tib
31382@kindex maint show show-all-tib
31383@item maint set show-all-tib
31384@itemx maint show show-all-tib
31385Control whether to show all non zero areas within a 1k block starting
31386at thread local base, when using the @samp{info w32 thread-information-block}
31387command.
31388
09d4efe1
EZ
31389@kindex maint space
31390@cindex memory used by commands
31391@item maint space
31392Control whether to display memory usage for each command. If set to a
31393nonzero value, @value{GDBN} will display how much memory each command
31394took, following the command's own output. This can also be requested
31395by invoking @value{GDBN} with the @option{--statistics} command-line
31396switch (@pxref{Mode Options}).
31397
31398@kindex maint time
31399@cindex time of command execution
31400@item maint time
31401Control whether to display the execution time for each command. If
31402set to a nonzero value, @value{GDBN} will display how much time it
31403took to execute each command, following the command's own output.
e2b7ddea
VP
31404The time is not printed for the commands that run the target, since
31405there's no mechanism currently to compute how much time was spend
31406by @value{GDBN} and how much time was spend by the program been debugged.
31407it's not possibly currently
09d4efe1
EZ
31408This can also be requested by invoking @value{GDBN} with the
31409@option{--statistics} command-line switch (@pxref{Mode Options}).
31410
31411@kindex maint translate-address
31412@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
31413Find the symbol stored at the location specified by the address
31414@var{addr} and an optional section name @var{section}. If found,
31415@value{GDBN} prints the name of the closest symbol and an offset from
31416the symbol's location to the specified address. This is similar to
31417the @code{info address} command (@pxref{Symbols}), except that this
31418command also allows to find symbols in other sections.
ae038cb0 31419
c14c28ba
PP
31420If section was not specified, the section in which the symbol was found
31421is also printed. For dynamically linked executables, the name of
31422executable or shared library containing the symbol is printed as well.
31423
8e04817f 31424@end table
c906108c 31425
9c16f35a
EZ
31426The following command is useful for non-interactive invocations of
31427@value{GDBN}, such as in the test suite.
31428
31429@table @code
31430@item set watchdog @var{nsec}
31431@kindex set watchdog
31432@cindex watchdog timer
31433@cindex timeout for commands
31434Set the maximum number of seconds @value{GDBN} will wait for the
31435target operation to finish. If this time expires, @value{GDBN}
31436reports and error and the command is aborted.
31437
31438@item show watchdog
31439Show the current setting of the target wait timeout.
31440@end table
c906108c 31441
e0ce93ac 31442@node Remote Protocol
8e04817f 31443@appendix @value{GDBN} Remote Serial Protocol
c906108c 31444
ee2d5c50
AC
31445@menu
31446* Overview::
31447* Packets::
31448* Stop Reply Packets::
31449* General Query Packets::
a1dcb23a 31450* Architecture-Specific Protocol Details::
9d29849a 31451* Tracepoint Packets::
a6b151f1 31452* Host I/O Packets::
9a6253be 31453* Interrupts::
8b23ecc4
SL
31454* Notification Packets::
31455* Remote Non-Stop::
a6f3e723 31456* Packet Acknowledgment::
ee2d5c50 31457* Examples::
79a6e687 31458* File-I/O Remote Protocol Extension::
cfa9d6d9 31459* Library List Format::
79a6e687 31460* Memory Map Format::
dc146f7c 31461* Thread List Format::
ee2d5c50
AC
31462@end menu
31463
31464@node Overview
31465@section Overview
31466
8e04817f
AC
31467There may be occasions when you need to know something about the
31468protocol---for example, if there is only one serial port to your target
31469machine, you might want your program to do something special if it
31470recognizes a packet meant for @value{GDBN}.
c906108c 31471
d2c6833e 31472In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 31473transmitted and received data, respectively.
c906108c 31474
8e04817f
AC
31475@cindex protocol, @value{GDBN} remote serial
31476@cindex serial protocol, @value{GDBN} remote
31477@cindex remote serial protocol
8b23ecc4
SL
31478All @value{GDBN} commands and responses (other than acknowledgments
31479and notifications, see @ref{Notification Packets}) are sent as a
31480@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
31481@samp{$}, the actual @var{packet-data}, and the terminating character
31482@samp{#} followed by a two-digit @var{checksum}:
c906108c 31483
474c8240 31484@smallexample
8e04817f 31485@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 31486@end smallexample
8e04817f 31487@noindent
c906108c 31488
8e04817f
AC
31489@cindex checksum, for @value{GDBN} remote
31490@noindent
31491The two-digit @var{checksum} is computed as the modulo 256 sum of all
31492characters between the leading @samp{$} and the trailing @samp{#} (an
31493eight bit unsigned checksum).
c906108c 31494
8e04817f
AC
31495Implementors should note that prior to @value{GDBN} 5.0 the protocol
31496specification also included an optional two-digit @var{sequence-id}:
c906108c 31497
474c8240 31498@smallexample
8e04817f 31499@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 31500@end smallexample
c906108c 31501
8e04817f
AC
31502@cindex sequence-id, for @value{GDBN} remote
31503@noindent
31504That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
31505has never output @var{sequence-id}s. Stubs that handle packets added
31506since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 31507
8e04817f
AC
31508When either the host or the target machine receives a packet, the first
31509response expected is an acknowledgment: either @samp{+} (to indicate
31510the package was received correctly) or @samp{-} (to request
31511retransmission):
c906108c 31512
474c8240 31513@smallexample
d2c6833e
AC
31514-> @code{$}@var{packet-data}@code{#}@var{checksum}
31515<- @code{+}
474c8240 31516@end smallexample
8e04817f 31517@noindent
53a5351d 31518
a6f3e723
SL
31519The @samp{+}/@samp{-} acknowledgments can be disabled
31520once a connection is established.
31521@xref{Packet Acknowledgment}, for details.
31522
8e04817f
AC
31523The host (@value{GDBN}) sends @var{command}s, and the target (the
31524debugging stub incorporated in your program) sends a @var{response}. In
31525the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
31526when the operation has completed, and the target has again stopped all
31527threads in all attached processes. This is the default all-stop mode
31528behavior, but the remote protocol also supports @value{GDBN}'s non-stop
31529execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 31530
8e04817f
AC
31531@var{packet-data} consists of a sequence of characters with the
31532exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
31533exceptions).
c906108c 31534
ee2d5c50 31535@cindex remote protocol, field separator
0876f84a 31536Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 31537@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 31538@sc{hex} with leading zeros suppressed.
c906108c 31539
8e04817f
AC
31540Implementors should note that prior to @value{GDBN} 5.0, the character
31541@samp{:} could not appear as the third character in a packet (as it
31542would potentially conflict with the @var{sequence-id}).
c906108c 31543
0876f84a
DJ
31544@cindex remote protocol, binary data
31545@anchor{Binary Data}
31546Binary data in most packets is encoded either as two hexadecimal
31547digits per byte of binary data. This allowed the traditional remote
31548protocol to work over connections which were only seven-bit clean.
31549Some packets designed more recently assume an eight-bit clean
31550connection, and use a more efficient encoding to send and receive
31551binary data.
31552
31553The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
31554as an escape character. Any escaped byte is transmitted as the escape
31555character followed by the original character XORed with @code{0x20}.
31556For example, the byte @code{0x7d} would be transmitted as the two
31557bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
31558@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
31559@samp{@}}) must always be escaped. Responses sent by the stub
31560must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
31561is not interpreted as the start of a run-length encoded sequence
31562(described next).
31563
1d3811f6
DJ
31564Response @var{data} can be run-length encoded to save space.
31565Run-length encoding replaces runs of identical characters with one
31566instance of the repeated character, followed by a @samp{*} and a
31567repeat count. The repeat count is itself sent encoded, to avoid
31568binary characters in @var{data}: a value of @var{n} is sent as
31569@code{@var{n}+29}. For a repeat count greater or equal to 3, this
31570produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
31571code 32) for a repeat count of 3. (This is because run-length
31572encoding starts to win for counts 3 or more.) Thus, for example,
31573@samp{0* } is a run-length encoding of ``0000'': the space character
31574after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
315753}} more times.
31576
31577The printable characters @samp{#} and @samp{$} or with a numeric value
31578greater than 126 must not be used. Runs of six repeats (@samp{#}) or
31579seven repeats (@samp{$}) can be expanded using a repeat count of only
31580five (@samp{"}). For example, @samp{00000000} can be encoded as
31581@samp{0*"00}.
c906108c 31582
8e04817f
AC
31583The error response returned for some packets includes a two character
31584error number. That number is not well defined.
c906108c 31585
f8da2bff 31586@cindex empty response, for unsupported packets
8e04817f
AC
31587For any @var{command} not supported by the stub, an empty response
31588(@samp{$#00}) should be returned. That way it is possible to extend the
31589protocol. A newer @value{GDBN} can tell if a packet is supported based
31590on that response.
c906108c 31591
b383017d
RM
31592A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
31593@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 31594optional.
c906108c 31595
ee2d5c50
AC
31596@node Packets
31597@section Packets
31598
31599The following table provides a complete list of all currently defined
31600@var{command}s and their corresponding response @var{data}.
79a6e687 31601@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 31602I/O extension of the remote protocol.
ee2d5c50 31603
b8ff78ce
JB
31604Each packet's description has a template showing the packet's overall
31605syntax, followed by an explanation of the packet's meaning. We
31606include spaces in some of the templates for clarity; these are not
31607part of the packet's syntax. No @value{GDBN} packet uses spaces to
31608separate its components. For example, a template like @samp{foo
31609@var{bar} @var{baz}} describes a packet beginning with the three ASCII
31610bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 31611@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
31612@samp{foo} and the @var{bar}, or between the @var{bar} and the
31613@var{baz}.
31614
b90a069a
SL
31615@cindex @var{thread-id}, in remote protocol
31616@anchor{thread-id syntax}
31617Several packets and replies include a @var{thread-id} field to identify
31618a thread. Normally these are positive numbers with a target-specific
31619interpretation, formatted as big-endian hex strings. A @var{thread-id}
31620can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
31621pick any thread.
31622
31623In addition, the remote protocol supports a multiprocess feature in
31624which the @var{thread-id} syntax is extended to optionally include both
31625process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
31626The @var{pid} (process) and @var{tid} (thread) components each have the
31627format described above: a positive number with target-specific
31628interpretation formatted as a big-endian hex string, literal @samp{-1}
31629to indicate all processes or threads (respectively), or @samp{0} to
31630indicate an arbitrary process or thread. Specifying just a process, as
31631@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
31632error to specify all processes but a specific thread, such as
31633@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
31634for those packets and replies explicitly documented to include a process
31635ID, rather than a @var{thread-id}.
31636
31637The multiprocess @var{thread-id} syntax extensions are only used if both
31638@value{GDBN} and the stub report support for the @samp{multiprocess}
31639feature using @samp{qSupported}. @xref{multiprocess extensions}, for
31640more information.
31641
8ffe2530
JB
31642Note that all packet forms beginning with an upper- or lower-case
31643letter, other than those described here, are reserved for future use.
31644
b8ff78ce 31645Here are the packet descriptions.
ee2d5c50 31646
b8ff78ce 31647@table @samp
ee2d5c50 31648
b8ff78ce
JB
31649@item !
31650@cindex @samp{!} packet
2d717e4f 31651@anchor{extended mode}
8e04817f
AC
31652Enable extended mode. In extended mode, the remote server is made
31653persistent. The @samp{R} packet is used to restart the program being
31654debugged.
ee2d5c50
AC
31655
31656Reply:
31657@table @samp
31658@item OK
8e04817f 31659The remote target both supports and has enabled extended mode.
ee2d5c50 31660@end table
c906108c 31661
b8ff78ce
JB
31662@item ?
31663@cindex @samp{?} packet
ee2d5c50 31664Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
31665step and continue. This packet has a special interpretation when the
31666target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 31667
ee2d5c50
AC
31668Reply:
31669@xref{Stop Reply Packets}, for the reply specifications.
31670
b8ff78ce
JB
31671@item A @var{arglen},@var{argnum},@var{arg},@dots{}
31672@cindex @samp{A} packet
31673Initialized @code{argv[]} array passed into program. @var{arglen}
31674specifies the number of bytes in the hex encoded byte stream
31675@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
31676
31677Reply:
31678@table @samp
31679@item OK
b8ff78ce
JB
31680The arguments were set.
31681@item E @var{NN}
31682An error occurred.
ee2d5c50
AC
31683@end table
31684
b8ff78ce
JB
31685@item b @var{baud}
31686@cindex @samp{b} packet
31687(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
31688Change the serial line speed to @var{baud}.
31689
31690JTC: @emph{When does the transport layer state change? When it's
31691received, or after the ACK is transmitted. In either case, there are
31692problems if the command or the acknowledgment packet is dropped.}
31693
31694Stan: @emph{If people really wanted to add something like this, and get
31695it working for the first time, they ought to modify ser-unix.c to send
31696some kind of out-of-band message to a specially-setup stub and have the
31697switch happen "in between" packets, so that from remote protocol's point
31698of view, nothing actually happened.}
31699
b8ff78ce
JB
31700@item B @var{addr},@var{mode}
31701@cindex @samp{B} packet
8e04817f 31702Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
31703breakpoint at @var{addr}.
31704
b8ff78ce 31705Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 31706(@pxref{insert breakpoint or watchpoint packet}).
c906108c 31707
bacec72f 31708@cindex @samp{bc} packet
0d772ac9
MS
31709@anchor{bc}
31710@item bc
bacec72f
MS
31711Backward continue. Execute the target system in reverse. No parameter.
31712@xref{Reverse Execution}, for more information.
31713
31714Reply:
31715@xref{Stop Reply Packets}, for the reply specifications.
31716
bacec72f 31717@cindex @samp{bs} packet
0d772ac9
MS
31718@anchor{bs}
31719@item bs
bacec72f
MS
31720Backward single step. Execute one instruction in reverse. No parameter.
31721@xref{Reverse Execution}, for more information.
31722
31723Reply:
31724@xref{Stop Reply Packets}, for the reply specifications.
31725
4f553f88 31726@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
31727@cindex @samp{c} packet
31728Continue. @var{addr} is address to resume. If @var{addr} is omitted,
31729resume at current address.
c906108c 31730
ee2d5c50
AC
31731Reply:
31732@xref{Stop Reply Packets}, for the reply specifications.
31733
4f553f88 31734@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 31735@cindex @samp{C} packet
8e04817f 31736Continue with signal @var{sig} (hex signal number). If
b8ff78ce 31737@samp{;@var{addr}} is omitted, resume at same address.
c906108c 31738
ee2d5c50
AC
31739Reply:
31740@xref{Stop Reply Packets}, for the reply specifications.
c906108c 31741
b8ff78ce
JB
31742@item d
31743@cindex @samp{d} packet
ee2d5c50
AC
31744Toggle debug flag.
31745
b8ff78ce
JB
31746Don't use this packet; instead, define a general set packet
31747(@pxref{General Query Packets}).
ee2d5c50 31748
b8ff78ce 31749@item D
b90a069a 31750@itemx D;@var{pid}
b8ff78ce 31751@cindex @samp{D} packet
b90a069a
SL
31752The first form of the packet is used to detach @value{GDBN} from the
31753remote system. It is sent to the remote target
07f31aa6 31754before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 31755
b90a069a
SL
31756The second form, including a process ID, is used when multiprocess
31757protocol extensions are enabled (@pxref{multiprocess extensions}), to
31758detach only a specific process. The @var{pid} is specified as a
31759big-endian hex string.
31760
ee2d5c50
AC
31761Reply:
31762@table @samp
10fac096
NW
31763@item OK
31764for success
b8ff78ce 31765@item E @var{NN}
10fac096 31766for an error
ee2d5c50 31767@end table
c906108c 31768
b8ff78ce
JB
31769@item F @var{RC},@var{EE},@var{CF};@var{XX}
31770@cindex @samp{F} packet
31771A reply from @value{GDBN} to an @samp{F} packet sent by the target.
31772This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 31773Remote Protocol Extension}, for the specification.
ee2d5c50 31774
b8ff78ce 31775@item g
ee2d5c50 31776@anchor{read registers packet}
b8ff78ce 31777@cindex @samp{g} packet
ee2d5c50
AC
31778Read general registers.
31779
31780Reply:
31781@table @samp
31782@item @var{XX@dots{}}
8e04817f
AC
31783Each byte of register data is described by two hex digits. The bytes
31784with the register are transmitted in target byte order. The size of
b8ff78ce 31785each register and their position within the @samp{g} packet are
4a9bb1df
UW
31786determined by the @value{GDBN} internal gdbarch functions
31787@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce
JB
31788specification of several standard @samp{g} packets is specified below.
31789@item E @var{NN}
ee2d5c50
AC
31790for an error.
31791@end table
c906108c 31792
b8ff78ce
JB
31793@item G @var{XX@dots{}}
31794@cindex @samp{G} packet
31795Write general registers. @xref{read registers packet}, for a
31796description of the @var{XX@dots{}} data.
ee2d5c50
AC
31797
31798Reply:
31799@table @samp
31800@item OK
31801for success
b8ff78ce 31802@item E @var{NN}
ee2d5c50
AC
31803for an error
31804@end table
31805
b90a069a 31806@item H @var{c} @var{thread-id}
b8ff78ce 31807@cindex @samp{H} packet
8e04817f 31808Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
31809@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
31810should be @samp{c} for step and continue operations, @samp{g} for other
b90a069a
SL
31811operations. The thread designator @var{thread-id} has the format and
31812interpretation described in @ref{thread-id syntax}.
ee2d5c50
AC
31813
31814Reply:
31815@table @samp
31816@item OK
31817for success
b8ff78ce 31818@item E @var{NN}
ee2d5c50
AC
31819for an error
31820@end table
c906108c 31821
8e04817f
AC
31822@c FIXME: JTC:
31823@c 'H': How restrictive (or permissive) is the thread model. If a
31824@c thread is selected and stopped, are other threads allowed
31825@c to continue to execute? As I mentioned above, I think the
31826@c semantics of each command when a thread is selected must be
31827@c described. For example:
31828@c
31829@c 'g': If the stub supports threads and a specific thread is
31830@c selected, returns the register block from that thread;
31831@c otherwise returns current registers.
31832@c
31833@c 'G' If the stub supports threads and a specific thread is
31834@c selected, sets the registers of the register block of
31835@c that thread; otherwise sets current registers.
c906108c 31836
b8ff78ce 31837@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 31838@anchor{cycle step packet}
b8ff78ce
JB
31839@cindex @samp{i} packet
31840Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
31841present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
31842step starting at that address.
c906108c 31843
b8ff78ce
JB
31844@item I
31845@cindex @samp{I} packet
31846Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
31847step packet}.
ee2d5c50 31848
b8ff78ce
JB
31849@item k
31850@cindex @samp{k} packet
31851Kill request.
c906108c 31852
ac282366 31853FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
31854thread context has been selected (i.e.@: does 'k' kill only that
31855thread?)}.
c906108c 31856
b8ff78ce
JB
31857@item m @var{addr},@var{length}
31858@cindex @samp{m} packet
8e04817f 31859Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
31860Note that @var{addr} may not be aligned to any particular boundary.
31861
31862The stub need not use any particular size or alignment when gathering
31863data from memory for the response; even if @var{addr} is word-aligned
31864and @var{length} is a multiple of the word size, the stub is free to
31865use byte accesses, or not. For this reason, this packet may not be
31866suitable for accessing memory-mapped I/O devices.
c43c5473
JB
31867@cindex alignment of remote memory accesses
31868@cindex size of remote memory accesses
31869@cindex memory, alignment and size of remote accesses
c906108c 31870
ee2d5c50
AC
31871Reply:
31872@table @samp
31873@item @var{XX@dots{}}
599b237a 31874Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
31875number. The reply may contain fewer bytes than requested if the
31876server was able to read only part of the region of memory.
31877@item E @var{NN}
ee2d5c50
AC
31878@var{NN} is errno
31879@end table
31880
b8ff78ce
JB
31881@item M @var{addr},@var{length}:@var{XX@dots{}}
31882@cindex @samp{M} packet
8e04817f 31883Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 31884@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 31885hexadecimal number.
ee2d5c50
AC
31886
31887Reply:
31888@table @samp
31889@item OK
31890for success
b8ff78ce 31891@item E @var{NN}
8e04817f
AC
31892for an error (this includes the case where only part of the data was
31893written).
ee2d5c50 31894@end table
c906108c 31895
b8ff78ce
JB
31896@item p @var{n}
31897@cindex @samp{p} packet
31898Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
31899@xref{read registers packet}, for a description of how the returned
31900register value is encoded.
ee2d5c50
AC
31901
31902Reply:
31903@table @samp
2e868123
AC
31904@item @var{XX@dots{}}
31905the register's value
b8ff78ce 31906@item E @var{NN}
2e868123
AC
31907for an error
31908@item
31909Indicating an unrecognized @var{query}.
ee2d5c50
AC
31910@end table
31911
b8ff78ce 31912@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 31913@anchor{write register packet}
b8ff78ce
JB
31914@cindex @samp{P} packet
31915Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 31916number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 31917digits for each byte in the register (target byte order).
c906108c 31918
ee2d5c50
AC
31919Reply:
31920@table @samp
31921@item OK
31922for success
b8ff78ce 31923@item E @var{NN}
ee2d5c50
AC
31924for an error
31925@end table
31926
5f3bebba
JB
31927@item q @var{name} @var{params}@dots{}
31928@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 31929@cindex @samp{q} packet
b8ff78ce 31930@cindex @samp{Q} packet
5f3bebba
JB
31931General query (@samp{q}) and set (@samp{Q}). These packets are
31932described fully in @ref{General Query Packets}.
c906108c 31933
b8ff78ce
JB
31934@item r
31935@cindex @samp{r} packet
8e04817f 31936Reset the entire system.
c906108c 31937
b8ff78ce 31938Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 31939
b8ff78ce
JB
31940@item R @var{XX}
31941@cindex @samp{R} packet
8e04817f 31942Restart the program being debugged. @var{XX}, while needed, is ignored.
2d717e4f 31943This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 31944
8e04817f 31945The @samp{R} packet has no reply.
ee2d5c50 31946
4f553f88 31947@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
31948@cindex @samp{s} packet
31949Single step. @var{addr} is the address at which to resume. If
31950@var{addr} is omitted, resume at same address.
c906108c 31951
ee2d5c50
AC
31952Reply:
31953@xref{Stop Reply Packets}, for the reply specifications.
31954
4f553f88 31955@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 31956@anchor{step with signal packet}
b8ff78ce
JB
31957@cindex @samp{S} packet
31958Step with signal. This is analogous to the @samp{C} packet, but
31959requests a single-step, rather than a normal resumption of execution.
c906108c 31960
ee2d5c50
AC
31961Reply:
31962@xref{Stop Reply Packets}, for the reply specifications.
31963
b8ff78ce
JB
31964@item t @var{addr}:@var{PP},@var{MM}
31965@cindex @samp{t} packet
8e04817f 31966Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
31967@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
31968@var{addr} must be at least 3 digits.
c906108c 31969
b90a069a 31970@item T @var{thread-id}
b8ff78ce 31971@cindex @samp{T} packet
b90a069a 31972Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 31973
ee2d5c50
AC
31974Reply:
31975@table @samp
31976@item OK
31977thread is still alive
b8ff78ce 31978@item E @var{NN}
ee2d5c50
AC
31979thread is dead
31980@end table
31981
b8ff78ce
JB
31982@item v
31983Packets starting with @samp{v} are identified by a multi-letter name,
31984up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 31985
2d717e4f
DJ
31986@item vAttach;@var{pid}
31987@cindex @samp{vAttach} packet
8b23ecc4
SL
31988Attach to a new process with the specified process ID @var{pid}.
31989The process ID is a
31990hexadecimal integer identifying the process. In all-stop mode, all
31991threads in the attached process are stopped; in non-stop mode, it may be
31992attached without being stopped if that is supported by the target.
31993
31994@c In non-stop mode, on a successful vAttach, the stub should set the
31995@c current thread to a thread of the newly-attached process. After
31996@c attaching, GDB queries for the attached process's thread ID with qC.
31997@c Also note that, from a user perspective, whether or not the
31998@c target is stopped on attach in non-stop mode depends on whether you
31999@c use the foreground or background version of the attach command, not
32000@c on what vAttach does; GDB does the right thing with respect to either
32001@c stopping or restarting threads.
2d717e4f
DJ
32002
32003This packet is only available in extended mode (@pxref{extended mode}).
32004
32005Reply:
32006@table @samp
32007@item E @var{nn}
32008for an error
32009@item @r{Any stop packet}
8b23ecc4
SL
32010for success in all-stop mode (@pxref{Stop Reply Packets})
32011@item OK
32012for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
32013@end table
32014
b90a069a 32015@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce
JB
32016@cindex @samp{vCont} packet
32017Resume the inferior, specifying different actions for each thread.
b90a069a 32018If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 32019threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
32020specified then other threads should remain stopped in all-stop mode and
32021in their current state in non-stop mode.
32022Specifying multiple
86d30acc 32023default actions is an error; specifying no actions is also an error.
b90a069a
SL
32024Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
32025
32026Currently supported actions are:
86d30acc 32027
b8ff78ce 32028@table @samp
86d30acc
DJ
32029@item c
32030Continue.
b8ff78ce 32031@item C @var{sig}
8b23ecc4 32032Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
32033@item s
32034Step.
b8ff78ce 32035@item S @var{sig}
8b23ecc4
SL
32036Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
32037@item t
32038Stop.
86d30acc
DJ
32039@end table
32040
8b23ecc4
SL
32041The optional argument @var{addr} normally associated with the
32042@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 32043not supported in @samp{vCont}.
86d30acc 32044
08a0efd0
PA
32045The @samp{t} action is only relevant in non-stop mode
32046(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
32047A stop reply should be generated for any affected thread not already stopped.
32048When a thread is stopped by means of a @samp{t} action,
32049the corresponding stop reply should indicate that the thread has stopped with
32050signal @samp{0}, regardless of whether the target uses some other signal
32051as an implementation detail.
32052
86d30acc
DJ
32053Reply:
32054@xref{Stop Reply Packets}, for the reply specifications.
32055
b8ff78ce
JB
32056@item vCont?
32057@cindex @samp{vCont?} packet
d3e8051b 32058Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
32059
32060Reply:
32061@table @samp
b8ff78ce
JB
32062@item vCont@r{[};@var{action}@dots{}@r{]}
32063The @samp{vCont} packet is supported. Each @var{action} is a supported
32064command in the @samp{vCont} packet.
86d30acc 32065@item
b8ff78ce 32066The @samp{vCont} packet is not supported.
86d30acc 32067@end table
ee2d5c50 32068
a6b151f1
DJ
32069@item vFile:@var{operation}:@var{parameter}@dots{}
32070@cindex @samp{vFile} packet
32071Perform a file operation on the target system. For details,
32072see @ref{Host I/O Packets}.
32073
68437a39
DJ
32074@item vFlashErase:@var{addr},@var{length}
32075@cindex @samp{vFlashErase} packet
32076Direct the stub to erase @var{length} bytes of flash starting at
32077@var{addr}. The region may enclose any number of flash blocks, but
32078its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
32079flash block size appearing in the memory map (@pxref{Memory Map
32080Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
32081together, and sends a @samp{vFlashDone} request after each group; the
32082stub is allowed to delay erase operation until the @samp{vFlashDone}
32083packet is received.
32084
b90a069a
SL
32085The stub must support @samp{vCont} if it reports support for
32086multiprocess extensions (@pxref{multiprocess extensions}). Note that in
32087this case @samp{vCont} actions can be specified to apply to all threads
32088in a process by using the @samp{p@var{pid}.-1} form of the
32089@var{thread-id}.
32090
68437a39
DJ
32091Reply:
32092@table @samp
32093@item OK
32094for success
32095@item E @var{NN}
32096for an error
32097@end table
32098
32099@item vFlashWrite:@var{addr}:@var{XX@dots{}}
32100@cindex @samp{vFlashWrite} packet
32101Direct the stub to write data to flash address @var{addr}. The data
32102is passed in binary form using the same encoding as for the @samp{X}
32103packet (@pxref{Binary Data}). The memory ranges specified by
32104@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
32105not overlap, and must appear in order of increasing addresses
32106(although @samp{vFlashErase} packets for higher addresses may already
32107have been received; the ordering is guaranteed only between
32108@samp{vFlashWrite} packets). If a packet writes to an address that was
32109neither erased by a preceding @samp{vFlashErase} packet nor by some other
32110target-specific method, the results are unpredictable.
32111
32112
32113Reply:
32114@table @samp
32115@item OK
32116for success
32117@item E.memtype
32118for vFlashWrite addressing non-flash memory
32119@item E @var{NN}
32120for an error
32121@end table
32122
32123@item vFlashDone
32124@cindex @samp{vFlashDone} packet
32125Indicate to the stub that flash programming operation is finished.
32126The stub is permitted to delay or batch the effects of a group of
32127@samp{vFlashErase} and @samp{vFlashWrite} packets until a
32128@samp{vFlashDone} packet is received. The contents of the affected
32129regions of flash memory are unpredictable until the @samp{vFlashDone}
32130request is completed.
32131
b90a069a
SL
32132@item vKill;@var{pid}
32133@cindex @samp{vKill} packet
32134Kill the process with the specified process ID. @var{pid} is a
32135hexadecimal integer identifying the process. This packet is used in
32136preference to @samp{k} when multiprocess protocol extensions are
32137supported; see @ref{multiprocess extensions}.
32138
32139Reply:
32140@table @samp
32141@item E @var{nn}
32142for an error
32143@item OK
32144for success
32145@end table
32146
2d717e4f
DJ
32147@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
32148@cindex @samp{vRun} packet
32149Run the program @var{filename}, passing it each @var{argument} on its
32150command line. The file and arguments are hex-encoded strings. If
32151@var{filename} is an empty string, the stub may use a default program
32152(e.g.@: the last program run). The program is created in the stopped
9b562ab8 32153state.
2d717e4f 32154
8b23ecc4
SL
32155@c FIXME: What about non-stop mode?
32156
2d717e4f
DJ
32157This packet is only available in extended mode (@pxref{extended mode}).
32158
32159Reply:
32160@table @samp
32161@item E @var{nn}
32162for an error
32163@item @r{Any stop packet}
32164for success (@pxref{Stop Reply Packets})
32165@end table
32166
8b23ecc4
SL
32167@item vStopped
32168@anchor{vStopped packet}
32169@cindex @samp{vStopped} packet
32170
32171In non-stop mode (@pxref{Remote Non-Stop}), acknowledge a previous stop
32172reply and prompt for the stub to report another one.
32173
32174Reply:
32175@table @samp
32176@item @r{Any stop packet}
32177if there is another unreported stop event (@pxref{Stop Reply Packets})
32178@item OK
32179if there are no unreported stop events
32180@end table
32181
b8ff78ce 32182@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 32183@anchor{X packet}
b8ff78ce
JB
32184@cindex @samp{X} packet
32185Write data to memory, where the data is transmitted in binary.
32186@var{addr} is address, @var{length} is number of bytes,
0876f84a 32187@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 32188
ee2d5c50
AC
32189Reply:
32190@table @samp
32191@item OK
32192for success
b8ff78ce 32193@item E @var{NN}
ee2d5c50
AC
32194for an error
32195@end table
32196
a1dcb23a
DJ
32197@item z @var{type},@var{addr},@var{kind}
32198@itemx Z @var{type},@var{addr},@var{kind}
2f870471 32199@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
32200@cindex @samp{z} packet
32201@cindex @samp{Z} packets
32202Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 32203watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 32204
2f870471
AC
32205Each breakpoint and watchpoint packet @var{type} is documented
32206separately.
32207
512217c7
AC
32208@emph{Implementation notes: A remote target shall return an empty string
32209for an unrecognized breakpoint or watchpoint packet @var{type}. A
32210remote target shall support either both or neither of a given
b8ff78ce 32211@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
32212avoid potential problems with duplicate packets, the operations should
32213be implemented in an idempotent way.}
32214
a1dcb23a
DJ
32215@item z0,@var{addr},@var{kind}
32216@itemx Z0,@var{addr},@var{kind}
b8ff78ce
JB
32217@cindex @samp{z0} packet
32218@cindex @samp{Z0} packet
32219Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
a1dcb23a 32220@var{addr} of type @var{kind}.
2f870471
AC
32221
32222A memory breakpoint is implemented by replacing the instruction at
32223@var{addr} with a software breakpoint or trap instruction. The
a1dcb23a
DJ
32224@var{kind} is target-specific and typically indicates the size of
32225the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
32226and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
32227architectures have additional meanings for @var{kind};
32228see @ref{Architecture-Specific Protocol Details}.
c906108c 32229
2f870471
AC
32230@emph{Implementation note: It is possible for a target to copy or move
32231code that contains memory breakpoints (e.g., when implementing
32232overlays). The behavior of this packet, in the presence of such a
32233target, is not defined.}
c906108c 32234
ee2d5c50
AC
32235Reply:
32236@table @samp
2f870471
AC
32237@item OK
32238success
32239@item
32240not supported
b8ff78ce 32241@item E @var{NN}
ee2d5c50 32242for an error
2f870471
AC
32243@end table
32244
a1dcb23a
DJ
32245@item z1,@var{addr},@var{kind}
32246@itemx Z1,@var{addr},@var{kind}
b8ff78ce
JB
32247@cindex @samp{z1} packet
32248@cindex @samp{Z1} packet
32249Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 32250address @var{addr}.
2f870471
AC
32251
32252A hardware breakpoint is implemented using a mechanism that is not
a1dcb23a
DJ
32253dependant on being able to modify the target's memory. @var{kind}
32254has the same meaning as in @samp{Z0} packets.
2f870471
AC
32255
32256@emph{Implementation note: A hardware breakpoint is not affected by code
32257movement.}
32258
32259Reply:
32260@table @samp
ee2d5c50 32261@item OK
2f870471
AC
32262success
32263@item
32264not supported
b8ff78ce 32265@item E @var{NN}
2f870471
AC
32266for an error
32267@end table
32268
a1dcb23a
DJ
32269@item z2,@var{addr},@var{kind}
32270@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
32271@cindex @samp{z2} packet
32272@cindex @samp{Z2} packet
a1dcb23a
DJ
32273Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
32274@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
32275
32276Reply:
32277@table @samp
32278@item OK
32279success
32280@item
32281not supported
b8ff78ce 32282@item E @var{NN}
2f870471
AC
32283for an error
32284@end table
32285
a1dcb23a
DJ
32286@item z3,@var{addr},@var{kind}
32287@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
32288@cindex @samp{z3} packet
32289@cindex @samp{Z3} packet
a1dcb23a
DJ
32290Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
32291@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
32292
32293Reply:
32294@table @samp
32295@item OK
32296success
32297@item
32298not supported
b8ff78ce 32299@item E @var{NN}
2f870471
AC
32300for an error
32301@end table
32302
a1dcb23a
DJ
32303@item z4,@var{addr},@var{kind}
32304@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
32305@cindex @samp{z4} packet
32306@cindex @samp{Z4} packet
a1dcb23a
DJ
32307Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
32308@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
32309
32310Reply:
32311@table @samp
32312@item OK
32313success
32314@item
32315not supported
b8ff78ce 32316@item E @var{NN}
2f870471 32317for an error
ee2d5c50
AC
32318@end table
32319
32320@end table
c906108c 32321
ee2d5c50
AC
32322@node Stop Reply Packets
32323@section Stop Reply Packets
32324@cindex stop reply packets
c906108c 32325
8b23ecc4
SL
32326The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
32327@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
32328receive any of the below as a reply. Except for @samp{?}
32329and @samp{vStopped}, that reply is only returned
b8ff78ce 32330when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
32331number} is defined by the header @file{include/gdb/signals.h} in the
32332@value{GDBN} source code.
c906108c 32333
b8ff78ce
JB
32334As in the description of request packets, we include spaces in the
32335reply templates for clarity; these are not part of the reply packet's
32336syntax. No @value{GDBN} stop reply packet uses spaces to separate its
32337components.
c906108c 32338
b8ff78ce 32339@table @samp
ee2d5c50 32340
b8ff78ce 32341@item S @var{AA}
599b237a 32342The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
32343number). This is equivalent to a @samp{T} response with no
32344@var{n}:@var{r} pairs.
c906108c 32345
b8ff78ce
JB
32346@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
32347@cindex @samp{T} packet reply
599b237a 32348The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
32349number). This is equivalent to an @samp{S} response, except that the
32350@samp{@var{n}:@var{r}} pairs can carry values of important registers
32351and other information directly in the stop reply packet, reducing
32352round-trip latency. Single-step and breakpoint traps are reported
32353this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
32354
32355@itemize @bullet
b8ff78ce 32356@item
599b237a 32357If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
32358corresponding @var{r} gives that register's value. @var{r} is a
32359series of bytes in target byte order, with each byte given by a
32360two-digit hex number.
cfa9d6d9 32361
b8ff78ce 32362@item
b90a069a
SL
32363If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
32364the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 32365
dc146f7c
VP
32366@item
32367If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
32368the core on which the stop event was detected.
32369
b8ff78ce 32370@item
cfa9d6d9
DJ
32371If @var{n} is a recognized @dfn{stop reason}, it describes a more
32372specific event that stopped the target. The currently defined stop
32373reasons are listed below. @var{aa} should be @samp{05}, the trap
32374signal. At most one stop reason should be present.
32375
b8ff78ce
JB
32376@item
32377Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
32378and go on to the next; this allows us to extend the protocol in the
32379future.
cfa9d6d9
DJ
32380@end itemize
32381
32382The currently defined stop reasons are:
32383
32384@table @samp
32385@item watch
32386@itemx rwatch
32387@itemx awatch
32388The packet indicates a watchpoint hit, and @var{r} is the data address, in
32389hex.
32390
32391@cindex shared library events, remote reply
32392@item library
32393The packet indicates that the loaded libraries have changed.
32394@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
32395list of loaded libraries. @var{r} is ignored.
bacec72f
MS
32396
32397@cindex replay log events, remote reply
32398@item replaylog
32399The packet indicates that the target cannot continue replaying
32400logged execution events, because it has reached the end (or the
32401beginning when executing backward) of the log. The value of @var{r}
32402will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
32403for more information.
cfa9d6d9 32404@end table
ee2d5c50 32405
b8ff78ce 32406@item W @var{AA}
b90a069a 32407@itemx W @var{AA} ; process:@var{pid}
8e04817f 32408The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
32409applicable to certain targets.
32410
b90a069a
SL
32411The second form of the response, including the process ID of the exited
32412process, can be used only when @value{GDBN} has reported support for
32413multiprocess protocol extensions; see @ref{multiprocess extensions}.
32414The @var{pid} is formatted as a big-endian hex string.
32415
b8ff78ce 32416@item X @var{AA}
b90a069a 32417@itemx X @var{AA} ; process:@var{pid}
8e04817f 32418The process terminated with signal @var{AA}.
c906108c 32419
b90a069a
SL
32420The second form of the response, including the process ID of the
32421terminated process, can be used only when @value{GDBN} has reported
32422support for multiprocess protocol extensions; see @ref{multiprocess
32423extensions}. The @var{pid} is formatted as a big-endian hex string.
32424
b8ff78ce
JB
32425@item O @var{XX}@dots{}
32426@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
32427written as the program's console output. This can happen at any time
32428while the program is running and the debugger should continue to wait
8b23ecc4 32429for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 32430
b8ff78ce 32431@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
32432@var{call-id} is the identifier which says which host system call should
32433be called. This is just the name of the function. Translation into the
32434correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 32435@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
32436system calls.
32437
b8ff78ce
JB
32438@samp{@var{parameter}@dots{}} is a list of parameters as defined for
32439this very system call.
0ce1b118 32440
b8ff78ce
JB
32441The target replies with this packet when it expects @value{GDBN} to
32442call a host system call on behalf of the target. @value{GDBN} replies
32443with an appropriate @samp{F} packet and keeps up waiting for the next
32444reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
32445or @samp{s} action is expected to be continued. @xref{File-I/O Remote
32446Protocol Extension}, for more details.
0ce1b118 32447
ee2d5c50
AC
32448@end table
32449
32450@node General Query Packets
32451@section General Query Packets
9c16f35a 32452@cindex remote query requests
c906108c 32453
5f3bebba
JB
32454Packets starting with @samp{q} are @dfn{general query packets};
32455packets starting with @samp{Q} are @dfn{general set packets}. General
32456query and set packets are a semi-unified form for retrieving and
32457sending information to and from the stub.
32458
32459The initial letter of a query or set packet is followed by a name
32460indicating what sort of thing the packet applies to. For example,
32461@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
32462definitions with the stub. These packet names follow some
32463conventions:
32464
32465@itemize @bullet
32466@item
32467The name must not contain commas, colons or semicolons.
32468@item
32469Most @value{GDBN} query and set packets have a leading upper case
32470letter.
32471@item
32472The names of custom vendor packets should use a company prefix, in
32473lower case, followed by a period. For example, packets designed at
32474the Acme Corporation might begin with @samp{qacme.foo} (for querying
32475foos) or @samp{Qacme.bar} (for setting bars).
32476@end itemize
32477
aa56d27a
JB
32478The name of a query or set packet should be separated from any
32479parameters by a @samp{:}; the parameters themselves should be
32480separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
32481full packet name, and check for a separator or the end of the packet,
32482in case two packet names share a common prefix. New packets should not begin
32483with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
32484packets predate these conventions, and have arguments without any terminator
32485for the packet name; we suspect they are in widespread use in places that
32486are difficult to upgrade. The @samp{qC} packet has no arguments, but some
32487existing stubs (e.g.@: RedBoot) are known to not check for the end of the
32488packet.}.
c906108c 32489
b8ff78ce
JB
32490Like the descriptions of the other packets, each description here
32491has a template showing the packet's overall syntax, followed by an
32492explanation of the packet's meaning. We include spaces in some of the
32493templates for clarity; these are not part of the packet's syntax. No
32494@value{GDBN} packet uses spaces to separate its components.
32495
5f3bebba
JB
32496Here are the currently defined query and set packets:
32497
b8ff78ce 32498@table @samp
c906108c 32499
d914c394
SS
32500@item QAllow:@var{op}:@var{val}@dots{}
32501@cindex @samp{QAllow} packet
32502Specify which operations @value{GDBN} expects to request of the
32503target, as a semicolon-separated list of operation name and value
32504pairs. Possible values for @var{op} include @samp{WriteReg},
32505@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
32506@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
32507indicating that @value{GDBN} will not request the operation, or 1,
32508indicating that it may. (The target can then use this to set up its
32509own internals optimally, for instance if the debugger never expects to
32510insert breakpoints, it may not need to install its own trap handler.)
32511
b8ff78ce 32512@item qC
9c16f35a 32513@cindex current thread, remote request
b8ff78ce 32514@cindex @samp{qC} packet
b90a069a 32515Return the current thread ID.
ee2d5c50
AC
32516
32517Reply:
32518@table @samp
b90a069a
SL
32519@item QC @var{thread-id}
32520Where @var{thread-id} is a thread ID as documented in
32521@ref{thread-id syntax}.
b8ff78ce 32522@item @r{(anything else)}
b90a069a 32523Any other reply implies the old thread ID.
ee2d5c50
AC
32524@end table
32525
b8ff78ce 32526@item qCRC:@var{addr},@var{length}
ff2587ec 32527@cindex CRC of memory block, remote request
b8ff78ce 32528@cindex @samp{qCRC} packet
99e008fe
EZ
32529Compute the CRC checksum of a block of memory using CRC-32 defined in
32530IEEE 802.3. The CRC is computed byte at a time, taking the most
32531significant bit of each byte first. The initial pattern code
32532@code{0xffffffff} is used to ensure leading zeros affect the CRC.
32533
32534@emph{Note:} This is the same CRC used in validating separate debug
32535files (@pxref{Separate Debug Files, , Debugging Information in Separate
32536Files}). However the algorithm is slightly different. When validating
32537separate debug files, the CRC is computed taking the @emph{least}
32538significant bit of each byte first, and the final result is inverted to
32539detect trailing zeros.
32540
ff2587ec
WZ
32541Reply:
32542@table @samp
b8ff78ce 32543@item E @var{NN}
ff2587ec 32544An error (such as memory fault)
b8ff78ce
JB
32545@item C @var{crc32}
32546The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
32547@end table
32548
b8ff78ce
JB
32549@item qfThreadInfo
32550@itemx qsThreadInfo
9c16f35a 32551@cindex list active threads, remote request
b8ff78ce
JB
32552@cindex @samp{qfThreadInfo} packet
32553@cindex @samp{qsThreadInfo} packet
b90a069a 32554Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
32555may be too many active threads to fit into one reply packet, this query
32556works iteratively: it may require more than one query/reply sequence to
32557obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
32558be the @samp{qfThreadInfo} query; subsequent queries in the
32559sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 32560
b8ff78ce 32561NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
32562
32563Reply:
32564@table @samp
b90a069a
SL
32565@item m @var{thread-id}
32566A single thread ID
32567@item m @var{thread-id},@var{thread-id}@dots{}
32568a comma-separated list of thread IDs
b8ff78ce
JB
32569@item l
32570(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
32571@end table
32572
32573In response to each query, the target will reply with a list of one or
b90a069a 32574more thread IDs, separated by commas.
e1aac25b 32575@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 32576ids (using the @samp{qs} form of the query), until the target responds
501994c0 32577with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
32578Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
32579fields.
c906108c 32580
b8ff78ce 32581@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 32582@cindex get thread-local storage address, remote request
b8ff78ce 32583@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
32584Fetch the address associated with thread local storage specified
32585by @var{thread-id}, @var{offset}, and @var{lm}.
32586
b90a069a
SL
32587@var{thread-id} is the thread ID associated with the
32588thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
32589
32590@var{offset} is the (big endian, hex encoded) offset associated with the
32591thread local variable. (This offset is obtained from the debug
32592information associated with the variable.)
32593
db2e3e2e 32594@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
ff2587ec
WZ
32595the load module associated with the thread local storage. For example,
32596a @sc{gnu}/Linux system will pass the link map address of the shared
32597object associated with the thread local storage under consideration.
32598Other operating environments may choose to represent the load module
32599differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
32600
32601Reply:
b8ff78ce
JB
32602@table @samp
32603@item @var{XX}@dots{}
ff2587ec
WZ
32604Hex encoded (big endian) bytes representing the address of the thread
32605local storage requested.
32606
b8ff78ce
JB
32607@item E @var{nn}
32608An error occurred. @var{nn} are hex digits.
ff2587ec 32609
b8ff78ce
JB
32610@item
32611An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
32612@end table
32613
711e434b
PM
32614@item qGetTIBAddr:@var{thread-id}
32615@cindex get thread information block address
32616@cindex @samp{qGetTIBAddr} packet
32617Fetch address of the Windows OS specific Thread Information Block.
32618
32619@var{thread-id} is the thread ID associated with the thread.
32620
32621Reply:
32622@table @samp
32623@item @var{XX}@dots{}
32624Hex encoded (big endian) bytes representing the linear address of the
32625thread information block.
32626
32627@item E @var{nn}
32628An error occured. This means that either the thread was not found, or the
32629address could not be retrieved.
32630
32631@item
32632An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
32633@end table
32634
b8ff78ce 32635@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
32636Obtain thread information from RTOS. Where: @var{startflag} (one hex
32637digit) is one to indicate the first query and zero to indicate a
32638subsequent query; @var{threadcount} (two hex digits) is the maximum
32639number of threads the response packet can contain; and @var{nextthread}
32640(eight hex digits), for subsequent queries (@var{startflag} is zero), is
32641returned in the response as @var{argthread}.
ee2d5c50 32642
b8ff78ce 32643Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
32644
32645Reply:
32646@table @samp
b8ff78ce 32647@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
32648Where: @var{count} (two hex digits) is the number of threads being
32649returned; @var{done} (one hex digit) is zero to indicate more threads
32650and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 32651digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 32652is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 32653digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 32654@end table
c906108c 32655
b8ff78ce 32656@item qOffsets
9c16f35a 32657@cindex section offsets, remote request
b8ff78ce 32658@cindex @samp{qOffsets} packet
31d99776
DJ
32659Get section offsets that the target used when relocating the downloaded
32660image.
c906108c 32661
ee2d5c50
AC
32662Reply:
32663@table @samp
31d99776
DJ
32664@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
32665Relocate the @code{Text} section by @var{xxx} from its original address.
32666Relocate the @code{Data} section by @var{yyy} from its original address.
32667If the object file format provides segment information (e.g.@: @sc{elf}
32668@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
32669segments by the supplied offsets.
32670
32671@emph{Note: while a @code{Bss} offset may be included in the response,
32672@value{GDBN} ignores this and instead applies the @code{Data} offset
32673to the @code{Bss} section.}
32674
32675@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
32676Relocate the first segment of the object file, which conventionally
32677contains program code, to a starting address of @var{xxx}. If
32678@samp{DataSeg} is specified, relocate the second segment, which
32679conventionally contains modifiable data, to a starting address of
32680@var{yyy}. @value{GDBN} will report an error if the object file
32681does not contain segment information, or does not contain at least
32682as many segments as mentioned in the reply. Extra segments are
32683kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
32684@end table
32685
b90a069a 32686@item qP @var{mode} @var{thread-id}
9c16f35a 32687@cindex thread information, remote request
b8ff78ce 32688@cindex @samp{qP} packet
b90a069a
SL
32689Returns information on @var{thread-id}. Where: @var{mode} is a hex
32690encoded 32 bit mode; @var{thread-id} is a thread ID
32691(@pxref{thread-id syntax}).
ee2d5c50 32692
aa56d27a
JB
32693Don't use this packet; use the @samp{qThreadExtraInfo} query instead
32694(see below).
32695
b8ff78ce 32696Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 32697
8b23ecc4
SL
32698@item QNonStop:1
32699@item QNonStop:0
32700@cindex non-stop mode, remote request
32701@cindex @samp{QNonStop} packet
32702@anchor{QNonStop}
32703Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
32704@xref{Remote Non-Stop}, for more information.
32705
32706Reply:
32707@table @samp
32708@item OK
32709The request succeeded.
32710
32711@item E @var{nn}
32712An error occurred. @var{nn} are hex digits.
32713
32714@item
32715An empty reply indicates that @samp{QNonStop} is not supported by
32716the stub.
32717@end table
32718
32719This packet is not probed by default; the remote stub must request it,
32720by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32721Use of this packet is controlled by the @code{set non-stop} command;
32722@pxref{Non-Stop Mode}.
32723
89be2091
DJ
32724@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
32725@cindex pass signals to inferior, remote request
32726@cindex @samp{QPassSignals} packet
23181151 32727@anchor{QPassSignals}
89be2091
DJ
32728Each listed @var{signal} should be passed directly to the inferior process.
32729Signals are numbered identically to continue packets and stop replies
32730(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
32731strictly greater than the previous item. These signals do not need to stop
32732the inferior, or be reported to @value{GDBN}. All other signals should be
32733reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
32734combine; any earlier @samp{QPassSignals} list is completely replaced by the
32735new list. This packet improves performance when using @samp{handle
32736@var{signal} nostop noprint pass}.
32737
32738Reply:
32739@table @samp
32740@item OK
32741The request succeeded.
32742
32743@item E @var{nn}
32744An error occurred. @var{nn} are hex digits.
32745
32746@item
32747An empty reply indicates that @samp{QPassSignals} is not supported by
32748the stub.
32749@end table
32750
32751Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 32752command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
32753This packet is not probed by default; the remote stub must request it,
32754by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32755
b8ff78ce 32756@item qRcmd,@var{command}
ff2587ec 32757@cindex execute remote command, remote request
b8ff78ce 32758@cindex @samp{qRcmd} packet
ff2587ec 32759@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
32760execution. Invalid commands should be reported using the output
32761string. Before the final result packet, the target may also respond
32762with a number of intermediate @samp{O@var{output}} console output
32763packets. @emph{Implementors should note that providing access to a
32764stubs's interpreter may have security implications}.
fa93a9d8 32765
ff2587ec
WZ
32766Reply:
32767@table @samp
32768@item OK
32769A command response with no output.
32770@item @var{OUTPUT}
32771A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 32772@item E @var{NN}
ff2587ec 32773Indicate a badly formed request.
b8ff78ce
JB
32774@item
32775An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 32776@end table
fa93a9d8 32777
aa56d27a
JB
32778(Note that the @code{qRcmd} packet's name is separated from the
32779command by a @samp{,}, not a @samp{:}, contrary to the naming
32780conventions above. Please don't use this packet as a model for new
32781packets.)
32782
08388c79
DE
32783@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
32784@cindex searching memory, in remote debugging
32785@cindex @samp{qSearch:memory} packet
32786@anchor{qSearch memory}
32787Search @var{length} bytes at @var{address} for @var{search-pattern}.
32788@var{address} and @var{length} are encoded in hex.
32789@var{search-pattern} is a sequence of bytes, hex encoded.
32790
32791Reply:
32792@table @samp
32793@item 0
32794The pattern was not found.
32795@item 1,address
32796The pattern was found at @var{address}.
32797@item E @var{NN}
32798A badly formed request or an error was encountered while searching memory.
32799@item
32800An empty reply indicates that @samp{qSearch:memory} is not recognized.
32801@end table
32802
a6f3e723
SL
32803@item QStartNoAckMode
32804@cindex @samp{QStartNoAckMode} packet
32805@anchor{QStartNoAckMode}
32806Request that the remote stub disable the normal @samp{+}/@samp{-}
32807protocol acknowledgments (@pxref{Packet Acknowledgment}).
32808
32809Reply:
32810@table @samp
32811@item OK
32812The stub has switched to no-acknowledgment mode.
32813@value{GDBN} acknowledges this reponse,
32814but neither the stub nor @value{GDBN} shall send or expect further
32815@samp{+}/@samp{-} acknowledgments in the current connection.
32816@item
32817An empty reply indicates that the stub does not support no-acknowledgment mode.
32818@end table
32819
be2a5f71
DJ
32820@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
32821@cindex supported packets, remote query
32822@cindex features of the remote protocol
32823@cindex @samp{qSupported} packet
0876f84a 32824@anchor{qSupported}
be2a5f71
DJ
32825Tell the remote stub about features supported by @value{GDBN}, and
32826query the stub for features it supports. This packet allows
32827@value{GDBN} and the remote stub to take advantage of each others'
32828features. @samp{qSupported} also consolidates multiple feature probes
32829at startup, to improve @value{GDBN} performance---a single larger
32830packet performs better than multiple smaller probe packets on
32831high-latency links. Some features may enable behavior which must not
32832be on by default, e.g.@: because it would confuse older clients or
32833stubs. Other features may describe packets which could be
32834automatically probed for, but are not. These features must be
32835reported before @value{GDBN} will use them. This ``default
32836unsupported'' behavior is not appropriate for all packets, but it
32837helps to keep the initial connection time under control with new
32838versions of @value{GDBN} which support increasing numbers of packets.
32839
32840Reply:
32841@table @samp
32842@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
32843The stub supports or does not support each returned @var{stubfeature},
32844depending on the form of each @var{stubfeature} (see below for the
32845possible forms).
32846@item
32847An empty reply indicates that @samp{qSupported} is not recognized,
32848or that no features needed to be reported to @value{GDBN}.
32849@end table
32850
32851The allowed forms for each feature (either a @var{gdbfeature} in the
32852@samp{qSupported} packet, or a @var{stubfeature} in the response)
32853are:
32854
32855@table @samp
32856@item @var{name}=@var{value}
32857The remote protocol feature @var{name} is supported, and associated
32858with the specified @var{value}. The format of @var{value} depends
32859on the feature, but it must not include a semicolon.
32860@item @var{name}+
32861The remote protocol feature @var{name} is supported, and does not
32862need an associated value.
32863@item @var{name}-
32864The remote protocol feature @var{name} is not supported.
32865@item @var{name}?
32866The remote protocol feature @var{name} may be supported, and
32867@value{GDBN} should auto-detect support in some other way when it is
32868needed. This form will not be used for @var{gdbfeature} notifications,
32869but may be used for @var{stubfeature} responses.
32870@end table
32871
32872Whenever the stub receives a @samp{qSupported} request, the
32873supplied set of @value{GDBN} features should override any previous
32874request. This allows @value{GDBN} to put the stub in a known
32875state, even if the stub had previously been communicating with
32876a different version of @value{GDBN}.
32877
b90a069a
SL
32878The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
32879are defined:
32880
32881@table @samp
32882@item multiprocess
32883This feature indicates whether @value{GDBN} supports multiprocess
32884extensions to the remote protocol. @value{GDBN} does not use such
32885extensions unless the stub also reports that it supports them by
32886including @samp{multiprocess+} in its @samp{qSupported} reply.
32887@xref{multiprocess extensions}, for details.
c8d5aac9
L
32888
32889@item xmlRegisters
32890This feature indicates that @value{GDBN} supports the XML target
32891description. If the stub sees @samp{xmlRegisters=} with target
32892specific strings separated by a comma, it will report register
32893description.
dde08ee1
PA
32894
32895@item qRelocInsn
32896This feature indicates whether @value{GDBN} supports the
32897@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
32898instruction reply packet}).
b90a069a
SL
32899@end table
32900
32901Stubs should ignore any unknown values for
be2a5f71
DJ
32902@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
32903packet supports receiving packets of unlimited length (earlier
b90a069a 32904versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
32905for @var{gdbfeature} may be defined in the future to let the stub take
32906advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
32907improvements in the remote protocol---the @samp{multiprocess} feature is
32908an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
32909of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
32910describes all the features it supports, and then the stub replies with
32911all the features it supports.
32912
32913Similarly, @value{GDBN} will silently ignore unrecognized stub feature
32914responses, as long as each response uses one of the standard forms.
32915
32916Some features are flags. A stub which supports a flag feature
32917should respond with a @samp{+} form response. Other features
32918require values, and the stub should respond with an @samp{=}
32919form response.
32920
32921Each feature has a default value, which @value{GDBN} will use if
32922@samp{qSupported} is not available or if the feature is not mentioned
32923in the @samp{qSupported} response. The default values are fixed; a
32924stub is free to omit any feature responses that match the defaults.
32925
32926Not all features can be probed, but for those which can, the probing
32927mechanism is useful: in some cases, a stub's internal
32928architecture may not allow the protocol layer to know some information
32929about the underlying target in advance. This is especially common in
32930stubs which may be configured for multiple targets.
32931
32932These are the currently defined stub features and their properties:
32933
cfa9d6d9 32934@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
32935@c NOTE: The first row should be @headitem, but we do not yet require
32936@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 32937@item Feature Name
be2a5f71
DJ
32938@tab Value Required
32939@tab Default
32940@tab Probe Allowed
32941
32942@item @samp{PacketSize}
32943@tab Yes
32944@tab @samp{-}
32945@tab No
32946
0876f84a
DJ
32947@item @samp{qXfer:auxv:read}
32948@tab No
32949@tab @samp{-}
32950@tab Yes
32951
23181151
DJ
32952@item @samp{qXfer:features:read}
32953@tab No
32954@tab @samp{-}
32955@tab Yes
32956
cfa9d6d9
DJ
32957@item @samp{qXfer:libraries:read}
32958@tab No
32959@tab @samp{-}
32960@tab Yes
32961
68437a39
DJ
32962@item @samp{qXfer:memory-map:read}
32963@tab No
32964@tab @samp{-}
32965@tab Yes
32966
0fb4aa4b
PA
32967@item @samp{qXfer:sdata:read}
32968@tab No
32969@tab @samp{-}
32970@tab Yes
32971
0e7f50da
UW
32972@item @samp{qXfer:spu:read}
32973@tab No
32974@tab @samp{-}
32975@tab Yes
32976
32977@item @samp{qXfer:spu:write}
32978@tab No
32979@tab @samp{-}
32980@tab Yes
32981
4aa995e1
PA
32982@item @samp{qXfer:siginfo:read}
32983@tab No
32984@tab @samp{-}
32985@tab Yes
32986
32987@item @samp{qXfer:siginfo:write}
32988@tab No
32989@tab @samp{-}
32990@tab Yes
32991
dc146f7c
VP
32992@item @samp{qXfer:threads:read}
32993@tab No
32994@tab @samp{-}
32995@tab Yes
32996
32997
8b23ecc4
SL
32998@item @samp{QNonStop}
32999@tab No
33000@tab @samp{-}
33001@tab Yes
33002
89be2091
DJ
33003@item @samp{QPassSignals}
33004@tab No
33005@tab @samp{-}
33006@tab Yes
33007
a6f3e723
SL
33008@item @samp{QStartNoAckMode}
33009@tab No
33010@tab @samp{-}
33011@tab Yes
33012
b90a069a
SL
33013@item @samp{multiprocess}
33014@tab No
33015@tab @samp{-}
33016@tab No
33017
782b2b07
SS
33018@item @samp{ConditionalTracepoints}
33019@tab No
33020@tab @samp{-}
33021@tab No
33022
0d772ac9
MS
33023@item @samp{ReverseContinue}
33024@tab No
2f8132f3 33025@tab @samp{-}
0d772ac9
MS
33026@tab No
33027
33028@item @samp{ReverseStep}
33029@tab No
2f8132f3 33030@tab @samp{-}
0d772ac9
MS
33031@tab No
33032
409873ef
SS
33033@item @samp{TracepointSource}
33034@tab No
33035@tab @samp{-}
33036@tab No
33037
d914c394
SS
33038@item @samp{QAllow}
33039@tab No
33040@tab @samp{-}
33041@tab No
33042
be2a5f71
DJ
33043@end multitable
33044
33045These are the currently defined stub features, in more detail:
33046
33047@table @samp
33048@cindex packet size, remote protocol
33049@item PacketSize=@var{bytes}
33050The remote stub can accept packets up to at least @var{bytes} in
33051length. @value{GDBN} will send packets up to this size for bulk
33052transfers, and will never send larger packets. This is a limit on the
33053data characters in the packet, including the frame and checksum.
33054There is no trailing NUL byte in a remote protocol packet; if the stub
33055stores packets in a NUL-terminated format, it should allow an extra
33056byte in its buffer for the NUL. If this stub feature is not supported,
33057@value{GDBN} guesses based on the size of the @samp{g} packet response.
33058
0876f84a
DJ
33059@item qXfer:auxv:read
33060The remote stub understands the @samp{qXfer:auxv:read} packet
33061(@pxref{qXfer auxiliary vector read}).
33062
23181151
DJ
33063@item qXfer:features:read
33064The remote stub understands the @samp{qXfer:features:read} packet
33065(@pxref{qXfer target description read}).
33066
cfa9d6d9
DJ
33067@item qXfer:libraries:read
33068The remote stub understands the @samp{qXfer:libraries:read} packet
33069(@pxref{qXfer library list read}).
33070
23181151
DJ
33071@item qXfer:memory-map:read
33072The remote stub understands the @samp{qXfer:memory-map:read} packet
33073(@pxref{qXfer memory map read}).
33074
0fb4aa4b
PA
33075@item qXfer:sdata:read
33076The remote stub understands the @samp{qXfer:sdata:read} packet
33077(@pxref{qXfer sdata read}).
33078
0e7f50da
UW
33079@item qXfer:spu:read
33080The remote stub understands the @samp{qXfer:spu:read} packet
33081(@pxref{qXfer spu read}).
33082
33083@item qXfer:spu:write
33084The remote stub understands the @samp{qXfer:spu:write} packet
33085(@pxref{qXfer spu write}).
33086
4aa995e1
PA
33087@item qXfer:siginfo:read
33088The remote stub understands the @samp{qXfer:siginfo:read} packet
33089(@pxref{qXfer siginfo read}).
33090
33091@item qXfer:siginfo:write
33092The remote stub understands the @samp{qXfer:siginfo:write} packet
33093(@pxref{qXfer siginfo write}).
33094
dc146f7c
VP
33095@item qXfer:threads:read
33096The remote stub understands the @samp{qXfer:threads:read} packet
33097(@pxref{qXfer threads read}).
33098
8b23ecc4
SL
33099@item QNonStop
33100The remote stub understands the @samp{QNonStop} packet
33101(@pxref{QNonStop}).
33102
23181151
DJ
33103@item QPassSignals
33104The remote stub understands the @samp{QPassSignals} packet
33105(@pxref{QPassSignals}).
33106
a6f3e723
SL
33107@item QStartNoAckMode
33108The remote stub understands the @samp{QStartNoAckMode} packet and
33109prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
33110
b90a069a
SL
33111@item multiprocess
33112@anchor{multiprocess extensions}
33113@cindex multiprocess extensions, in remote protocol
33114The remote stub understands the multiprocess extensions to the remote
33115protocol syntax. The multiprocess extensions affect the syntax of
33116thread IDs in both packets and replies (@pxref{thread-id syntax}), and
33117add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
33118replies. Note that reporting this feature indicates support for the
33119syntactic extensions only, not that the stub necessarily supports
33120debugging of more than one process at a time. The stub must not use
33121multiprocess extensions in packet replies unless @value{GDBN} has also
33122indicated it supports them in its @samp{qSupported} request.
33123
07e059b5
VP
33124@item qXfer:osdata:read
33125The remote stub understands the @samp{qXfer:osdata:read} packet
33126((@pxref{qXfer osdata read}).
33127
782b2b07
SS
33128@item ConditionalTracepoints
33129The remote stub accepts and implements conditional expressions defined
33130for tracepoints (@pxref{Tracepoint Conditions}).
33131
0d772ac9
MS
33132@item ReverseContinue
33133The remote stub accepts and implements the reverse continue packet
33134(@pxref{bc}).
33135
33136@item ReverseStep
33137The remote stub accepts and implements the reverse step packet
33138(@pxref{bs}).
33139
409873ef
SS
33140@item TracepointSource
33141The remote stub understands the @samp{QTDPsrc} packet that supplies
33142the source form of tracepoint definitions.
33143
d914c394
SS
33144@item QAllow
33145The remote stub understands the @samp{QAllow} packet.
33146
0fb4aa4b
PA
33147@item StaticTracepoint
33148@cindex static tracepoints, in remote protocol
33149The remote stub supports static tracepoints.
33150
be2a5f71
DJ
33151@end table
33152
b8ff78ce 33153@item qSymbol::
ff2587ec 33154@cindex symbol lookup, remote request
b8ff78ce 33155@cindex @samp{qSymbol} packet
ff2587ec
WZ
33156Notify the target that @value{GDBN} is prepared to serve symbol lookup
33157requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
33158
33159Reply:
ff2587ec 33160@table @samp
b8ff78ce 33161@item OK
ff2587ec 33162The target does not need to look up any (more) symbols.
b8ff78ce 33163@item qSymbol:@var{sym_name}
ff2587ec
WZ
33164The target requests the value of symbol @var{sym_name} (hex encoded).
33165@value{GDBN} may provide the value by using the
b8ff78ce
JB
33166@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
33167below.
ff2587ec 33168@end table
83761cbd 33169
b8ff78ce 33170@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
33171Set the value of @var{sym_name} to @var{sym_value}.
33172
33173@var{sym_name} (hex encoded) is the name of a symbol whose value the
33174target has previously requested.
33175
33176@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
33177@value{GDBN} cannot supply a value for @var{sym_name}, then this field
33178will be empty.
33179
33180Reply:
33181@table @samp
b8ff78ce 33182@item OK
ff2587ec 33183The target does not need to look up any (more) symbols.
b8ff78ce 33184@item qSymbol:@var{sym_name}
ff2587ec
WZ
33185The target requests the value of a new symbol @var{sym_name} (hex
33186encoded). @value{GDBN} will continue to supply the values of symbols
33187(if available), until the target ceases to request them.
fa93a9d8 33188@end table
0abb7bc7 33189
00bf0b85 33190@item qTBuffer
4daf5ac0 33191@item QTBuffer
d5551862
SS
33192@item QTDisconnected
33193@itemx QTDP
409873ef 33194@itemx QTDPsrc
d5551862 33195@itemx QTDV
00bf0b85
SS
33196@itemx qTfP
33197@itemx qTfV
9d29849a
JB
33198@itemx QTFrame
33199@xref{Tracepoint Packets}.
33200
b90a069a 33201@item qThreadExtraInfo,@var{thread-id}
ff2587ec 33202@cindex thread attributes info, remote request
b8ff78ce
JB
33203@cindex @samp{qThreadExtraInfo} packet
33204Obtain a printable string description of a thread's attributes from
b90a069a
SL
33205the target OS. @var{thread-id} is a thread ID;
33206see @ref{thread-id syntax}. This
b8ff78ce
JB
33207string may contain anything that the target OS thinks is interesting
33208for @value{GDBN} to tell the user about the thread. The string is
33209displayed in @value{GDBN}'s @code{info threads} display. Some
33210examples of possible thread extra info strings are @samp{Runnable}, or
33211@samp{Blocked on Mutex}.
ff2587ec
WZ
33212
33213Reply:
33214@table @samp
b8ff78ce
JB
33215@item @var{XX}@dots{}
33216Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
33217comprising the printable string containing the extra information about
33218the thread's attributes.
ff2587ec 33219@end table
814e32d7 33220
aa56d27a
JB
33221(Note that the @code{qThreadExtraInfo} packet's name is separated from
33222the command by a @samp{,}, not a @samp{:}, contrary to the naming
33223conventions above. Please don't use this packet as a model for new
33224packets.)
33225
00bf0b85
SS
33226@item QTSave
33227@item qTsP
33228@item qTsV
d5551862 33229@itemx QTStart
9d29849a
JB
33230@itemx QTStop
33231@itemx QTinit
33232@itemx QTro
33233@itemx qTStatus
d5551862 33234@itemx qTV
0fb4aa4b
PA
33235@itemx qTfSTM
33236@itemx qTsSTM
33237@itemx qTSTMat
9d29849a
JB
33238@xref{Tracepoint Packets}.
33239
0876f84a
DJ
33240@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
33241@cindex read special object, remote request
33242@cindex @samp{qXfer} packet
68437a39 33243@anchor{qXfer read}
0876f84a
DJ
33244Read uninterpreted bytes from the target's special data area
33245identified by the keyword @var{object}. Request @var{length} bytes
33246starting at @var{offset} bytes into the data. The content and
0e7f50da 33247encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
33248additional details about what data to access.
33249
33250Here are the specific requests of this form defined so far. All
33251@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
33252formats, listed below.
33253
33254@table @samp
33255@item qXfer:auxv:read::@var{offset},@var{length}
33256@anchor{qXfer auxiliary vector read}
33257Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 33258auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
33259
33260This packet is not probed by default; the remote stub must request it,
89be2091 33261by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 33262
23181151
DJ
33263@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
33264@anchor{qXfer target description read}
33265Access the @dfn{target description}. @xref{Target Descriptions}. The
33266annex specifies which XML document to access. The main description is
33267always loaded from the @samp{target.xml} annex.
33268
33269This packet is not probed by default; the remote stub must request it,
33270by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
33271
cfa9d6d9
DJ
33272@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
33273@anchor{qXfer library list read}
33274Access the target's list of loaded libraries. @xref{Library List Format}.
33275The annex part of the generic @samp{qXfer} packet must be empty
33276(@pxref{qXfer read}).
33277
33278Targets which maintain a list of libraries in the program's memory do
33279not need to implement this packet; it is designed for platforms where
33280the operating system manages the list of loaded libraries.
33281
33282This packet is not probed by default; the remote stub must request it,
33283by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
33284
68437a39
DJ
33285@item qXfer:memory-map:read::@var{offset},@var{length}
33286@anchor{qXfer memory map read}
79a6e687 33287Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
33288annex part of the generic @samp{qXfer} packet must be empty
33289(@pxref{qXfer read}).
33290
0e7f50da
UW
33291This packet is not probed by default; the remote stub must request it,
33292by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
33293
0fb4aa4b
PA
33294@item qXfer:sdata:read::@var{offset},@var{length}
33295@anchor{qXfer sdata read}
33296
33297Read contents of the extra collected static tracepoint marker
33298information. The annex part of the generic @samp{qXfer} packet must
33299be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
33300Action Lists}.
33301
33302This packet is not probed by default; the remote stub must request it,
33303by supplying an appropriate @samp{qSupported} response
33304(@pxref{qSupported}).
33305
4aa995e1
PA
33306@item qXfer:siginfo:read::@var{offset},@var{length}
33307@anchor{qXfer siginfo read}
33308Read contents of the extra signal information on the target
33309system. The annex part of the generic @samp{qXfer} packet must be
33310empty (@pxref{qXfer read}).
33311
33312This packet is not probed by default; the remote stub must request it,
33313by supplying an appropriate @samp{qSupported} response
33314(@pxref{qSupported}).
33315
0e7f50da
UW
33316@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
33317@anchor{qXfer spu read}
33318Read contents of an @code{spufs} file on the target system. The
33319annex specifies which file to read; it must be of the form
33320@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
33321in the target process, and @var{name} identifes the @code{spufs} file
33322in that context to be accessed.
33323
68437a39 33324This packet is not probed by default; the remote stub must request it,
07e059b5
VP
33325by supplying an appropriate @samp{qSupported} response
33326(@pxref{qSupported}).
33327
dc146f7c
VP
33328@item qXfer:threads:read::@var{offset},@var{length}
33329@anchor{qXfer threads read}
33330Access the list of threads on target. @xref{Thread List Format}. The
33331annex part of the generic @samp{qXfer} packet must be empty
33332(@pxref{qXfer read}).
33333
33334This packet is not probed by default; the remote stub must request it,
33335by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
33336
07e059b5
VP
33337@item qXfer:osdata:read::@var{offset},@var{length}
33338@anchor{qXfer osdata read}
33339Access the target's @dfn{operating system information}.
33340@xref{Operating System Information}.
33341
68437a39
DJ
33342@end table
33343
0876f84a
DJ
33344Reply:
33345@table @samp
33346@item m @var{data}
33347Data @var{data} (@pxref{Binary Data}) has been read from the
33348target. There may be more data at a higher address (although
33349it is permitted to return @samp{m} even for the last valid
33350block of data, as long as at least one byte of data was read).
33351@var{data} may have fewer bytes than the @var{length} in the
33352request.
33353
33354@item l @var{data}
33355Data @var{data} (@pxref{Binary Data}) has been read from the target.
33356There is no more data to be read. @var{data} may have fewer bytes
33357than the @var{length} in the request.
33358
33359@item l
33360The @var{offset} in the request is at the end of the data.
33361There is no more data to be read.
33362
33363@item E00
33364The request was malformed, or @var{annex} was invalid.
33365
33366@item E @var{nn}
33367The offset was invalid, or there was an error encountered reading the data.
33368@var{nn} is a hex-encoded @code{errno} value.
33369
33370@item
33371An empty reply indicates the @var{object} string was not recognized by
33372the stub, or that the object does not support reading.
33373@end table
33374
33375@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
33376@cindex write data into object, remote request
4aa995e1 33377@anchor{qXfer write}
0876f84a
DJ
33378Write uninterpreted bytes into the target's special data area
33379identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 33380into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 33381(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 33382is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
33383to access.
33384
0e7f50da
UW
33385Here are the specific requests of this form defined so far. All
33386@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
33387formats, listed below.
33388
33389@table @samp
4aa995e1
PA
33390@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
33391@anchor{qXfer siginfo write}
33392Write @var{data} to the extra signal information on the target system.
33393The annex part of the generic @samp{qXfer} packet must be
33394empty (@pxref{qXfer write}).
33395
33396This packet is not probed by default; the remote stub must request it,
33397by supplying an appropriate @samp{qSupported} response
33398(@pxref{qSupported}).
33399
84fcdf95 33400@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
33401@anchor{qXfer spu write}
33402Write @var{data} to an @code{spufs} file on the target system. The
33403annex specifies which file to write; it must be of the form
33404@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
33405in the target process, and @var{name} identifes the @code{spufs} file
33406in that context to be accessed.
33407
33408This packet is not probed by default; the remote stub must request it,
33409by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
33410@end table
0876f84a
DJ
33411
33412Reply:
33413@table @samp
33414@item @var{nn}
33415@var{nn} (hex encoded) is the number of bytes written.
33416This may be fewer bytes than supplied in the request.
33417
33418@item E00
33419The request was malformed, or @var{annex} was invalid.
33420
33421@item E @var{nn}
33422The offset was invalid, or there was an error encountered writing the data.
33423@var{nn} is a hex-encoded @code{errno} value.
33424
33425@item
33426An empty reply indicates the @var{object} string was not
33427recognized by the stub, or that the object does not support writing.
33428@end table
33429
33430@item qXfer:@var{object}:@var{operation}:@dots{}
33431Requests of this form may be added in the future. When a stub does
33432not recognize the @var{object} keyword, or its support for
33433@var{object} does not recognize the @var{operation} keyword, the stub
33434must respond with an empty packet.
33435
0b16c5cf
PA
33436@item qAttached:@var{pid}
33437@cindex query attached, remote request
33438@cindex @samp{qAttached} packet
33439Return an indication of whether the remote server attached to an
33440existing process or created a new process. When the multiprocess
33441protocol extensions are supported (@pxref{multiprocess extensions}),
33442@var{pid} is an integer in hexadecimal format identifying the target
33443process. Otherwise, @value{GDBN} will omit the @var{pid} field and
33444the query packet will be simplified as @samp{qAttached}.
33445
33446This query is used, for example, to know whether the remote process
33447should be detached or killed when a @value{GDBN} session is ended with
33448the @code{quit} command.
33449
33450Reply:
33451@table @samp
33452@item 1
33453The remote server attached to an existing process.
33454@item 0
33455The remote server created a new process.
33456@item E @var{NN}
33457A badly formed request or an error was encountered.
33458@end table
33459
ee2d5c50
AC
33460@end table
33461
a1dcb23a
DJ
33462@node Architecture-Specific Protocol Details
33463@section Architecture-Specific Protocol Details
33464
33465This section describes how the remote protocol is applied to specific
33466target architectures. Also see @ref{Standard Target Features}, for
33467details of XML target descriptions for each architecture.
33468
33469@subsection ARM
33470
33471@subsubsection Breakpoint Kinds
33472
33473These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
33474
33475@table @r
33476
33477@item 2
3347816-bit Thumb mode breakpoint.
33479
33480@item 3
3348132-bit Thumb mode (Thumb-2) breakpoint.
33482
33483@item 4
3348432-bit ARM mode breakpoint.
33485
33486@end table
33487
33488@subsection MIPS
33489
33490@subsubsection Register Packet Format
eb12ee30 33491
b8ff78ce 33492The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
33493In the below, some thirty-two bit registers are transferred as
33494sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
33495to fill the space allocated. Register bytes are transferred in target
33496byte order. The two nibbles within a register byte are transferred
ee2d5c50 33497most-significant - least-significant.
eb12ee30 33498
ee2d5c50 33499@table @r
eb12ee30 33500
8e04817f 33501@item MIPS32
ee2d5c50 33502
599b237a 33503All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
3350432 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
33505registers; fsr; fir; fp.
eb12ee30 33506
8e04817f 33507@item MIPS64
ee2d5c50 33508
599b237a 33509All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
33510thirty-two bit registers such as @code{sr}). The ordering is the same
33511as @code{MIPS32}.
eb12ee30 33512
ee2d5c50
AC
33513@end table
33514
9d29849a
JB
33515@node Tracepoint Packets
33516@section Tracepoint Packets
33517@cindex tracepoint packets
33518@cindex packets, tracepoint
33519
33520Here we describe the packets @value{GDBN} uses to implement
33521tracepoints (@pxref{Tracepoints}).
33522
33523@table @samp
33524
7a697b8d 33525@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
9d29849a
JB
33526Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
33527is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
33528the tracepoint is disabled. @var{step} is the tracepoint's step
7a697b8d
SS
33529count, and @var{pass} is its pass count. If an @samp{F} is present,
33530then the tracepoint is to be a fast tracepoint, and the @var{flen} is
33531the number of bytes that the target should copy elsewhere to make room
33532for the tracepoint. If an @samp{X} is present, it introduces a
33533tracepoint condition, which consists of a hexadecimal length, followed
33534by a comma and hex-encoded bytes, in a manner similar to action
33535encodings as described below. If the trailing @samp{-} is present,
33536further @samp{QTDP} packets will follow to specify this tracepoint's
33537actions.
9d29849a
JB
33538
33539Replies:
33540@table @samp
33541@item OK
33542The packet was understood and carried out.
dde08ee1
PA
33543@item qRelocInsn
33544@xref{Tracepoint Packets,,Relocate instruction reply packet}.
9d29849a
JB
33545@item
33546The packet was not recognized.
33547@end table
33548
33549@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
33550Define actions to be taken when a tracepoint is hit. @var{n} and
33551@var{addr} must be the same as in the initial @samp{QTDP} packet for
33552this tracepoint. This packet may only be sent immediately after
33553another @samp{QTDP} packet that ended with a @samp{-}. If the
33554trailing @samp{-} is present, further @samp{QTDP} packets will follow,
33555specifying more actions for this tracepoint.
33556
33557In the series of action packets for a given tracepoint, at most one
33558can have an @samp{S} before its first @var{action}. If such a packet
33559is sent, it and the following packets define ``while-stepping''
33560actions. Any prior packets define ordinary actions --- that is, those
33561taken when the tracepoint is first hit. If no action packet has an
33562@samp{S}, then all the packets in the series specify ordinary
33563tracepoint actions.
33564
33565The @samp{@var{action}@dots{}} portion of the packet is a series of
33566actions, concatenated without separators. Each action has one of the
33567following forms:
33568
33569@table @samp
33570
33571@item R @var{mask}
33572Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 33573a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
33574@var{i} should be collected. (The least significant bit is numbered
33575zero.) Note that @var{mask} may be any number of digits long; it may
33576not fit in a 32-bit word.
33577
33578@item M @var{basereg},@var{offset},@var{len}
33579Collect @var{len} bytes of memory starting at the address in register
33580number @var{basereg}, plus @var{offset}. If @var{basereg} is
33581@samp{-1}, then the range has a fixed address: @var{offset} is the
33582address of the lowest byte to collect. The @var{basereg},
599b237a 33583@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
33584values (the @samp{-1} value for @var{basereg} is a special case).
33585
33586@item X @var{len},@var{expr}
33587Evaluate @var{expr}, whose length is @var{len}, and collect memory as
33588it directs. @var{expr} is an agent expression, as described in
33589@ref{Agent Expressions}. Each byte of the expression is encoded as a
33590two-digit hex number in the packet; @var{len} is the number of bytes
33591in the expression (and thus one-half the number of hex digits in the
33592packet).
33593
33594@end table
33595
33596Any number of actions may be packed together in a single @samp{QTDP}
33597packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
33598length (400 bytes, for many stubs). There may be only one @samp{R}
33599action per tracepoint, and it must precede any @samp{M} or @samp{X}
33600actions. Any registers referred to by @samp{M} and @samp{X} actions
33601must be collected by a preceding @samp{R} action. (The
33602``while-stepping'' actions are treated as if they were attached to a
33603separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
33604
33605Replies:
33606@table @samp
33607@item OK
33608The packet was understood and carried out.
dde08ee1
PA
33609@item qRelocInsn
33610@xref{Tracepoint Packets,,Relocate instruction reply packet}.
9d29849a
JB
33611@item
33612The packet was not recognized.
33613@end table
33614
409873ef
SS
33615@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
33616@cindex @samp{QTDPsrc} packet
33617Specify a source string of tracepoint @var{n} at address @var{addr}.
33618This is useful to get accurate reproduction of the tracepoints
33619originally downloaded at the beginning of the trace run. @var{type}
33620is the name of the tracepoint part, such as @samp{cond} for the
33621tracepoint's conditional expression (see below for a list of types), while
33622@var{bytes} is the string, encoded in hexadecimal.
33623
33624@var{start} is the offset of the @var{bytes} within the overall source
33625string, while @var{slen} is the total length of the source string.
33626This is intended for handling source strings that are longer than will
33627fit in a single packet.
33628@c Add detailed example when this info is moved into a dedicated
33629@c tracepoint descriptions section.
33630
33631The available string types are @samp{at} for the location,
33632@samp{cond} for the conditional, and @samp{cmd} for an action command.
33633@value{GDBN} sends a separate packet for each command in the action
33634list, in the same order in which the commands are stored in the list.
33635
33636The target does not need to do anything with source strings except
33637report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
33638query packets.
33639
33640Although this packet is optional, and @value{GDBN} will only send it
33641if the target replies with @samp{TracepointSource} @xref{General
33642Query Packets}, it makes both disconnected tracing and trace files
33643much easier to use. Otherwise the user must be careful that the
33644tracepoints in effect while looking at trace frames are identical to
33645the ones in effect during the trace run; even a small discrepancy
33646could cause @samp{tdump} not to work, or a particular trace frame not
33647be found.
33648
f61e138d
SS
33649@item QTDV:@var{n}:@var{value}
33650@cindex define trace state variable, remote request
33651@cindex @samp{QTDV} packet
33652Create a new trace state variable, number @var{n}, with an initial
33653value of @var{value}, which is a 64-bit signed integer. Both @var{n}
33654and @var{value} are encoded as hexadecimal values. @value{GDBN} has
33655the option of not using this packet for initial values of zero; the
33656target should simply create the trace state variables as they are
33657mentioned in expressions.
33658
9d29849a
JB
33659@item QTFrame:@var{n}
33660Select the @var{n}'th tracepoint frame from the buffer, and use the
33661register and memory contents recorded there to answer subsequent
33662request packets from @value{GDBN}.
33663
33664A successful reply from the stub indicates that the stub has found the
33665requested frame. The response is a series of parts, concatenated
33666without separators, describing the frame we selected. Each part has
33667one of the following forms:
33668
33669@table @samp
33670@item F @var{f}
33671The selected frame is number @var{n} in the trace frame buffer;
599b237a 33672@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
33673was no frame matching the criteria in the request packet.
33674
33675@item T @var{t}
33676The selected trace frame records a hit of tracepoint number @var{t};
599b237a 33677@var{t} is a hexadecimal number.
9d29849a
JB
33678
33679@end table
33680
33681@item QTFrame:pc:@var{addr}
33682Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
33683currently selected frame whose PC is @var{addr};
599b237a 33684@var{addr} is a hexadecimal number.
9d29849a
JB
33685
33686@item QTFrame:tdp:@var{t}
33687Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
33688currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 33689is a hexadecimal number.
9d29849a
JB
33690
33691@item QTFrame:range:@var{start}:@var{end}
33692Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
33693currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 33694and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
33695numbers.
33696
33697@item QTFrame:outside:@var{start}:@var{end}
33698Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 33699frame @emph{outside} the given range of addresses (exclusive).
9d29849a
JB
33700
33701@item QTStart
dde08ee1
PA
33702Begin the tracepoint experiment. Begin collecting data from
33703tracepoint hits in the trace frame buffer. This packet supports the
33704@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
33705instruction reply packet}).
9d29849a
JB
33706
33707@item QTStop
33708End the tracepoint experiment. Stop collecting trace frames.
33709
33710@item QTinit
33711Clear the table of tracepoints, and empty the trace frame buffer.
33712
33713@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
33714Establish the given ranges of memory as ``transparent''. The stub
33715will answer requests for these ranges from memory's current contents,
33716if they were not collected as part of the tracepoint hit.
33717
33718@value{GDBN} uses this to mark read-only regions of memory, like those
33719containing program code. Since these areas never change, they should
33720still have the same contents they did when the tracepoint was hit, so
33721there's no reason for the stub to refuse to provide their contents.
33722
d5551862
SS
33723@item QTDisconnected:@var{value}
33724Set the choice to what to do with the tracing run when @value{GDBN}
33725disconnects from the target. A @var{value} of 1 directs the target to
33726continue the tracing run, while 0 tells the target to stop tracing if
33727@value{GDBN} is no longer in the picture.
33728
9d29849a
JB
33729@item qTStatus
33730Ask the stub if there is a trace experiment running right now.
33731
4daf5ac0
SS
33732The reply has the form:
33733
33734@table @samp
33735
33736@item T@var{running}@r{[};@var{field}@r{]}@dots{}
33737@var{running} is a single digit @code{1} if the trace is presently
33738running, or @code{0} if not. It is followed by semicolon-separated
33739optional fields that an agent may use to report additional status.
33740
33741@end table
33742
33743If the trace is not running, the agent may report any of several
33744explanations as one of the optional fields:
33745
33746@table @samp
33747
33748@item tnotrun:0
33749No trace has been run yet.
33750
33751@item tstop:0
33752The trace was stopped by a user-originated stop command.
33753
33754@item tfull:0
33755The trace stopped because the trace buffer filled up.
33756
33757@item tdisconnected:0
33758The trace stopped because @value{GDBN} disconnected from the target.
33759
33760@item tpasscount:@var{tpnum}
33761The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
33762
6c28cbf2
SS
33763@item terror:@var{text}:@var{tpnum}
33764The trace stopped because tracepoint @var{tpnum} had an error. The
33765string @var{text} is available to describe the nature of the error
33766(for instance, a divide by zero in the condition expression).
99b5e152 33767@var{text} is hex encoded.
6c28cbf2 33768
4daf5ac0
SS
33769@item tunknown:0
33770The trace stopped for some other reason.
33771
33772@end table
33773
33da3f1c
SS
33774Additional optional fields supply statistical and other information.
33775Although not required, they are extremely useful for users monitoring
33776the progress of a trace run. If a trace has stopped, and these
33777numbers are reported, they must reflect the state of the just-stopped
33778trace.
4daf5ac0 33779
9d29849a 33780@table @samp
4daf5ac0
SS
33781
33782@item tframes:@var{n}
33783The number of trace frames in the buffer.
33784
33785@item tcreated:@var{n}
33786The total number of trace frames created during the run. This may
33787be larger than the trace frame count, if the buffer is circular.
33788
33789@item tsize:@var{n}
33790The total size of the trace buffer, in bytes.
33791
33792@item tfree:@var{n}
33793The number of bytes still unused in the buffer.
33794
33da3f1c
SS
33795@item circular:@var{n}
33796The value of the circular trace buffer flag. @code{1} means that the
33797trace buffer is circular and old trace frames will be discarded if
33798necessary to make room, @code{0} means that the trace buffer is linear
33799and may fill up.
33800
33801@item disconn:@var{n}
33802The value of the disconnected tracing flag. @code{1} means that
33803tracing will continue after @value{GDBN} disconnects, @code{0} means
33804that the trace run will stop.
33805
9d29849a
JB
33806@end table
33807
f61e138d
SS
33808@item qTV:@var{var}
33809@cindex trace state variable value, remote request
33810@cindex @samp{qTV} packet
33811Ask the stub for the value of the trace state variable number @var{var}.
33812
33813Replies:
33814@table @samp
33815@item V@var{value}
33816The value of the variable is @var{value}. This will be the current
33817value of the variable if the user is examining a running target, or a
33818saved value if the variable was collected in the trace frame that the
33819user is looking at. Note that multiple requests may result in
33820different reply values, such as when requesting values while the
33821program is running.
33822
33823@item U
33824The value of the variable is unknown. This would occur, for example,
33825if the user is examining a trace frame in which the requested variable
33826was not collected.
9d29849a
JB
33827@end table
33828
d5551862
SS
33829@item qTfP
33830@itemx qTsP
33831These packets request data about tracepoints that are being used by
33832the target. @value{GDBN} sends @code{qTfP} to get the first piece
33833of data, and multiple @code{qTsP} to get additional pieces. Replies
33834to these packets generally take the form of the @code{QTDP} packets
33835that define tracepoints. (FIXME add detailed syntax)
33836
00bf0b85
SS
33837@item qTfV
33838@itemx qTsV
33839These packets request data about trace state variables that are on the
33840target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
33841and multiple @code{qTsV} to get additional variables. Replies to
33842these packets follow the syntax of the @code{QTDV} packets that define
33843trace state variables.
33844
0fb4aa4b
PA
33845@item qTfSTM
33846@itemx qTsSTM
33847These packets request data about static tracepoint markers that exist
33848in the target program. @value{GDBN} sends @code{qTfSTM} to get the
33849first piece of data, and multiple @code{qTsSTM} to get additional
33850pieces. Replies to these packets take the following form:
33851
33852Reply:
33853@table @samp
33854@item m @var{address}:@var{id}:@var{extra}
33855A single marker
33856@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
33857a comma-separated list of markers
33858@item l
33859(lower case letter @samp{L}) denotes end of list.
33860@item E @var{nn}
33861An error occurred. @var{nn} are hex digits.
33862@item
33863An empty reply indicates that the request is not supported by the
33864stub.
33865@end table
33866
33867@var{address} is encoded in hex.
33868@var{id} and @var{extra} are strings encoded in hex.
33869
33870In response to each query, the target will reply with a list of one or
33871more markers, separated by commas. @value{GDBN} will respond to each
33872reply with a request for more markers (using the @samp{qs} form of the
33873query), until the target responds with @samp{l} (lower-case ell, for
33874@dfn{last}).
33875
33876@item qTSTMat:@var{address}
33877This packets requests data about static tracepoint markers in the
33878target program at @var{address}. Replies to this packet follow the
33879syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
33880tracepoint markers.
33881
00bf0b85
SS
33882@item QTSave:@var{filename}
33883This packet directs the target to save trace data to the file name
33884@var{filename} in the target's filesystem. @var{filename} is encoded
33885as a hex string; the interpretation of the file name (relative vs
33886absolute, wild cards, etc) is up to the target.
33887
33888@item qTBuffer:@var{offset},@var{len}
33889Return up to @var{len} bytes of the current contents of trace buffer,
33890starting at @var{offset}. The trace buffer is treated as if it were
33891a contiguous collection of traceframes, as per the trace file format.
33892The reply consists as many hex-encoded bytes as the target can deliver
33893in a packet; it is not an error to return fewer than were asked for.
33894A reply consisting of just @code{l} indicates that no bytes are
33895available.
33896
4daf5ac0
SS
33897@item QTBuffer:circular:@var{value}
33898This packet directs the target to use a circular trace buffer if
33899@var{value} is 1, or a linear buffer if the value is 0.
33900
f61e138d 33901@end table
9d29849a 33902
dde08ee1
PA
33903@subsection Relocate instruction reply packet
33904When installing fast tracepoints in memory, the target may need to
33905relocate the instruction currently at the tracepoint address to a
33906different address in memory. For most instructions, a simple copy is
33907enough, but, for example, call instructions that implicitly push the
33908return address on the stack, and relative branches or other
33909PC-relative instructions require offset adjustment, so that the effect
33910of executing the instruction at a different address is the same as if
33911it had executed in the original location.
33912
33913In response to several of the tracepoint packets, the target may also
33914respond with a number of intermediate @samp{qRelocInsn} request
33915packets before the final result packet, to have @value{GDBN} handle
33916this relocation operation. If a packet supports this mechanism, its
33917documentation will explicitly say so. See for example the above
33918descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
33919format of the request is:
33920
33921@table @samp
33922@item qRelocInsn:@var{from};@var{to}
33923
33924This requests @value{GDBN} to copy instruction at address @var{from}
33925to address @var{to}, possibly adjusted so that executing the
33926instruction at @var{to} has the same effect as executing it at
33927@var{from}. @value{GDBN} writes the adjusted instruction to target
33928memory starting at @var{to}.
33929@end table
33930
33931Replies:
33932@table @samp
33933@item qRelocInsn:@var{adjusted_size}
33934Informs the stub the relocation is complete. @var{adjusted_size} is
33935the length in bytes of resulting relocated instruction sequence.
33936@item E @var{NN}
33937A badly formed request was detected, or an error was encountered while
33938relocating the instruction.
33939@end table
33940
a6b151f1
DJ
33941@node Host I/O Packets
33942@section Host I/O Packets
33943@cindex Host I/O, remote protocol
33944@cindex file transfer, remote protocol
33945
33946The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
33947operations on the far side of a remote link. For example, Host I/O is
33948used to upload and download files to a remote target with its own
33949filesystem. Host I/O uses the same constant values and data structure
33950layout as the target-initiated File-I/O protocol. However, the
33951Host I/O packets are structured differently. The target-initiated
33952protocol relies on target memory to store parameters and buffers.
33953Host I/O requests are initiated by @value{GDBN}, and the
33954target's memory is not involved. @xref{File-I/O Remote Protocol
33955Extension}, for more details on the target-initiated protocol.
33956
33957The Host I/O request packets all encode a single operation along with
33958its arguments. They have this format:
33959
33960@table @samp
33961
33962@item vFile:@var{operation}: @var{parameter}@dots{}
33963@var{operation} is the name of the particular request; the target
33964should compare the entire packet name up to the second colon when checking
33965for a supported operation. The format of @var{parameter} depends on
33966the operation. Numbers are always passed in hexadecimal. Negative
33967numbers have an explicit minus sign (i.e.@: two's complement is not
33968used). Strings (e.g.@: filenames) are encoded as a series of
33969hexadecimal bytes. The last argument to a system call may be a
33970buffer of escaped binary data (@pxref{Binary Data}).
33971
33972@end table
33973
33974The valid responses to Host I/O packets are:
33975
33976@table @samp
33977
33978@item F @var{result} [, @var{errno}] [; @var{attachment}]
33979@var{result} is the integer value returned by this operation, usually
33980non-negative for success and -1 for errors. If an error has occured,
33981@var{errno} will be included in the result. @var{errno} will have a
33982value defined by the File-I/O protocol (@pxref{Errno Values}). For
33983operations which return data, @var{attachment} supplies the data as a
33984binary buffer. Binary buffers in response packets are escaped in the
33985normal way (@pxref{Binary Data}). See the individual packet
33986documentation for the interpretation of @var{result} and
33987@var{attachment}.
33988
33989@item
33990An empty response indicates that this operation is not recognized.
33991
33992@end table
33993
33994These are the supported Host I/O operations:
33995
33996@table @samp
33997@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
33998Open a file at @var{pathname} and return a file descriptor for it, or
33999return -1 if an error occurs. @var{pathname} is a string,
34000@var{flags} is an integer indicating a mask of open flags
34001(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
34002of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 34003@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
34004
34005@item vFile:close: @var{fd}
34006Close the open file corresponding to @var{fd} and return 0, or
34007-1 if an error occurs.
34008
34009@item vFile:pread: @var{fd}, @var{count}, @var{offset}
34010Read data from the open file corresponding to @var{fd}. Up to
34011@var{count} bytes will be read from the file, starting at @var{offset}
34012relative to the start of the file. The target may read fewer bytes;
34013common reasons include packet size limits and an end-of-file
34014condition. The number of bytes read is returned. Zero should only be
34015returned for a successful read at the end of the file, or if
34016@var{count} was zero.
34017
34018The data read should be returned as a binary attachment on success.
34019If zero bytes were read, the response should include an empty binary
34020attachment (i.e.@: a trailing semicolon). The return value is the
34021number of target bytes read; the binary attachment may be longer if
34022some characters were escaped.
34023
34024@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
34025Write @var{data} (a binary buffer) to the open file corresponding
34026to @var{fd}. Start the write at @var{offset} from the start of the
34027file. Unlike many @code{write} system calls, there is no
34028separate @var{count} argument; the length of @var{data} in the
34029packet is used. @samp{vFile:write} returns the number of bytes written,
34030which may be shorter than the length of @var{data}, or -1 if an
34031error occurred.
34032
34033@item vFile:unlink: @var{pathname}
34034Delete the file at @var{pathname} on the target. Return 0,
34035or -1 if an error occurs. @var{pathname} is a string.
34036
34037@end table
34038
9a6253be
KB
34039@node Interrupts
34040@section Interrupts
34041@cindex interrupts (remote protocol)
34042
34043When a program on the remote target is running, @value{GDBN} may
9a7071a8
JB
34044attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
34045a @code{BREAK} followed by @code{g},
34046control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
34047
34048The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
34049mechanism and may, in fact, be undefined. @value{GDBN} does not
34050currently define a @code{BREAK} mechanism for any of the network
34051interfaces except for TCP, in which case @value{GDBN} sends the
34052@code{telnet} BREAK sequence.
9a6253be
KB
34053
34054@samp{Ctrl-C}, on the other hand, is defined and implemented for all
34055transport mechanisms. It is represented by sending the single byte
34056@code{0x03} without any of the usual packet overhead described in
34057the Overview section (@pxref{Overview}). When a @code{0x03} byte is
34058transmitted as part of a packet, it is considered to be packet data
34059and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 34060(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
34061@code{0x03} as part of its packet.
34062
9a7071a8
JB
34063@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
34064When Linux kernel receives this sequence from serial port,
34065it stops execution and connects to gdb.
34066
9a6253be
KB
34067Stubs are not required to recognize these interrupt mechanisms and the
34068precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
34069implementation defined. If the target supports debugging of multiple
34070threads and/or processes, it should attempt to interrupt all
34071currently-executing threads and processes.
34072If the stub is successful at interrupting the
34073running program, it should send one of the stop
34074reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
34075of successfully stopping the program in all-stop mode, and a stop reply
34076for each stopped thread in non-stop mode.
34077Interrupts received while the
34078program is stopped are discarded.
34079
34080@node Notification Packets
34081@section Notification Packets
34082@cindex notification packets
34083@cindex packets, notification
34084
34085The @value{GDBN} remote serial protocol includes @dfn{notifications},
34086packets that require no acknowledgment. Both the GDB and the stub
34087may send notifications (although the only notifications defined at
34088present are sent by the stub). Notifications carry information
34089without incurring the round-trip latency of an acknowledgment, and so
34090are useful for low-impact communications where occasional packet loss
34091is not a problem.
34092
34093A notification packet has the form @samp{% @var{data} #
34094@var{checksum}}, where @var{data} is the content of the notification,
34095and @var{checksum} is a checksum of @var{data}, computed and formatted
34096as for ordinary @value{GDBN} packets. A notification's @var{data}
34097never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
34098receiving a notification, the recipient sends no @samp{+} or @samp{-}
34099to acknowledge the notification's receipt or to report its corruption.
34100
34101Every notification's @var{data} begins with a name, which contains no
34102colon characters, followed by a colon character.
34103
34104Recipients should silently ignore corrupted notifications and
34105notifications they do not understand. Recipients should restart
34106timeout periods on receipt of a well-formed notification, whether or
34107not they understand it.
34108
34109Senders should only send the notifications described here when this
34110protocol description specifies that they are permitted. In the
34111future, we may extend the protocol to permit existing notifications in
34112new contexts; this rule helps older senders avoid confusing newer
34113recipients.
34114
34115(Older versions of @value{GDBN} ignore bytes received until they see
34116the @samp{$} byte that begins an ordinary packet, so new stubs may
34117transmit notifications without fear of confusing older clients. There
34118are no notifications defined for @value{GDBN} to send at the moment, but we
34119assume that most older stubs would ignore them, as well.)
34120
34121The following notification packets from the stub to @value{GDBN} are
34122defined:
34123
34124@table @samp
34125@item Stop: @var{reply}
34126Report an asynchronous stop event in non-stop mode.
34127The @var{reply} has the form of a stop reply, as
34128described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
34129for information on how these notifications are acknowledged by
34130@value{GDBN}.
34131@end table
34132
34133@node Remote Non-Stop
34134@section Remote Protocol Support for Non-Stop Mode
34135
34136@value{GDBN}'s remote protocol supports non-stop debugging of
34137multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
34138supports non-stop mode, it should report that to @value{GDBN} by including
34139@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
34140
34141@value{GDBN} typically sends a @samp{QNonStop} packet only when
34142establishing a new connection with the stub. Entering non-stop mode
34143does not alter the state of any currently-running threads, but targets
34144must stop all threads in any already-attached processes when entering
34145all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
34146probe the target state after a mode change.
34147
34148In non-stop mode, when an attached process encounters an event that
34149would otherwise be reported with a stop reply, it uses the
34150asynchronous notification mechanism (@pxref{Notification Packets}) to
34151inform @value{GDBN}. In contrast to all-stop mode, where all threads
34152in all processes are stopped when a stop reply is sent, in non-stop
34153mode only the thread reporting the stop event is stopped. That is,
34154when reporting a @samp{S} or @samp{T} response to indicate completion
34155of a step operation, hitting a breakpoint, or a fault, only the
34156affected thread is stopped; any other still-running threads continue
34157to run. When reporting a @samp{W} or @samp{X} response, all running
34158threads belonging to other attached processes continue to run.
34159
34160Only one stop reply notification at a time may be pending; if
34161additional stop events occur before @value{GDBN} has acknowledged the
34162previous notification, they must be queued by the stub for later
34163synchronous transmission in response to @samp{vStopped} packets from
34164@value{GDBN}. Because the notification mechanism is unreliable,
34165the stub is permitted to resend a stop reply notification
34166if it believes @value{GDBN} may not have received it. @value{GDBN}
34167ignores additional stop reply notifications received before it has
34168finished processing a previous notification and the stub has completed
34169sending any queued stop events.
34170
34171Otherwise, @value{GDBN} must be prepared to receive a stop reply
34172notification at any time. Specifically, they may appear when
34173@value{GDBN} is not otherwise reading input from the stub, or when
34174@value{GDBN} is expecting to read a normal synchronous response or a
34175@samp{+}/@samp{-} acknowledgment to a packet it has sent.
34176Notification packets are distinct from any other communication from
34177the stub so there is no ambiguity.
34178
34179After receiving a stop reply notification, @value{GDBN} shall
34180acknowledge it by sending a @samp{vStopped} packet (@pxref{vStopped packet})
34181as a regular, synchronous request to the stub. Such acknowledgment
34182is not required to happen immediately, as @value{GDBN} is permitted to
34183send other, unrelated packets to the stub first, which the stub should
34184process normally.
34185
34186Upon receiving a @samp{vStopped} packet, if the stub has other queued
34187stop events to report to @value{GDBN}, it shall respond by sending a
34188normal stop reply response. @value{GDBN} shall then send another
34189@samp{vStopped} packet to solicit further responses; again, it is
34190permitted to send other, unrelated packets as well which the stub
34191should process normally.
34192
34193If the stub receives a @samp{vStopped} packet and there are no
34194additional stop events to report, the stub shall return an @samp{OK}
34195response. At this point, if further stop events occur, the stub shall
34196send a new stop reply notification, @value{GDBN} shall accept the
34197notification, and the process shall be repeated.
34198
34199In non-stop mode, the target shall respond to the @samp{?} packet as
34200follows. First, any incomplete stop reply notification/@samp{vStopped}
34201sequence in progress is abandoned. The target must begin a new
34202sequence reporting stop events for all stopped threads, whether or not
34203it has previously reported those events to @value{GDBN}. The first
34204stop reply is sent as a synchronous reply to the @samp{?} packet, and
34205subsequent stop replies are sent as responses to @samp{vStopped} packets
34206using the mechanism described above. The target must not send
34207asynchronous stop reply notifications until the sequence is complete.
34208If all threads are running when the target receives the @samp{?} packet,
34209or if the target is not attached to any process, it shall respond
34210@samp{OK}.
9a6253be 34211
a6f3e723
SL
34212@node Packet Acknowledgment
34213@section Packet Acknowledgment
34214
34215@cindex acknowledgment, for @value{GDBN} remote
34216@cindex packet acknowledgment, for @value{GDBN} remote
34217By default, when either the host or the target machine receives a packet,
34218the first response expected is an acknowledgment: either @samp{+} (to indicate
34219the package was received correctly) or @samp{-} (to request retransmission).
34220This mechanism allows the @value{GDBN} remote protocol to operate over
34221unreliable transport mechanisms, such as a serial line.
34222
34223In cases where the transport mechanism is itself reliable (such as a pipe or
34224TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
34225It may be desirable to disable them in that case to reduce communication
34226overhead, or for other reasons. This can be accomplished by means of the
34227@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
34228
34229When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
34230expect @samp{+}/@samp{-} protocol acknowledgments. The packet
34231and response format still includes the normal checksum, as described in
34232@ref{Overview}, but the checksum may be ignored by the receiver.
34233
34234If the stub supports @samp{QStartNoAckMode} and prefers to operate in
34235no-acknowledgment mode, it should report that to @value{GDBN}
34236by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
34237@pxref{qSupported}.
34238If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
34239disabled via the @code{set remote noack-packet off} command
34240(@pxref{Remote Configuration}),
34241@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
34242Only then may the stub actually turn off packet acknowledgments.
34243@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
34244response, which can be safely ignored by the stub.
34245
34246Note that @code{set remote noack-packet} command only affects negotiation
34247between @value{GDBN} and the stub when subsequent connections are made;
34248it does not affect the protocol acknowledgment state for any current
34249connection.
34250Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
34251new connection is established,
34252there is also no protocol request to re-enable the acknowledgments
34253for the current connection, once disabled.
34254
ee2d5c50
AC
34255@node Examples
34256@section Examples
eb12ee30 34257
8e04817f
AC
34258Example sequence of a target being re-started. Notice how the restart
34259does not get any direct output:
eb12ee30 34260
474c8240 34261@smallexample
d2c6833e
AC
34262-> @code{R00}
34263<- @code{+}
8e04817f 34264@emph{target restarts}
d2c6833e 34265-> @code{?}
8e04817f 34266<- @code{+}
d2c6833e
AC
34267<- @code{T001:1234123412341234}
34268-> @code{+}
474c8240 34269@end smallexample
eb12ee30 34270
8e04817f 34271Example sequence of a target being stepped by a single instruction:
eb12ee30 34272
474c8240 34273@smallexample
d2c6833e 34274-> @code{G1445@dots{}}
8e04817f 34275<- @code{+}
d2c6833e
AC
34276-> @code{s}
34277<- @code{+}
34278@emph{time passes}
34279<- @code{T001:1234123412341234}
8e04817f 34280-> @code{+}
d2c6833e 34281-> @code{g}
8e04817f 34282<- @code{+}
d2c6833e
AC
34283<- @code{1455@dots{}}
34284-> @code{+}
474c8240 34285@end smallexample
eb12ee30 34286
79a6e687
BW
34287@node File-I/O Remote Protocol Extension
34288@section File-I/O Remote Protocol Extension
0ce1b118
CV
34289@cindex File-I/O remote protocol extension
34290
34291@menu
34292* File-I/O Overview::
79a6e687
BW
34293* Protocol Basics::
34294* The F Request Packet::
34295* The F Reply Packet::
34296* The Ctrl-C Message::
0ce1b118 34297* Console I/O::
79a6e687 34298* List of Supported Calls::
db2e3e2e 34299* Protocol-specific Representation of Datatypes::
0ce1b118
CV
34300* Constants::
34301* File-I/O Examples::
34302@end menu
34303
34304@node File-I/O Overview
34305@subsection File-I/O Overview
34306@cindex file-i/o overview
34307
9c16f35a 34308The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 34309target to use the host's file system and console I/O to perform various
0ce1b118 34310system calls. System calls on the target system are translated into a
fc320d37
SL
34311remote protocol packet to the host system, which then performs the needed
34312actions and returns a response packet to the target system.
0ce1b118
CV
34313This simulates file system operations even on targets that lack file systems.
34314
fc320d37
SL
34315The protocol is defined to be independent of both the host and target systems.
34316It uses its own internal representation of datatypes and values. Both
0ce1b118 34317@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
34318translating the system-dependent value representations into the internal
34319protocol representations when data is transmitted.
0ce1b118 34320
fc320d37
SL
34321The communication is synchronous. A system call is possible only when
34322@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
34323or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 34324the target is stopped to allow deterministic access to the target's
fc320d37
SL
34325memory. Therefore File-I/O is not interruptible by target signals. On
34326the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 34327(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
34328
34329The target's request to perform a host system call does not finish
34330the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
34331after finishing the system call, the target returns to continuing the
34332previous activity (continue, step). No additional continue or step
34333request from @value{GDBN} is required.
34334
34335@smallexample
f7dc1244 34336(@value{GDBP}) continue
0ce1b118
CV
34337 <- target requests 'system call X'
34338 target is stopped, @value{GDBN} executes system call
3f94c067
BW
34339 -> @value{GDBN} returns result
34340 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
34341 <- target hits breakpoint and sends a Txx packet
34342@end smallexample
34343
fc320d37
SL
34344The protocol only supports I/O on the console and to regular files on
34345the host file system. Character or block special devices, pipes,
34346named pipes, sockets or any other communication method on the host
0ce1b118
CV
34347system are not supported by this protocol.
34348
8b23ecc4
SL
34349File I/O is not supported in non-stop mode.
34350
79a6e687
BW
34351@node Protocol Basics
34352@subsection Protocol Basics
0ce1b118
CV
34353@cindex protocol basics, file-i/o
34354
fc320d37
SL
34355The File-I/O protocol uses the @code{F} packet as the request as well
34356as reply packet. Since a File-I/O system call can only occur when
34357@value{GDBN} is waiting for a response from the continuing or stepping target,
34358the File-I/O request is a reply that @value{GDBN} has to expect as a result
34359of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
34360This @code{F} packet contains all information needed to allow @value{GDBN}
34361to call the appropriate host system call:
34362
34363@itemize @bullet
b383017d 34364@item
0ce1b118
CV
34365A unique identifier for the requested system call.
34366
34367@item
34368All parameters to the system call. Pointers are given as addresses
34369in the target memory address space. Pointers to strings are given as
b383017d 34370pointer/length pair. Numerical values are given as they are.
db2e3e2e 34371Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
34372
34373@end itemize
34374
fc320d37 34375At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
34376
34377@itemize @bullet
b383017d 34378@item
fc320d37
SL
34379If the parameters include pointer values to data needed as input to a
34380system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
34381standard @code{m} packet request. This additional communication has to be
34382expected by the target implementation and is handled as any other @code{m}
34383packet.
34384
34385@item
34386@value{GDBN} translates all value from protocol representation to host
34387representation as needed. Datatypes are coerced into the host types.
34388
34389@item
fc320d37 34390@value{GDBN} calls the system call.
0ce1b118
CV
34391
34392@item
34393It then coerces datatypes back to protocol representation.
34394
34395@item
fc320d37
SL
34396If the system call is expected to return data in buffer space specified
34397by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
34398target using a @code{M} or @code{X} packet. This packet has to be expected
34399by the target implementation and is handled as any other @code{M} or @code{X}
34400packet.
34401
34402@end itemize
34403
34404Eventually @value{GDBN} replies with another @code{F} packet which contains all
34405necessary information for the target to continue. This at least contains
34406
34407@itemize @bullet
34408@item
34409Return value.
34410
34411@item
34412@code{errno}, if has been changed by the system call.
34413
34414@item
34415``Ctrl-C'' flag.
34416
34417@end itemize
34418
34419After having done the needed type and value coercion, the target continues
34420the latest continue or step action.
34421
79a6e687
BW
34422@node The F Request Packet
34423@subsection The @code{F} Request Packet
0ce1b118
CV
34424@cindex file-i/o request packet
34425@cindex @code{F} request packet
34426
34427The @code{F} request packet has the following format:
34428
34429@table @samp
fc320d37 34430@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
34431
34432@var{call-id} is the identifier to indicate the host system call to be called.
34433This is just the name of the function.
34434
fc320d37
SL
34435@var{parameter@dots{}} are the parameters to the system call.
34436Parameters are hexadecimal integer values, either the actual values in case
34437of scalar datatypes, pointers to target buffer space in case of compound
34438datatypes and unspecified memory areas, or pointer/length pairs in case
34439of string parameters. These are appended to the @var{call-id} as a
34440comma-delimited list. All values are transmitted in ASCII
34441string representation, pointer/length pairs separated by a slash.
0ce1b118 34442
b383017d 34443@end table
0ce1b118 34444
fc320d37 34445
0ce1b118 34446
79a6e687
BW
34447@node The F Reply Packet
34448@subsection The @code{F} Reply Packet
0ce1b118
CV
34449@cindex file-i/o reply packet
34450@cindex @code{F} reply packet
34451
34452The @code{F} reply packet has the following format:
34453
34454@table @samp
34455
d3bdde98 34456@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
34457
34458@var{retcode} is the return code of the system call as hexadecimal value.
34459
db2e3e2e
BW
34460@var{errno} is the @code{errno} set by the call, in protocol-specific
34461representation.
0ce1b118
CV
34462This parameter can be omitted if the call was successful.
34463
fc320d37
SL
34464@var{Ctrl-C flag} is only sent if the user requested a break. In this
34465case, @var{errno} must be sent as well, even if the call was successful.
34466The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
34467
34468@smallexample
34469F0,0,C
34470@end smallexample
34471
34472@noindent
fc320d37 34473or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
34474
34475@smallexample
34476F-1,4,C
34477@end smallexample
34478
34479@noindent
db2e3e2e 34480assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
34481
34482@end table
34483
0ce1b118 34484
79a6e687
BW
34485@node The Ctrl-C Message
34486@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
34487@cindex ctrl-c message, in file-i/o protocol
34488
c8aa23ab 34489If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 34490reply packet (@pxref{The F Reply Packet}),
fc320d37 34491the target should behave as if it had
0ce1b118 34492gotten a break message. The meaning for the target is ``system call
fc320d37 34493interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 34494(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 34495packet.
fc320d37
SL
34496
34497It's important for the target to know in which
34498state the system call was interrupted. There are two possible cases:
0ce1b118
CV
34499
34500@itemize @bullet
34501@item
34502The system call hasn't been performed on the host yet.
34503
34504@item
34505The system call on the host has been finished.
34506
34507@end itemize
34508
34509These two states can be distinguished by the target by the value of the
34510returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
34511call hasn't been performed. This is equivalent to the @code{EINTR} handling
34512on POSIX systems. In any other case, the target may presume that the
fc320d37 34513system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
34514as if the break message arrived right after the system call.
34515
fc320d37 34516@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
34517yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
34518@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
34519before the user requests a break, the full action must be finished by
34520@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
34521The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
34522or the full action has been completed.
34523
34524@node Console I/O
34525@subsection Console I/O
34526@cindex console i/o as part of file-i/o
34527
d3e8051b 34528By default and if not explicitly closed by the target system, the file
0ce1b118
CV
34529descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
34530on the @value{GDBN} console is handled as any other file output operation
34531(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
34532by @value{GDBN} so that after the target read request from file descriptor
345330 all following typing is buffered until either one of the following
34534conditions is met:
34535
34536@itemize @bullet
34537@item
c8aa23ab 34538The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
34539@code{read}
34540system call is treated as finished.
34541
34542@item
7f9087cb 34543The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 34544newline.
0ce1b118
CV
34545
34546@item
c8aa23ab
EZ
34547The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
34548character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
34549
34550@end itemize
34551
fc320d37
SL
34552If the user has typed more characters than fit in the buffer given to
34553the @code{read} call, the trailing characters are buffered in @value{GDBN} until
34554either another @code{read(0, @dots{})} is requested by the target, or debugging
34555is stopped at the user's request.
0ce1b118 34556
0ce1b118 34557
79a6e687
BW
34558@node List of Supported Calls
34559@subsection List of Supported Calls
0ce1b118
CV
34560@cindex list of supported file-i/o calls
34561
34562@menu
34563* open::
34564* close::
34565* read::
34566* write::
34567* lseek::
34568* rename::
34569* unlink::
34570* stat/fstat::
34571* gettimeofday::
34572* isatty::
34573* system::
34574@end menu
34575
34576@node open
34577@unnumberedsubsubsec open
34578@cindex open, file-i/o system call
34579
fc320d37
SL
34580@table @asis
34581@item Synopsis:
0ce1b118 34582@smallexample
0ce1b118
CV
34583int open(const char *pathname, int flags);
34584int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
34585@end smallexample
34586
fc320d37
SL
34587@item Request:
34588@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
34589
0ce1b118 34590@noindent
fc320d37 34591@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
34592
34593@table @code
b383017d 34594@item O_CREAT
0ce1b118
CV
34595If the file does not exist it will be created. The host
34596rules apply as far as file ownership and time stamps
34597are concerned.
34598
b383017d 34599@item O_EXCL
fc320d37 34600When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
34601an error and open() fails.
34602
b383017d 34603@item O_TRUNC
0ce1b118 34604If the file already exists and the open mode allows
fc320d37
SL
34605writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
34606truncated to zero length.
0ce1b118 34607
b383017d 34608@item O_APPEND
0ce1b118
CV
34609The file is opened in append mode.
34610
b383017d 34611@item O_RDONLY
0ce1b118
CV
34612The file is opened for reading only.
34613
b383017d 34614@item O_WRONLY
0ce1b118
CV
34615The file is opened for writing only.
34616
b383017d 34617@item O_RDWR
0ce1b118 34618The file is opened for reading and writing.
fc320d37 34619@end table
0ce1b118
CV
34620
34621@noindent
fc320d37 34622Other bits are silently ignored.
0ce1b118 34623
0ce1b118
CV
34624
34625@noindent
fc320d37 34626@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
34627
34628@table @code
b383017d 34629@item S_IRUSR
0ce1b118
CV
34630User has read permission.
34631
b383017d 34632@item S_IWUSR
0ce1b118
CV
34633User has write permission.
34634
b383017d 34635@item S_IRGRP
0ce1b118
CV
34636Group has read permission.
34637
b383017d 34638@item S_IWGRP
0ce1b118
CV
34639Group has write permission.
34640
b383017d 34641@item S_IROTH
0ce1b118
CV
34642Others have read permission.
34643
b383017d 34644@item S_IWOTH
0ce1b118 34645Others have write permission.
fc320d37 34646@end table
0ce1b118
CV
34647
34648@noindent
fc320d37 34649Other bits are silently ignored.
0ce1b118 34650
0ce1b118 34651
fc320d37
SL
34652@item Return value:
34653@code{open} returns the new file descriptor or -1 if an error
34654occurred.
0ce1b118 34655
fc320d37 34656@item Errors:
0ce1b118
CV
34657
34658@table @code
b383017d 34659@item EEXIST
fc320d37 34660@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 34661
b383017d 34662@item EISDIR
fc320d37 34663@var{pathname} refers to a directory.
0ce1b118 34664
b383017d 34665@item EACCES
0ce1b118
CV
34666The requested access is not allowed.
34667
34668@item ENAMETOOLONG
fc320d37 34669@var{pathname} was too long.
0ce1b118 34670
b383017d 34671@item ENOENT
fc320d37 34672A directory component in @var{pathname} does not exist.
0ce1b118 34673
b383017d 34674@item ENODEV
fc320d37 34675@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 34676
b383017d 34677@item EROFS
fc320d37 34678@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
34679write access was requested.
34680
b383017d 34681@item EFAULT
fc320d37 34682@var{pathname} is an invalid pointer value.
0ce1b118 34683
b383017d 34684@item ENOSPC
0ce1b118
CV
34685No space on device to create the file.
34686
b383017d 34687@item EMFILE
0ce1b118
CV
34688The process already has the maximum number of files open.
34689
b383017d 34690@item ENFILE
0ce1b118
CV
34691The limit on the total number of files open on the system
34692has been reached.
34693
b383017d 34694@item EINTR
0ce1b118
CV
34695The call was interrupted by the user.
34696@end table
34697
fc320d37
SL
34698@end table
34699
0ce1b118
CV
34700@node close
34701@unnumberedsubsubsec close
34702@cindex close, file-i/o system call
34703
fc320d37
SL
34704@table @asis
34705@item Synopsis:
0ce1b118 34706@smallexample
0ce1b118 34707int close(int fd);
fc320d37 34708@end smallexample
0ce1b118 34709
fc320d37
SL
34710@item Request:
34711@samp{Fclose,@var{fd}}
0ce1b118 34712
fc320d37
SL
34713@item Return value:
34714@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 34715
fc320d37 34716@item Errors:
0ce1b118
CV
34717
34718@table @code
b383017d 34719@item EBADF
fc320d37 34720@var{fd} isn't a valid open file descriptor.
0ce1b118 34721
b383017d 34722@item EINTR
0ce1b118
CV
34723The call was interrupted by the user.
34724@end table
34725
fc320d37
SL
34726@end table
34727
0ce1b118
CV
34728@node read
34729@unnumberedsubsubsec read
34730@cindex read, file-i/o system call
34731
fc320d37
SL
34732@table @asis
34733@item Synopsis:
0ce1b118 34734@smallexample
0ce1b118 34735int read(int fd, void *buf, unsigned int count);
fc320d37 34736@end smallexample
0ce1b118 34737
fc320d37
SL
34738@item Request:
34739@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 34740
fc320d37 34741@item Return value:
0ce1b118
CV
34742On success, the number of bytes read is returned.
34743Zero indicates end of file. If count is zero, read
b383017d 34744returns zero as well. On error, -1 is returned.
0ce1b118 34745
fc320d37 34746@item Errors:
0ce1b118
CV
34747
34748@table @code
b383017d 34749@item EBADF
fc320d37 34750@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
34751reading.
34752
b383017d 34753@item EFAULT
fc320d37 34754@var{bufptr} is an invalid pointer value.
0ce1b118 34755
b383017d 34756@item EINTR
0ce1b118
CV
34757The call was interrupted by the user.
34758@end table
34759
fc320d37
SL
34760@end table
34761
0ce1b118
CV
34762@node write
34763@unnumberedsubsubsec write
34764@cindex write, file-i/o system call
34765
fc320d37
SL
34766@table @asis
34767@item Synopsis:
0ce1b118 34768@smallexample
0ce1b118 34769int write(int fd, const void *buf, unsigned int count);
fc320d37 34770@end smallexample
0ce1b118 34771
fc320d37
SL
34772@item Request:
34773@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 34774
fc320d37 34775@item Return value:
0ce1b118
CV
34776On success, the number of bytes written are returned.
34777Zero indicates nothing was written. On error, -1
34778is returned.
34779
fc320d37 34780@item Errors:
0ce1b118
CV
34781
34782@table @code
b383017d 34783@item EBADF
fc320d37 34784@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
34785writing.
34786
b383017d 34787@item EFAULT
fc320d37 34788@var{bufptr} is an invalid pointer value.
0ce1b118 34789
b383017d 34790@item EFBIG
0ce1b118 34791An attempt was made to write a file that exceeds the
db2e3e2e 34792host-specific maximum file size allowed.
0ce1b118 34793
b383017d 34794@item ENOSPC
0ce1b118
CV
34795No space on device to write the data.
34796
b383017d 34797@item EINTR
0ce1b118
CV
34798The call was interrupted by the user.
34799@end table
34800
fc320d37
SL
34801@end table
34802
0ce1b118
CV
34803@node lseek
34804@unnumberedsubsubsec lseek
34805@cindex lseek, file-i/o system call
34806
fc320d37
SL
34807@table @asis
34808@item Synopsis:
0ce1b118 34809@smallexample
0ce1b118 34810long lseek (int fd, long offset, int flag);
0ce1b118
CV
34811@end smallexample
34812
fc320d37
SL
34813@item Request:
34814@samp{Flseek,@var{fd},@var{offset},@var{flag}}
34815
34816@var{flag} is one of:
0ce1b118
CV
34817
34818@table @code
b383017d 34819@item SEEK_SET
fc320d37 34820The offset is set to @var{offset} bytes.
0ce1b118 34821
b383017d 34822@item SEEK_CUR
fc320d37 34823The offset is set to its current location plus @var{offset}
0ce1b118
CV
34824bytes.
34825
b383017d 34826@item SEEK_END
fc320d37 34827The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
34828bytes.
34829@end table
34830
fc320d37 34831@item Return value:
0ce1b118
CV
34832On success, the resulting unsigned offset in bytes from
34833the beginning of the file is returned. Otherwise, a
34834value of -1 is returned.
34835
fc320d37 34836@item Errors:
0ce1b118
CV
34837
34838@table @code
b383017d 34839@item EBADF
fc320d37 34840@var{fd} is not a valid open file descriptor.
0ce1b118 34841
b383017d 34842@item ESPIPE
fc320d37 34843@var{fd} is associated with the @value{GDBN} console.
0ce1b118 34844
b383017d 34845@item EINVAL
fc320d37 34846@var{flag} is not a proper value.
0ce1b118 34847
b383017d 34848@item EINTR
0ce1b118
CV
34849The call was interrupted by the user.
34850@end table
34851
fc320d37
SL
34852@end table
34853
0ce1b118
CV
34854@node rename
34855@unnumberedsubsubsec rename
34856@cindex rename, file-i/o system call
34857
fc320d37
SL
34858@table @asis
34859@item Synopsis:
0ce1b118 34860@smallexample
0ce1b118 34861int rename(const char *oldpath, const char *newpath);
fc320d37 34862@end smallexample
0ce1b118 34863
fc320d37
SL
34864@item Request:
34865@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 34866
fc320d37 34867@item Return value:
0ce1b118
CV
34868On success, zero is returned. On error, -1 is returned.
34869
fc320d37 34870@item Errors:
0ce1b118
CV
34871
34872@table @code
b383017d 34873@item EISDIR
fc320d37 34874@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
34875directory.
34876
b383017d 34877@item EEXIST
fc320d37 34878@var{newpath} is a non-empty directory.
0ce1b118 34879
b383017d 34880@item EBUSY
fc320d37 34881@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
34882process.
34883
b383017d 34884@item EINVAL
0ce1b118
CV
34885An attempt was made to make a directory a subdirectory
34886of itself.
34887
b383017d 34888@item ENOTDIR
fc320d37
SL
34889A component used as a directory in @var{oldpath} or new
34890path is not a directory. Or @var{oldpath} is a directory
34891and @var{newpath} exists but is not a directory.
0ce1b118 34892
b383017d 34893@item EFAULT
fc320d37 34894@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 34895
b383017d 34896@item EACCES
0ce1b118
CV
34897No access to the file or the path of the file.
34898
34899@item ENAMETOOLONG
b383017d 34900
fc320d37 34901@var{oldpath} or @var{newpath} was too long.
0ce1b118 34902
b383017d 34903@item ENOENT
fc320d37 34904A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 34905
b383017d 34906@item EROFS
0ce1b118
CV
34907The file is on a read-only filesystem.
34908
b383017d 34909@item ENOSPC
0ce1b118
CV
34910The device containing the file has no room for the new
34911directory entry.
34912
b383017d 34913@item EINTR
0ce1b118
CV
34914The call was interrupted by the user.
34915@end table
34916
fc320d37
SL
34917@end table
34918
0ce1b118
CV
34919@node unlink
34920@unnumberedsubsubsec unlink
34921@cindex unlink, file-i/o system call
34922
fc320d37
SL
34923@table @asis
34924@item Synopsis:
0ce1b118 34925@smallexample
0ce1b118 34926int unlink(const char *pathname);
fc320d37 34927@end smallexample
0ce1b118 34928
fc320d37
SL
34929@item Request:
34930@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 34931
fc320d37 34932@item Return value:
0ce1b118
CV
34933On success, zero is returned. On error, -1 is returned.
34934
fc320d37 34935@item Errors:
0ce1b118
CV
34936
34937@table @code
b383017d 34938@item EACCES
0ce1b118
CV
34939No access to the file or the path of the file.
34940
b383017d 34941@item EPERM
0ce1b118
CV
34942The system does not allow unlinking of directories.
34943
b383017d 34944@item EBUSY
fc320d37 34945The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
34946being used by another process.
34947
b383017d 34948@item EFAULT
fc320d37 34949@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
34950
34951@item ENAMETOOLONG
fc320d37 34952@var{pathname} was too long.
0ce1b118 34953
b383017d 34954@item ENOENT
fc320d37 34955A directory component in @var{pathname} does not exist.
0ce1b118 34956
b383017d 34957@item ENOTDIR
0ce1b118
CV
34958A component of the path is not a directory.
34959
b383017d 34960@item EROFS
0ce1b118
CV
34961The file is on a read-only filesystem.
34962
b383017d 34963@item EINTR
0ce1b118
CV
34964The call was interrupted by the user.
34965@end table
34966
fc320d37
SL
34967@end table
34968
0ce1b118
CV
34969@node stat/fstat
34970@unnumberedsubsubsec stat/fstat
34971@cindex fstat, file-i/o system call
34972@cindex stat, file-i/o system call
34973
fc320d37
SL
34974@table @asis
34975@item Synopsis:
0ce1b118 34976@smallexample
0ce1b118
CV
34977int stat(const char *pathname, struct stat *buf);
34978int fstat(int fd, struct stat *buf);
fc320d37 34979@end smallexample
0ce1b118 34980
fc320d37
SL
34981@item Request:
34982@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
34983@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 34984
fc320d37 34985@item Return value:
0ce1b118
CV
34986On success, zero is returned. On error, -1 is returned.
34987
fc320d37 34988@item Errors:
0ce1b118
CV
34989
34990@table @code
b383017d 34991@item EBADF
fc320d37 34992@var{fd} is not a valid open file.
0ce1b118 34993
b383017d 34994@item ENOENT
fc320d37 34995A directory component in @var{pathname} does not exist or the
0ce1b118
CV
34996path is an empty string.
34997
b383017d 34998@item ENOTDIR
0ce1b118
CV
34999A component of the path is not a directory.
35000
b383017d 35001@item EFAULT
fc320d37 35002@var{pathnameptr} is an invalid pointer value.
0ce1b118 35003
b383017d 35004@item EACCES
0ce1b118
CV
35005No access to the file or the path of the file.
35006
35007@item ENAMETOOLONG
fc320d37 35008@var{pathname} was too long.
0ce1b118 35009
b383017d 35010@item EINTR
0ce1b118
CV
35011The call was interrupted by the user.
35012@end table
35013
fc320d37
SL
35014@end table
35015
0ce1b118
CV
35016@node gettimeofday
35017@unnumberedsubsubsec gettimeofday
35018@cindex gettimeofday, file-i/o system call
35019
fc320d37
SL
35020@table @asis
35021@item Synopsis:
0ce1b118 35022@smallexample
0ce1b118 35023int gettimeofday(struct timeval *tv, void *tz);
fc320d37 35024@end smallexample
0ce1b118 35025
fc320d37
SL
35026@item Request:
35027@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 35028
fc320d37 35029@item Return value:
0ce1b118
CV
35030On success, 0 is returned, -1 otherwise.
35031
fc320d37 35032@item Errors:
0ce1b118
CV
35033
35034@table @code
b383017d 35035@item EINVAL
fc320d37 35036@var{tz} is a non-NULL pointer.
0ce1b118 35037
b383017d 35038@item EFAULT
fc320d37
SL
35039@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
35040@end table
35041
0ce1b118
CV
35042@end table
35043
35044@node isatty
35045@unnumberedsubsubsec isatty
35046@cindex isatty, file-i/o system call
35047
fc320d37
SL
35048@table @asis
35049@item Synopsis:
0ce1b118 35050@smallexample
0ce1b118 35051int isatty(int fd);
fc320d37 35052@end smallexample
0ce1b118 35053
fc320d37
SL
35054@item Request:
35055@samp{Fisatty,@var{fd}}
0ce1b118 35056
fc320d37
SL
35057@item Return value:
35058Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 35059
fc320d37 35060@item Errors:
0ce1b118
CV
35061
35062@table @code
b383017d 35063@item EINTR
0ce1b118
CV
35064The call was interrupted by the user.
35065@end table
35066
fc320d37
SL
35067@end table
35068
35069Note that the @code{isatty} call is treated as a special case: it returns
350701 to the target if the file descriptor is attached
35071to the @value{GDBN} console, 0 otherwise. Implementing through system calls
35072would require implementing @code{ioctl} and would be more complex than
35073needed.
35074
35075
0ce1b118
CV
35076@node system
35077@unnumberedsubsubsec system
35078@cindex system, file-i/o system call
35079
fc320d37
SL
35080@table @asis
35081@item Synopsis:
0ce1b118 35082@smallexample
0ce1b118 35083int system(const char *command);
fc320d37 35084@end smallexample
0ce1b118 35085
fc320d37
SL
35086@item Request:
35087@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 35088
fc320d37 35089@item Return value:
5600ea19
NS
35090If @var{len} is zero, the return value indicates whether a shell is
35091available. A zero return value indicates a shell is not available.
35092For non-zero @var{len}, the value returned is -1 on error and the
35093return status of the command otherwise. Only the exit status of the
35094command is returned, which is extracted from the host's @code{system}
35095return value by calling @code{WEXITSTATUS(retval)}. In case
35096@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 35097
fc320d37 35098@item Errors:
0ce1b118
CV
35099
35100@table @code
b383017d 35101@item EINTR
0ce1b118
CV
35102The call was interrupted by the user.
35103@end table
35104
fc320d37
SL
35105@end table
35106
35107@value{GDBN} takes over the full task of calling the necessary host calls
35108to perform the @code{system} call. The return value of @code{system} on
35109the host is simplified before it's returned
35110to the target. Any termination signal information from the child process
35111is discarded, and the return value consists
35112entirely of the exit status of the called command.
35113
35114Due to security concerns, the @code{system} call is by default refused
35115by @value{GDBN}. The user has to allow this call explicitly with the
35116@code{set remote system-call-allowed 1} command.
35117
35118@table @code
35119@item set remote system-call-allowed
35120@kindex set remote system-call-allowed
35121Control whether to allow the @code{system} calls in the File I/O
35122protocol for the remote target. The default is zero (disabled).
35123
35124@item show remote system-call-allowed
35125@kindex show remote system-call-allowed
35126Show whether the @code{system} calls are allowed in the File I/O
35127protocol.
35128@end table
35129
db2e3e2e
BW
35130@node Protocol-specific Representation of Datatypes
35131@subsection Protocol-specific Representation of Datatypes
35132@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
35133
35134@menu
79a6e687
BW
35135* Integral Datatypes::
35136* Pointer Values::
35137* Memory Transfer::
0ce1b118
CV
35138* struct stat::
35139* struct timeval::
35140@end menu
35141
79a6e687
BW
35142@node Integral Datatypes
35143@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
35144@cindex integral datatypes, in file-i/o protocol
35145
fc320d37
SL
35146The integral datatypes used in the system calls are @code{int},
35147@code{unsigned int}, @code{long}, @code{unsigned long},
35148@code{mode_t}, and @code{time_t}.
0ce1b118 35149
fc320d37 35150@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
35151implemented as 32 bit values in this protocol.
35152
fc320d37 35153@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 35154
0ce1b118
CV
35155@xref{Limits}, for corresponding MIN and MAX values (similar to those
35156in @file{limits.h}) to allow range checking on host and target.
35157
35158@code{time_t} datatypes are defined as seconds since the Epoch.
35159
35160All integral datatypes transferred as part of a memory read or write of a
35161structured datatype e.g.@: a @code{struct stat} have to be given in big endian
35162byte order.
35163
79a6e687
BW
35164@node Pointer Values
35165@unnumberedsubsubsec Pointer Values
0ce1b118
CV
35166@cindex pointer values, in file-i/o protocol
35167
35168Pointers to target data are transmitted as they are. An exception
35169is made for pointers to buffers for which the length isn't
35170transmitted as part of the function call, namely strings. Strings
35171are transmitted as a pointer/length pair, both as hex values, e.g.@:
35172
35173@smallexample
35174@code{1aaf/12}
35175@end smallexample
35176
35177@noindent
35178which is a pointer to data of length 18 bytes at position 0x1aaf.
35179The length is defined as the full string length in bytes, including
fc320d37
SL
35180the trailing null byte. For example, the string @code{"hello world"}
35181at address 0x123456 is transmitted as
0ce1b118
CV
35182
35183@smallexample
fc320d37 35184@code{123456/d}
0ce1b118
CV
35185@end smallexample
35186
79a6e687
BW
35187@node Memory Transfer
35188@unnumberedsubsubsec Memory Transfer
fc320d37
SL
35189@cindex memory transfer, in file-i/o protocol
35190
35191Structured data which is transferred using a memory read or write (for
db2e3e2e 35192example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
35193with all scalar multibyte datatypes being big endian. Translation to
35194this representation needs to be done both by the target before the @code{F}
35195packet is sent, and by @value{GDBN} before
35196it transfers memory to the target. Transferred pointers to structured
35197data should point to the already-coerced data at any time.
0ce1b118 35198
0ce1b118
CV
35199
35200@node struct stat
35201@unnumberedsubsubsec struct stat
35202@cindex struct stat, in file-i/o protocol
35203
fc320d37
SL
35204The buffer of type @code{struct stat} used by the target and @value{GDBN}
35205is defined as follows:
0ce1b118
CV
35206
35207@smallexample
35208struct stat @{
35209 unsigned int st_dev; /* device */
35210 unsigned int st_ino; /* inode */
35211 mode_t st_mode; /* protection */
35212 unsigned int st_nlink; /* number of hard links */
35213 unsigned int st_uid; /* user ID of owner */
35214 unsigned int st_gid; /* group ID of owner */
35215 unsigned int st_rdev; /* device type (if inode device) */
35216 unsigned long st_size; /* total size, in bytes */
35217 unsigned long st_blksize; /* blocksize for filesystem I/O */
35218 unsigned long st_blocks; /* number of blocks allocated */
35219 time_t st_atime; /* time of last access */
35220 time_t st_mtime; /* time of last modification */
35221 time_t st_ctime; /* time of last change */
35222@};
35223@end smallexample
35224
fc320d37 35225The integral datatypes conform to the definitions given in the
79a6e687 35226appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
35227structure is of size 64 bytes.
35228
35229The values of several fields have a restricted meaning and/or
35230range of values.
35231
fc320d37 35232@table @code
0ce1b118 35233
fc320d37
SL
35234@item st_dev
35235A value of 0 represents a file, 1 the console.
0ce1b118 35236
fc320d37
SL
35237@item st_ino
35238No valid meaning for the target. Transmitted unchanged.
0ce1b118 35239
fc320d37
SL
35240@item st_mode
35241Valid mode bits are described in @ref{Constants}. Any other
35242bits have currently no meaning for the target.
0ce1b118 35243
fc320d37
SL
35244@item st_uid
35245@itemx st_gid
35246@itemx st_rdev
35247No valid meaning for the target. Transmitted unchanged.
0ce1b118 35248
fc320d37
SL
35249@item st_atime
35250@itemx st_mtime
35251@itemx st_ctime
35252These values have a host and file system dependent
35253accuracy. Especially on Windows hosts, the file system may not
35254support exact timing values.
35255@end table
0ce1b118 35256
fc320d37
SL
35257The target gets a @code{struct stat} of the above representation and is
35258responsible for coercing it to the target representation before
0ce1b118
CV
35259continuing.
35260
fc320d37
SL
35261Note that due to size differences between the host, target, and protocol
35262representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
35263get truncated on the target.
35264
35265@node struct timeval
35266@unnumberedsubsubsec struct timeval
35267@cindex struct timeval, in file-i/o protocol
35268
fc320d37 35269The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
35270is defined as follows:
35271
35272@smallexample
b383017d 35273struct timeval @{
0ce1b118
CV
35274 time_t tv_sec; /* second */
35275 long tv_usec; /* microsecond */
35276@};
35277@end smallexample
35278
fc320d37 35279The integral datatypes conform to the definitions given in the
79a6e687 35280appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
35281structure is of size 8 bytes.
35282
35283@node Constants
35284@subsection Constants
35285@cindex constants, in file-i/o protocol
35286
35287The following values are used for the constants inside of the
fc320d37 35288protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
35289values before and after the call as needed.
35290
35291@menu
79a6e687
BW
35292* Open Flags::
35293* mode_t Values::
35294* Errno Values::
35295* Lseek Flags::
0ce1b118
CV
35296* Limits::
35297@end menu
35298
79a6e687
BW
35299@node Open Flags
35300@unnumberedsubsubsec Open Flags
0ce1b118
CV
35301@cindex open flags, in file-i/o protocol
35302
35303All values are given in hexadecimal representation.
35304
35305@smallexample
35306 O_RDONLY 0x0
35307 O_WRONLY 0x1
35308 O_RDWR 0x2
35309 O_APPEND 0x8
35310 O_CREAT 0x200
35311 O_TRUNC 0x400
35312 O_EXCL 0x800
35313@end smallexample
35314
79a6e687
BW
35315@node mode_t Values
35316@unnumberedsubsubsec mode_t Values
0ce1b118
CV
35317@cindex mode_t values, in file-i/o protocol
35318
35319All values are given in octal representation.
35320
35321@smallexample
35322 S_IFREG 0100000
35323 S_IFDIR 040000
35324 S_IRUSR 0400
35325 S_IWUSR 0200
35326 S_IXUSR 0100
35327 S_IRGRP 040
35328 S_IWGRP 020
35329 S_IXGRP 010
35330 S_IROTH 04
35331 S_IWOTH 02
35332 S_IXOTH 01
35333@end smallexample
35334
79a6e687
BW
35335@node Errno Values
35336@unnumberedsubsubsec Errno Values
0ce1b118
CV
35337@cindex errno values, in file-i/o protocol
35338
35339All values are given in decimal representation.
35340
35341@smallexample
35342 EPERM 1
35343 ENOENT 2
35344 EINTR 4
35345 EBADF 9
35346 EACCES 13
35347 EFAULT 14
35348 EBUSY 16
35349 EEXIST 17
35350 ENODEV 19
35351 ENOTDIR 20
35352 EISDIR 21
35353 EINVAL 22
35354 ENFILE 23
35355 EMFILE 24
35356 EFBIG 27
35357 ENOSPC 28
35358 ESPIPE 29
35359 EROFS 30
35360 ENAMETOOLONG 91
35361 EUNKNOWN 9999
35362@end smallexample
35363
fc320d37 35364 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
35365 any error value not in the list of supported error numbers.
35366
79a6e687
BW
35367@node Lseek Flags
35368@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
35369@cindex lseek flags, in file-i/o protocol
35370
35371@smallexample
35372 SEEK_SET 0
35373 SEEK_CUR 1
35374 SEEK_END 2
35375@end smallexample
35376
35377@node Limits
35378@unnumberedsubsubsec Limits
35379@cindex limits, in file-i/o protocol
35380
35381All values are given in decimal representation.
35382
35383@smallexample
35384 INT_MIN -2147483648
35385 INT_MAX 2147483647
35386 UINT_MAX 4294967295
35387 LONG_MIN -9223372036854775808
35388 LONG_MAX 9223372036854775807
35389 ULONG_MAX 18446744073709551615
35390@end smallexample
35391
35392@node File-I/O Examples
35393@subsection File-I/O Examples
35394@cindex file-i/o examples
35395
35396Example sequence of a write call, file descriptor 3, buffer is at target
35397address 0x1234, 6 bytes should be written:
35398
35399@smallexample
35400<- @code{Fwrite,3,1234,6}
35401@emph{request memory read from target}
35402-> @code{m1234,6}
35403<- XXXXXX
35404@emph{return "6 bytes written"}
35405-> @code{F6}
35406@end smallexample
35407
35408Example sequence of a read call, file descriptor 3, buffer is at target
35409address 0x1234, 6 bytes should be read:
35410
35411@smallexample
35412<- @code{Fread,3,1234,6}
35413@emph{request memory write to target}
35414-> @code{X1234,6:XXXXXX}
35415@emph{return "6 bytes read"}
35416-> @code{F6}
35417@end smallexample
35418
35419Example sequence of a read call, call fails on the host due to invalid
fc320d37 35420file descriptor (@code{EBADF}):
0ce1b118
CV
35421
35422@smallexample
35423<- @code{Fread,3,1234,6}
35424-> @code{F-1,9}
35425@end smallexample
35426
c8aa23ab 35427Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
35428host is called:
35429
35430@smallexample
35431<- @code{Fread,3,1234,6}
35432-> @code{F-1,4,C}
35433<- @code{T02}
35434@end smallexample
35435
c8aa23ab 35436Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
35437host is called:
35438
35439@smallexample
35440<- @code{Fread,3,1234,6}
35441-> @code{X1234,6:XXXXXX}
35442<- @code{T02}
35443@end smallexample
35444
cfa9d6d9
DJ
35445@node Library List Format
35446@section Library List Format
35447@cindex library list format, remote protocol
35448
35449On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
35450same process as your application to manage libraries. In this case,
35451@value{GDBN} can use the loader's symbol table and normal memory
35452operations to maintain a list of shared libraries. On other
35453platforms, the operating system manages loaded libraries.
35454@value{GDBN} can not retrieve the list of currently loaded libraries
35455through memory operations, so it uses the @samp{qXfer:libraries:read}
35456packet (@pxref{qXfer library list read}) instead. The remote stub
35457queries the target's operating system and reports which libraries
35458are loaded.
35459
35460The @samp{qXfer:libraries:read} packet returns an XML document which
35461lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
35462associated name and one or more segment or section base addresses,
35463which report where the library was loaded in memory.
35464
35465For the common case of libraries that are fully linked binaries, the
35466library should have a list of segments. If the target supports
35467dynamic linking of a relocatable object file, its library XML element
35468should instead include a list of allocated sections. The segment or
35469section bases are start addresses, not relocation offsets; they do not
35470depend on the library's link-time base addresses.
cfa9d6d9 35471
9cceb671
DJ
35472@value{GDBN} must be linked with the Expat library to support XML
35473library lists. @xref{Expat}.
35474
cfa9d6d9
DJ
35475A simple memory map, with one loaded library relocated by a single
35476offset, looks like this:
35477
35478@smallexample
35479<library-list>
35480 <library name="/lib/libc.so.6">
35481 <segment address="0x10000000"/>
35482 </library>
35483</library-list>
35484@end smallexample
35485
1fddbabb
PA
35486Another simple memory map, with one loaded library with three
35487allocated sections (.text, .data, .bss), looks like this:
35488
35489@smallexample
35490<library-list>
35491 <library name="sharedlib.o">
35492 <section address="0x10000000"/>
35493 <section address="0x20000000"/>
35494 <section address="0x30000000"/>
35495 </library>
35496</library-list>
35497@end smallexample
35498
cfa9d6d9
DJ
35499The format of a library list is described by this DTD:
35500
35501@smallexample
35502<!-- library-list: Root element with versioning -->
35503<!ELEMENT library-list (library)*>
35504<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 35505<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
35506<!ATTLIST library name CDATA #REQUIRED>
35507<!ELEMENT segment EMPTY>
35508<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
35509<!ELEMENT section EMPTY>
35510<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
35511@end smallexample
35512
1fddbabb
PA
35513In addition, segments and section descriptors cannot be mixed within a
35514single library element, and you must supply at least one segment or
35515section for each library.
35516
79a6e687
BW
35517@node Memory Map Format
35518@section Memory Map Format
68437a39
DJ
35519@cindex memory map format
35520
35521To be able to write into flash memory, @value{GDBN} needs to obtain a
35522memory map from the target. This section describes the format of the
35523memory map.
35524
35525The memory map is obtained using the @samp{qXfer:memory-map:read}
35526(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
35527lists memory regions.
35528
35529@value{GDBN} must be linked with the Expat library to support XML
35530memory maps. @xref{Expat}.
35531
35532The top-level structure of the document is shown below:
68437a39
DJ
35533
35534@smallexample
35535<?xml version="1.0"?>
35536<!DOCTYPE memory-map
35537 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
35538 "http://sourceware.org/gdb/gdb-memory-map.dtd">
35539<memory-map>
35540 region...
35541</memory-map>
35542@end smallexample
35543
35544Each region can be either:
35545
35546@itemize
35547
35548@item
35549A region of RAM starting at @var{addr} and extending for @var{length}
35550bytes from there:
35551
35552@smallexample
35553<memory type="ram" start="@var{addr}" length="@var{length}"/>
35554@end smallexample
35555
35556
35557@item
35558A region of read-only memory:
35559
35560@smallexample
35561<memory type="rom" start="@var{addr}" length="@var{length}"/>
35562@end smallexample
35563
35564
35565@item
35566A region of flash memory, with erasure blocks @var{blocksize}
35567bytes in length:
35568
35569@smallexample
35570<memory type="flash" start="@var{addr}" length="@var{length}">
35571 <property name="blocksize">@var{blocksize}</property>
35572</memory>
35573@end smallexample
35574
35575@end itemize
35576
35577Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
35578by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
35579packets to write to addresses in such ranges.
35580
35581The formal DTD for memory map format is given below:
35582
35583@smallexample
35584<!-- ................................................... -->
35585<!-- Memory Map XML DTD ................................ -->
35586<!-- File: memory-map.dtd .............................. -->
35587<!-- .................................... .............. -->
35588<!-- memory-map.dtd -->
35589<!-- memory-map: Root element with versioning -->
35590<!ELEMENT memory-map (memory | property)>
35591<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
35592<!ELEMENT memory (property)>
35593<!-- memory: Specifies a memory region,
35594 and its type, or device. -->
35595<!ATTLIST memory type CDATA #REQUIRED
35596 start CDATA #REQUIRED
35597 length CDATA #REQUIRED
35598 device CDATA #IMPLIED>
35599<!-- property: Generic attribute tag -->
35600<!ELEMENT property (#PCDATA | property)*>
35601<!ATTLIST property name CDATA #REQUIRED>
35602@end smallexample
35603
dc146f7c
VP
35604@node Thread List Format
35605@section Thread List Format
35606@cindex thread list format
35607
35608To efficiently update the list of threads and their attributes,
35609@value{GDBN} issues the @samp{qXfer:threads:read} packet
35610(@pxref{qXfer threads read}) and obtains the XML document with
35611the following structure:
35612
35613@smallexample
35614<?xml version="1.0"?>
35615<threads>
35616 <thread id="id" core="0">
35617 ... description ...
35618 </thread>
35619</threads>
35620@end smallexample
35621
35622Each @samp{thread} element must have the @samp{id} attribute that
35623identifies the thread (@pxref{thread-id syntax}). The
35624@samp{core} attribute, if present, specifies which processor core
35625the thread was last executing on. The content of the of @samp{thread}
35626element is interpreted as human-readable auxilliary information.
35627
f418dd93
DJ
35628@include agentexpr.texi
35629
00bf0b85
SS
35630@node Trace File Format
35631@appendix Trace File Format
35632@cindex trace file format
35633
35634The trace file comes in three parts: a header, a textual description
35635section, and a trace frame section with binary data.
35636
35637The header has the form @code{\x7fTRACE0\n}. The first byte is
35638@code{0x7f} so as to indicate that the file contains binary data,
35639while the @code{0} is a version number that may have different values
35640in the future.
35641
35642The description section consists of multiple lines of @sc{ascii} text
35643separated by newline characters (@code{0xa}). The lines may include a
35644variety of optional descriptive or context-setting information, such
35645as tracepoint definitions or register set size. @value{GDBN} will
35646ignore any line that it does not recognize. An empty line marks the end
35647of this section.
35648
35649@c FIXME add some specific types of data
35650
35651The trace frame section consists of a number of consecutive frames.
35652Each frame begins with a two-byte tracepoint number, followed by a
35653four-byte size giving the amount of data in the frame. The data in
35654the frame consists of a number of blocks, each introduced by a
35655character indicating its type (at least register, memory, and trace
35656state variable). The data in this section is raw binary, not a
35657hexadecimal or other encoding; its endianness matches the target's
35658endianness.
35659
35660@c FIXME bi-arch may require endianness/arch info in description section
35661
35662@table @code
35663@item R @var{bytes}
35664Register block. The number and ordering of bytes matches that of a
35665@code{g} packet in the remote protocol. Note that these are the
35666actual bytes, in target order and @value{GDBN} register order, not a
35667hexadecimal encoding.
35668
35669@item M @var{address} @var{length} @var{bytes}...
35670Memory block. This is a contiguous block of memory, at the 8-byte
35671address @var{address}, with a 2-byte length @var{length}, followed by
35672@var{length} bytes.
35673
35674@item V @var{number} @var{value}
35675Trace state variable block. This records the 8-byte signed value
35676@var{value} of trace state variable numbered @var{number}.
35677
35678@end table
35679
35680Future enhancements of the trace file format may include additional types
35681of blocks.
35682
23181151
DJ
35683@node Target Descriptions
35684@appendix Target Descriptions
35685@cindex target descriptions
35686
35687@strong{Warning:} target descriptions are still under active development,
35688and the contents and format may change between @value{GDBN} releases.
35689The format is expected to stabilize in the future.
35690
35691One of the challenges of using @value{GDBN} to debug embedded systems
35692is that there are so many minor variants of each processor
35693architecture in use. It is common practice for vendors to start with
35694a standard processor core --- ARM, PowerPC, or MIPS, for example ---
35695and then make changes to adapt it to a particular market niche. Some
35696architectures have hundreds of variants, available from dozens of
35697vendors. This leads to a number of problems:
35698
35699@itemize @bullet
35700@item
35701With so many different customized processors, it is difficult for
35702the @value{GDBN} maintainers to keep up with the changes.
35703@item
35704Since individual variants may have short lifetimes or limited
35705audiences, it may not be worthwhile to carry information about every
35706variant in the @value{GDBN} source tree.
35707@item
35708When @value{GDBN} does support the architecture of the embedded system
35709at hand, the task of finding the correct architecture name to give the
35710@command{set architecture} command can be error-prone.
35711@end itemize
35712
35713To address these problems, the @value{GDBN} remote protocol allows a
35714target system to not only identify itself to @value{GDBN}, but to
35715actually describe its own features. This lets @value{GDBN} support
35716processor variants it has never seen before --- to the extent that the
35717descriptions are accurate, and that @value{GDBN} understands them.
35718
9cceb671
DJ
35719@value{GDBN} must be linked with the Expat library to support XML
35720target descriptions. @xref{Expat}.
123dc839 35721
23181151
DJ
35722@menu
35723* Retrieving Descriptions:: How descriptions are fetched from a target.
35724* Target Description Format:: The contents of a target description.
123dc839
DJ
35725* Predefined Target Types:: Standard types available for target
35726 descriptions.
35727* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
35728@end menu
35729
35730@node Retrieving Descriptions
35731@section Retrieving Descriptions
35732
35733Target descriptions can be read from the target automatically, or
35734specified by the user manually. The default behavior is to read the
35735description from the target. @value{GDBN} retrieves it via the remote
35736protocol using @samp{qXfer} requests (@pxref{General Query Packets,
35737qXfer}). The @var{annex} in the @samp{qXfer} packet will be
35738@samp{target.xml}. The contents of the @samp{target.xml} annex are an
35739XML document, of the form described in @ref{Target Description
35740Format}.
35741
35742Alternatively, you can specify a file to read for the target description.
35743If a file is set, the target will not be queried. The commands to
35744specify a file are:
35745
35746@table @code
35747@cindex set tdesc filename
35748@item set tdesc filename @var{path}
35749Read the target description from @var{path}.
35750
35751@cindex unset tdesc filename
35752@item unset tdesc filename
35753Do not read the XML target description from a file. @value{GDBN}
35754will use the description supplied by the current target.
35755
35756@cindex show tdesc filename
35757@item show tdesc filename
35758Show the filename to read for a target description, if any.
35759@end table
35760
35761
35762@node Target Description Format
35763@section Target Description Format
35764@cindex target descriptions, XML format
35765
35766A target description annex is an @uref{http://www.w3.org/XML/, XML}
35767document which complies with the Document Type Definition provided in
35768the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
35769means you can use generally available tools like @command{xmllint} to
35770check that your feature descriptions are well-formed and valid.
35771However, to help people unfamiliar with XML write descriptions for
35772their targets, we also describe the grammar here.
35773
123dc839
DJ
35774Target descriptions can identify the architecture of the remote target
35775and (for some architectures) provide information about custom register
08d16641
PA
35776sets. They can also identify the OS ABI of the remote target.
35777@value{GDBN} can use this information to autoconfigure for your
123dc839 35778target, or to warn you if you connect to an unsupported target.
23181151
DJ
35779
35780Here is a simple target description:
35781
123dc839 35782@smallexample
1780a0ed 35783<target version="1.0">
23181151
DJ
35784 <architecture>i386:x86-64</architecture>
35785</target>
123dc839 35786@end smallexample
23181151
DJ
35787
35788@noindent
35789This minimal description only says that the target uses
35790the x86-64 architecture.
35791
123dc839
DJ
35792A target description has the following overall form, with [ ] marking
35793optional elements and @dots{} marking repeatable elements. The elements
35794are explained further below.
23181151 35795
123dc839 35796@smallexample
23181151
DJ
35797<?xml version="1.0"?>
35798<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 35799<target version="1.0">
123dc839 35800 @r{[}@var{architecture}@r{]}
08d16641 35801 @r{[}@var{osabi}@r{]}
e35359c5 35802 @r{[}@var{compatible}@r{]}
123dc839 35803 @r{[}@var{feature}@dots{}@r{]}
23181151 35804</target>
123dc839 35805@end smallexample
23181151
DJ
35806
35807@noindent
35808The description is generally insensitive to whitespace and line
35809breaks, under the usual common-sense rules. The XML version
35810declaration and document type declaration can generally be omitted
35811(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
35812useful for XML validation tools. The @samp{version} attribute for
35813@samp{<target>} may also be omitted, but we recommend
35814including it; if future versions of @value{GDBN} use an incompatible
35815revision of @file{gdb-target.dtd}, they will detect and report
35816the version mismatch.
23181151 35817
108546a0
DJ
35818@subsection Inclusion
35819@cindex target descriptions, inclusion
35820@cindex XInclude
35821@ifnotinfo
35822@cindex <xi:include>
35823@end ifnotinfo
35824
35825It can sometimes be valuable to split a target description up into
35826several different annexes, either for organizational purposes, or to
35827share files between different possible target descriptions. You can
35828divide a description into multiple files by replacing any element of
35829the target description with an inclusion directive of the form:
35830
123dc839 35831@smallexample
108546a0 35832<xi:include href="@var{document}"/>
123dc839 35833@end smallexample
108546a0
DJ
35834
35835@noindent
35836When @value{GDBN} encounters an element of this form, it will retrieve
35837the named XML @var{document}, and replace the inclusion directive with
35838the contents of that document. If the current description was read
35839using @samp{qXfer}, then so will be the included document;
35840@var{document} will be interpreted as the name of an annex. If the
35841current description was read from a file, @value{GDBN} will look for
35842@var{document} as a file in the same directory where it found the
35843original description.
35844
123dc839
DJ
35845@subsection Architecture
35846@cindex <architecture>
35847
35848An @samp{<architecture>} element has this form:
35849
35850@smallexample
35851 <architecture>@var{arch}</architecture>
35852@end smallexample
35853
e35359c5
UW
35854@var{arch} is one of the architectures from the set accepted by
35855@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 35856
08d16641
PA
35857@subsection OS ABI
35858@cindex @code{<osabi>}
35859
35860This optional field was introduced in @value{GDBN} version 7.0.
35861Previous versions of @value{GDBN} ignore it.
35862
35863An @samp{<osabi>} element has this form:
35864
35865@smallexample
35866 <osabi>@var{abi-name}</osabi>
35867@end smallexample
35868
35869@var{abi-name} is an OS ABI name from the same selection accepted by
35870@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
35871
e35359c5
UW
35872@subsection Compatible Architecture
35873@cindex @code{<compatible>}
35874
35875This optional field was introduced in @value{GDBN} version 7.0.
35876Previous versions of @value{GDBN} ignore it.
35877
35878A @samp{<compatible>} element has this form:
35879
35880@smallexample
35881 <compatible>@var{arch}</compatible>
35882@end smallexample
35883
35884@var{arch} is one of the architectures from the set accepted by
35885@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
35886
35887A @samp{<compatible>} element is used to specify that the target
35888is able to run binaries in some other than the main target architecture
35889given by the @samp{<architecture>} element. For example, on the
35890Cell Broadband Engine, the main architecture is @code{powerpc:common}
35891or @code{powerpc:common64}, but the system is able to run binaries
35892in the @code{spu} architecture as well. The way to describe this
35893capability with @samp{<compatible>} is as follows:
35894
35895@smallexample
35896 <architecture>powerpc:common</architecture>
35897 <compatible>spu</compatible>
35898@end smallexample
35899
123dc839
DJ
35900@subsection Features
35901@cindex <feature>
35902
35903Each @samp{<feature>} describes some logical portion of the target
35904system. Features are currently used to describe available CPU
35905registers and the types of their contents. A @samp{<feature>} element
35906has this form:
35907
35908@smallexample
35909<feature name="@var{name}">
35910 @r{[}@var{type}@dots{}@r{]}
35911 @var{reg}@dots{}
35912</feature>
35913@end smallexample
35914
35915@noindent
35916Each feature's name should be unique within the description. The name
35917of a feature does not matter unless @value{GDBN} has some special
35918knowledge of the contents of that feature; if it does, the feature
35919should have its standard name. @xref{Standard Target Features}.
35920
35921@subsection Types
35922
35923Any register's value is a collection of bits which @value{GDBN} must
35924interpret. The default interpretation is a two's complement integer,
35925but other types can be requested by name in the register description.
35926Some predefined types are provided by @value{GDBN} (@pxref{Predefined
35927Target Types}), and the description can define additional composite types.
35928
35929Each type element must have an @samp{id} attribute, which gives
35930a unique (within the containing @samp{<feature>}) name to the type.
35931Types must be defined before they are used.
35932
35933@cindex <vector>
35934Some targets offer vector registers, which can be treated as arrays
35935of scalar elements. These types are written as @samp{<vector>} elements,
35936specifying the array element type, @var{type}, and the number of elements,
35937@var{count}:
35938
35939@smallexample
35940<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
35941@end smallexample
35942
35943@cindex <union>
35944If a register's value is usefully viewed in multiple ways, define it
35945with a union type containing the useful representations. The
35946@samp{<union>} element contains one or more @samp{<field>} elements,
35947each of which has a @var{name} and a @var{type}:
35948
35949@smallexample
35950<union id="@var{id}">
35951 <field name="@var{name}" type="@var{type}"/>
35952 @dots{}
35953</union>
35954@end smallexample
35955
f5dff777
DJ
35956@cindex <struct>
35957If a register's value is composed from several separate values, define
35958it with a structure type. There are two forms of the @samp{<struct>}
35959element; a @samp{<struct>} element must either contain only bitfields
35960or contain no bitfields. If the structure contains only bitfields,
35961its total size in bytes must be specified, each bitfield must have an
35962explicit start and end, and bitfields are automatically assigned an
35963integer type. The field's @var{start} should be less than or
35964equal to its @var{end}, and zero represents the least significant bit.
35965
35966@smallexample
35967<struct id="@var{id}" size="@var{size}">
35968 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
35969 @dots{}
35970</struct>
35971@end smallexample
35972
35973If the structure contains no bitfields, then each field has an
35974explicit type, and no implicit padding is added.
35975
35976@smallexample
35977<struct id="@var{id}">
35978 <field name="@var{name}" type="@var{type}"/>
35979 @dots{}
35980</struct>
35981@end smallexample
35982
35983@cindex <flags>
35984If a register's value is a series of single-bit flags, define it with
35985a flags type. The @samp{<flags>} element has an explicit @var{size}
35986and contains one or more @samp{<field>} elements. Each field has a
35987@var{name}, a @var{start}, and an @var{end}. Only single-bit flags
35988are supported.
35989
35990@smallexample
35991<flags id="@var{id}" size="@var{size}">
35992 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
35993 @dots{}
35994</flags>
35995@end smallexample
35996
123dc839
DJ
35997@subsection Registers
35998@cindex <reg>
35999
36000Each register is represented as an element with this form:
36001
36002@smallexample
36003<reg name="@var{name}"
36004 bitsize="@var{size}"
36005 @r{[}regnum="@var{num}"@r{]}
36006 @r{[}save-restore="@var{save-restore}"@r{]}
36007 @r{[}type="@var{type}"@r{]}
36008 @r{[}group="@var{group}"@r{]}/>
36009@end smallexample
36010
36011@noindent
36012The components are as follows:
36013
36014@table @var
36015
36016@item name
36017The register's name; it must be unique within the target description.
36018
36019@item bitsize
36020The register's size, in bits.
36021
36022@item regnum
36023The register's number. If omitted, a register's number is one greater
36024than that of the previous register (either in the current feature or in
36025a preceeding feature); the first register in the target description
36026defaults to zero. This register number is used to read or write
36027the register; e.g.@: it is used in the remote @code{p} and @code{P}
36028packets, and registers appear in the @code{g} and @code{G} packets
36029in order of increasing register number.
36030
36031@item save-restore
36032Whether the register should be preserved across inferior function
36033calls; this must be either @code{yes} or @code{no}. The default is
36034@code{yes}, which is appropriate for most registers except for
36035some system control registers; this is not related to the target's
36036ABI.
36037
36038@item type
36039The type of the register. @var{type} may be a predefined type, a type
36040defined in the current feature, or one of the special types @code{int}
36041and @code{float}. @code{int} is an integer type of the correct size
36042for @var{bitsize}, and @code{float} is a floating point type (in the
36043architecture's normal floating point format) of the correct size for
36044@var{bitsize}. The default is @code{int}.
36045
36046@item group
36047The register group to which this register belongs. @var{group} must
36048be either @code{general}, @code{float}, or @code{vector}. If no
36049@var{group} is specified, @value{GDBN} will not display the register
36050in @code{info registers}.
36051
36052@end table
36053
36054@node Predefined Target Types
36055@section Predefined Target Types
36056@cindex target descriptions, predefined types
36057
36058Type definitions in the self-description can build up composite types
36059from basic building blocks, but can not define fundamental types. Instead,
36060standard identifiers are provided by @value{GDBN} for the fundamental
36061types. The currently supported types are:
36062
36063@table @code
36064
36065@item int8
36066@itemx int16
36067@itemx int32
36068@itemx int64
7cc46491 36069@itemx int128
123dc839
DJ
36070Signed integer types holding the specified number of bits.
36071
36072@item uint8
36073@itemx uint16
36074@itemx uint32
36075@itemx uint64
7cc46491 36076@itemx uint128
123dc839
DJ
36077Unsigned integer types holding the specified number of bits.
36078
36079@item code_ptr
36080@itemx data_ptr
36081Pointers to unspecified code and data. The program counter and
36082any dedicated return address register may be marked as code
36083pointers; printing a code pointer converts it into a symbolic
36084address. The stack pointer and any dedicated address registers
36085may be marked as data pointers.
36086
6e3bbd1a
PB
36087@item ieee_single
36088Single precision IEEE floating point.
36089
36090@item ieee_double
36091Double precision IEEE floating point.
36092
123dc839
DJ
36093@item arm_fpa_ext
36094The 12-byte extended precision format used by ARM FPA registers.
36095
075b51b7
L
36096@item i387_ext
36097The 10-byte extended precision format used by x87 registers.
36098
36099@item i386_eflags
3610032bit @sc{eflags} register used by x86.
36101
36102@item i386_mxcsr
3610332bit @sc{mxcsr} register used by x86.
36104
123dc839
DJ
36105@end table
36106
36107@node Standard Target Features
36108@section Standard Target Features
36109@cindex target descriptions, standard features
36110
36111A target description must contain either no registers or all the
36112target's registers. If the description contains no registers, then
36113@value{GDBN} will assume a default register layout, selected based on
36114the architecture. If the description contains any registers, the
36115default layout will not be used; the standard registers must be
36116described in the target description, in such a way that @value{GDBN}
36117can recognize them.
36118
36119This is accomplished by giving specific names to feature elements
36120which contain standard registers. @value{GDBN} will look for features
36121with those names and verify that they contain the expected registers;
36122if any known feature is missing required registers, or if any required
36123feature is missing, @value{GDBN} will reject the target
36124description. You can add additional registers to any of the
36125standard features --- @value{GDBN} will display them just as if
36126they were added to an unrecognized feature.
36127
36128This section lists the known features and their expected contents.
36129Sample XML documents for these features are included in the
36130@value{GDBN} source tree, in the directory @file{gdb/features}.
36131
36132Names recognized by @value{GDBN} should include the name of the
36133company or organization which selected the name, and the overall
36134architecture to which the feature applies; so e.g.@: the feature
36135containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
36136
ff6f572f
DJ
36137The names of registers are not case sensitive for the purpose
36138of recognizing standard features, but @value{GDBN} will only display
36139registers using the capitalization used in the description.
36140
e9c17194
VP
36141@menu
36142* ARM Features::
3bb8d5c3 36143* i386 Features::
1e26b4f8 36144* MIPS Features::
e9c17194 36145* M68K Features::
1e26b4f8 36146* PowerPC Features::
e9c17194
VP
36147@end menu
36148
36149
36150@node ARM Features
123dc839
DJ
36151@subsection ARM Features
36152@cindex target descriptions, ARM features
36153
9779414d
DJ
36154The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
36155ARM targets.
123dc839
DJ
36156It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
36157@samp{lr}, @samp{pc}, and @samp{cpsr}.
36158
9779414d
DJ
36159For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
36160feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
36161registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
36162and @samp{xpsr}.
36163
123dc839
DJ
36164The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
36165should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
36166
ff6f572f
DJ
36167The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
36168it should contain at least registers @samp{wR0} through @samp{wR15} and
36169@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
36170@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 36171
58d6951d
DJ
36172The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
36173should contain at least registers @samp{d0} through @samp{d15}. If
36174they are present, @samp{d16} through @samp{d31} should also be included.
36175@value{GDBN} will synthesize the single-precision registers from
36176halves of the double-precision registers.
36177
36178The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
36179need to contain registers; it instructs @value{GDBN} to display the
36180VFP double-precision registers as vectors and to synthesize the
36181quad-precision registers from pairs of double-precision registers.
36182If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
36183be present and include 32 double-precision registers.
36184
3bb8d5c3
L
36185@node i386 Features
36186@subsection i386 Features
36187@cindex target descriptions, i386 features
36188
36189The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
36190targets. It should describe the following registers:
36191
36192@itemize @minus
36193@item
36194@samp{eax} through @samp{edi} plus @samp{eip} for i386
36195@item
36196@samp{rax} through @samp{r15} plus @samp{rip} for amd64
36197@item
36198@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
36199@samp{fs}, @samp{gs}
36200@item
36201@samp{st0} through @samp{st7}
36202@item
36203@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
36204@samp{foseg}, @samp{fooff} and @samp{fop}
36205@end itemize
36206
36207The register sets may be different, depending on the target.
36208
3a13a53b 36209The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
36210describe registers:
36211
36212@itemize @minus
36213@item
36214@samp{xmm0} through @samp{xmm7} for i386
36215@item
36216@samp{xmm0} through @samp{xmm15} for amd64
36217@item
36218@samp{mxcsr}
36219@end itemize
36220
3a13a53b
L
36221The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
36222@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
36223describe the upper 128 bits of @sc{ymm} registers:
36224
36225@itemize @minus
36226@item
36227@samp{ymm0h} through @samp{ymm7h} for i386
36228@item
36229@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
36230@end itemize
36231
3bb8d5c3
L
36232The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
36233describe a single register, @samp{orig_eax}.
36234
1e26b4f8 36235@node MIPS Features
f8b73d13
DJ
36236@subsection MIPS Features
36237@cindex target descriptions, MIPS features
36238
36239The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
36240It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
36241@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
36242on the target.
36243
36244The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
36245contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
36246registers. They may be 32-bit or 64-bit depending on the target.
36247
36248The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
36249it may be optional in a future version of @value{GDBN}. It should
36250contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
36251@samp{fir}. They may be 32-bit or 64-bit depending on the target.
36252
822b6570
DJ
36253The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
36254contain a single register, @samp{restart}, which is used by the
36255Linux kernel to control restartable syscalls.
36256
e9c17194
VP
36257@node M68K Features
36258@subsection M68K Features
36259@cindex target descriptions, M68K features
36260
36261@table @code
36262@item @samp{org.gnu.gdb.m68k.core}
36263@itemx @samp{org.gnu.gdb.coldfire.core}
36264@itemx @samp{org.gnu.gdb.fido.core}
36265One of those features must be always present.
249e1128 36266The feature that is present determines which flavor of m68k is
e9c17194
VP
36267used. The feature that is present should contain registers
36268@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
36269@samp{sp}, @samp{ps} and @samp{pc}.
36270
36271@item @samp{org.gnu.gdb.coldfire.fp}
36272This feature is optional. If present, it should contain registers
36273@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
36274@samp{fpiaddr}.
36275@end table
36276
1e26b4f8 36277@node PowerPC Features
7cc46491
DJ
36278@subsection PowerPC Features
36279@cindex target descriptions, PowerPC features
36280
36281The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
36282targets. It should contain registers @samp{r0} through @samp{r31},
36283@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
36284@samp{xer}. They may be 32-bit or 64-bit depending on the target.
36285
36286The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
36287contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
36288
36289The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
36290contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
36291and @samp{vrsave}.
36292
677c5bb1
LM
36293The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
36294contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
36295will combine these registers with the floating point registers
36296(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 36297through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
36298through @samp{vs63}, the set of vector registers for POWER7.
36299
7cc46491
DJ
36300The @samp{org.gnu.gdb.power.spe} feature is optional. It should
36301contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
36302@samp{spefscr}. SPE targets should provide 32-bit registers in
36303@samp{org.gnu.gdb.power.core} and provide the upper halves in
36304@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
36305these to present registers @samp{ev0} through @samp{ev31} to the
36306user.
36307
07e059b5
VP
36308@node Operating System Information
36309@appendix Operating System Information
36310@cindex operating system information
36311
36312@menu
36313* Process list::
36314@end menu
36315
36316Users of @value{GDBN} often wish to obtain information about the state of
36317the operating system running on the target---for example the list of
36318processes, or the list of open files. This section describes the
36319mechanism that makes it possible. This mechanism is similar to the
36320target features mechanism (@pxref{Target Descriptions}), but focuses
36321on a different aspect of target.
36322
36323Operating system information is retrived from the target via the
36324remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
36325read}). The object name in the request should be @samp{osdata}, and
36326the @var{annex} identifies the data to be fetched.
36327
36328@node Process list
36329@appendixsection Process list
36330@cindex operating system information, process list
36331
36332When requesting the process list, the @var{annex} field in the
36333@samp{qXfer} request should be @samp{processes}. The returned data is
36334an XML document. The formal syntax of this document is defined in
36335@file{gdb/features/osdata.dtd}.
36336
36337An example document is:
36338
36339@smallexample
36340<?xml version="1.0"?>
36341<!DOCTYPE target SYSTEM "osdata.dtd">
36342<osdata type="processes">
36343 <item>
36344 <column name="pid">1</column>
36345 <column name="user">root</column>
36346 <column name="command">/sbin/init</column>
dc146f7c 36347 <column name="cores">1,2,3</column>
07e059b5
VP
36348 </item>
36349</osdata>
36350@end smallexample
36351
36352Each item should include a column whose name is @samp{pid}. The value
36353of that column should identify the process on the target. The
36354@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
36355displayed by @value{GDBN}. The @samp{cores} column, if present,
36356should contain a comma-separated list of cores that this process
36357is running on. Target may provide additional columns,
07e059b5
VP
36358which @value{GDBN} currently ignores.
36359
aab4e0ec 36360@include gpl.texi
eb12ee30 36361
e4c0cfae
SS
36362@node GNU Free Documentation License
36363@appendix GNU Free Documentation License
6826cf00
EZ
36364@include fdl.texi
36365
6d2ebf8b 36366@node Index
c906108c
SS
36367@unnumbered Index
36368
36369@printindex cp
36370
36371@tex
36372% I think something like @colophon should be in texinfo. In the
36373% meantime:
36374\long\def\colophon{\hbox to0pt{}\vfill
36375\centerline{The body of this manual is set in}
36376\centerline{\fontname\tenrm,}
36377\centerline{with headings in {\bf\fontname\tenbf}}
36378\centerline{and examples in {\tt\fontname\tentt}.}
36379\centerline{{\it\fontname\tenit\/},}
36380\centerline{{\bf\fontname\tenbf}, and}
36381\centerline{{\sl\fontname\tensl\/}}
36382\centerline{are used for emphasis.}\vfill}
36383\page\colophon
36384% Blame: doc@cygnus.com, 1991.
36385@end tex
36386
c906108c 36387@bye
This page took 4.509594 seconds and 4 git commands to generate.